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 | |
Damien Lespiau | 669506e | 2015-02-26 18:20:38 +0000 | [diff] [blame] | 70 | if (INTEL_REVID(dev) <= SKL_REVID_B0) { |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 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); |
Damien Lespiau | f9fc42f | 2015-02-26 18:20:39 +0000 | [diff] [blame] | 78 | |
| 79 | /* WaDisableVFUnitClockGating:skl */ |
| 80 | I915_WRITE(GEN6_UCGCTL2, I915_READ(GEN6_UCGCTL2) | |
| 81 | GEN6_VFUNIT_CLOCK_GATE_DISABLE); |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 82 | } |
Damien Lespiau | 8bc0ccf | 2015-02-09 19:33:18 +0000 | [diff] [blame] | 83 | |
Damien Lespiau | 2caa3b2 | 2015-02-09 19:33:20 +0000 | [diff] [blame] | 84 | if (INTEL_REVID(dev) <= SKL_REVID_D0) { |
Damien Lespiau | 81e231a | 2015-02-09 19:33:19 +0000 | [diff] [blame] | 85 | /* WaDisableHDCInvalidation:skl */ |
| 86 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | |
| 87 | BDW_DISABLE_HDC_INVALIDATION); |
| 88 | |
Damien Lespiau | 2caa3b2 | 2015-02-09 19:33:20 +0000 | [diff] [blame] | 89 | /* WaDisableChickenBitTSGBarrierAckForFFSliceCS:skl */ |
| 90 | I915_WRITE(FF_SLICE_CS_CHICKEN2, |
| 91 | I915_READ(FF_SLICE_CS_CHICKEN2) | |
| 92 | GEN9_TSG_BARRIER_ACK_DISABLE); |
| 93 | } |
Damien Lespiau | 81e231a | 2015-02-09 19:33:19 +0000 | [diff] [blame] | 94 | |
Damien Lespiau | 8bc0ccf | 2015-02-09 19:33:18 +0000 | [diff] [blame] | 95 | if (INTEL_REVID(dev) <= SKL_REVID_E0) |
| 96 | /* WaDisableLSQCROPERFforOCL:skl */ |
| 97 | I915_WRITE(GEN8_L3SQCREG4, I915_READ(GEN8_L3SQCREG4) | |
| 98 | GEN8_LQSC_RO_PERF_DIS); |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 101 | static void bxt_init_clock_gating(struct drm_device *dev) |
| 102 | { |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 103 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 104 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 105 | gen9_init_clock_gating(dev); |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * FIXME: |
| 109 | * GEN8_SDEUNIT_CLOCK_GATE_DISABLE applies on A0 only. |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 110 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 111 | */ |
| 112 | /* WaDisableSDEUnitClockGating:bxt */ |
| 113 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 114 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE | |
| 115 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 116 | |
Robert Beckett | e3a2905 | 2015-03-11 10:28:25 +0200 | [diff] [blame] | 117 | /* FIXME: apply on A0 only */ |
| 118 | I915_WRITE(TILECTL, I915_READ(TILECTL) | TILECTL_TLBPF); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 119 | } |
| 120 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 121 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 122 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 123 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 124 | u32 tmp; |
| 125 | |
| 126 | tmp = I915_READ(CLKCFG); |
| 127 | |
| 128 | switch (tmp & CLKCFG_FSB_MASK) { |
| 129 | case CLKCFG_FSB_533: |
| 130 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 131 | break; |
| 132 | case CLKCFG_FSB_800: |
| 133 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 134 | break; |
| 135 | case CLKCFG_FSB_667: |
| 136 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 137 | break; |
| 138 | case CLKCFG_FSB_400: |
| 139 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 140 | break; |
| 141 | } |
| 142 | |
| 143 | switch (tmp & CLKCFG_MEM_MASK) { |
| 144 | case CLKCFG_MEM_533: |
| 145 | dev_priv->mem_freq = 533; |
| 146 | break; |
| 147 | case CLKCFG_MEM_667: |
| 148 | dev_priv->mem_freq = 667; |
| 149 | break; |
| 150 | case CLKCFG_MEM_800: |
| 151 | dev_priv->mem_freq = 800; |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | /* detect pineview DDR3 setting */ |
| 156 | tmp = I915_READ(CSHRDDR3CTL); |
| 157 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 158 | } |
| 159 | |
| 160 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 161 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 162 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 163 | u16 ddrpll, csipll; |
| 164 | |
| 165 | ddrpll = I915_READ16(DDRMPLL1); |
| 166 | csipll = I915_READ16(CSIPLL0); |
| 167 | |
| 168 | switch (ddrpll & 0xff) { |
| 169 | case 0xc: |
| 170 | dev_priv->mem_freq = 800; |
| 171 | break; |
| 172 | case 0x10: |
| 173 | dev_priv->mem_freq = 1066; |
| 174 | break; |
| 175 | case 0x14: |
| 176 | dev_priv->mem_freq = 1333; |
| 177 | break; |
| 178 | case 0x18: |
| 179 | dev_priv->mem_freq = 1600; |
| 180 | break; |
| 181 | default: |
| 182 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 183 | ddrpll & 0xff); |
| 184 | dev_priv->mem_freq = 0; |
| 185 | break; |
| 186 | } |
| 187 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 188 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 189 | |
| 190 | switch (csipll & 0x3ff) { |
| 191 | case 0x00c: |
| 192 | dev_priv->fsb_freq = 3200; |
| 193 | break; |
| 194 | case 0x00e: |
| 195 | dev_priv->fsb_freq = 3733; |
| 196 | break; |
| 197 | case 0x010: |
| 198 | dev_priv->fsb_freq = 4266; |
| 199 | break; |
| 200 | case 0x012: |
| 201 | dev_priv->fsb_freq = 4800; |
| 202 | break; |
| 203 | case 0x014: |
| 204 | dev_priv->fsb_freq = 5333; |
| 205 | break; |
| 206 | case 0x016: |
| 207 | dev_priv->fsb_freq = 5866; |
| 208 | break; |
| 209 | case 0x018: |
| 210 | dev_priv->fsb_freq = 6400; |
| 211 | break; |
| 212 | default: |
| 213 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 214 | csipll & 0x3ff); |
| 215 | dev_priv->fsb_freq = 0; |
| 216 | break; |
| 217 | } |
| 218 | |
| 219 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 220 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 221 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 222 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 223 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 224 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 228 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 229 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 230 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 231 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 232 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 233 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 234 | |
| 235 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 236 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 237 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 238 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 239 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 240 | |
| 241 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 242 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 243 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 244 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 245 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 246 | |
| 247 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 248 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 249 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 250 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 251 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 252 | |
| 253 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 254 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 255 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 256 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 257 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 258 | |
| 259 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 260 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 261 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 262 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 263 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 264 | }; |
| 265 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 266 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 267 | int is_ddr3, |
| 268 | int fsb, |
| 269 | int mem) |
| 270 | { |
| 271 | const struct cxsr_latency *latency; |
| 272 | int i; |
| 273 | |
| 274 | if (fsb == 0 || mem == 0) |
| 275 | return NULL; |
| 276 | |
| 277 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 278 | latency = &cxsr_latency_table[i]; |
| 279 | if (is_desktop == latency->is_desktop && |
| 280 | is_ddr3 == latency->is_ddr3 && |
| 281 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 282 | return latency; |
| 283 | } |
| 284 | |
| 285 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 286 | |
| 287 | return NULL; |
| 288 | } |
| 289 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 290 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 291 | { |
| 292 | u32 val; |
| 293 | |
| 294 | mutex_lock(&dev_priv->rps.hw_lock); |
| 295 | |
| 296 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 297 | if (enable) |
| 298 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 299 | else |
| 300 | val |= FORCE_DDR_HIGH_FREQ; |
| 301 | val &= ~FORCE_DDR_LOW_FREQ; |
| 302 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 303 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 304 | |
| 305 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 306 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 307 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 308 | |
| 309 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 310 | } |
| 311 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 312 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 313 | { |
| 314 | u32 val; |
| 315 | |
| 316 | mutex_lock(&dev_priv->rps.hw_lock); |
| 317 | |
| 318 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 319 | if (enable) |
| 320 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 321 | else |
| 322 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
| 323 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 324 | |
| 325 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 326 | } |
| 327 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 328 | #define FW_WM(value, plane) \ |
| 329 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 330 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 331 | 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] | 332 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 333 | struct drm_device *dev = dev_priv->dev; |
| 334 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 335 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 336 | if (IS_VALLEYVIEW(dev)) { |
| 337 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 338 | if (IS_CHERRYVIEW(dev)) |
| 339 | chv_set_memory_pm5(dev_priv, enable); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 340 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 341 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 342 | } else if (IS_PINEVIEW(dev)) { |
| 343 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 344 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 345 | I915_WRITE(DSPFW3, val); |
| 346 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 347 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 348 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 349 | I915_WRITE(FW_BLC_SELF, val); |
| 350 | } else if (IS_I915GM(dev)) { |
| 351 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 352 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 353 | I915_WRITE(INSTPM, val); |
| 354 | } else { |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 359 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 360 | } |
| 361 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 362 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 363 | /* |
| 364 | * Latency for FIFO fetches is dependent on several factors: |
| 365 | * - memory configuration (speed, channels) |
| 366 | * - chipset |
| 367 | * - current MCH state |
| 368 | * It can be fairly high in some situations, so here we assume a fairly |
| 369 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 370 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 371 | * and power consumption (set it too low to save power and we might see |
| 372 | * FIFO underruns and display "flicker"). |
| 373 | * |
| 374 | * A value of 5us seems to be a good balance; safe for very low end |
| 375 | * platforms but not overly aggressive on lower latency configs. |
| 376 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 377 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 378 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 379 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 380 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 381 | |
| 382 | static int vlv_get_fifo_size(struct drm_device *dev, |
| 383 | enum pipe pipe, int plane) |
| 384 | { |
| 385 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 386 | int sprite0_start, sprite1_start, size; |
| 387 | |
| 388 | switch (pipe) { |
| 389 | uint32_t dsparb, dsparb2, dsparb3; |
| 390 | case PIPE_A: |
| 391 | dsparb = I915_READ(DSPARB); |
| 392 | dsparb2 = I915_READ(DSPARB2); |
| 393 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 394 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 395 | break; |
| 396 | case PIPE_B: |
| 397 | dsparb = I915_READ(DSPARB); |
| 398 | dsparb2 = I915_READ(DSPARB2); |
| 399 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 400 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 401 | break; |
| 402 | case PIPE_C: |
| 403 | dsparb2 = I915_READ(DSPARB2); |
| 404 | dsparb3 = I915_READ(DSPARB3); |
| 405 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 406 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 407 | break; |
| 408 | default: |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | switch (plane) { |
| 413 | case 0: |
| 414 | size = sprite0_start; |
| 415 | break; |
| 416 | case 1: |
| 417 | size = sprite1_start - sprite0_start; |
| 418 | break; |
| 419 | case 2: |
| 420 | size = 512 - 1 - sprite1_start; |
| 421 | break; |
| 422 | default: |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | DRM_DEBUG_KMS("Pipe %c %s %c FIFO size: %d\n", |
| 427 | pipe_name(pipe), plane == 0 ? "primary" : "sprite", |
| 428 | plane == 0 ? plane_name(pipe) : sprite_name(pipe, plane - 1), |
| 429 | size); |
| 430 | |
| 431 | return size; |
| 432 | } |
| 433 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 434 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 435 | { |
| 436 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 437 | uint32_t dsparb = I915_READ(DSPARB); |
| 438 | int size; |
| 439 | |
| 440 | size = dsparb & 0x7f; |
| 441 | if (plane) |
| 442 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 443 | |
| 444 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 445 | plane ? "B" : "A", size); |
| 446 | |
| 447 | return size; |
| 448 | } |
| 449 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 450 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 451 | { |
| 452 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 453 | uint32_t dsparb = I915_READ(DSPARB); |
| 454 | int size; |
| 455 | |
| 456 | size = dsparb & 0x1ff; |
| 457 | if (plane) |
| 458 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 459 | size >>= 1; /* Convert to cachelines */ |
| 460 | |
| 461 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 462 | plane ? "B" : "A", size); |
| 463 | |
| 464 | return size; |
| 465 | } |
| 466 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 467 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 468 | { |
| 469 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 470 | uint32_t dsparb = I915_READ(DSPARB); |
| 471 | int size; |
| 472 | |
| 473 | size = dsparb & 0x7f; |
| 474 | size >>= 2; /* Convert to cachelines */ |
| 475 | |
| 476 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 477 | plane ? "B" : "A", |
| 478 | size); |
| 479 | |
| 480 | return size; |
| 481 | } |
| 482 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 483 | /* Pineview has different values for various configs */ |
| 484 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 485 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 486 | .max_wm = PINEVIEW_MAX_WM, |
| 487 | .default_wm = PINEVIEW_DFT_WM, |
| 488 | .guard_size = PINEVIEW_GUARD_WM, |
| 489 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 490 | }; |
| 491 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 492 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 493 | .max_wm = PINEVIEW_MAX_WM, |
| 494 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 495 | .guard_size = PINEVIEW_GUARD_WM, |
| 496 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 497 | }; |
| 498 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 499 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 500 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 501 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 502 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 503 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 504 | }; |
| 505 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 506 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 507 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 508 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 509 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 510 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 511 | }; |
| 512 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 513 | .fifo_size = G4X_FIFO_SIZE, |
| 514 | .max_wm = G4X_MAX_WM, |
| 515 | .default_wm = G4X_MAX_WM, |
| 516 | .guard_size = 2, |
| 517 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 518 | }; |
| 519 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 520 | .fifo_size = I965_CURSOR_FIFO, |
| 521 | .max_wm = I965_CURSOR_MAX_WM, |
| 522 | .default_wm = I965_CURSOR_DFT_WM, |
| 523 | .guard_size = 2, |
| 524 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 525 | }; |
| 526 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 527 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 528 | .max_wm = VALLEYVIEW_MAX_WM, |
| 529 | .default_wm = VALLEYVIEW_MAX_WM, |
| 530 | .guard_size = 2, |
| 531 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 532 | }; |
| 533 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 534 | .fifo_size = I965_CURSOR_FIFO, |
| 535 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 536 | .default_wm = I965_CURSOR_DFT_WM, |
| 537 | .guard_size = 2, |
| 538 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 539 | }; |
| 540 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 541 | .fifo_size = I965_CURSOR_FIFO, |
| 542 | .max_wm = I965_CURSOR_MAX_WM, |
| 543 | .default_wm = I965_CURSOR_DFT_WM, |
| 544 | .guard_size = 2, |
| 545 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 546 | }; |
| 547 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 548 | .fifo_size = I945_FIFO_SIZE, |
| 549 | .max_wm = I915_MAX_WM, |
| 550 | .default_wm = 1, |
| 551 | .guard_size = 2, |
| 552 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 553 | }; |
| 554 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 555 | .fifo_size = I915_FIFO_SIZE, |
| 556 | .max_wm = I915_MAX_WM, |
| 557 | .default_wm = 1, |
| 558 | .guard_size = 2, |
| 559 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 560 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 561 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 562 | .fifo_size = I855GM_FIFO_SIZE, |
| 563 | .max_wm = I915_MAX_WM, |
| 564 | .default_wm = 1, |
| 565 | .guard_size = 2, |
| 566 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 567 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 568 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 569 | .fifo_size = I855GM_FIFO_SIZE, |
| 570 | .max_wm = I915_MAX_WM/2, |
| 571 | .default_wm = 1, |
| 572 | .guard_size = 2, |
| 573 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 574 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 575 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 576 | .fifo_size = I830_FIFO_SIZE, |
| 577 | .max_wm = I915_MAX_WM, |
| 578 | .default_wm = 1, |
| 579 | .guard_size = 2, |
| 580 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 581 | }; |
| 582 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 583 | /** |
| 584 | * intel_calculate_wm - calculate watermark level |
| 585 | * @clock_in_khz: pixel clock |
| 586 | * @wm: chip FIFO params |
| 587 | * @pixel_size: display pixel size |
| 588 | * @latency_ns: memory latency for the platform |
| 589 | * |
| 590 | * Calculate the watermark level (the level at which the display plane will |
| 591 | * start fetching from memory again). Each chip has a different display |
| 592 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 593 | * in the correct intel_watermark_params structure. |
| 594 | * |
| 595 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 596 | * on the pixel size. When it reaches the watermark level, it'll start |
| 597 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 598 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 599 | * will occur, and a display engine hang could result. |
| 600 | */ |
| 601 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 602 | const struct intel_watermark_params *wm, |
| 603 | int fifo_size, |
| 604 | int pixel_size, |
| 605 | unsigned long latency_ns) |
| 606 | { |
| 607 | long entries_required, wm_size; |
| 608 | |
| 609 | /* |
| 610 | * Note: we need to make sure we don't overflow for various clock & |
| 611 | * latency values. |
| 612 | * clocks go from a few thousand to several hundred thousand. |
| 613 | * latency is usually a few thousand |
| 614 | */ |
| 615 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 616 | 1000; |
| 617 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 618 | |
| 619 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 620 | |
| 621 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 622 | |
| 623 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 624 | |
| 625 | /* Don't promote wm_size to unsigned... */ |
| 626 | if (wm_size > (long)wm->max_wm) |
| 627 | wm_size = wm->max_wm; |
| 628 | if (wm_size <= 0) |
| 629 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 630 | |
| 631 | /* |
| 632 | * Bspec seems to indicate that the value shouldn't be lower than |
| 633 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 634 | * Lets go for 8 which is the burst size since certain platforms |
| 635 | * already use a hardcoded 8 (which is what the spec says should be |
| 636 | * done). |
| 637 | */ |
| 638 | if (wm_size <= 8) |
| 639 | wm_size = 8; |
| 640 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 641 | return wm_size; |
| 642 | } |
| 643 | |
| 644 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 645 | { |
| 646 | struct drm_crtc *crtc, *enabled = NULL; |
| 647 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 648 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 649 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 650 | if (enabled) |
| 651 | return NULL; |
| 652 | enabled = crtc; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | return enabled; |
| 657 | } |
| 658 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 659 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 660 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 661 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 662 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 663 | struct drm_crtc *crtc; |
| 664 | const struct cxsr_latency *latency; |
| 665 | u32 reg; |
| 666 | unsigned long wm; |
| 667 | |
| 668 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 669 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 670 | if (!latency) { |
| 671 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 672 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 673 | return; |
| 674 | } |
| 675 | |
| 676 | crtc = single_enabled_crtc(dev); |
| 677 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 678 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 679 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 680 | int clock; |
| 681 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 682 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 683 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 684 | |
| 685 | /* Display SR */ |
| 686 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 687 | pineview_display_wm.fifo_size, |
| 688 | pixel_size, latency->display_sr); |
| 689 | reg = I915_READ(DSPFW1); |
| 690 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 691 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 692 | I915_WRITE(DSPFW1, reg); |
| 693 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 694 | |
| 695 | /* cursor SR */ |
| 696 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 697 | pineview_display_wm.fifo_size, |
| 698 | pixel_size, latency->cursor_sr); |
| 699 | reg = I915_READ(DSPFW3); |
| 700 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 701 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 702 | I915_WRITE(DSPFW3, reg); |
| 703 | |
| 704 | /* Display HPLL off SR */ |
| 705 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 706 | pineview_display_hplloff_wm.fifo_size, |
| 707 | pixel_size, latency->display_hpll_disable); |
| 708 | reg = I915_READ(DSPFW3); |
| 709 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 710 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 711 | I915_WRITE(DSPFW3, reg); |
| 712 | |
| 713 | /* cursor HPLL off SR */ |
| 714 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 715 | pineview_display_hplloff_wm.fifo_size, |
| 716 | pixel_size, latency->cursor_hpll_disable); |
| 717 | reg = I915_READ(DSPFW3); |
| 718 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 719 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 720 | I915_WRITE(DSPFW3, reg); |
| 721 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 722 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 723 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 724 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 725 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
| 729 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 730 | int plane, |
| 731 | const struct intel_watermark_params *display, |
| 732 | int display_latency_ns, |
| 733 | const struct intel_watermark_params *cursor, |
| 734 | int cursor_latency_ns, |
| 735 | int *plane_wm, |
| 736 | int *cursor_wm) |
| 737 | { |
| 738 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 739 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 740 | int htotal, hdisplay, clock, pixel_size; |
| 741 | int line_time_us, line_count; |
| 742 | int entries, tlb_miss; |
| 743 | |
| 744 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 745 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 746 | *cursor_wm = cursor->guard_size; |
| 747 | *plane_wm = display->guard_size; |
| 748 | return false; |
| 749 | } |
| 750 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 751 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 752 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 753 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 754 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 755 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 756 | |
| 757 | /* Use the small buffer method to calculate plane watermark */ |
| 758 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 759 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 760 | if (tlb_miss > 0) |
| 761 | entries += tlb_miss; |
| 762 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 763 | *plane_wm = entries + display->guard_size; |
| 764 | if (*plane_wm > (int)display->max_wm) |
| 765 | *plane_wm = display->max_wm; |
| 766 | |
| 767 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 768 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 769 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 770 | entries = line_count * crtc->cursor->state->crtc_w * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 771 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 772 | if (tlb_miss > 0) |
| 773 | entries += tlb_miss; |
| 774 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 775 | *cursor_wm = entries + cursor->guard_size; |
| 776 | if (*cursor_wm > (int)cursor->max_wm) |
| 777 | *cursor_wm = (int)cursor->max_wm; |
| 778 | |
| 779 | return true; |
| 780 | } |
| 781 | |
| 782 | /* |
| 783 | * Check the wm result. |
| 784 | * |
| 785 | * If any calculated watermark values is larger than the maximum value that |
| 786 | * can be programmed into the associated watermark register, that watermark |
| 787 | * must be disabled. |
| 788 | */ |
| 789 | static bool g4x_check_srwm(struct drm_device *dev, |
| 790 | int display_wm, int cursor_wm, |
| 791 | const struct intel_watermark_params *display, |
| 792 | const struct intel_watermark_params *cursor) |
| 793 | { |
| 794 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 795 | display_wm, cursor_wm); |
| 796 | |
| 797 | if (display_wm > display->max_wm) { |
| 798 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 799 | display_wm, display->max_wm); |
| 800 | return false; |
| 801 | } |
| 802 | |
| 803 | if (cursor_wm > cursor->max_wm) { |
| 804 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 805 | cursor_wm, cursor->max_wm); |
| 806 | return false; |
| 807 | } |
| 808 | |
| 809 | if (!(display_wm || cursor_wm)) { |
| 810 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 811 | return false; |
| 812 | } |
| 813 | |
| 814 | return true; |
| 815 | } |
| 816 | |
| 817 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 818 | int plane, |
| 819 | int latency_ns, |
| 820 | const struct intel_watermark_params *display, |
| 821 | const struct intel_watermark_params *cursor, |
| 822 | int *display_wm, int *cursor_wm) |
| 823 | { |
| 824 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 825 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 826 | int hdisplay, htotal, pixel_size, clock; |
| 827 | unsigned long line_time_us; |
| 828 | int line_count, line_size; |
| 829 | int small, large; |
| 830 | int entries; |
| 831 | |
| 832 | if (!latency_ns) { |
| 833 | *display_wm = *cursor_wm = 0; |
| 834 | return false; |
| 835 | } |
| 836 | |
| 837 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 838 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 839 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 840 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 841 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 842 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 843 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 844 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 845 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 846 | line_size = hdisplay * pixel_size; |
| 847 | |
| 848 | /* Use the minimum of the small and large buffer method for primary */ |
| 849 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 850 | large = line_count * line_size; |
| 851 | |
| 852 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 853 | *display_wm = entries + display->guard_size; |
| 854 | |
| 855 | /* calculate the self-refresh watermark for display cursor */ |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 856 | entries = line_count * pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 857 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 858 | *cursor_wm = entries + cursor->guard_size; |
| 859 | |
| 860 | return g4x_check_srwm(dev, |
| 861 | *display_wm, *cursor_wm, |
| 862 | display, cursor); |
| 863 | } |
| 864 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 865 | #define FW_WM_VLV(value, plane) \ |
| 866 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 867 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 868 | static void vlv_write_wm_values(struct intel_crtc *crtc, |
| 869 | const struct vlv_wm_values *wm) |
| 870 | { |
| 871 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 872 | enum pipe pipe = crtc->pipe; |
| 873 | |
| 874 | I915_WRITE(VLV_DDL(pipe), |
| 875 | (wm->ddl[pipe].cursor << DDL_CURSOR_SHIFT) | |
| 876 | (wm->ddl[pipe].sprite[1] << DDL_SPRITE_SHIFT(1)) | |
| 877 | (wm->ddl[pipe].sprite[0] << DDL_SPRITE_SHIFT(0)) | |
| 878 | (wm->ddl[pipe].primary << DDL_PLANE_SHIFT)); |
| 879 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 880 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 881 | FW_WM(wm->sr.plane, SR) | |
| 882 | FW_WM(wm->pipe[PIPE_B].cursor, CURSORB) | |
| 883 | FW_WM_VLV(wm->pipe[PIPE_B].primary, PLANEB) | |
| 884 | FW_WM_VLV(wm->pipe[PIPE_A].primary, PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 885 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 886 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[1], SPRITEB) | |
| 887 | FW_WM(wm->pipe[PIPE_A].cursor, CURSORA) | |
| 888 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 889 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 890 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 891 | |
| 892 | if (IS_CHERRYVIEW(dev_priv)) { |
| 893 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 894 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 895 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 896 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 897 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[1], SPRITEF) | |
| 898 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 899 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 900 | FW_WM_VLV(wm->pipe[PIPE_C].primary, PLANEC) | |
| 901 | FW_WM(wm->pipe[PIPE_C].cursor, CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 902 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 903 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 904 | FW_WM(wm->pipe[PIPE_C].sprite[1] >> 8, SPRITEF_HI) | |
| 905 | FW_WM(wm->pipe[PIPE_C].sprite[0] >> 8, SPRITEE_HI) | |
| 906 | FW_WM(wm->pipe[PIPE_C].primary >> 8, PLANEC_HI) | |
| 907 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 908 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 909 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 910 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 911 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 912 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 913 | } else { |
| 914 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 915 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 916 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 917 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 918 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 919 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 920 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 921 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 922 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 923 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 924 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | POSTING_READ(DSPFW1); |
| 928 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 929 | dev_priv->wm.vlv = *wm; |
| 930 | } |
| 931 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 932 | #undef FW_WM_VLV |
| 933 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 934 | static uint8_t vlv_compute_drain_latency(struct drm_crtc *crtc, |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 935 | struct drm_plane *plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 936 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 937 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 938 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 939 | int entries, prec_mult, drain_latency, pixel_size; |
| 940 | int clock = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 941 | const int high_precision = IS_CHERRYVIEW(dev) ? 16 : 64; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 942 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 943 | /* |
| 944 | * FIXME the plane might have an fb |
| 945 | * but be invisible (eg. due to clipping) |
| 946 | */ |
| 947 | if (!intel_crtc->active || !plane->state->fb) |
| 948 | return 0; |
| 949 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 950 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 951 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 952 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 953 | pixel_size = drm_format_plane_cpp(plane->state->fb->pixel_format, 0); |
| 954 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 955 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 956 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 957 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 958 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 959 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 960 | prec_mult = high_precision; |
| 961 | drain_latency = 64 * prec_mult * 4 / entries; |
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 | if (drain_latency > DRAIN_LATENCY_MASK) { |
| 964 | prec_mult /= 2; |
| 965 | drain_latency = 64 * prec_mult * 4 / entries; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 966 | } |
| 967 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 968 | if (drain_latency > DRAIN_LATENCY_MASK) |
| 969 | drain_latency = DRAIN_LATENCY_MASK; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 970 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 971 | return drain_latency | (prec_mult == high_precision ? |
| 972 | DDL_PRECISION_HIGH : DDL_PRECISION_LOW); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 973 | } |
| 974 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 975 | static int vlv_compute_wm(struct intel_crtc *crtc, |
| 976 | struct intel_plane *plane, |
| 977 | int fifo_size) |
| 978 | { |
| 979 | int clock, entries, pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 980 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 981 | /* |
| 982 | * FIXME the plane might have an fb |
| 983 | * but be invisible (eg. due to clipping) |
| 984 | */ |
| 985 | if (!crtc->active || !plane->base.state->fb) |
| 986 | return 0; |
| 987 | |
| 988 | pixel_size = drm_format_plane_cpp(plane->base.state->fb->pixel_format, 0); |
| 989 | clock = crtc->config->base.adjusted_mode.crtc_clock; |
| 990 | |
| 991 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
| 992 | |
| 993 | /* |
| 994 | * Set up the watermark such that we don't start issuing memory |
| 995 | * requests until we are within PND's max deadline value (256us). |
| 996 | * Idea being to be idle as long as possible while still taking |
| 997 | * advatange of PND's deadline scheduling. The limit of 8 |
| 998 | * cachelines (used when the FIFO will anyway drain in less time |
| 999 | * than 256us) should match what we would be done if trickle |
| 1000 | * feed were enabled. |
| 1001 | */ |
| 1002 | return fifo_size - clamp(DIV_ROUND_UP(256 * entries, 64), 0, fifo_size - 8); |
| 1003 | } |
| 1004 | |
| 1005 | static bool vlv_compute_sr_wm(struct drm_device *dev, |
| 1006 | struct vlv_wm_values *wm) |
| 1007 | { |
| 1008 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 1009 | struct drm_crtc *crtc; |
| 1010 | enum pipe pipe = INVALID_PIPE; |
| 1011 | int num_planes = 0; |
| 1012 | int fifo_size = 0; |
| 1013 | struct intel_plane *plane; |
| 1014 | |
| 1015 | wm->sr.cursor = wm->sr.plane = 0; |
| 1016 | |
| 1017 | crtc = single_enabled_crtc(dev); |
| 1018 | /* maxfifo not supported on pipe C */ |
| 1019 | if (crtc && to_intel_crtc(crtc)->pipe != PIPE_C) { |
| 1020 | pipe = to_intel_crtc(crtc)->pipe; |
| 1021 | num_planes = !!wm->pipe[pipe].primary + |
| 1022 | !!wm->pipe[pipe].sprite[0] + |
| 1023 | !!wm->pipe[pipe].sprite[1]; |
| 1024 | fifo_size = INTEL_INFO(dev_priv)->num_pipes * 512 - 1; |
| 1025 | } |
| 1026 | |
| 1027 | if (fifo_size == 0 || num_planes > 1) |
| 1028 | return false; |
| 1029 | |
| 1030 | wm->sr.cursor = vlv_compute_wm(to_intel_crtc(crtc), |
| 1031 | to_intel_plane(crtc->cursor), 0x3f); |
| 1032 | |
| 1033 | list_for_each_entry(plane, &dev->mode_config.plane_list, base.head) { |
| 1034 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 1035 | continue; |
| 1036 | |
| 1037 | if (plane->pipe != pipe) |
| 1038 | continue; |
| 1039 | |
| 1040 | wm->sr.plane = vlv_compute_wm(to_intel_crtc(crtc), |
| 1041 | plane, fifo_size); |
| 1042 | if (wm->sr.plane != 0) |
| 1043 | break; |
| 1044 | } |
| 1045 | |
| 1046 | return true; |
| 1047 | } |
| 1048 | |
| 1049 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1050 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1051 | struct drm_device *dev = crtc->dev; |
| 1052 | struct drm_i915_private *dev_priv = dev->dev_private; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1053 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1054 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1055 | bool cxsr_enabled; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1056 | struct vlv_wm_values wm = dev_priv->wm.vlv; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1057 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1058 | wm.ddl[pipe].primary = vlv_compute_drain_latency(crtc, crtc->primary); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1059 | wm.pipe[pipe].primary = vlv_compute_wm(intel_crtc, |
| 1060 | to_intel_plane(crtc->primary), |
| 1061 | vlv_get_fifo_size(dev, pipe, 0)); |
| 1062 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1063 | wm.ddl[pipe].cursor = vlv_compute_drain_latency(crtc, crtc->cursor); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1064 | wm.pipe[pipe].cursor = vlv_compute_wm(intel_crtc, |
| 1065 | to_intel_plane(crtc->cursor), |
| 1066 | 0x3f); |
| 1067 | |
| 1068 | cxsr_enabled = vlv_compute_sr_wm(dev, &wm); |
| 1069 | |
| 1070 | if (memcmp(&wm, &dev_priv->wm.vlv, sizeof(wm)) == 0) |
| 1071 | return; |
| 1072 | |
| 1073 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: plane=%d, cursor=%d, " |
| 1074 | "SR: plane=%d, cursor=%d\n", pipe_name(pipe), |
| 1075 | wm.pipe[pipe].primary, wm.pipe[pipe].cursor, |
| 1076 | wm.sr.plane, wm.sr.cursor); |
| 1077 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 1078 | /* |
| 1079 | * FIXME DDR DVFS introduces massive memory latencies which |
| 1080 | * are not known to system agent so any deadline specified |
| 1081 | * by the display may not be respected. To support DDR DVFS |
| 1082 | * the watermark code needs to be rewritten to essentially |
| 1083 | * bypass deadline mechanism and rely solely on the |
| 1084 | * watermarks. For now disable DDR DVFS. |
| 1085 | */ |
| 1086 | if (IS_CHERRYVIEW(dev_priv)) |
| 1087 | chv_set_memory_dvfs(dev_priv, false); |
| 1088 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1089 | if (!cxsr_enabled) |
| 1090 | intel_set_memory_cxsr(dev_priv, false); |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1091 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1092 | vlv_write_wm_values(intel_crtc, &wm); |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1093 | |
| 1094 | if (cxsr_enabled) |
| 1095 | intel_set_memory_cxsr(dev_priv, true); |
| 1096 | } |
| 1097 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1098 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 1099 | struct drm_crtc *crtc, |
| 1100 | uint32_t sprite_width, |
| 1101 | uint32_t sprite_height, |
| 1102 | int pixel_size, |
| 1103 | bool enabled, bool scaled) |
| 1104 | { |
| 1105 | struct drm_device *dev = crtc->dev; |
| 1106 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1107 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1108 | enum pipe pipe = intel_crtc->pipe; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1109 | int sprite = to_intel_plane(plane)->plane; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1110 | bool cxsr_enabled; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1111 | struct vlv_wm_values wm = dev_priv->wm.vlv; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1112 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1113 | if (enabled) { |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1114 | wm.ddl[pipe].sprite[sprite] = |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1115 | vlv_compute_drain_latency(crtc, plane); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1116 | |
| 1117 | wm.pipe[pipe].sprite[sprite] = |
| 1118 | vlv_compute_wm(intel_crtc, |
| 1119 | to_intel_plane(plane), |
| 1120 | vlv_get_fifo_size(dev, pipe, sprite+1)); |
| 1121 | } else { |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1122 | wm.ddl[pipe].sprite[sprite] = 0; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1123 | wm.pipe[pipe].sprite[sprite] = 0; |
| 1124 | } |
| 1125 | |
| 1126 | cxsr_enabled = vlv_compute_sr_wm(dev, &wm); |
| 1127 | |
| 1128 | if (memcmp(&wm, &dev_priv->wm.vlv, sizeof(wm)) == 0) |
| 1129 | return; |
| 1130 | |
| 1131 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: sprite %c=%d, " |
| 1132 | "SR: plane=%d, cursor=%d\n", pipe_name(pipe), |
| 1133 | sprite_name(pipe, sprite), |
| 1134 | wm.pipe[pipe].sprite[sprite], |
| 1135 | wm.sr.plane, wm.sr.cursor); |
| 1136 | |
| 1137 | if (!cxsr_enabled) |
| 1138 | intel_set_memory_cxsr(dev_priv, false); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1139 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1140 | vlv_write_wm_values(intel_crtc, &wm); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1141 | |
| 1142 | if (cxsr_enabled) |
| 1143 | intel_set_memory_cxsr(dev_priv, true); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1144 | } |
| 1145 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1146 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1147 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1148 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1149 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1150 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1151 | static const int sr_latency_ns = 12000; |
| 1152 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1153 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1154 | int plane_sr, cursor_sr; |
| 1155 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1156 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1157 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1158 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1159 | &g4x_wm_info, pessimal_latency_ns, |
| 1160 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1161 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1162 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1163 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1164 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1165 | &g4x_wm_info, pessimal_latency_ns, |
| 1166 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1167 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1168 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1169 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1170 | if (single_plane_enabled(enabled) && |
| 1171 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1172 | sr_latency_ns, |
| 1173 | &g4x_wm_info, |
| 1174 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1175 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1176 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1177 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1178 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1179 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1180 | plane_sr = cursor_sr = 0; |
| 1181 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1182 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1183 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1184 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1185 | planea_wm, cursora_wm, |
| 1186 | planeb_wm, cursorb_wm, |
| 1187 | plane_sr, cursor_sr); |
| 1188 | |
| 1189 | I915_WRITE(DSPFW1, |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1190 | FW_WM(plane_sr, SR) | |
| 1191 | FW_WM(cursorb_wm, CURSORB) | |
| 1192 | FW_WM(planeb_wm, PLANEB) | |
| 1193 | FW_WM(planea_wm, PLANEA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1194 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1195 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1196 | FW_WM(cursora_wm, CURSORA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1197 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1198 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1199 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1200 | FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1201 | |
| 1202 | if (cxsr_enabled) |
| 1203 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1204 | } |
| 1205 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1206 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1207 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1208 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1209 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1210 | struct drm_crtc *crtc; |
| 1211 | int srwm = 1; |
| 1212 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1213 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1214 | |
| 1215 | /* Calc sr entries for one plane configs */ |
| 1216 | crtc = single_enabled_crtc(dev); |
| 1217 | if (crtc) { |
| 1218 | /* self-refresh has much higher latency */ |
| 1219 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1220 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1221 | &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1222 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1223 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1224 | int hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1225 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1226 | unsigned long line_time_us; |
| 1227 | int entries; |
| 1228 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1229 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1230 | |
| 1231 | /* Use ns/us then divide to preserve precision */ |
| 1232 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1233 | pixel_size * hdisplay; |
| 1234 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1235 | srwm = I965_FIFO_SIZE - entries; |
| 1236 | if (srwm < 0) |
| 1237 | srwm = 1; |
| 1238 | srwm &= 0x1ff; |
| 1239 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1240 | entries, srwm); |
| 1241 | |
| 1242 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 1243 | pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1244 | entries = DIV_ROUND_UP(entries, |
| 1245 | i965_cursor_wm_info.cacheline_size); |
| 1246 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1247 | (entries + i965_cursor_wm_info.guard_size); |
| 1248 | |
| 1249 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1250 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1251 | |
| 1252 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1253 | "cursor %d\n", srwm, cursor_sr); |
| 1254 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1255 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1256 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1257 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1258 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1259 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1263 | srwm); |
| 1264 | |
| 1265 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1266 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 1267 | FW_WM(8, CURSORB) | |
| 1268 | FW_WM(8, PLANEB) | |
| 1269 | FW_WM(8, PLANEA)); |
| 1270 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 1271 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1272 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1273 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1274 | |
| 1275 | if (cxsr_enabled) |
| 1276 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1277 | } |
| 1278 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1279 | #undef FW_WM |
| 1280 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1281 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1282 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1283 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1284 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1285 | const struct intel_watermark_params *wm_info; |
| 1286 | uint32_t fwater_lo; |
| 1287 | uint32_t fwater_hi; |
| 1288 | int cwm, srwm = 1; |
| 1289 | int fifo_size; |
| 1290 | int planea_wm, planeb_wm; |
| 1291 | struct drm_crtc *crtc, *enabled = NULL; |
| 1292 | |
| 1293 | if (IS_I945GM(dev)) |
| 1294 | wm_info = &i945_wm_info; |
| 1295 | else if (!IS_GEN2(dev)) |
| 1296 | wm_info = &i915_wm_info; |
| 1297 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1298 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1299 | |
| 1300 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1301 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1302 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1303 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1304 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1305 | if (IS_GEN2(dev)) |
| 1306 | cpp = 4; |
| 1307 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1308 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1309 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1310 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1311 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1312 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1313 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1314 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1315 | if (planea_wm > (long)wm_info->max_wm) |
| 1316 | planea_wm = wm_info->max_wm; |
| 1317 | } |
| 1318 | |
| 1319 | if (IS_GEN2(dev)) |
| 1320 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1321 | |
| 1322 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1323 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1324 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1325 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1326 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1327 | if (IS_GEN2(dev)) |
| 1328 | cpp = 4; |
| 1329 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1330 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1331 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1332 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1333 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1334 | if (enabled == NULL) |
| 1335 | enabled = crtc; |
| 1336 | else |
| 1337 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1338 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1339 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1340 | if (planeb_wm > (long)wm_info->max_wm) |
| 1341 | planeb_wm = wm_info->max_wm; |
| 1342 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1343 | |
| 1344 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1345 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1346 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1347 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1348 | |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1349 | obj = intel_fb_obj(enabled->primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1350 | |
| 1351 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1352 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1353 | enabled = NULL; |
| 1354 | } |
| 1355 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1356 | /* |
| 1357 | * Overlay gets an aggressive default since video jitter is bad. |
| 1358 | */ |
| 1359 | cwm = 2; |
| 1360 | |
| 1361 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1362 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1363 | |
| 1364 | /* Calc sr entries for one plane configs */ |
| 1365 | if (HAS_FW_BLC(dev) && enabled) { |
| 1366 | /* self-refresh has much higher latency */ |
| 1367 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1368 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1369 | &to_intel_crtc(enabled)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1370 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1371 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1372 | int hdisplay = to_intel_crtc(enabled)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1373 | int pixel_size = enabled->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1374 | unsigned long line_time_us; |
| 1375 | int entries; |
| 1376 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1377 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1378 | |
| 1379 | /* Use ns/us then divide to preserve precision */ |
| 1380 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1381 | pixel_size * hdisplay; |
| 1382 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1383 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1384 | srwm = wm_info->fifo_size - entries; |
| 1385 | if (srwm < 0) |
| 1386 | srwm = 1; |
| 1387 | |
| 1388 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1389 | I915_WRITE(FW_BLC_SELF, |
| 1390 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1391 | else if (IS_I915GM(dev)) |
| 1392 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1393 | } |
| 1394 | |
| 1395 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1396 | planea_wm, planeb_wm, cwm, srwm); |
| 1397 | |
| 1398 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1399 | fwater_hi = (cwm & 0x1f); |
| 1400 | |
| 1401 | /* Set request length to 8 cachelines per fetch */ |
| 1402 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1403 | fwater_hi = fwater_hi | (1 << 8); |
| 1404 | |
| 1405 | I915_WRITE(FW_BLC, fwater_lo); |
| 1406 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1407 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1408 | if (enabled) |
| 1409 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1410 | } |
| 1411 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1412 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1413 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1414 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1415 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1416 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1417 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1418 | uint32_t fwater_lo; |
| 1419 | int planea_wm; |
| 1420 | |
| 1421 | crtc = single_enabled_crtc(dev); |
| 1422 | if (crtc == NULL) |
| 1423 | return; |
| 1424 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1425 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1426 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1427 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1428 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1429 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1430 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1431 | fwater_lo |= (3<<8) | planea_wm; |
| 1432 | |
| 1433 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1434 | |
| 1435 | I915_WRITE(FW_BLC, fwater_lo); |
| 1436 | } |
| 1437 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1438 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1439 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1440 | { |
| 1441 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1442 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1443 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1444 | pixel_rate = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1445 | |
| 1446 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1447 | * adjust the pixel_rate here. */ |
| 1448 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1449 | if (intel_crtc->config->pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1450 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1451 | uint32_t pfit_size = intel_crtc->config->pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1452 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1453 | pipe_w = intel_crtc->config->pipe_src_w; |
| 1454 | pipe_h = intel_crtc->config->pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1455 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1456 | pfit_h = pfit_size & 0xFFFF; |
| 1457 | if (pipe_w < pfit_w) |
| 1458 | pipe_w = pfit_w; |
| 1459 | if (pipe_h < pfit_h) |
| 1460 | pipe_h = pfit_h; |
| 1461 | |
| 1462 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1463 | pfit_w * pfit_h); |
| 1464 | } |
| 1465 | |
| 1466 | return pixel_rate; |
| 1467 | } |
| 1468 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1469 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1470 | 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] | 1471 | uint32_t latency) |
| 1472 | { |
| 1473 | uint64_t ret; |
| 1474 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1475 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1476 | return UINT_MAX; |
| 1477 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1478 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1479 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1480 | |
| 1481 | return ret; |
| 1482 | } |
| 1483 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1484 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1485 | 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] | 1486 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1487 | uint32_t latency) |
| 1488 | { |
| 1489 | uint32_t ret; |
| 1490 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1491 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1492 | return UINT_MAX; |
| 1493 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1494 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1495 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1496 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1497 | return ret; |
| 1498 | } |
| 1499 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1500 | 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] | 1501 | uint8_t bytes_per_pixel) |
| 1502 | { |
| 1503 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1504 | } |
| 1505 | |
Pradeep Bhat | 2ac96d2 | 2014-11-04 17:06:40 +0000 | [diff] [blame] | 1506 | struct skl_pipe_wm_parameters { |
| 1507 | bool active; |
| 1508 | uint32_t pipe_htotal; |
| 1509 | uint32_t pixel_rate; /* in KHz */ |
| 1510 | struct intel_plane_wm_parameters plane[I915_MAX_PLANES]; |
| 1511 | struct intel_plane_wm_parameters cursor; |
| 1512 | }; |
| 1513 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1514 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1515 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1516 | uint32_t pipe_htotal; |
| 1517 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1518 | struct intel_plane_wm_parameters pri; |
| 1519 | struct intel_plane_wm_parameters spr; |
| 1520 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1521 | }; |
| 1522 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1523 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1524 | uint16_t pri; |
| 1525 | uint16_t spr; |
| 1526 | uint16_t cur; |
| 1527 | uint16_t fbc; |
| 1528 | }; |
| 1529 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1530 | /* used in computing the new watermarks state */ |
| 1531 | struct intel_wm_config { |
| 1532 | unsigned int num_pipes_active; |
| 1533 | bool sprites_enabled; |
| 1534 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1535 | }; |
| 1536 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1537 | /* |
| 1538 | * For both WM_PIPE and WM_LP. |
| 1539 | * mem_value must be in 0.1us units. |
| 1540 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1541 | 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] | 1542 | uint32_t mem_value, |
| 1543 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1544 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1545 | uint32_t method1, method2; |
| 1546 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1547 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1548 | return 0; |
| 1549 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1550 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1551 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1552 | mem_value); |
| 1553 | |
| 1554 | if (!is_lp) |
| 1555 | return method1; |
| 1556 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1557 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1558 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1559 | params->pri.horiz_pixels, |
| 1560 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1561 | mem_value); |
| 1562 | |
| 1563 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1564 | } |
| 1565 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1566 | /* |
| 1567 | * For both WM_PIPE and WM_LP. |
| 1568 | * mem_value must be in 0.1us units. |
| 1569 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1570 | 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] | 1571 | uint32_t mem_value) |
| 1572 | { |
| 1573 | uint32_t method1, method2; |
| 1574 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1575 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1576 | return 0; |
| 1577 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1578 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1579 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1580 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1581 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1582 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1583 | params->spr.horiz_pixels, |
| 1584 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1585 | mem_value); |
| 1586 | return min(method1, method2); |
| 1587 | } |
| 1588 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1589 | /* |
| 1590 | * For both WM_PIPE and WM_LP. |
| 1591 | * mem_value must be in 0.1us units. |
| 1592 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1593 | 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] | 1594 | uint32_t mem_value) |
| 1595 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1596 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1597 | return 0; |
| 1598 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1599 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1600 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1601 | params->cur.horiz_pixels, |
| 1602 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1603 | mem_value); |
| 1604 | } |
| 1605 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1606 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1607 | 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] | 1608 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1609 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1610 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1611 | return 0; |
| 1612 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1613 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1614 | params->pri.horiz_pixels, |
| 1615 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1616 | } |
| 1617 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1618 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1619 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1620 | if (INTEL_INFO(dev)->gen >= 8) |
| 1621 | return 3072; |
| 1622 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1623 | return 768; |
| 1624 | else |
| 1625 | return 512; |
| 1626 | } |
| 1627 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1628 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1629 | int level, bool is_sprite) |
| 1630 | { |
| 1631 | if (INTEL_INFO(dev)->gen >= 8) |
| 1632 | /* BDW primary/sprite plane watermarks */ |
| 1633 | return level == 0 ? 255 : 2047; |
| 1634 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1635 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1636 | return level == 0 ? 127 : 1023; |
| 1637 | else if (!is_sprite) |
| 1638 | /* ILK/SNB primary plane watermarks */ |
| 1639 | return level == 0 ? 127 : 511; |
| 1640 | else |
| 1641 | /* ILK/SNB sprite plane watermarks */ |
| 1642 | return level == 0 ? 63 : 255; |
| 1643 | } |
| 1644 | |
| 1645 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1646 | int level) |
| 1647 | { |
| 1648 | if (INTEL_INFO(dev)->gen >= 7) |
| 1649 | return level == 0 ? 63 : 255; |
| 1650 | else |
| 1651 | return level == 0 ? 31 : 63; |
| 1652 | } |
| 1653 | |
| 1654 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1655 | { |
| 1656 | if (INTEL_INFO(dev)->gen >= 8) |
| 1657 | return 31; |
| 1658 | else |
| 1659 | return 15; |
| 1660 | } |
| 1661 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1662 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1663 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1664 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1665 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1666 | enum intel_ddb_partitioning ddb_partitioning, |
| 1667 | bool is_sprite) |
| 1668 | { |
| 1669 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1670 | |
| 1671 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1672 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1673 | return 0; |
| 1674 | |
| 1675 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1676 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1677 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1678 | |
| 1679 | /* |
| 1680 | * For some reason the non self refresh |
| 1681 | * FIFO size is only half of the self |
| 1682 | * refresh FIFO size on ILK/SNB. |
| 1683 | */ |
| 1684 | if (INTEL_INFO(dev)->gen <= 6) |
| 1685 | fifo_size /= 2; |
| 1686 | } |
| 1687 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1688 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1689 | /* level 0 is always calculated with 1:1 split */ |
| 1690 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1691 | if (is_sprite) |
| 1692 | fifo_size *= 5; |
| 1693 | fifo_size /= 6; |
| 1694 | } else { |
| 1695 | fifo_size /= 2; |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1700 | 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] | 1701 | } |
| 1702 | |
| 1703 | /* Calculate the maximum cursor plane watermark */ |
| 1704 | 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] | 1705 | int level, |
| 1706 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1707 | { |
| 1708 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1709 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1710 | return 64; |
| 1711 | |
| 1712 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1713 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1714 | } |
| 1715 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1716 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1717 | int level, |
| 1718 | const struct intel_wm_config *config, |
| 1719 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1720 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1721 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1722 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1723 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1724 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1725 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1726 | } |
| 1727 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1728 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1729 | int level, |
| 1730 | struct ilk_wm_maximums *max) |
| 1731 | { |
| 1732 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1733 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1734 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1735 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1736 | } |
| 1737 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1738 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1739 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1740 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1741 | { |
| 1742 | bool ret; |
| 1743 | |
| 1744 | /* already determined to be invalid? */ |
| 1745 | if (!result->enable) |
| 1746 | return false; |
| 1747 | |
| 1748 | result->enable = result->pri_val <= max->pri && |
| 1749 | result->spr_val <= max->spr && |
| 1750 | result->cur_val <= max->cur; |
| 1751 | |
| 1752 | ret = result->enable; |
| 1753 | |
| 1754 | /* |
| 1755 | * HACK until we can pre-compute everything, |
| 1756 | * and thus fail gracefully if LP0 watermarks |
| 1757 | * are exceeded... |
| 1758 | */ |
| 1759 | if (level == 0 && !result->enable) { |
| 1760 | if (result->pri_val > max->pri) |
| 1761 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 1762 | level, result->pri_val, max->pri); |
| 1763 | if (result->spr_val > max->spr) |
| 1764 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 1765 | level, result->spr_val, max->spr); |
| 1766 | if (result->cur_val > max->cur) |
| 1767 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 1768 | level, result->cur_val, max->cur); |
| 1769 | |
| 1770 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 1771 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 1772 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 1773 | result->enable = true; |
| 1774 | } |
| 1775 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1776 | return ret; |
| 1777 | } |
| 1778 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1779 | 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] | 1780 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1781 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 1782 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1783 | { |
| 1784 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 1785 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 1786 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 1787 | |
| 1788 | /* WM1+ latency values stored in 0.5us units */ |
| 1789 | if (level > 0) { |
| 1790 | pri_latency *= 5; |
| 1791 | spr_latency *= 5; |
| 1792 | cur_latency *= 5; |
| 1793 | } |
| 1794 | |
| 1795 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 1796 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 1797 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 1798 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 1799 | result->enable = true; |
| 1800 | } |
| 1801 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1802 | static uint32_t |
| 1803 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1804 | { |
| 1805 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1806 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1807 | struct drm_display_mode *mode = &intel_crtc->config->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1808 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1809 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 1810 | if (!intel_crtc->active) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1811 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1812 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1813 | /* The WM are computed with base on how long it takes to fill a single |
| 1814 | * row at the given clock rate, multiplied by 8. |
| 1815 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1816 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 1817 | mode->crtc_clock); |
| 1818 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 1819 | dev_priv->display.get_display_clock_speed(dev_priv->dev)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1820 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1821 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 1822 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1823 | } |
| 1824 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1825 | 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] | 1826 | { |
| 1827 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1828 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1829 | if (IS_GEN9(dev)) { |
| 1830 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1831 | int ret, i; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1832 | int level, max_level = ilk_wm_max_level(dev); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1833 | |
| 1834 | /* read the first set of memory latencies[0:3] */ |
| 1835 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 1836 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1837 | ret = sandybridge_pcode_read(dev_priv, |
| 1838 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1839 | &val); |
| 1840 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1841 | |
| 1842 | if (ret) { |
| 1843 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1844 | return; |
| 1845 | } |
| 1846 | |
| 1847 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1848 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1849 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1850 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1851 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1852 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1853 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1854 | |
| 1855 | /* read the second set of memory latencies[4:7] */ |
| 1856 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 1857 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1858 | ret = sandybridge_pcode_read(dev_priv, |
| 1859 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1860 | &val); |
| 1861 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1862 | if (ret) { |
| 1863 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1864 | return; |
| 1865 | } |
| 1866 | |
| 1867 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1868 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1869 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1870 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1871 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1872 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1873 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1874 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1875 | /* |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 1876 | * WaWmMemoryReadLatency:skl |
| 1877 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1878 | * punit doesn't take into account the read latency so we need |
| 1879 | * to add 2us to the various latency levels we retrieve from |
| 1880 | * the punit. |
| 1881 | * - W0 is a bit special in that it's the only level that |
| 1882 | * can't be disabled if we want to have display working, so |
| 1883 | * we always add 2us there. |
| 1884 | * - For levels >=1, punit returns 0us latency when they are |
| 1885 | * disabled, so we respect that and don't add 2us then |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1886 | * |
| 1887 | * Additionally, if a level n (n > 1) has a 0us latency, all |
| 1888 | * levels m (m >= n) need to be disabled. We make sure to |
| 1889 | * sanitize the values out of the punit to satisfy this |
| 1890 | * requirement. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1891 | */ |
| 1892 | wm[0] += 2; |
| 1893 | for (level = 1; level <= max_level; level++) |
| 1894 | if (wm[level] != 0) |
| 1895 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1896 | else { |
| 1897 | for (i = level + 1; i <= max_level; i++) |
| 1898 | wm[i] = 0; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1899 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1900 | break; |
| 1901 | } |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1902 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1903 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 1904 | |
| 1905 | wm[0] = (sskpd >> 56) & 0xFF; |
| 1906 | if (wm[0] == 0) |
| 1907 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 1908 | wm[1] = (sskpd >> 4) & 0xFF; |
| 1909 | wm[2] = (sskpd >> 12) & 0xFF; |
| 1910 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 1911 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 1912 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 1913 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 1914 | |
| 1915 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 1916 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 1917 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 1918 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 1919 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1920 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 1921 | |
| 1922 | /* ILK primary LP0 latency is 700 ns */ |
| 1923 | wm[0] = 7; |
| 1924 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 1925 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1926 | } |
| 1927 | } |
| 1928 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1929 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1930 | { |
| 1931 | /* ILK sprite LP0 latency is 1300 ns */ |
| 1932 | if (INTEL_INFO(dev)->gen == 5) |
| 1933 | wm[0] = 13; |
| 1934 | } |
| 1935 | |
| 1936 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1937 | { |
| 1938 | /* ILK cursor LP0 latency is 1300 ns */ |
| 1939 | if (INTEL_INFO(dev)->gen == 5) |
| 1940 | wm[0] = 13; |
| 1941 | |
| 1942 | /* WaDoubleCursorLP3Latency:ivb */ |
| 1943 | if (IS_IVYBRIDGE(dev)) |
| 1944 | wm[3] *= 2; |
| 1945 | } |
| 1946 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 1947 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1948 | { |
| 1949 | /* how many WM levels are we expecting */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1950 | if (IS_GEN9(dev)) |
| 1951 | return 7; |
| 1952 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1953 | return 4; |
| 1954 | else if (INTEL_INFO(dev)->gen >= 6) |
| 1955 | return 3; |
| 1956 | else |
| 1957 | return 2; |
| 1958 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 1959 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1960 | static void intel_print_wm_latency(struct drm_device *dev, |
| 1961 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1962 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1963 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1964 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1965 | |
| 1966 | for (level = 0; level <= max_level; level++) { |
| 1967 | unsigned int latency = wm[level]; |
| 1968 | |
| 1969 | if (latency == 0) { |
| 1970 | DRM_ERROR("%s WM%d latency not provided\n", |
| 1971 | name, level); |
| 1972 | continue; |
| 1973 | } |
| 1974 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1975 | /* |
| 1976 | * - latencies are in us on gen9. |
| 1977 | * - before then, WM1+ latency values are in 0.5us units |
| 1978 | */ |
| 1979 | if (IS_GEN9(dev)) |
| 1980 | latency *= 10; |
| 1981 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1982 | latency *= 5; |
| 1983 | |
| 1984 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 1985 | name, level, wm[level], |
| 1986 | latency / 10, latency % 10); |
| 1987 | } |
| 1988 | } |
| 1989 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 1990 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 1991 | uint16_t wm[5], uint16_t min) |
| 1992 | { |
| 1993 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 1994 | |
| 1995 | if (wm[0] >= min) |
| 1996 | return false; |
| 1997 | |
| 1998 | wm[0] = max(wm[0], min); |
| 1999 | for (level = 1; level <= max_level; level++) |
| 2000 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2001 | |
| 2002 | return true; |
| 2003 | } |
| 2004 | |
| 2005 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 2006 | { |
| 2007 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2008 | bool changed; |
| 2009 | |
| 2010 | /* |
| 2011 | * The BIOS provided WM memory latency values are often |
| 2012 | * inadequate for high resolution displays. Adjust them. |
| 2013 | */ |
| 2014 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2015 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2016 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2017 | |
| 2018 | if (!changed) |
| 2019 | return; |
| 2020 | |
| 2021 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2022 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2023 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2024 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2025 | } |
| 2026 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2027 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2028 | { |
| 2029 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2030 | |
| 2031 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2032 | |
| 2033 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2034 | sizeof(dev_priv->wm.pri_latency)); |
| 2035 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2036 | sizeof(dev_priv->wm.pri_latency)); |
| 2037 | |
| 2038 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2039 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2040 | |
| 2041 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2042 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2043 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2044 | |
| 2045 | if (IS_GEN6(dev)) |
| 2046 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2047 | } |
| 2048 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2049 | static void skl_setup_wm_latency(struct drm_device *dev) |
| 2050 | { |
| 2051 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2052 | |
| 2053 | intel_read_wm_latency(dev, dev_priv->wm.skl_latency); |
| 2054 | intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency); |
| 2055 | } |
| 2056 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2057 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2058 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2059 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2060 | struct drm_device *dev = crtc->dev; |
| 2061 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2062 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2063 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2064 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2065 | if (!intel_crtc->active) |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2066 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2067 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2068 | p->active = true; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2069 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2070 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2071 | |
| 2072 | if (crtc->primary->state->fb) { |
| 2073 | p->pri.enabled = true; |
| 2074 | p->pri.bytes_per_pixel = |
| 2075 | crtc->primary->state->fb->bits_per_pixel / 8; |
| 2076 | } else { |
| 2077 | p->pri.enabled = false; |
| 2078 | p->pri.bytes_per_pixel = 0; |
| 2079 | } |
| 2080 | |
| 2081 | if (crtc->cursor->state->fb) { |
| 2082 | p->cur.enabled = true; |
| 2083 | p->cur.bytes_per_pixel = 4; |
| 2084 | } else { |
| 2085 | p->cur.enabled = false; |
| 2086 | p->cur.bytes_per_pixel = 0; |
| 2087 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2088 | p->pri.horiz_pixels = intel_crtc->config->pipe_src_w; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 2089 | p->cur.horiz_pixels = intel_crtc->base.cursor->state->crtc_w; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2090 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2091 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2092 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2093 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2094 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2095 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2096 | break; |
| 2097 | } |
| 2098 | } |
| 2099 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2100 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2101 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2102 | struct intel_wm_config *config) |
| 2103 | { |
| 2104 | struct intel_crtc *intel_crtc; |
| 2105 | |
| 2106 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2107 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2108 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2109 | |
| 2110 | if (!wm->pipe_enabled) |
| 2111 | continue; |
| 2112 | |
| 2113 | config->sprites_enabled |= wm->sprites_enabled; |
| 2114 | config->sprites_scaled |= wm->sprites_scaled; |
| 2115 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2119 | /* Compute new watermarks for the pipe */ |
| 2120 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2121 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2122 | struct intel_pipe_wm *pipe_wm) |
| 2123 | { |
| 2124 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2125 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2126 | int level, max_level = ilk_wm_max_level(dev); |
| 2127 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2128 | struct intel_wm_config config = { |
| 2129 | .num_pipes_active = 1, |
| 2130 | .sprites_enabled = params->spr.enabled, |
| 2131 | .sprites_scaled = params->spr.scaled, |
| 2132 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2133 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2134 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2135 | pipe_wm->pipe_enabled = params->active; |
| 2136 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2137 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2138 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2139 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2140 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2141 | max_level = 1; |
| 2142 | |
| 2143 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2144 | if (params->spr.scaled) |
| 2145 | max_level = 0; |
| 2146 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2147 | 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] | 2148 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2149 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2150 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2151 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2152 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2153 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2154 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2155 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2156 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2157 | return false; |
| 2158 | |
| 2159 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2160 | |
| 2161 | for (level = 1; level <= max_level; level++) { |
| 2162 | struct intel_wm_level wm = {}; |
| 2163 | |
| 2164 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2165 | |
| 2166 | /* |
| 2167 | * Disable any watermark level that exceeds the |
| 2168 | * register maximums since such watermarks are |
| 2169 | * always invalid. |
| 2170 | */ |
| 2171 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2172 | break; |
| 2173 | |
| 2174 | pipe_wm->wm[level] = wm; |
| 2175 | } |
| 2176 | |
| 2177 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | /* |
| 2181 | * Merge the watermarks from all active pipes for a specific level. |
| 2182 | */ |
| 2183 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2184 | int level, |
| 2185 | struct intel_wm_level *ret_wm) |
| 2186 | { |
| 2187 | const struct intel_crtc *intel_crtc; |
| 2188 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2189 | ret_wm->enable = true; |
| 2190 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2191 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2192 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2193 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2194 | |
| 2195 | if (!active->pipe_enabled) |
| 2196 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2197 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2198 | /* |
| 2199 | * The watermark values may have been used in the past, |
| 2200 | * so we must maintain them in the registers for some |
| 2201 | * time even if the level is now disabled. |
| 2202 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2203 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2204 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2205 | |
| 2206 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2207 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2208 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2209 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2210 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | /* |
| 2214 | * Merge all low power watermarks for all active pipes. |
| 2215 | */ |
| 2216 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2217 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2218 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2219 | struct intel_pipe_wm *merged) |
| 2220 | { |
| 2221 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2222 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2223 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2224 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2225 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2226 | config->num_pipes_active > 1) |
| 2227 | return; |
| 2228 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2229 | /* ILK: FBC WM must be disabled always */ |
| 2230 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2231 | |
| 2232 | /* merge each WM1+ level */ |
| 2233 | for (level = 1; level <= max_level; level++) { |
| 2234 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2235 | |
| 2236 | ilk_merge_wm_level(dev, level, wm); |
| 2237 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2238 | if (level > last_enabled_level) |
| 2239 | wm->enable = false; |
| 2240 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2241 | /* make sure all following levels get disabled */ |
| 2242 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2243 | |
| 2244 | /* |
| 2245 | * The spec says it is preferred to disable |
| 2246 | * FBC WMs instead of disabling a WM level. |
| 2247 | */ |
| 2248 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2249 | if (wm->enable) |
| 2250 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2251 | wm->fbc_val = 0; |
| 2252 | } |
| 2253 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2254 | |
| 2255 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2256 | /* |
| 2257 | * FIXME this is racy. FBC might get enabled later. |
| 2258 | * What we should check here is whether FBC can be |
| 2259 | * enabled sometime later. |
| 2260 | */ |
| 2261 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2262 | for (level = 2; level <= max_level; level++) { |
| 2263 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2264 | |
| 2265 | wm->enable = false; |
| 2266 | } |
| 2267 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2268 | } |
| 2269 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2270 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2271 | { |
| 2272 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2273 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2274 | } |
| 2275 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2276 | /* The value we need to program into the WM_LPx latency field */ |
| 2277 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2278 | { |
| 2279 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2280 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2281 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2282 | return 2 * level; |
| 2283 | else |
| 2284 | return dev_priv->wm.pri_latency[level]; |
| 2285 | } |
| 2286 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2287 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2288 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2289 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2290 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2291 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2292 | struct intel_crtc *intel_crtc; |
| 2293 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2294 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2295 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2296 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2297 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2298 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2299 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2300 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2301 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2302 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2303 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2304 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2305 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2306 | /* |
| 2307 | * Maintain the watermark values even if the level is |
| 2308 | * disabled. Doing otherwise could cause underruns. |
| 2309 | */ |
| 2310 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2311 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2312 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2313 | r->cur_val; |
| 2314 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2315 | if (r->enable) |
| 2316 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2317 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2318 | if (INTEL_INFO(dev)->gen >= 8) |
| 2319 | results->wm_lp[wm_lp - 1] |= |
| 2320 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2321 | else |
| 2322 | results->wm_lp[wm_lp - 1] |= |
| 2323 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2324 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2325 | /* |
| 2326 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2327 | * level is disabled. Doing otherwise could cause underruns. |
| 2328 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2329 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2330 | WARN_ON(wm_lp != 1); |
| 2331 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2332 | } else |
| 2333 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2334 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2335 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2336 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2337 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2338 | enum pipe pipe = intel_crtc->pipe; |
| 2339 | const struct intel_wm_level *r = |
| 2340 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2341 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2342 | if (WARN_ON(!r->enable)) |
| 2343 | continue; |
| 2344 | |
| 2345 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2346 | |
| 2347 | results->wm_pipe[pipe] = |
| 2348 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2349 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2350 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2354 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2355 | * 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] | 2356 | 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] | 2357 | struct intel_pipe_wm *r1, |
| 2358 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2359 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2360 | int level, max_level = ilk_wm_max_level(dev); |
| 2361 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2362 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2363 | for (level = 1; level <= max_level; level++) { |
| 2364 | if (r1->wm[level].enable) |
| 2365 | level1 = level; |
| 2366 | if (r2->wm[level].enable) |
| 2367 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2368 | } |
| 2369 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2370 | if (level1 == level2) { |
| 2371 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2372 | return r2; |
| 2373 | else |
| 2374 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2375 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2376 | return r1; |
| 2377 | } else { |
| 2378 | return r2; |
| 2379 | } |
| 2380 | } |
| 2381 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2382 | /* dirty bits used to track which watermarks need changes */ |
| 2383 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2384 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2385 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2386 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2387 | #define WM_DIRTY_FBC (1 << 24) |
| 2388 | #define WM_DIRTY_DDB (1 << 25) |
| 2389 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2390 | 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] | 2391 | const struct ilk_wm_values *old, |
| 2392 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2393 | { |
| 2394 | unsigned int dirty = 0; |
| 2395 | enum pipe pipe; |
| 2396 | int wm_lp; |
| 2397 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2398 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2399 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2400 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2401 | /* Must disable LP1+ watermarks too */ |
| 2402 | dirty |= WM_DIRTY_LP_ALL; |
| 2403 | } |
| 2404 | |
| 2405 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2406 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2407 | /* Must disable LP1+ watermarks too */ |
| 2408 | dirty |= WM_DIRTY_LP_ALL; |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2413 | dirty |= WM_DIRTY_FBC; |
| 2414 | /* Must disable LP1+ watermarks too */ |
| 2415 | dirty |= WM_DIRTY_LP_ALL; |
| 2416 | } |
| 2417 | |
| 2418 | if (old->partitioning != new->partitioning) { |
| 2419 | dirty |= WM_DIRTY_DDB; |
| 2420 | /* Must disable LP1+ watermarks too */ |
| 2421 | dirty |= WM_DIRTY_LP_ALL; |
| 2422 | } |
| 2423 | |
| 2424 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2425 | if (dirty & WM_DIRTY_LP_ALL) |
| 2426 | return dirty; |
| 2427 | |
| 2428 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2429 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2430 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2431 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2432 | break; |
| 2433 | } |
| 2434 | |
| 2435 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2436 | for (; wm_lp <= 3; wm_lp++) |
| 2437 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2438 | |
| 2439 | return dirty; |
| 2440 | } |
| 2441 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2442 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2443 | unsigned int dirty) |
| 2444 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2445 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2446 | bool changed = false; |
| 2447 | |
| 2448 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2449 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2450 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2451 | changed = true; |
| 2452 | } |
| 2453 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2454 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2455 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2456 | changed = true; |
| 2457 | } |
| 2458 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2459 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2460 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2461 | changed = true; |
| 2462 | } |
| 2463 | |
| 2464 | /* |
| 2465 | * Don't touch WM1S_LP_EN here. |
| 2466 | * Doing so could cause underruns. |
| 2467 | */ |
| 2468 | |
| 2469 | return changed; |
| 2470 | } |
| 2471 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2472 | /* |
| 2473 | * The spec says we shouldn't write when we don't need, because every write |
| 2474 | * causes WMs to be re-evaluated, expending some power. |
| 2475 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2476 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2477 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2478 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2479 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2480 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2481 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2482 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2483 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2484 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2485 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2486 | return; |
| 2487 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2488 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2489 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2490 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2491 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2492 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2493 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2494 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2495 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2496 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2497 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2498 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2499 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2500 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2501 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2502 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2503 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2504 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2505 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2506 | val = I915_READ(WM_MISC); |
| 2507 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2508 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2509 | else |
| 2510 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2511 | I915_WRITE(WM_MISC, val); |
| 2512 | } else { |
| 2513 | val = I915_READ(DISP_ARB_CTL2); |
| 2514 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2515 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2516 | else |
| 2517 | val |= DISP_DATA_PARTITION_5_6; |
| 2518 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2519 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2520 | } |
| 2521 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2522 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2523 | val = I915_READ(DISP_ARB_CTL); |
| 2524 | if (results->enable_fbc_wm) |
| 2525 | val &= ~DISP_FBC_WM_DIS; |
| 2526 | else |
| 2527 | val |= DISP_FBC_WM_DIS; |
| 2528 | I915_WRITE(DISP_ARB_CTL, val); |
| 2529 | } |
| 2530 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2531 | if (dirty & WM_DIRTY_LP(1) && |
| 2532 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2533 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2534 | |
| 2535 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2536 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2537 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2538 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2539 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2540 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2541 | |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2542 | 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] | 2543 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2544 | 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] | 2545 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2546 | 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] | 2547 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2548 | |
| 2549 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2550 | } |
| 2551 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2552 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2553 | { |
| 2554 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2555 | |
| 2556 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2557 | } |
| 2558 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2559 | /* |
| 2560 | * On gen9, we need to allocate Display Data Buffer (DDB) portions to the |
| 2561 | * different active planes. |
| 2562 | */ |
| 2563 | |
| 2564 | #define SKL_DDB_SIZE 896 /* in blocks */ |
Damien Lespiau | 43d735a | 2015-03-17 11:39:34 +0200 | [diff] [blame] | 2565 | #define BXT_DDB_SIZE 512 |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2566 | |
| 2567 | static void |
| 2568 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
| 2569 | struct drm_crtc *for_crtc, |
| 2570 | const struct intel_wm_config *config, |
| 2571 | const struct skl_pipe_wm_parameters *params, |
| 2572 | struct skl_ddb_entry *alloc /* out */) |
| 2573 | { |
| 2574 | struct drm_crtc *crtc; |
| 2575 | unsigned int pipe_size, ddb_size; |
| 2576 | int nth_active_pipe; |
| 2577 | |
| 2578 | if (!params->active) { |
| 2579 | alloc->start = 0; |
| 2580 | alloc->end = 0; |
| 2581 | return; |
| 2582 | } |
| 2583 | |
Damien Lespiau | 43d735a | 2015-03-17 11:39:34 +0200 | [diff] [blame] | 2584 | if (IS_BROXTON(dev)) |
| 2585 | ddb_size = BXT_DDB_SIZE; |
| 2586 | else |
| 2587 | ddb_size = SKL_DDB_SIZE; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2588 | |
| 2589 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 2590 | |
| 2591 | nth_active_pipe = 0; |
| 2592 | for_each_crtc(dev, crtc) { |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2593 | if (!to_intel_crtc(crtc)->active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2594 | continue; |
| 2595 | |
| 2596 | if (crtc == for_crtc) |
| 2597 | break; |
| 2598 | |
| 2599 | nth_active_pipe++; |
| 2600 | } |
| 2601 | |
| 2602 | pipe_size = ddb_size / config->num_pipes_active; |
| 2603 | alloc->start = nth_active_pipe * ddb_size / config->num_pipes_active; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2604 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | static unsigned int skl_cursor_allocation(const struct intel_wm_config *config) |
| 2608 | { |
| 2609 | if (config->num_pipes_active == 1) |
| 2610 | return 32; |
| 2611 | |
| 2612 | return 8; |
| 2613 | } |
| 2614 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2615 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 2616 | { |
| 2617 | entry->start = reg & 0x3ff; |
| 2618 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2619 | if (entry->end) |
| 2620 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2621 | } |
| 2622 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 2623 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 2624 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2625 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2626 | enum pipe pipe; |
| 2627 | int plane; |
| 2628 | u32 val; |
| 2629 | |
| 2630 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2631 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2632 | val = I915_READ(PLANE_BUF_CFG(pipe, plane)); |
| 2633 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane], |
| 2634 | val); |
| 2635 | } |
| 2636 | |
| 2637 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 2638 | skl_ddb_entry_init_from_hw(&ddb->cursor[pipe], val); |
| 2639 | } |
| 2640 | } |
| 2641 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2642 | static unsigned int |
| 2643 | skl_plane_relative_data_rate(const struct intel_plane_wm_parameters *p) |
| 2644 | { |
| 2645 | return p->horiz_pixels * p->vert_pixels * p->bytes_per_pixel; |
| 2646 | } |
| 2647 | |
| 2648 | /* |
| 2649 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 2650 | * a 8192x4096@32bpp framebuffer: |
| 2651 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 2652 | */ |
| 2653 | static unsigned int |
| 2654 | skl_get_total_relative_data_rate(struct intel_crtc *intel_crtc, |
| 2655 | const struct skl_pipe_wm_parameters *params) |
| 2656 | { |
| 2657 | unsigned int total_data_rate = 0; |
| 2658 | int plane; |
| 2659 | |
| 2660 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2661 | const struct intel_plane_wm_parameters *p; |
| 2662 | |
| 2663 | p = ¶ms->plane[plane]; |
| 2664 | if (!p->enabled) |
| 2665 | continue; |
| 2666 | |
| 2667 | total_data_rate += skl_plane_relative_data_rate(p); |
| 2668 | } |
| 2669 | |
| 2670 | return total_data_rate; |
| 2671 | } |
| 2672 | |
| 2673 | static void |
| 2674 | skl_allocate_pipe_ddb(struct drm_crtc *crtc, |
| 2675 | const struct intel_wm_config *config, |
| 2676 | const struct skl_pipe_wm_parameters *params, |
| 2677 | struct skl_ddb_allocation *ddb /* out */) |
| 2678 | { |
| 2679 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2680 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2681 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2682 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2683 | struct skl_ddb_entry *alloc = &ddb->pipe[pipe]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2684 | uint16_t alloc_size, start, cursor_blocks; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2685 | uint16_t minimum[I915_MAX_PLANES]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2686 | unsigned int total_data_rate; |
| 2687 | int plane; |
| 2688 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2689 | skl_ddb_get_pipe_allocation_limits(dev, crtc, config, params, alloc); |
| 2690 | alloc_size = skl_ddb_entry_size(alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2691 | if (alloc_size == 0) { |
| 2692 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 2693 | memset(&ddb->cursor[pipe], 0, sizeof(ddb->cursor[pipe])); |
| 2694 | return; |
| 2695 | } |
| 2696 | |
| 2697 | cursor_blocks = skl_cursor_allocation(config); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2698 | ddb->cursor[pipe].start = alloc->end - cursor_blocks; |
| 2699 | ddb->cursor[pipe].end = alloc->end; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2700 | |
| 2701 | alloc_size -= cursor_blocks; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2702 | alloc->end -= cursor_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2703 | |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2704 | /* 1. Allocate the mininum required blocks for each active plane */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2705 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2706 | const struct intel_plane_wm_parameters *p; |
| 2707 | |
| 2708 | p = ¶ms->plane[plane]; |
| 2709 | if (!p->enabled) |
| 2710 | continue; |
| 2711 | |
| 2712 | minimum[plane] = 8; |
| 2713 | alloc_size -= minimum[plane]; |
| 2714 | } |
| 2715 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2716 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2717 | * 2. Distribute the remaining space in proportion to the amount of |
| 2718 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2719 | * |
| 2720 | * FIXME: we may not allocate every single block here. |
| 2721 | */ |
| 2722 | total_data_rate = skl_get_total_relative_data_rate(intel_crtc, params); |
| 2723 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2724 | start = alloc->start; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2725 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2726 | const struct intel_plane_wm_parameters *p; |
| 2727 | unsigned int data_rate; |
| 2728 | uint16_t plane_blocks; |
| 2729 | |
| 2730 | p = ¶ms->plane[plane]; |
| 2731 | if (!p->enabled) |
| 2732 | continue; |
| 2733 | |
| 2734 | data_rate = skl_plane_relative_data_rate(p); |
| 2735 | |
| 2736 | /* |
| 2737 | * promote the expression to 64 bits to avoid overflowing, the |
| 2738 | * result is < available as data_rate / total_data_rate < 1 |
| 2739 | */ |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2740 | plane_blocks = minimum[plane]; |
| 2741 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 2742 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2743 | |
| 2744 | ddb->plane[pipe][plane].start = start; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2745 | ddb->plane[pipe][plane].end = start + plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2746 | |
| 2747 | start += plane_blocks; |
| 2748 | } |
| 2749 | |
| 2750 | } |
| 2751 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2752 | 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] | 2753 | { |
| 2754 | /* TODO: Take into account the scalers once we support them */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2755 | return config->base.adjusted_mode.crtc_clock; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | /* |
| 2759 | * The max latency should be 257 (max the punit can code is 255 and we add 2us |
| 2760 | * for the read latency) and bytes_per_pixel should always be <= 8, so that |
| 2761 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 2762 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 2763 | */ |
| 2764 | static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel, |
| 2765 | uint32_t latency) |
| 2766 | { |
| 2767 | uint32_t wm_intermediate_val, ret; |
| 2768 | |
| 2769 | if (latency == 0) |
| 2770 | return UINT_MAX; |
| 2771 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2772 | wm_intermediate_val = latency * pixel_rate * bytes_per_pixel / 512; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2773 | ret = DIV_ROUND_UP(wm_intermediate_val, 1000); |
| 2774 | |
| 2775 | return ret; |
| 2776 | } |
| 2777 | |
| 2778 | static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
| 2779 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2780 | uint64_t tiling, uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2781 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2782 | uint32_t ret; |
| 2783 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2784 | uint32_t wm_intermediate_val; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2785 | |
| 2786 | if (latency == 0) |
| 2787 | return UINT_MAX; |
| 2788 | |
| 2789 | plane_bytes_per_line = horiz_pixels * bytes_per_pixel; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2790 | |
| 2791 | if (tiling == I915_FORMAT_MOD_Y_TILED || |
| 2792 | tiling == I915_FORMAT_MOD_Yf_TILED) { |
| 2793 | plane_bytes_per_line *= 4; |
| 2794 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2795 | plane_blocks_per_line /= 4; |
| 2796 | } else { |
| 2797 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2798 | } |
| 2799 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2800 | wm_intermediate_val = latency * pixel_rate; |
| 2801 | ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) * |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2802 | plane_blocks_per_line; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2803 | |
| 2804 | return ret; |
| 2805 | } |
| 2806 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2807 | static bool skl_ddb_allocation_changed(const struct skl_ddb_allocation *new_ddb, |
| 2808 | const struct intel_crtc *intel_crtc) |
| 2809 | { |
| 2810 | struct drm_device *dev = intel_crtc->base.dev; |
| 2811 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2812 | const struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 2813 | enum pipe pipe = intel_crtc->pipe; |
| 2814 | |
| 2815 | if (memcmp(new_ddb->plane[pipe], cur_ddb->plane[pipe], |
| 2816 | sizeof(new_ddb->plane[pipe]))) |
| 2817 | return true; |
| 2818 | |
| 2819 | if (memcmp(&new_ddb->cursor[pipe], &cur_ddb->cursor[pipe], |
| 2820 | sizeof(new_ddb->cursor[pipe]))) |
| 2821 | return true; |
| 2822 | |
| 2823 | return false; |
| 2824 | } |
| 2825 | |
| 2826 | static void skl_compute_wm_global_parameters(struct drm_device *dev, |
| 2827 | struct intel_wm_config *config) |
| 2828 | { |
| 2829 | struct drm_crtc *crtc; |
| 2830 | struct drm_plane *plane; |
| 2831 | |
| 2832 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2833 | config->num_pipes_active += to_intel_crtc(crtc)->active; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2834 | |
| 2835 | /* FIXME: I don't think we need those two global parameters on SKL */ |
| 2836 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2837 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2838 | |
| 2839 | config->sprites_enabled |= intel_plane->wm.enabled; |
| 2840 | config->sprites_scaled |= intel_plane->wm.scaled; |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | static void skl_compute_wm_pipe_parameters(struct drm_crtc *crtc, |
| 2845 | struct skl_pipe_wm_parameters *p) |
| 2846 | { |
| 2847 | struct drm_device *dev = crtc->dev; |
| 2848 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2849 | enum pipe pipe = intel_crtc->pipe; |
| 2850 | struct drm_plane *plane; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2851 | struct drm_framebuffer *fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2852 | int i = 1; /* Index for sprite planes start */ |
| 2853 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2854 | p->active = intel_crtc->active; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2855 | if (p->active) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2856 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
| 2857 | p->pixel_rate = skl_pipe_pixel_rate(intel_crtc->config); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2858 | |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2859 | fb = crtc->primary->state->fb; |
| 2860 | if (fb) { |
| 2861 | p->plane[0].enabled = true; |
| 2862 | p->plane[0].bytes_per_pixel = fb->bits_per_pixel / 8; |
| 2863 | p->plane[0].tiling = fb->modifier[0]; |
| 2864 | } else { |
| 2865 | p->plane[0].enabled = false; |
| 2866 | p->plane[0].bytes_per_pixel = 0; |
| 2867 | p->plane[0].tiling = DRM_FORMAT_MOD_NONE; |
| 2868 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2869 | p->plane[0].horiz_pixels = intel_crtc->config->pipe_src_w; |
| 2870 | p->plane[0].vert_pixels = intel_crtc->config->pipe_src_h; |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2871 | p->plane[0].rotation = crtc->primary->state->rotation; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2872 | |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2873 | fb = crtc->cursor->state->fb; |
| 2874 | if (fb) { |
| 2875 | p->cursor.enabled = true; |
| 2876 | p->cursor.bytes_per_pixel = fb->bits_per_pixel / 8; |
| 2877 | p->cursor.horiz_pixels = crtc->cursor->state->crtc_w; |
| 2878 | p->cursor.vert_pixels = crtc->cursor->state->crtc_h; |
| 2879 | } else { |
| 2880 | p->cursor.enabled = false; |
| 2881 | p->cursor.bytes_per_pixel = 0; |
| 2882 | p->cursor.horiz_pixels = 64; |
| 2883 | p->cursor.vert_pixels = 64; |
| 2884 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2888 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2889 | |
Sonika Jindal | a712f8e | 2014-12-09 10:59:15 +0530 | [diff] [blame] | 2890 | if (intel_plane->pipe == pipe && |
| 2891 | plane->type == DRM_PLANE_TYPE_OVERLAY) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2892 | p->plane[i++] = intel_plane->wm; |
| 2893 | } |
| 2894 | } |
| 2895 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2896 | static bool skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 2897 | struct skl_pipe_wm_parameters *p, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2898 | struct intel_plane_wm_parameters *p_params, |
| 2899 | uint16_t ddb_allocation, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2900 | int level, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2901 | uint16_t *out_blocks, /* out */ |
| 2902 | uint8_t *out_lines /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2903 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2904 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
| 2905 | uint32_t method1, method2; |
| 2906 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2907 | uint32_t res_blocks, res_lines; |
| 2908 | uint32_t selected_result; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2909 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2910 | if (latency == 0 || !p->active || !p_params->enabled) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2911 | return false; |
| 2912 | |
| 2913 | method1 = skl_wm_method1(p->pixel_rate, |
| 2914 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2915 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2916 | method2 = skl_wm_method2(p->pixel_rate, |
| 2917 | p->pipe_htotal, |
| 2918 | p_params->horiz_pixels, |
| 2919 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2920 | p_params->tiling, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2921 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2922 | |
| 2923 | plane_bytes_per_line = p_params->horiz_pixels * |
| 2924 | p_params->bytes_per_pixel; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2925 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2926 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2927 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2928 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) { |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2929 | uint32_t min_scanlines = 4; |
| 2930 | uint32_t y_tile_minimum; |
| 2931 | if (intel_rotation_90_or_270(p_params->rotation)) { |
| 2932 | switch (p_params->bytes_per_pixel) { |
| 2933 | case 1: |
| 2934 | min_scanlines = 16; |
| 2935 | break; |
| 2936 | case 2: |
| 2937 | min_scanlines = 8; |
| 2938 | break; |
| 2939 | case 8: |
| 2940 | WARN(1, "Unsupported pixel depth for rotation"); |
kbuild test robot | 2f0b579 | 2015-03-26 22:30:21 +0800 | [diff] [blame] | 2941 | } |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2942 | } |
| 2943 | y_tile_minimum = plane_blocks_per_line * min_scanlines; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2944 | selected_result = max(method2, y_tile_minimum); |
| 2945 | } else { |
| 2946 | if ((ddb_allocation / plane_blocks_per_line) >= 1) |
| 2947 | selected_result = min(method1, method2); |
| 2948 | else |
| 2949 | selected_result = method1; |
| 2950 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2951 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2952 | res_blocks = selected_result + 1; |
| 2953 | res_lines = DIV_ROUND_UP(selected_result, plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2954 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2955 | if (level >= 1 && level <= 7) { |
| 2956 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2957 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) |
| 2958 | res_lines += 4; |
| 2959 | else |
| 2960 | res_blocks++; |
| 2961 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2962 | |
| 2963 | if (res_blocks >= ddb_allocation || res_lines > 31) |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2964 | return false; |
| 2965 | |
| 2966 | *out_blocks = res_blocks; |
| 2967 | *out_lines = res_lines; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2968 | |
| 2969 | return true; |
| 2970 | } |
| 2971 | |
| 2972 | static void skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 2973 | struct skl_ddb_allocation *ddb, |
| 2974 | struct skl_pipe_wm_parameters *p, |
| 2975 | enum pipe pipe, |
| 2976 | int level, |
| 2977 | int num_planes, |
| 2978 | struct skl_wm_level *result) |
| 2979 | { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2980 | uint16_t ddb_blocks; |
| 2981 | int i; |
| 2982 | |
| 2983 | for (i = 0; i < num_planes; i++) { |
| 2984 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]); |
| 2985 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2986 | result->plane_en[i] = skl_compute_plane_wm(dev_priv, |
| 2987 | p, &p->plane[i], |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2988 | ddb_blocks, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2989 | level, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2990 | &result->plane_res_b[i], |
| 2991 | &result->plane_res_l[i]); |
| 2992 | } |
| 2993 | |
| 2994 | ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]); |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2995 | result->cursor_en = skl_compute_plane_wm(dev_priv, p, &p->cursor, |
| 2996 | ddb_blocks, level, |
| 2997 | &result->cursor_res_b, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2998 | &result->cursor_res_l); |
| 2999 | } |
| 3000 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3001 | static uint32_t |
| 3002 | skl_compute_linetime_wm(struct drm_crtc *crtc, struct skl_pipe_wm_parameters *p) |
| 3003 | { |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3004 | if (!to_intel_crtc(crtc)->active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3005 | return 0; |
| 3006 | |
| 3007 | return DIV_ROUND_UP(8 * p->pipe_htotal * 1000, p->pixel_rate); |
| 3008 | |
| 3009 | } |
| 3010 | |
| 3011 | static void skl_compute_transition_wm(struct drm_crtc *crtc, |
| 3012 | struct skl_pipe_wm_parameters *params, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3013 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3014 | { |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3015 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3016 | int i; |
| 3017 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3018 | if (!params->active) |
| 3019 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3020 | |
| 3021 | /* Until we know more, just disable transition WMs */ |
| 3022 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3023 | trans_wm->plane_en[i] = false; |
| 3024 | trans_wm->cursor_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3025 | } |
| 3026 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3027 | static void skl_compute_pipe_wm(struct drm_crtc *crtc, |
| 3028 | struct skl_ddb_allocation *ddb, |
| 3029 | struct skl_pipe_wm_parameters *params, |
| 3030 | struct skl_pipe_wm *pipe_wm) |
| 3031 | { |
| 3032 | struct drm_device *dev = crtc->dev; |
| 3033 | const struct drm_i915_private *dev_priv = dev->dev_private; |
| 3034 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3035 | int level, max_level = ilk_wm_max_level(dev); |
| 3036 | |
| 3037 | for (level = 0; level <= max_level; level++) { |
| 3038 | skl_compute_wm_level(dev_priv, ddb, params, intel_crtc->pipe, |
| 3039 | level, intel_num_planes(intel_crtc), |
| 3040 | &pipe_wm->wm[level]); |
| 3041 | } |
| 3042 | pipe_wm->linetime = skl_compute_linetime_wm(crtc, params); |
| 3043 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3044 | skl_compute_transition_wm(crtc, params, &pipe_wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | static void skl_compute_wm_results(struct drm_device *dev, |
| 3048 | struct skl_pipe_wm_parameters *p, |
| 3049 | struct skl_pipe_wm *p_wm, |
| 3050 | struct skl_wm_values *r, |
| 3051 | struct intel_crtc *intel_crtc) |
| 3052 | { |
| 3053 | int level, max_level = ilk_wm_max_level(dev); |
| 3054 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3055 | uint32_t temp; |
| 3056 | int i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3057 | |
| 3058 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3059 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3060 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3061 | |
| 3062 | temp |= p_wm->wm[level].plane_res_l[i] << |
| 3063 | PLANE_WM_LINES_SHIFT; |
| 3064 | temp |= p_wm->wm[level].plane_res_b[i]; |
| 3065 | if (p_wm->wm[level].plane_en[i]) |
| 3066 | temp |= PLANE_WM_EN; |
| 3067 | |
| 3068 | r->plane[pipe][i][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3072 | |
| 3073 | temp |= p_wm->wm[level].cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3074 | temp |= p_wm->wm[level].cursor_res_b; |
| 3075 | |
| 3076 | if (p_wm->wm[level].cursor_en) |
| 3077 | temp |= PLANE_WM_EN; |
| 3078 | |
| 3079 | r->cursor[pipe][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3080 | |
| 3081 | } |
| 3082 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3083 | /* transition WMs */ |
| 3084 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3085 | temp = 0; |
| 3086 | temp |= p_wm->trans_wm.plane_res_l[i] << PLANE_WM_LINES_SHIFT; |
| 3087 | temp |= p_wm->trans_wm.plane_res_b[i]; |
| 3088 | if (p_wm->trans_wm.plane_en[i]) |
| 3089 | temp |= PLANE_WM_EN; |
| 3090 | |
| 3091 | r->plane_trans[pipe][i] = temp; |
| 3092 | } |
| 3093 | |
| 3094 | temp = 0; |
| 3095 | temp |= p_wm->trans_wm.cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3096 | temp |= p_wm->trans_wm.cursor_res_b; |
| 3097 | if (p_wm->trans_wm.cursor_en) |
| 3098 | temp |= PLANE_WM_EN; |
| 3099 | |
| 3100 | r->cursor_trans[pipe] = temp; |
| 3101 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3102 | r->wm_linetime[pipe] = p_wm->linetime; |
| 3103 | } |
| 3104 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3105 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, uint32_t reg, |
| 3106 | const struct skl_ddb_entry *entry) |
| 3107 | { |
| 3108 | if (entry->end) |
| 3109 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 3110 | else |
| 3111 | I915_WRITE(reg, 0); |
| 3112 | } |
| 3113 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3114 | static void skl_write_wm_values(struct drm_i915_private *dev_priv, |
| 3115 | const struct skl_wm_values *new) |
| 3116 | { |
| 3117 | struct drm_device *dev = dev_priv->dev; |
| 3118 | struct intel_crtc *crtc; |
| 3119 | |
| 3120 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
| 3121 | int i, level, max_level = ilk_wm_max_level(dev); |
| 3122 | enum pipe pipe = crtc->pipe; |
| 3123 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3124 | if (!new->dirty[pipe]) |
| 3125 | continue; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3126 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3127 | I915_WRITE(PIPE_WM_LINETIME(pipe), new->wm_linetime[pipe]); |
| 3128 | |
| 3129 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3130 | for (i = 0; i < intel_num_planes(crtc); i++) |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3131 | I915_WRITE(PLANE_WM(pipe, i, level), |
| 3132 | new->plane[pipe][i][level]); |
| 3133 | I915_WRITE(CUR_WM(pipe, level), |
| 3134 | new->cursor[pipe][level]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3135 | } |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3136 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3137 | I915_WRITE(PLANE_WM_TRANS(pipe, i), |
| 3138 | new->plane_trans[pipe][i]); |
| 3139 | I915_WRITE(CUR_WM_TRANS(pipe), new->cursor_trans[pipe]); |
| 3140 | |
| 3141 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3142 | skl_ddb_entry_write(dev_priv, |
| 3143 | PLANE_BUF_CFG(pipe, i), |
| 3144 | &new->ddb.plane[pipe][i]); |
| 3145 | |
| 3146 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
| 3147 | &new->ddb.cursor[pipe]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3148 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3149 | } |
| 3150 | |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3151 | /* |
| 3152 | * When setting up a new DDB allocation arrangement, we need to correctly |
| 3153 | * sequence the times at which the new allocations for the pipes are taken into |
| 3154 | * account or we'll have pipes fetching from space previously allocated to |
| 3155 | * another pipe. |
| 3156 | * |
| 3157 | * Roughly the sequence looks like: |
| 3158 | * 1. re-allocate the pipe(s) with the allocation being reduced and not |
| 3159 | * overlapping with a previous light-up pipe (another way to put it is: |
| 3160 | * pipes with their new allocation strickly included into their old ones). |
| 3161 | * 2. re-allocate the other pipes that get their allocation reduced |
| 3162 | * 3. allocate the pipes having their allocation increased |
| 3163 | * |
| 3164 | * Steps 1. and 2. are here to take care of the following case: |
| 3165 | * - Initially DDB looks like this: |
| 3166 | * | B | C | |
| 3167 | * - enable pipe A. |
| 3168 | * - pipe B has a reduced DDB allocation that overlaps with the old pipe C |
| 3169 | * allocation |
| 3170 | * | A | B | C | |
| 3171 | * |
| 3172 | * We need to sequence the re-allocation: C, B, A (and not B, C, A). |
| 3173 | */ |
| 3174 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3175 | static void |
| 3176 | 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] | 3177 | { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3178 | int plane; |
| 3179 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3180 | DRM_DEBUG_KMS("flush pipe %c (pass %d)\n", pipe_name(pipe), pass); |
| 3181 | |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 3182 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3183 | I915_WRITE(PLANE_SURF(pipe, plane), |
| 3184 | I915_READ(PLANE_SURF(pipe, plane))); |
| 3185 | } |
| 3186 | I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe))); |
| 3187 | } |
| 3188 | |
| 3189 | static bool |
| 3190 | skl_ddb_allocation_included(const struct skl_ddb_allocation *old, |
| 3191 | const struct skl_ddb_allocation *new, |
| 3192 | enum pipe pipe) |
| 3193 | { |
| 3194 | uint16_t old_size, new_size; |
| 3195 | |
| 3196 | old_size = skl_ddb_entry_size(&old->pipe[pipe]); |
| 3197 | new_size = skl_ddb_entry_size(&new->pipe[pipe]); |
| 3198 | |
| 3199 | return old_size != new_size && |
| 3200 | new->pipe[pipe].start >= old->pipe[pipe].start && |
| 3201 | new->pipe[pipe].end <= old->pipe[pipe].end; |
| 3202 | } |
| 3203 | |
| 3204 | static void skl_flush_wm_values(struct drm_i915_private *dev_priv, |
| 3205 | struct skl_wm_values *new_values) |
| 3206 | { |
| 3207 | struct drm_device *dev = dev_priv->dev; |
| 3208 | struct skl_ddb_allocation *cur_ddb, *new_ddb; |
Ville Syrjälä | c929cb4 | 2015-04-02 18:28:07 +0300 | [diff] [blame] | 3209 | bool reallocated[I915_MAX_PIPES] = {}; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3210 | struct intel_crtc *crtc; |
| 3211 | enum pipe pipe; |
| 3212 | |
| 3213 | new_ddb = &new_values->ddb; |
| 3214 | cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 3215 | |
| 3216 | /* |
| 3217 | * First pass: flush the pipes with the new allocation contained into |
| 3218 | * the old space. |
| 3219 | * |
| 3220 | * We'll wait for the vblank on those pipes to ensure we can safely |
| 3221 | * re-allocate the freed space without this pipe fetching from it. |
| 3222 | */ |
| 3223 | for_each_intel_crtc(dev, crtc) { |
| 3224 | if (!crtc->active) |
| 3225 | continue; |
| 3226 | |
| 3227 | pipe = crtc->pipe; |
| 3228 | |
| 3229 | if (!skl_ddb_allocation_included(cur_ddb, new_ddb, pipe)) |
| 3230 | continue; |
| 3231 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3232 | skl_wm_flush_pipe(dev_priv, pipe, 1); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3233 | intel_wait_for_vblank(dev, pipe); |
| 3234 | |
| 3235 | reallocated[pipe] = true; |
| 3236 | } |
| 3237 | |
| 3238 | |
| 3239 | /* |
| 3240 | * Second pass: flush the pipes that are having their allocation |
| 3241 | * reduced, but overlapping with a previous allocation. |
| 3242 | * |
| 3243 | * Here as well we need to wait for the vblank to make sure the freed |
| 3244 | * space is not used anymore. |
| 3245 | */ |
| 3246 | for_each_intel_crtc(dev, crtc) { |
| 3247 | if (!crtc->active) |
| 3248 | continue; |
| 3249 | |
| 3250 | pipe = crtc->pipe; |
| 3251 | |
| 3252 | if (reallocated[pipe]) |
| 3253 | continue; |
| 3254 | |
| 3255 | if (skl_ddb_entry_size(&new_ddb->pipe[pipe]) < |
| 3256 | skl_ddb_entry_size(&cur_ddb->pipe[pipe])) { |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3257 | skl_wm_flush_pipe(dev_priv, pipe, 2); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3258 | intel_wait_for_vblank(dev, pipe); |
Sonika Jindal | d9d8e6b | 2014-12-11 17:58:15 +0530 | [diff] [blame] | 3259 | reallocated[pipe] = true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3260 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | /* |
| 3264 | * Third pass: flush the pipes that got more space allocated. |
| 3265 | * |
| 3266 | * We don't need to actively wait for the update here, next vblank |
| 3267 | * will just get more DDB space with the correct WM values. |
| 3268 | */ |
| 3269 | for_each_intel_crtc(dev, crtc) { |
| 3270 | if (!crtc->active) |
| 3271 | continue; |
| 3272 | |
| 3273 | pipe = crtc->pipe; |
| 3274 | |
| 3275 | /* |
| 3276 | * At this point, only the pipes more space than before are |
| 3277 | * left to re-allocate. |
| 3278 | */ |
| 3279 | if (reallocated[pipe]) |
| 3280 | continue; |
| 3281 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3282 | skl_wm_flush_pipe(dev_priv, pipe, 3); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3283 | } |
| 3284 | } |
| 3285 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3286 | static bool skl_update_pipe_wm(struct drm_crtc *crtc, |
| 3287 | struct skl_pipe_wm_parameters *params, |
| 3288 | struct intel_wm_config *config, |
| 3289 | struct skl_ddb_allocation *ddb, /* out */ |
| 3290 | struct skl_pipe_wm *pipe_wm /* out */) |
| 3291 | { |
| 3292 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3293 | |
| 3294 | skl_compute_wm_pipe_parameters(crtc, params); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3295 | skl_allocate_pipe_ddb(crtc, config, params, ddb); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3296 | skl_compute_pipe_wm(crtc, ddb, params, pipe_wm); |
| 3297 | |
| 3298 | if (!memcmp(&intel_crtc->wm.skl_active, pipe_wm, sizeof(*pipe_wm))) |
| 3299 | return false; |
| 3300 | |
| 3301 | intel_crtc->wm.skl_active = *pipe_wm; |
| 3302 | return true; |
| 3303 | } |
| 3304 | |
| 3305 | static void skl_update_other_pipe_wm(struct drm_device *dev, |
| 3306 | struct drm_crtc *crtc, |
| 3307 | struct intel_wm_config *config, |
| 3308 | struct skl_wm_values *r) |
| 3309 | { |
| 3310 | struct intel_crtc *intel_crtc; |
| 3311 | struct intel_crtc *this_crtc = to_intel_crtc(crtc); |
| 3312 | |
| 3313 | /* |
| 3314 | * If the WM update hasn't changed the allocation for this_crtc (the |
| 3315 | * crtc we are currently computing the new WM values for), other |
| 3316 | * enabled crtcs will keep the same allocation and we don't need to |
| 3317 | * recompute anything for them. |
| 3318 | */ |
| 3319 | if (!skl_ddb_allocation_changed(&r->ddb, this_crtc)) |
| 3320 | return; |
| 3321 | |
| 3322 | /* |
| 3323 | * Otherwise, because of this_crtc being freshly enabled/disabled, the |
| 3324 | * other active pipes need new DDB allocation and WM values. |
| 3325 | */ |
| 3326 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 3327 | base.head) { |
| 3328 | struct skl_pipe_wm_parameters params = {}; |
| 3329 | struct skl_pipe_wm pipe_wm = {}; |
| 3330 | bool wm_changed; |
| 3331 | |
| 3332 | if (this_crtc->pipe == intel_crtc->pipe) |
| 3333 | continue; |
| 3334 | |
| 3335 | if (!intel_crtc->active) |
| 3336 | continue; |
| 3337 | |
| 3338 | wm_changed = skl_update_pipe_wm(&intel_crtc->base, |
| 3339 | ¶ms, config, |
| 3340 | &r->ddb, &pipe_wm); |
| 3341 | |
| 3342 | /* |
| 3343 | * If we end up re-computing the other pipe WM values, it's |
| 3344 | * because it was really needed, so we expect the WM values to |
| 3345 | * be different. |
| 3346 | */ |
| 3347 | WARN_ON(!wm_changed); |
| 3348 | |
| 3349 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, r, intel_crtc); |
| 3350 | r->dirty[intel_crtc->pipe] = true; |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | static void skl_update_wm(struct drm_crtc *crtc) |
| 3355 | { |
| 3356 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3357 | struct drm_device *dev = crtc->dev; |
| 3358 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3359 | struct skl_pipe_wm_parameters params = {}; |
| 3360 | struct skl_wm_values *results = &dev_priv->wm.skl_results; |
| 3361 | struct skl_pipe_wm pipe_wm = {}; |
| 3362 | struct intel_wm_config config = {}; |
| 3363 | |
| 3364 | memset(results, 0, sizeof(*results)); |
| 3365 | |
| 3366 | skl_compute_wm_global_parameters(dev, &config); |
| 3367 | |
| 3368 | if (!skl_update_pipe_wm(crtc, ¶ms, &config, |
| 3369 | &results->ddb, &pipe_wm)) |
| 3370 | return; |
| 3371 | |
| 3372 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, results, intel_crtc); |
| 3373 | results->dirty[intel_crtc->pipe] = true; |
| 3374 | |
| 3375 | skl_update_other_pipe_wm(dev, crtc, &config, results); |
| 3376 | skl_write_wm_values(dev_priv, results); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3377 | skl_flush_wm_values(dev_priv, results); |
Damien Lespiau | 53b0deb | 2014-11-04 17:06:48 +0000 | [diff] [blame] | 3378 | |
| 3379 | /* store the new configuration */ |
| 3380 | dev_priv->wm.skl_hw = *results; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | static void |
| 3384 | skl_update_sprite_wm(struct drm_plane *plane, struct drm_crtc *crtc, |
| 3385 | uint32_t sprite_width, uint32_t sprite_height, |
| 3386 | int pixel_size, bool enabled, bool scaled) |
| 3387 | { |
| 3388 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3389 | struct drm_framebuffer *fb = plane->state->fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3390 | |
| 3391 | intel_plane->wm.enabled = enabled; |
| 3392 | intel_plane->wm.scaled = scaled; |
| 3393 | intel_plane->wm.horiz_pixels = sprite_width; |
| 3394 | intel_plane->wm.vert_pixels = sprite_height; |
| 3395 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3396 | intel_plane->wm.tiling = DRM_FORMAT_MOD_NONE; |
| 3397 | /* |
| 3398 | * Framebuffer can be NULL on plane disable, but it does not |
| 3399 | * matter for watermarks if we assume no tiling in that case. |
| 3400 | */ |
| 3401 | if (fb) |
| 3402 | intel_plane->wm.tiling = fb->modifier[0]; |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 3403 | intel_plane->wm.rotation = plane->state->rotation; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3404 | |
| 3405 | skl_update_wm(crtc); |
| 3406 | } |
| 3407 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3408 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3409 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3410 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3411 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3412 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3413 | struct ilk_wm_maximums max; |
| 3414 | struct ilk_pipe_wm_parameters params = {}; |
| 3415 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3416 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3417 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3418 | 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] | 3419 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3420 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3421 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3422 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3423 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 3424 | |
| 3425 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 3426 | return; |
| 3427 | |
| 3428 | intel_crtc->wm.active = pipe_wm; |
| 3429 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3430 | ilk_compute_wm_config(dev, &config); |
| 3431 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3432 | 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] | 3433 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3434 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3435 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 3436 | if (INTEL_INFO(dev)->gen >= 7 && |
| 3437 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3438 | 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] | 3439 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3440 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3441 | 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] | 3442 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3443 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3444 | } |
| 3445 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3446 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3447 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3448 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3449 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3450 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3451 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3452 | } |
| 3453 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3454 | static void |
| 3455 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 3456 | struct drm_crtc *crtc, |
| 3457 | uint32_t sprite_width, uint32_t sprite_height, |
| 3458 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3459 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3460 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3461 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3462 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3463 | intel_plane->wm.enabled = enabled; |
| 3464 | intel_plane->wm.scaled = scaled; |
| 3465 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3466 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3467 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3468 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3469 | /* |
| 3470 | * IVB workaround: must disable low power watermarks for at least |
| 3471 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 3472 | * when scaling is disabled. |
| 3473 | * |
| 3474 | * WaCxSRDisabledForSpriteScaling:ivb |
| 3475 | */ |
| 3476 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 3477 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 3478 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3479 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3480 | } |
| 3481 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3482 | static void skl_pipe_wm_active_state(uint32_t val, |
| 3483 | struct skl_pipe_wm *active, |
| 3484 | bool is_transwm, |
| 3485 | bool is_cursor, |
| 3486 | int i, |
| 3487 | int level) |
| 3488 | { |
| 3489 | bool is_enabled = (val & PLANE_WM_EN) != 0; |
| 3490 | |
| 3491 | if (!is_transwm) { |
| 3492 | if (!is_cursor) { |
| 3493 | active->wm[level].plane_en[i] = is_enabled; |
| 3494 | active->wm[level].plane_res_b[i] = |
| 3495 | val & PLANE_WM_BLOCKS_MASK; |
| 3496 | active->wm[level].plane_res_l[i] = |
| 3497 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3498 | PLANE_WM_LINES_MASK; |
| 3499 | } else { |
| 3500 | active->wm[level].cursor_en = is_enabled; |
| 3501 | active->wm[level].cursor_res_b = |
| 3502 | val & PLANE_WM_BLOCKS_MASK; |
| 3503 | active->wm[level].cursor_res_l = |
| 3504 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3505 | PLANE_WM_LINES_MASK; |
| 3506 | } |
| 3507 | } else { |
| 3508 | if (!is_cursor) { |
| 3509 | active->trans_wm.plane_en[i] = is_enabled; |
| 3510 | active->trans_wm.plane_res_b[i] = |
| 3511 | val & PLANE_WM_BLOCKS_MASK; |
| 3512 | active->trans_wm.plane_res_l[i] = |
| 3513 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3514 | PLANE_WM_LINES_MASK; |
| 3515 | } else { |
| 3516 | active->trans_wm.cursor_en = is_enabled; |
| 3517 | active->trans_wm.cursor_res_b = |
| 3518 | val & PLANE_WM_BLOCKS_MASK; |
| 3519 | active->trans_wm.cursor_res_l = |
| 3520 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3521 | PLANE_WM_LINES_MASK; |
| 3522 | } |
| 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3527 | { |
| 3528 | struct drm_device *dev = crtc->dev; |
| 3529 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3530 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
| 3531 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3532 | struct skl_pipe_wm *active = &intel_crtc->wm.skl_active; |
| 3533 | enum pipe pipe = intel_crtc->pipe; |
| 3534 | int level, i, max_level; |
| 3535 | uint32_t temp; |
| 3536 | |
| 3537 | max_level = ilk_wm_max_level(dev); |
| 3538 | |
| 3539 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
| 3540 | |
| 3541 | for (level = 0; level <= max_level; level++) { |
| 3542 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3543 | hw->plane[pipe][i][level] = |
| 3544 | I915_READ(PLANE_WM(pipe, i, level)); |
| 3545 | hw->cursor[pipe][level] = I915_READ(CUR_WM(pipe, level)); |
| 3546 | } |
| 3547 | |
| 3548 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3549 | hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i)); |
| 3550 | hw->cursor_trans[pipe] = I915_READ(CUR_WM_TRANS(pipe)); |
| 3551 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3552 | if (!intel_crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3553 | return; |
| 3554 | |
| 3555 | hw->dirty[pipe] = true; |
| 3556 | |
| 3557 | active->linetime = hw->wm_linetime[pipe]; |
| 3558 | |
| 3559 | for (level = 0; level <= max_level; level++) { |
| 3560 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3561 | temp = hw->plane[pipe][i][level]; |
| 3562 | skl_pipe_wm_active_state(temp, active, false, |
| 3563 | false, i, level); |
| 3564 | } |
| 3565 | temp = hw->cursor[pipe][level]; |
| 3566 | skl_pipe_wm_active_state(temp, active, false, true, i, level); |
| 3567 | } |
| 3568 | |
| 3569 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3570 | temp = hw->plane_trans[pipe][i]; |
| 3571 | skl_pipe_wm_active_state(temp, active, true, false, i, 0); |
| 3572 | } |
| 3573 | |
| 3574 | temp = hw->cursor_trans[pipe]; |
| 3575 | skl_pipe_wm_active_state(temp, active, true, true, i, 0); |
| 3576 | } |
| 3577 | |
| 3578 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 3579 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3580 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3581 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3582 | struct drm_crtc *crtc; |
| 3583 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3584 | skl_ddb_get_hw_state(dev_priv, ddb); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3585 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3586 | skl_pipe_wm_get_hw_state(crtc); |
| 3587 | } |
| 3588 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3589 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3590 | { |
| 3591 | struct drm_device *dev = crtc->dev; |
| 3592 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3593 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3594 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3595 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 3596 | enum pipe pipe = intel_crtc->pipe; |
| 3597 | static const unsigned int wm0_pipe_reg[] = { |
| 3598 | [PIPE_A] = WM0_PIPEA_ILK, |
| 3599 | [PIPE_B] = WM0_PIPEB_ILK, |
| 3600 | [PIPE_C] = WM0_PIPEC_IVB, |
| 3601 | }; |
| 3602 | |
| 3603 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3604 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 3605 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3606 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3607 | active->pipe_enabled = intel_crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3608 | |
| 3609 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3610 | u32 tmp = hw->wm_pipe[pipe]; |
| 3611 | |
| 3612 | /* |
| 3613 | * For active pipes LP0 watermark is marked as |
| 3614 | * enabled, and LP1+ watermaks as disabled since |
| 3615 | * we can't really reverse compute them in case |
| 3616 | * multiple pipes are active. |
| 3617 | */ |
| 3618 | active->wm[0].enable = true; |
| 3619 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 3620 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 3621 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 3622 | active->linetime = hw->wm_linetime[pipe]; |
| 3623 | } else { |
| 3624 | int level, max_level = ilk_wm_max_level(dev); |
| 3625 | |
| 3626 | /* |
| 3627 | * For inactive pipes, all watermark levels |
| 3628 | * should be marked as enabled but zeroed, |
| 3629 | * which is what we'd compute them to. |
| 3630 | */ |
| 3631 | for (level = 0; level <= max_level; level++) |
| 3632 | active->wm[level].enable = true; |
| 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 3637 | { |
| 3638 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3639 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3640 | struct drm_crtc *crtc; |
| 3641 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3642 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3643 | ilk_pipe_wm_get_hw_state(crtc); |
| 3644 | |
| 3645 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 3646 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 3647 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 3648 | |
| 3649 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 3650 | if (INTEL_INFO(dev)->gen >= 7) { |
| 3651 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 3652 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 3653 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3654 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3655 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3656 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 3657 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 3658 | else if (IS_IVYBRIDGE(dev)) |
| 3659 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 3660 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3661 | |
| 3662 | hw->enable_fbc_wm = |
| 3663 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3664 | } |
| 3665 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3666 | /** |
| 3667 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3668 | * |
| 3669 | * Calculate watermark values for the various WM regs based on current mode |
| 3670 | * and plane configuration. |
| 3671 | * |
| 3672 | * There are several cases to deal with here: |
| 3673 | * - normal (i.e. non-self-refresh) |
| 3674 | * - self-refresh (SR) mode |
| 3675 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3676 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3677 | * lines), so need to account for TLB latency |
| 3678 | * |
| 3679 | * The normal calculation is: |
| 3680 | * watermark = dotclock * bytes per pixel * latency |
| 3681 | * where latency is platform & configuration dependent (we assume pessimal |
| 3682 | * values here). |
| 3683 | * |
| 3684 | * The SR calculation is: |
| 3685 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3686 | * bytes per pixel |
| 3687 | * where |
| 3688 | * line time = htotal / dotclock |
| 3689 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3690 | * and latency is assumed to be high, as above. |
| 3691 | * |
| 3692 | * The final value programmed to the register should always be rounded up, |
| 3693 | * and include an extra 2 entries to account for clock crossings. |
| 3694 | * |
| 3695 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3696 | * to set the non-SR watermarks to 8. |
| 3697 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3698 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3699 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3700 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3701 | |
| 3702 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3703 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3704 | } |
| 3705 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3706 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3707 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3708 | uint32_t sprite_width, |
| 3709 | uint32_t sprite_height, |
| 3710 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3711 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3712 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3713 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3714 | |
| 3715 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3716 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3717 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3718 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3719 | } |
| 3720 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3721 | /** |
| 3722 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3723 | */ |
| 3724 | DEFINE_SPINLOCK(mchdev_lock); |
| 3725 | |
| 3726 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3727 | * mchdev_lock. */ |
| 3728 | static struct drm_i915_private *i915_mch_dev; |
| 3729 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3730 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3731 | { |
| 3732 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3733 | u16 rgvswctl; |
| 3734 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3735 | assert_spin_locked(&mchdev_lock); |
| 3736 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3737 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3738 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3739 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3740 | return false; /* still busy with another command */ |
| 3741 | } |
| 3742 | |
| 3743 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3744 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3745 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3746 | POSTING_READ16(MEMSWCTL); |
| 3747 | |
| 3748 | rgvswctl |= MEMCTL_CMD_STS; |
| 3749 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3750 | |
| 3751 | return true; |
| 3752 | } |
| 3753 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3754 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3755 | { |
| 3756 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3757 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 3758 | u8 fmax, fmin, fstart, vstart; |
| 3759 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3760 | spin_lock_irq(&mchdev_lock); |
| 3761 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3762 | /* Enable temp reporting */ |
| 3763 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 3764 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 3765 | |
| 3766 | /* 100ms RC evaluation intervals */ |
| 3767 | I915_WRITE(RCUPEI, 100000); |
| 3768 | I915_WRITE(RCDNEI, 100000); |
| 3769 | |
| 3770 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 3771 | I915_WRITE(RCBMAXAVG, 90000); |
| 3772 | I915_WRITE(RCBMINAVG, 80000); |
| 3773 | |
| 3774 | I915_WRITE(MEMIHYST, 1); |
| 3775 | |
| 3776 | /* Set up min, max, and cur for interrupt handling */ |
| 3777 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 3778 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3779 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3780 | MEMMODE_FSTART_SHIFT; |
| 3781 | |
| 3782 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3783 | PXVFREQ_PX_SHIFT; |
| 3784 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3785 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3786 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3787 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3788 | dev_priv->ips.max_delay = fstart; |
| 3789 | dev_priv->ips.min_delay = fmin; |
| 3790 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3791 | |
| 3792 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3793 | fmax, fmin, fstart); |
| 3794 | |
| 3795 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3796 | |
| 3797 | /* |
| 3798 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3799 | */ |
| 3800 | |
| 3801 | I915_WRITE(VIDSTART, vstart); |
| 3802 | POSTING_READ(VIDSTART); |
| 3803 | |
| 3804 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3805 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3806 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3807 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3808 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3809 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3810 | |
| 3811 | ironlake_set_drps(dev, fstart); |
| 3812 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3813 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3814 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3815 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3816 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 3817 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3818 | |
| 3819 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3820 | } |
| 3821 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3822 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3823 | { |
| 3824 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3825 | u16 rgvswctl; |
| 3826 | |
| 3827 | spin_lock_irq(&mchdev_lock); |
| 3828 | |
| 3829 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3830 | |
| 3831 | /* Ack interrupts, disable EFC interrupt */ |
| 3832 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3833 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3834 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3835 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3836 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3837 | |
| 3838 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3839 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3840 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3841 | rgvswctl |= MEMCTL_CMD_STS; |
| 3842 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3843 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3844 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3845 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3846 | } |
| 3847 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3848 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3849 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3850 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3851 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3852 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3853 | 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] | 3854 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3855 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3856 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3857 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3858 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3859 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3860 | * the hw runs at the minimal clock before selecting the desired |
| 3861 | * frequency, if the down threshold expires in that window we will not |
| 3862 | * receive a down interrupt. */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3863 | if (IS_GEN9(dev_priv->dev)) { |
| 3864 | limits = (dev_priv->rps.max_freq_softlimit) << 23; |
| 3865 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3866 | limits |= (dev_priv->rps.min_freq_softlimit) << 14; |
| 3867 | } else { |
| 3868 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3869 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3870 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
| 3871 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3872 | |
| 3873 | return limits; |
| 3874 | } |
| 3875 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3876 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3877 | { |
| 3878 | int new_power; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3879 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 3880 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3881 | |
| 3882 | new_power = dev_priv->rps.power; |
| 3883 | switch (dev_priv->rps.power) { |
| 3884 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3885 | 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] | 3886 | new_power = BETWEEN; |
| 3887 | break; |
| 3888 | |
| 3889 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3890 | 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] | 3891 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3892 | 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] | 3893 | new_power = HIGH_POWER; |
| 3894 | break; |
| 3895 | |
| 3896 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3897 | 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] | 3898 | new_power = BETWEEN; |
| 3899 | break; |
| 3900 | } |
| 3901 | /* Max/min bins are special */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3902 | if (val <= dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3903 | new_power = LOW_POWER; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3904 | if (val >= dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3905 | new_power = HIGH_POWER; |
| 3906 | if (new_power == dev_priv->rps.power) |
| 3907 | return; |
| 3908 | |
| 3909 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3910 | switch (new_power) { |
| 3911 | case LOW_POWER: |
| 3912 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3913 | ei_up = 16000; |
| 3914 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3915 | |
| 3916 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3917 | ei_down = 32000; |
| 3918 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3919 | break; |
| 3920 | |
| 3921 | case BETWEEN: |
| 3922 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3923 | ei_up = 13000; |
| 3924 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3925 | |
| 3926 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3927 | ei_down = 32000; |
| 3928 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3929 | break; |
| 3930 | |
| 3931 | case HIGH_POWER: |
| 3932 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3933 | ei_up = 10000; |
| 3934 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3935 | |
| 3936 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3937 | ei_down = 32000; |
| 3938 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3939 | break; |
| 3940 | } |
| 3941 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3942 | I915_WRITE(GEN6_RP_UP_EI, |
| 3943 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
| 3944 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
| 3945 | GT_INTERVAL_FROM_US(dev_priv, (ei_up * threshold_up / 100))); |
| 3946 | |
| 3947 | I915_WRITE(GEN6_RP_DOWN_EI, |
| 3948 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
| 3949 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
| 3950 | GT_INTERVAL_FROM_US(dev_priv, (ei_down * threshold_down / 100))); |
| 3951 | |
| 3952 | I915_WRITE(GEN6_RP_CONTROL, |
| 3953 | GEN6_RP_MEDIA_TURBO | |
| 3954 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3955 | GEN6_RP_MEDIA_IS_GFX | |
| 3956 | GEN6_RP_ENABLE | |
| 3957 | GEN6_RP_UP_BUSY_AVG | |
| 3958 | GEN6_RP_DOWN_IDLE_AVG); |
| 3959 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3960 | dev_priv->rps.power = new_power; |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 3961 | dev_priv->rps.up_threshold = threshold_up; |
| 3962 | dev_priv->rps.down_threshold = threshold_down; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3963 | dev_priv->rps.last_adj = 0; |
| 3964 | } |
| 3965 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3966 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3967 | { |
| 3968 | u32 mask = 0; |
| 3969 | |
| 3970 | if (val > dev_priv->rps.min_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 3971 | 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] | 3972 | if (val < dev_priv->rps.max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 3973 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3974 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3975 | mask &= dev_priv->pm_rps_events; |
| 3976 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 3977 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3978 | } |
| 3979 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3980 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3981 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3982 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3983 | static void gen6_set_rps(struct drm_device *dev, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3984 | { |
| 3985 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3986 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3987 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3988 | WARN_ON(val > dev_priv->rps.max_freq); |
| 3989 | WARN_ON(val < dev_priv->rps.min_freq); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3990 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3991 | /* min/max delay may still have been modified so be sure to |
| 3992 | * write the limits value. |
| 3993 | */ |
| 3994 | if (val != dev_priv->rps.cur_freq) { |
| 3995 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3996 | |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 3997 | if (IS_GEN9(dev)) |
| 3998 | I915_WRITE(GEN6_RPNSWREQ, |
| 3999 | GEN9_FREQUENCY(val)); |
| 4000 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 4001 | I915_WRITE(GEN6_RPNSWREQ, |
| 4002 | HSW_FREQUENCY(val)); |
| 4003 | else |
| 4004 | I915_WRITE(GEN6_RPNSWREQ, |
| 4005 | GEN6_FREQUENCY(val) | |
| 4006 | GEN6_OFFSET(0) | |
| 4007 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 4008 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4009 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4010 | /* Make sure we continue to get interrupts |
| 4011 | * until we hit the minimum or maximum frequencies. |
| 4012 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 4013 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4014 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4015 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 4016 | POSTING_READ(GEN6_RPNSWREQ); |
| 4017 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4018 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9 | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 4019 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4020 | } |
| 4021 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4022 | static void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 4023 | { |
| 4024 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4025 | |
| 4026 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4027 | WARN_ON(val > dev_priv->rps.max_freq); |
| 4028 | WARN_ON(val < dev_priv->rps.min_freq); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4029 | |
| 4030 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 4031 | "Odd GPU freq value\n")) |
| 4032 | val &= ~1; |
| 4033 | |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 4034 | if (val != dev_priv->rps.cur_freq) { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4035 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 4036 | if (!IS_CHERRYVIEW(dev_priv)) |
| 4037 | gen6_set_rps_thresholds(dev_priv, val); |
| 4038 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4039 | |
| 4040 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 4041 | |
| 4042 | dev_priv->rps.cur_freq = val; |
| 4043 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
| 4044 | } |
| 4045 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4046 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 4047 | * |
| 4048 | * * If Gfx is Idle, then |
| 4049 | * 1. Mask Turbo interrupts |
| 4050 | * 2. Bring up Gfx clock |
| 4051 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 4052 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 4053 | * 5. Unmask Turbo interrupts |
| 4054 | */ |
| 4055 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 4056 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4057 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4058 | u32 val = dev_priv->rps.idle_freq; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4059 | |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 4060 | /* CHV and latest VLV don't need to force the gfx clock */ |
| 4061 | if (IS_CHERRYVIEW(dev) || dev->pdev->revision >= 0xd) { |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4062 | valleyview_set_rps(dev_priv->dev, val); |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4063 | return; |
| 4064 | } |
| 4065 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4066 | /* |
| 4067 | * When we are idle. Drop to min voltage state. |
| 4068 | */ |
| 4069 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4070 | if (dev_priv->rps.cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4071 | return; |
| 4072 | |
| 4073 | /* Mask turbo interrupt so that they will not come in between */ |
Imre Deak | f24eeb1 | 2014-12-19 19:33:27 +0200 | [diff] [blame] | 4074 | I915_WRITE(GEN6_PMINTRMSK, |
| 4075 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4076 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4077 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4078 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4079 | dev_priv->rps.cur_freq = val; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4080 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4081 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4082 | |
| 4083 | 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] | 4084 | & GENFREQSTATUS) == 0, 100)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4085 | DRM_ERROR("timed out waiting for Punit\n"); |
| 4086 | |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 4087 | gen6_set_rps_thresholds(dev_priv, val); |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4088 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4089 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4090 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4091 | } |
| 4092 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4093 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 4094 | { |
| 4095 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4096 | if (dev_priv->rps.enabled) { |
| 4097 | if (dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) |
| 4098 | gen6_rps_reset_ei(dev_priv); |
| 4099 | I915_WRITE(GEN6_PMINTRMSK, |
| 4100 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
| 4101 | } |
| 4102 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4103 | } |
| 4104 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4105 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 4106 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 4107 | struct drm_device *dev = dev_priv->dev; |
| 4108 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4109 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4110 | if (dev_priv->rps.enabled) { |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 4111 | if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4112 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4113 | else |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4114 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4115 | dev_priv->rps.last_adj = 0; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4116 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4117 | } |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 4118 | |
| 4119 | while (!list_empty(&dev_priv->rps.clients)) |
| 4120 | list_del_init(dev_priv->rps.clients.next); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4121 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4122 | } |
| 4123 | |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 4124 | void gen6_rps_boost(struct drm_i915_private *dev_priv, |
| 4125 | struct drm_i915_file_private *file_priv) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4126 | { |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4127 | u32 val; |
| 4128 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4129 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4130 | val = dev_priv->rps.max_freq_softlimit; |
| 4131 | if (dev_priv->rps.enabled && |
| 4132 | dev_priv->mm.busy && |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 4133 | dev_priv->rps.cur_freq < val && |
| 4134 | (file_priv == NULL || list_empty(&file_priv->rps_boost))) { |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4135 | intel_set_rps(dev_priv->dev, val); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4136 | dev_priv->rps.last_adj = 0; |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 4137 | |
| 4138 | if (file_priv != NULL) { |
| 4139 | list_add(&file_priv->rps_boost, &dev_priv->rps.clients); |
| 4140 | file_priv->rps_boosts++; |
| 4141 | } else |
| 4142 | dev_priv->rps.boosts++; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4143 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4144 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4145 | } |
| 4146 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4147 | void intel_set_rps(struct drm_device *dev, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4148 | { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4149 | if (IS_VALLEYVIEW(dev)) |
| 4150 | valleyview_set_rps(dev, val); |
| 4151 | else |
| 4152 | gen6_set_rps(dev, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4155 | static void gen9_disable_rps(struct drm_device *dev) |
| 4156 | { |
| 4157 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4158 | |
| 4159 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4160 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4163 | static void gen6_disable_rps(struct drm_device *dev) |
| 4164 | { |
| 4165 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4166 | |
| 4167 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4168 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4169 | } |
| 4170 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4171 | static void cherryview_disable_rps(struct drm_device *dev) |
| 4172 | { |
| 4173 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4174 | |
| 4175 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4176 | } |
| 4177 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4178 | static void valleyview_disable_rps(struct drm_device *dev) |
| 4179 | { |
| 4180 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4181 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4182 | /* we're doing forcewake before Disabling RC6, |
| 4183 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4184 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4185 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4186 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4187 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4188 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4191 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 4192 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4193 | if (IS_VALLEYVIEW(dev)) { |
| 4194 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 4195 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 4196 | else |
| 4197 | mode = 0; |
| 4198 | } |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4199 | if (HAS_RC6p(dev)) |
| 4200 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s RC6p %s RC6pp %s\n", |
| 4201 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 4202 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 4203 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
| 4204 | |
| 4205 | else |
| 4206 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s\n", |
| 4207 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4210 | 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] | 4211 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 4212 | /* No RC6 before Ironlake */ |
| 4213 | if (INTEL_INFO(dev)->gen < 5) |
| 4214 | return 0; |
| 4215 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4216 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 4217 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 4218 | return 0; |
| 4219 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 4220 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4221 | if (enable_rc6 >= 0) { |
| 4222 | int mask; |
| 4223 | |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4224 | if (HAS_RC6p(dev)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4225 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 4226 | INTEL_RC6pp_ENABLE; |
| 4227 | else |
| 4228 | mask = INTEL_RC6_ENABLE; |
| 4229 | |
| 4230 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 4231 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 4232 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4233 | |
| 4234 | return enable_rc6 & mask; |
| 4235 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4236 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 4237 | /* Disable RC6 on Ironlake */ |
| 4238 | if (INTEL_INFO(dev)->gen == 5) |
| 4239 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4240 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4241 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 4242 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4243 | |
| 4244 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4245 | } |
| 4246 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4247 | int intel_enable_rc6(const struct drm_device *dev) |
| 4248 | { |
| 4249 | return i915.enable_rc6; |
| 4250 | } |
| 4251 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4252 | static void gen6_init_rps_frequencies(struct drm_device *dev) |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4253 | { |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4254 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4255 | uint32_t rp_state_cap; |
| 4256 | u32 ddcc_status = 0; |
| 4257 | int ret; |
| 4258 | |
| 4259 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4260 | /* All of these values are in units of 50MHz */ |
| 4261 | dev_priv->rps.cur_freq = 0; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4262 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4263 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4264 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4265 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
Akash Goel | cee991c | 2015-03-06 11:07:16 +0530 | [diff] [blame] | 4266 | if (IS_SKYLAKE(dev)) { |
| 4267 | /* Store the frequency values in 16.66 MHZ units, which is |
| 4268 | the natural hardware unit for SKL */ |
| 4269 | dev_priv->rps.rp0_freq *= GEN9_FREQ_SCALER; |
| 4270 | dev_priv->rps.rp1_freq *= GEN9_FREQ_SCALER; |
| 4271 | dev_priv->rps.min_freq *= GEN9_FREQ_SCALER; |
| 4272 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4273 | /* hw_max = RP0 until we check for overclocking */ |
| 4274 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 4275 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4276 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 4277 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
| 4278 | ret = sandybridge_pcode_read(dev_priv, |
| 4279 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 4280 | &ddcc_status); |
| 4281 | if (0 == ret) |
| 4282 | dev_priv->rps.efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 4283 | clamp_t(u8, |
| 4284 | ((ddcc_status >> 8) & 0xff), |
| 4285 | dev_priv->rps.min_freq, |
| 4286 | dev_priv->rps.max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4287 | } |
| 4288 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4289 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4290 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4291 | /* Preserve min/max settings in case of re-init */ |
| 4292 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4293 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4294 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4295 | if (dev_priv->rps.min_freq_softlimit == 0) { |
| 4296 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 4297 | dev_priv->rps.min_freq_softlimit = |
Tom O'Rourke | f4ab408 | 2014-11-19 14:21:53 -0800 | [diff] [blame] | 4298 | /* max(RPe, 450 MHz) */ |
| 4299 | max(dev_priv->rps.efficient_freq, (u8) 9); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4300 | else |
| 4301 | dev_priv->rps.min_freq_softlimit = |
| 4302 | dev_priv->rps.min_freq; |
| 4303 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4304 | } |
| 4305 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4306 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4307 | static void gen9_enable_rps(struct drm_device *dev) |
| 4308 | { |
| 4309 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4310 | |
| 4311 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 4312 | |
Damien Lespiau | ba1c554 | 2015-01-16 18:07:26 +0000 | [diff] [blame] | 4313 | gen6_init_rps_frequencies(dev); |
| 4314 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4315 | /* Program defaults and thresholds for RPS*/ |
| 4316 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4317 | GEN9_FREQUENCY(dev_priv->rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4318 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4319 | /* 1 second timeout*/ |
| 4320 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 4321 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 4322 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4323 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4324 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4325 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 4326 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 4327 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
| 4328 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
| 4329 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4330 | |
| 4331 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 4332 | } |
| 4333 | |
| 4334 | static void gen9_enable_rc6(struct drm_device *dev) |
| 4335 | { |
| 4336 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4337 | struct intel_engine_cs *ring; |
| 4338 | uint32_t rc6_mask = 0; |
| 4339 | int unused; |
| 4340 | |
| 4341 | /* 1a: Software RC state - RC0 */ |
| 4342 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4343 | |
| 4344 | /* 1b: Get forcewake during program sequence. Although the driver |
| 4345 | * 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] | 4346 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4347 | |
| 4348 | /* 2a: Disable RC states. */ |
| 4349 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4350 | |
| 4351 | /* 2b: Program RC6 thresholds.*/ |
| 4352 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
| 4353 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4354 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4355 | for_each_ring(ring, dev_priv, unused) |
| 4356 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4357 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4358 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
| 4359 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4360 | /* 2c: Program Coarse Power Gating Policies. */ |
| 4361 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 4362 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 4363 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4364 | /* 3a: Enable RC6 */ |
| 4365 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4366 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 4367 | DRM_INFO("RC6 %s\n", (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 4368 | "on" : "off"); |
| 4369 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4370 | GEN6_RC_CTL_EI_MODE(1) | |
| 4371 | rc6_mask); |
| 4372 | |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 4373 | /* |
| 4374 | * 3b: Enable Coarse Power Gating only when RC6 is enabled. |
| 4375 | * WaDisableRenderPowerGating:skl,bxt - Render PG need to be disabled with RC6. |
| 4376 | */ |
Sagar Kamble | a4104c5 | 2015-04-10 14:11:29 +0530 | [diff] [blame] | 4377 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 4378 | GEN9_MEDIA_PG_ENABLE : 0); |
Sagar Kamble | a4104c5 | 2015-04-10 14:11:29 +0530 | [diff] [blame] | 4379 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4380 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4381 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4382 | |
| 4383 | } |
| 4384 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4385 | static void gen8_enable_rps(struct drm_device *dev) |
| 4386 | { |
| 4387 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4388 | struct intel_engine_cs *ring; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4389 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4390 | int unused; |
| 4391 | |
| 4392 | /* 1a: Software RC state - RC0 */ |
| 4393 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4394 | |
| 4395 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 4396 | * 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] | 4397 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4398 | |
| 4399 | /* 2a: Disable RC states. */ |
| 4400 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4401 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4402 | /* Initialize rps frequencies */ |
| 4403 | gen6_init_rps_frequencies(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4404 | |
| 4405 | /* 2b: Program RC6 thresholds.*/ |
| 4406 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4407 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4408 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4409 | for_each_ring(ring, dev_priv, unused) |
| 4410 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4411 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4412 | if (IS_BROADWELL(dev)) |
| 4413 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 4414 | else |
| 4415 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4416 | |
| 4417 | /* 3: Enable RC6 */ |
| 4418 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4419 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 4420 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4421 | if (IS_BROADWELL(dev)) |
| 4422 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4423 | GEN7_RC_CTL_TO_MODE | |
| 4424 | rc6_mask); |
| 4425 | else |
| 4426 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4427 | GEN6_RC_CTL_EI_MODE(1) | |
| 4428 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4429 | |
| 4430 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 4431 | I915_WRITE(GEN6_RPNSWREQ, |
| 4432 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 4433 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4434 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4435 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 4436 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4437 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4438 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 4439 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 4440 | dev_priv->rps.max_freq_softlimit << 24 | |
| 4441 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4442 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4443 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 4444 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 4445 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 4446 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4447 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4448 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4449 | |
| 4450 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4451 | I915_WRITE(GEN6_RP_CONTROL, |
| 4452 | GEN6_RP_MEDIA_TURBO | |
| 4453 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4454 | GEN6_RP_MEDIA_IS_GFX | |
| 4455 | GEN6_RP_ENABLE | |
| 4456 | GEN6_RP_UP_BUSY_AVG | |
| 4457 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4458 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4459 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4460 | |
Tom O'Rourke | c7f3153 | 2014-11-19 14:21:54 -0800 | [diff] [blame] | 4461 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4462 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4463 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4464 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4467 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4468 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4469 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4470 | struct intel_engine_cs *ring; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4471 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4472 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4473 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4474 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4475 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4476 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4477 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4478 | /* Here begins a magic sequence of register writes to enable |
| 4479 | * auto-downclocking. |
| 4480 | * |
| 4481 | * Perhaps there might be some value in exposing these to |
| 4482 | * userspace... |
| 4483 | */ |
| 4484 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4485 | |
| 4486 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 4487 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 4488 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 4489 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4490 | } |
| 4491 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4492 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4493 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4494 | /* Initialize rps frequencies */ |
| 4495 | gen6_init_rps_frequencies(dev); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 4496 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4497 | /* disable the counters and set deterministic thresholds */ |
| 4498 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4499 | |
| 4500 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 4501 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 4502 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 4503 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4504 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4505 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 4506 | for_each_ring(ring, dev_priv, i) |
| 4507 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4508 | |
| 4509 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4510 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 4511 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 4512 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 4513 | else |
| 4514 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 4515 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4516 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 4517 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4518 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4519 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 4520 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 4521 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 4522 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4523 | /* We don't use those on Haswell */ |
| 4524 | if (!IS_HASWELL(dev)) { |
| 4525 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 4526 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4527 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4528 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 4529 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 4530 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4531 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4532 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4533 | |
| 4534 | I915_WRITE(GEN6_RC_CONTROL, |
| 4535 | rc6_mask | |
| 4536 | GEN6_RC_CTL_EI_MODE(1) | |
| 4537 | GEN6_RC_CTL_HW_ENABLE); |
| 4538 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4539 | /* Power down if completely idle for over 50ms */ |
| 4540 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4541 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4542 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4543 | 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] | 4544 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4545 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4546 | |
| 4547 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 4548 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 4549 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4550 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4551 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4552 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4553 | } |
| 4554 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4555 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4556 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4557 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4558 | rc6vids = 0; |
| 4559 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4560 | if (IS_GEN6(dev) && ret) { |
| 4561 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4562 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4563 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4564 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4565 | rc6vids &= 0xffff00; |
| 4566 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4567 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4568 | if (ret) |
| 4569 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4570 | } |
| 4571 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4572 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4573 | } |
| 4574 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4575 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4576 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4577 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4578 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4579 | unsigned int gpu_freq; |
| 4580 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4581 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4582 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4583 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4584 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4585 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4586 | policy = cpufreq_cpu_get(0); |
| 4587 | if (policy) { |
| 4588 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4589 | cpufreq_cpu_put(policy); |
| 4590 | } else { |
| 4591 | /* |
| 4592 | * Default to measured freq if none found, PCU will ensure we |
| 4593 | * don't go over |
| 4594 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4595 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4596 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4597 | |
| 4598 | /* Convert from kHz to MHz */ |
| 4599 | max_ia_freq /= 1000; |
| 4600 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4601 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4602 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4603 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4604 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4605 | /* |
| 4606 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4607 | * to use for memory access. We do this by specifying the IA frequency |
| 4608 | * the PCU should use as a reference to determine the ring frequency. |
| 4609 | */ |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4610 | 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] | 4611 | gpu_freq--) { |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4612 | int diff = dev_priv->rps.max_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4613 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4614 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4615 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4616 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4617 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4618 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4619 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4620 | ring_freq = max(min_ring_freq, ring_freq); |
| 4621 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4622 | } else { |
| 4623 | /* On older processors, there is no separate ring |
| 4624 | * clock domain, so in order to boost the bandwidth |
| 4625 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4626 | * |
| 4627 | * For GPU frequencies less than 750MHz, |
| 4628 | * just use the lowest ring freq. |
| 4629 | */ |
| 4630 | if (gpu_freq < min_freq) |
| 4631 | ia_freq = 800; |
| 4632 | else |
| 4633 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4634 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4635 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4636 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4637 | sandybridge_pcode_write(dev_priv, |
| 4638 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4639 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4640 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4641 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4642 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4643 | } |
| 4644 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4645 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4646 | { |
| 4647 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4648 | |
| 4649 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4650 | return; |
| 4651 | |
| 4652 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4653 | __gen6_update_ring_freq(dev); |
| 4654 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4655 | } |
| 4656 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4657 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4658 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4659 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4660 | u32 val, rp0; |
| 4661 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4662 | if (dev->pdev->revision >= 0x20) { |
| 4663 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4664 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4665 | switch (INTEL_INFO(dev)->eu_total) { |
| 4666 | case 8: |
| 4667 | /* (2 * 4) config */ |
| 4668 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 4669 | break; |
| 4670 | case 12: |
| 4671 | /* (2 * 6) config */ |
| 4672 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 4673 | break; |
| 4674 | case 16: |
| 4675 | /* (2 * 8) config */ |
| 4676 | default: |
| 4677 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 4678 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 4679 | break; |
| 4680 | } |
| 4681 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 4682 | } else { |
| 4683 | /* For pre-production hardware */ |
| 4684 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4685 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4686 | PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4687 | } |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4688 | return rp0; |
| 4689 | } |
| 4690 | |
| 4691 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4692 | { |
| 4693 | u32 val, rpe; |
| 4694 | |
| 4695 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4696 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4697 | |
| 4698 | return rpe; |
| 4699 | } |
| 4700 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4701 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4702 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4703 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4704 | u32 val, rp1; |
| 4705 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4706 | if (dev->pdev->revision >= 0x20) { |
| 4707 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 4708 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 4709 | } else { |
| 4710 | /* For pre-production hardware */ |
| 4711 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4712 | rp1 = ((val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4713 | PUNIT_GPU_STATUS_MAX_FREQ_MASK); |
| 4714 | } |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4715 | return rp1; |
| 4716 | } |
| 4717 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4718 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4719 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4720 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4721 | u32 val, rpn; |
| 4722 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4723 | if (dev->pdev->revision >= 0x20) { |
| 4724 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 4725 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 4726 | FB_GFX_FREQ_FUSE_MASK); |
| 4727 | } else { /* For pre-production hardware */ |
| 4728 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4729 | rpn = ((val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & |
| 4730 | PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK); |
| 4731 | } |
| 4732 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4733 | return rpn; |
| 4734 | } |
| 4735 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4736 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4737 | { |
| 4738 | u32 val, rp1; |
| 4739 | |
| 4740 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4741 | |
| 4742 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4743 | |
| 4744 | return rp1; |
| 4745 | } |
| 4746 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4747 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4748 | { |
| 4749 | u32 val, rp0; |
| 4750 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4751 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4752 | |
| 4753 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4754 | /* Clamp to max */ |
| 4755 | rp0 = min_t(u32, rp0, 0xea); |
| 4756 | |
| 4757 | return rp0; |
| 4758 | } |
| 4759 | |
| 4760 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4761 | { |
| 4762 | u32 val, rpe; |
| 4763 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4764 | 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] | 4765 | 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] | 4766 | 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] | 4767 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4768 | |
| 4769 | return rpe; |
| 4770 | } |
| 4771 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4772 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4773 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4774 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4777 | /* Check that the pctx buffer wasn't move under us. */ |
| 4778 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4779 | { |
| 4780 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4781 | |
| 4782 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4783 | dev_priv->vlv_pctx->stolen->start); |
| 4784 | } |
| 4785 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4786 | |
| 4787 | /* Check that the pcbr address is not empty. */ |
| 4788 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4789 | { |
| 4790 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4791 | |
| 4792 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4793 | } |
| 4794 | |
| 4795 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4796 | { |
| 4797 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4798 | unsigned long pctx_paddr, paddr; |
| 4799 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4800 | u32 pcbr; |
| 4801 | int pctx_size = 32*1024; |
| 4802 | |
| 4803 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4804 | |
| 4805 | pcbr = I915_READ(VLV_PCBR); |
| 4806 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4807 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4808 | paddr = (dev_priv->mm.stolen_base + |
| 4809 | (gtt->stolen_size - pctx_size)); |
| 4810 | |
| 4811 | pctx_paddr = (paddr & (~4095)); |
| 4812 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4813 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4814 | |
| 4815 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4816 | } |
| 4817 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4818 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4819 | { |
| 4820 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4821 | struct drm_i915_gem_object *pctx; |
| 4822 | unsigned long pctx_paddr; |
| 4823 | u32 pcbr; |
| 4824 | int pctx_size = 24*1024; |
| 4825 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4826 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4827 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4828 | pcbr = I915_READ(VLV_PCBR); |
| 4829 | if (pcbr) { |
| 4830 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4831 | int pcbr_offset; |
| 4832 | |
| 4833 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4834 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4835 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4836 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4837 | pctx_size); |
| 4838 | goto out; |
| 4839 | } |
| 4840 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4841 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 4842 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4843 | /* |
| 4844 | * From the Gunit register HAS: |
| 4845 | * The Gfx driver is expected to program this register and ensure |
| 4846 | * proper allocation within Gfx stolen memory. For example, this |
| 4847 | * register should be programmed such than the PCBR range does not |
| 4848 | * overlap with other ranges, such as the frame buffer, protected |
| 4849 | * memory, or any other relevant ranges. |
| 4850 | */ |
| 4851 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4852 | if (!pctx) { |
| 4853 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4854 | return; |
| 4855 | } |
| 4856 | |
| 4857 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4858 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4859 | |
| 4860 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4861 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4862 | dev_priv->vlv_pctx = pctx; |
| 4863 | } |
| 4864 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4865 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4866 | { |
| 4867 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4868 | |
| 4869 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4870 | return; |
| 4871 | |
| 4872 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 4873 | dev_priv->vlv_pctx = NULL; |
| 4874 | } |
| 4875 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4876 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 4877 | { |
| 4878 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4879 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4880 | |
| 4881 | valleyview_setup_pctx(dev); |
| 4882 | |
| 4883 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4884 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4885 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4886 | switch ((val >> 6) & 3) { |
| 4887 | case 0: |
| 4888 | case 1: |
| 4889 | dev_priv->mem_freq = 800; |
| 4890 | break; |
| 4891 | case 2: |
| 4892 | dev_priv->mem_freq = 1066; |
| 4893 | break; |
| 4894 | case 3: |
| 4895 | dev_priv->mem_freq = 1333; |
| 4896 | break; |
| 4897 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4898 | 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] | 4899 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4900 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 4901 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4902 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4903 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4904 | dev_priv->rps.max_freq); |
| 4905 | |
| 4906 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 4907 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4908 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4909 | dev_priv->rps.efficient_freq); |
| 4910 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4911 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 4912 | 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] | 4913 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4914 | dev_priv->rps.rp1_freq); |
| 4915 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4916 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 4917 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4918 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4919 | dev_priv->rps.min_freq); |
| 4920 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4921 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4922 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4923 | /* Preserve min/max settings in case of re-init */ |
| 4924 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4925 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4926 | |
| 4927 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4928 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4929 | |
| 4930 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4931 | } |
| 4932 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4933 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4934 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4935 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4936 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4937 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4938 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4939 | |
| 4940 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4941 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 4942 | mutex_lock(&dev_priv->dpio_lock); |
| 4943 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
| 4944 | mutex_unlock(&dev_priv->dpio_lock); |
| 4945 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4946 | switch ((val >> 2) & 0x7) { |
| 4947 | case 0: |
| 4948 | case 1: |
| 4949 | dev_priv->rps.cz_freq = 200; |
| 4950 | dev_priv->mem_freq = 1600; |
| 4951 | break; |
| 4952 | case 2: |
| 4953 | dev_priv->rps.cz_freq = 267; |
| 4954 | dev_priv->mem_freq = 1600; |
| 4955 | break; |
| 4956 | case 3: |
| 4957 | dev_priv->rps.cz_freq = 333; |
| 4958 | dev_priv->mem_freq = 2000; |
| 4959 | break; |
| 4960 | case 4: |
| 4961 | dev_priv->rps.cz_freq = 320; |
| 4962 | dev_priv->mem_freq = 1600; |
| 4963 | break; |
| 4964 | case 5: |
| 4965 | dev_priv->rps.cz_freq = 400; |
| 4966 | dev_priv->mem_freq = 1600; |
| 4967 | break; |
| 4968 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4969 | 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] | 4970 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4971 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4972 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4973 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4974 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4975 | dev_priv->rps.max_freq); |
| 4976 | |
| 4977 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4978 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4979 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4980 | dev_priv->rps.efficient_freq); |
| 4981 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4982 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4983 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4984 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4985 | dev_priv->rps.rp1_freq); |
| 4986 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4987 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4988 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4989 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4990 | dev_priv->rps.min_freq); |
| 4991 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4992 | WARN_ONCE((dev_priv->rps.max_freq | |
| 4993 | dev_priv->rps.efficient_freq | |
| 4994 | dev_priv->rps.rp1_freq | |
| 4995 | dev_priv->rps.min_freq) & 1, |
| 4996 | "Odd GPU freq values\n"); |
| 4997 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4998 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4999 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5000 | /* Preserve min/max settings in case of re-init */ |
| 5001 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 5002 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 5003 | |
| 5004 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 5005 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 5006 | |
| 5007 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5008 | } |
| 5009 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5010 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 5011 | { |
| 5012 | valleyview_cleanup_pctx(dev); |
| 5013 | } |
| 5014 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5015 | static void cherryview_enable_rps(struct drm_device *dev) |
| 5016 | { |
| 5017 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5018 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5019 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5020 | int i; |
| 5021 | |
| 5022 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 5023 | |
| 5024 | gtfifodbg = I915_READ(GTFIFODBG); |
| 5025 | if (gtfifodbg) { |
| 5026 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 5027 | gtfifodbg); |
| 5028 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5029 | } |
| 5030 | |
| 5031 | cherryview_check_pctx(dev_priv); |
| 5032 | |
| 5033 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 5034 | * 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] | 5035 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5036 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 5037 | /* Disable RC states. */ |
| 5038 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5039 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5040 | /* 2a: Program RC6 thresholds.*/ |
| 5041 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 5042 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 5043 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 5044 | |
| 5045 | for_each_ring(ring, dev_priv, i) |
| 5046 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5047 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 5048 | |
Deepak S | f4f71c7 | 2015-03-28 15:23:35 +0530 | [diff] [blame] | 5049 | /* TO threshold set to 500 us ( 0x186 * 1.28 us) */ |
| 5050 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x186); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5051 | |
| 5052 | /* allows RC6 residency counter to work */ |
| 5053 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 5054 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 5055 | VLV_MEDIA_RC6_COUNT_EN | |
| 5056 | VLV_RENDER_RC6_COUNT_EN)); |
| 5057 | |
| 5058 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 5059 | pcbr = I915_READ(VLV_PCBR); |
| 5060 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5061 | /* 3: Enable RC6 */ |
| 5062 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 5063 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 5064 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5065 | |
| 5066 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 5067 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5068 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 5069 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5070 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5071 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5072 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5073 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5074 | |
| 5075 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5076 | |
| 5077 | /* 5: Enable RPS */ |
| 5078 | I915_WRITE(GEN6_RP_CONTROL, |
| 5079 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 5080 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5081 | GEN6_RP_ENABLE | |
| 5082 | GEN6_RP_UP_BUSY_AVG | |
| 5083 | GEN6_RP_DOWN_IDLE_AVG); |
| 5084 | |
| 5085 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5086 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 5087 | /* RPS code assumes GPLL is used */ |
| 5088 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 5089 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 5090 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5091 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5092 | |
| 5093 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 5094 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5095 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5096 | dev_priv->rps.cur_freq); |
| 5097 | |
| 5098 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5099 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5100 | dev_priv->rps.efficient_freq); |
| 5101 | |
| 5102 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 5103 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5104 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5105 | } |
| 5106 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5107 | static void valleyview_enable_rps(struct drm_device *dev) |
| 5108 | { |
| 5109 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5110 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 5111 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5112 | int i; |
| 5113 | |
| 5114 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 5115 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5116 | valleyview_check_pctx(dev_priv); |
| 5117 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5118 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 5119 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 5120 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5121 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5122 | } |
| 5123 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 5124 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5125 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5126 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 5127 | /* Disable RC states. */ |
| 5128 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5129 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 5130 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5131 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5132 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5133 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5134 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5135 | |
| 5136 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5137 | |
| 5138 | I915_WRITE(GEN6_RP_CONTROL, |
| 5139 | GEN6_RP_MEDIA_TURBO | |
| 5140 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 5141 | GEN6_RP_MEDIA_IS_GFX | |
| 5142 | GEN6_RP_ENABLE | |
| 5143 | GEN6_RP_UP_BUSY_AVG | |
| 5144 | GEN6_RP_DOWN_IDLE_CONT); |
| 5145 | |
| 5146 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 5147 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 5148 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 5149 | |
| 5150 | for_each_ring(ring, dev_priv, i) |
| 5151 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5152 | |
Jesse Barnes | 2f0aa30 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 5153 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5154 | |
| 5155 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5156 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5157 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 5158 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5159 | VLV_MEDIA_RC6_COUNT_EN | |
| 5160 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5161 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5162 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 5163 | 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] | 5164 | |
| 5165 | intel_print_rc6_info(dev, rc6_mode); |
| 5166 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5167 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5168 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 5169 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5170 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 5171 | /* RPS code assumes GPLL is used */ |
| 5172 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 5173 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 5174 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5175 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5176 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5177 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5178 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5179 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5180 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5181 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5182 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5183 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5184 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5185 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5186 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5187 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5188 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5191 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 5192 | { |
| 5193 | unsigned long freq; |
| 5194 | int div = (vidfreq & 0x3f0000) >> 16; |
| 5195 | int post = (vidfreq & 0x3000) >> 12; |
| 5196 | int pre = (vidfreq & 0x7); |
| 5197 | |
| 5198 | if (!pre) |
| 5199 | return 0; |
| 5200 | |
| 5201 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 5202 | |
| 5203 | return freq; |
| 5204 | } |
| 5205 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5206 | static const struct cparams { |
| 5207 | u16 i; |
| 5208 | u16 t; |
| 5209 | u16 m; |
| 5210 | u16 c; |
| 5211 | } cparams[] = { |
| 5212 | { 1, 1333, 301, 28664 }, |
| 5213 | { 1, 1066, 294, 24460 }, |
| 5214 | { 1, 800, 294, 25192 }, |
| 5215 | { 0, 1333, 276, 27605 }, |
| 5216 | { 0, 1066, 276, 27605 }, |
| 5217 | { 0, 800, 231, 23784 }, |
| 5218 | }; |
| 5219 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5220 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5221 | { |
| 5222 | u64 total_count, diff, ret; |
| 5223 | u32 count1, count2, count3, m = 0, c = 0; |
| 5224 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 5225 | int i; |
| 5226 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5227 | assert_spin_locked(&mchdev_lock); |
| 5228 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5229 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5230 | |
| 5231 | /* Prevent division-by-zero if we are asking too fast. |
| 5232 | * Also, we don't get interesting results if we are polling |
| 5233 | * faster than once in 10ms, so just return the saved value |
| 5234 | * in such cases. |
| 5235 | */ |
| 5236 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5237 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5238 | |
| 5239 | count1 = I915_READ(DMIEC); |
| 5240 | count2 = I915_READ(DDREC); |
| 5241 | count3 = I915_READ(CSIEC); |
| 5242 | |
| 5243 | total_count = count1 + count2 + count3; |
| 5244 | |
| 5245 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5246 | if (total_count < dev_priv->ips.last_count1) { |
| 5247 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5248 | diff += total_count; |
| 5249 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5250 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5254 | if (cparams[i].i == dev_priv->ips.c_m && |
| 5255 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5256 | m = cparams[i].m; |
| 5257 | c = cparams[i].c; |
| 5258 | break; |
| 5259 | } |
| 5260 | } |
| 5261 | |
| 5262 | diff = div_u64(diff, diff1); |
| 5263 | ret = ((m * diff) + c); |
| 5264 | ret = div_u64(ret, 10); |
| 5265 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5266 | dev_priv->ips.last_count1 = total_count; |
| 5267 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5268 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5269 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5270 | |
| 5271 | return ret; |
| 5272 | } |
| 5273 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5274 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 5275 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5276 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5277 | unsigned long val; |
| 5278 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5279 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5280 | return 0; |
| 5281 | |
| 5282 | spin_lock_irq(&mchdev_lock); |
| 5283 | |
| 5284 | val = __i915_chipset_val(dev_priv); |
| 5285 | |
| 5286 | spin_unlock_irq(&mchdev_lock); |
| 5287 | |
| 5288 | return val; |
| 5289 | } |
| 5290 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5291 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 5292 | { |
| 5293 | unsigned long m, x, b; |
| 5294 | u32 tsfs; |
| 5295 | |
| 5296 | tsfs = I915_READ(TSFS); |
| 5297 | |
| 5298 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 5299 | x = I915_READ8(TR1); |
| 5300 | |
| 5301 | b = tsfs & TSFS_INTR_MASK; |
| 5302 | |
| 5303 | return ((m * x) / 127) - b; |
| 5304 | } |
| 5305 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5306 | static int _pxvid_to_vd(u8 pxvid) |
| 5307 | { |
| 5308 | if (pxvid == 0) |
| 5309 | return 0; |
| 5310 | |
| 5311 | if (pxvid >= 8 && pxvid < 31) |
| 5312 | pxvid = 31; |
| 5313 | |
| 5314 | return (pxvid + 2) * 125; |
| 5315 | } |
| 5316 | |
| 5317 | 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] | 5318 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5319 | struct drm_device *dev = dev_priv->dev; |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5320 | const int vd = _pxvid_to_vd(pxvid); |
| 5321 | const int vm = vd - 1125; |
| 5322 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5323 | if (INTEL_INFO(dev)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5324 | return vm > 0 ? vm : 0; |
| 5325 | |
| 5326 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5327 | } |
| 5328 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5329 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5330 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5331 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5332 | u32 count; |
| 5333 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5334 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5335 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5336 | now = ktime_get_raw_ns(); |
| 5337 | diffms = now - dev_priv->ips.last_time2; |
| 5338 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5339 | |
| 5340 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5341 | if (!diffms) |
| 5342 | return; |
| 5343 | |
| 5344 | count = I915_READ(GFXEC); |
| 5345 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5346 | if (count < dev_priv->ips.last_count2) { |
| 5347 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5348 | diff += count; |
| 5349 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5350 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5351 | } |
| 5352 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5353 | dev_priv->ips.last_count2 = count; |
| 5354 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5355 | |
| 5356 | /* More magic constants... */ |
| 5357 | diff = diff * 1181; |
| 5358 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5359 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5360 | } |
| 5361 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5362 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 5363 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5364 | struct drm_device *dev = dev_priv->dev; |
| 5365 | |
| 5366 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5367 | return; |
| 5368 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5369 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5370 | |
| 5371 | __i915_update_gfx_val(dev_priv); |
| 5372 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5373 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5374 | } |
| 5375 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5376 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5377 | { |
| 5378 | unsigned long t, corr, state1, corr2, state2; |
| 5379 | u32 pxvid, ext_v; |
| 5380 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5381 | assert_spin_locked(&mchdev_lock); |
| 5382 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5383 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5384 | pxvid = (pxvid >> 24) & 0x7f; |
| 5385 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5386 | |
| 5387 | state1 = ext_v; |
| 5388 | |
| 5389 | t = i915_mch_val(dev_priv); |
| 5390 | |
| 5391 | /* Revel in the empirically derived constants */ |
| 5392 | |
| 5393 | /* Correction factor in 1/100000 units */ |
| 5394 | if (t > 80) |
| 5395 | corr = ((t * 2349) + 135940); |
| 5396 | else if (t >= 50) |
| 5397 | corr = ((t * 964) + 29317); |
| 5398 | else /* < 50 */ |
| 5399 | corr = ((t * 301) + 1004); |
| 5400 | |
| 5401 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5402 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5403 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5404 | |
| 5405 | state2 = (corr2 * state1) / 10000; |
| 5406 | state2 /= 100; /* convert to mW */ |
| 5407 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5408 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5409 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5410 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5411 | } |
| 5412 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5413 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5414 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5415 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5416 | unsigned long val; |
| 5417 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5418 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5419 | return 0; |
| 5420 | |
| 5421 | spin_lock_irq(&mchdev_lock); |
| 5422 | |
| 5423 | val = __i915_gfx_val(dev_priv); |
| 5424 | |
| 5425 | spin_unlock_irq(&mchdev_lock); |
| 5426 | |
| 5427 | return val; |
| 5428 | } |
| 5429 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5430 | /** |
| 5431 | * i915_read_mch_val - return value for IPS use |
| 5432 | * |
| 5433 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5434 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5435 | */ |
| 5436 | unsigned long i915_read_mch_val(void) |
| 5437 | { |
| 5438 | struct drm_i915_private *dev_priv; |
| 5439 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5440 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5441 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5442 | if (!i915_mch_dev) |
| 5443 | goto out_unlock; |
| 5444 | dev_priv = i915_mch_dev; |
| 5445 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5446 | chipset_val = __i915_chipset_val(dev_priv); |
| 5447 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5448 | |
| 5449 | ret = chipset_val + graphics_val; |
| 5450 | |
| 5451 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5452 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5453 | |
| 5454 | return ret; |
| 5455 | } |
| 5456 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5457 | |
| 5458 | /** |
| 5459 | * i915_gpu_raise - raise GPU frequency limit |
| 5460 | * |
| 5461 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5462 | */ |
| 5463 | bool i915_gpu_raise(void) |
| 5464 | { |
| 5465 | struct drm_i915_private *dev_priv; |
| 5466 | bool ret = true; |
| 5467 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5468 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5469 | if (!i915_mch_dev) { |
| 5470 | ret = false; |
| 5471 | goto out_unlock; |
| 5472 | } |
| 5473 | dev_priv = i915_mch_dev; |
| 5474 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5475 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5476 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5477 | |
| 5478 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5479 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5480 | |
| 5481 | return ret; |
| 5482 | } |
| 5483 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5484 | |
| 5485 | /** |
| 5486 | * i915_gpu_lower - lower GPU frequency limit |
| 5487 | * |
| 5488 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5489 | * frequency maximum. |
| 5490 | */ |
| 5491 | bool i915_gpu_lower(void) |
| 5492 | { |
| 5493 | struct drm_i915_private *dev_priv; |
| 5494 | bool ret = true; |
| 5495 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5496 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5497 | if (!i915_mch_dev) { |
| 5498 | ret = false; |
| 5499 | goto out_unlock; |
| 5500 | } |
| 5501 | dev_priv = i915_mch_dev; |
| 5502 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5503 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 5504 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5505 | |
| 5506 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5507 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5508 | |
| 5509 | return ret; |
| 5510 | } |
| 5511 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 5512 | |
| 5513 | /** |
| 5514 | * i915_gpu_busy - indicate GPU business to IPS |
| 5515 | * |
| 5516 | * Tell the IPS driver whether or not the GPU is busy. |
| 5517 | */ |
| 5518 | bool i915_gpu_busy(void) |
| 5519 | { |
| 5520 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5521 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5522 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5523 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5524 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5525 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5526 | if (!i915_mch_dev) |
| 5527 | goto out_unlock; |
| 5528 | dev_priv = i915_mch_dev; |
| 5529 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5530 | for_each_ring(ring, dev_priv, i) |
| 5531 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 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_busy); |
| 5539 | |
| 5540 | /** |
| 5541 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5542 | * |
| 5543 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5544 | * current frequency to the default. |
| 5545 | */ |
| 5546 | bool i915_gpu_turbo_disable(void) |
| 5547 | { |
| 5548 | struct drm_i915_private *dev_priv; |
| 5549 | bool ret = true; |
| 5550 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5551 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5552 | if (!i915_mch_dev) { |
| 5553 | ret = false; |
| 5554 | goto out_unlock; |
| 5555 | } |
| 5556 | dev_priv = i915_mch_dev; |
| 5557 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5558 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5559 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5560 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5561 | ret = false; |
| 5562 | |
| 5563 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5564 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5565 | |
| 5566 | return ret; |
| 5567 | } |
| 5568 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5569 | |
| 5570 | /** |
| 5571 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5572 | * IPS got loaded first. |
| 5573 | * |
| 5574 | * This awkward dance is so that neither module has to depend on the |
| 5575 | * other in order for IPS to do the appropriate communication of |
| 5576 | * GPU turbo limits to i915. |
| 5577 | */ |
| 5578 | static void |
| 5579 | ips_ping_for_i915_load(void) |
| 5580 | { |
| 5581 | void (*link)(void); |
| 5582 | |
| 5583 | link = symbol_get(ips_link_to_i915_driver); |
| 5584 | if (link) { |
| 5585 | link(); |
| 5586 | symbol_put(ips_link_to_i915_driver); |
| 5587 | } |
| 5588 | } |
| 5589 | |
| 5590 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5591 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5592 | /* We only register the i915 ips part with intel-ips once everything is |
| 5593 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5594 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5595 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5596 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5597 | |
| 5598 | ips_ping_for_i915_load(); |
| 5599 | } |
| 5600 | |
| 5601 | void intel_gpu_ips_teardown(void) |
| 5602 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5603 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5604 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5605 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5606 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5607 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5608 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5609 | { |
| 5610 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5611 | u32 lcfuse; |
| 5612 | u8 pxw[16]; |
| 5613 | int i; |
| 5614 | |
| 5615 | /* Disable to program */ |
| 5616 | I915_WRITE(ECR, 0); |
| 5617 | POSTING_READ(ECR); |
| 5618 | |
| 5619 | /* Program energy weights for various events */ |
| 5620 | I915_WRITE(SDEW, 0x15040d00); |
| 5621 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5622 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5623 | I915_WRITE(CSIEW2, 0x04000004); |
| 5624 | |
| 5625 | for (i = 0; i < 5; i++) |
| 5626 | I915_WRITE(PEW + (i * 4), 0); |
| 5627 | for (i = 0; i < 3; i++) |
| 5628 | I915_WRITE(DEW + (i * 4), 0); |
| 5629 | |
| 5630 | /* Program P-state weights to account for frequency power adjustment */ |
| 5631 | for (i = 0; i < 16; i++) { |
| 5632 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5633 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5634 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5635 | PXVFREQ_PX_SHIFT; |
| 5636 | unsigned long val; |
| 5637 | |
| 5638 | val = vid * vid; |
| 5639 | val *= (freq / 1000); |
| 5640 | val *= 255; |
| 5641 | val /= (127*127*900); |
| 5642 | if (val > 0xff) |
| 5643 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5644 | pxw[i] = val; |
| 5645 | } |
| 5646 | /* Render standby states get 0 weight */ |
| 5647 | pxw[14] = 0; |
| 5648 | pxw[15] = 0; |
| 5649 | |
| 5650 | for (i = 0; i < 4; i++) { |
| 5651 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 5652 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 5653 | I915_WRITE(PXW + (i * 4), val); |
| 5654 | } |
| 5655 | |
| 5656 | /* Adjust magic regs to magic values (more experimental results) */ |
| 5657 | I915_WRITE(OGW0, 0); |
| 5658 | I915_WRITE(OGW1, 0); |
| 5659 | I915_WRITE(EG0, 0x00007f00); |
| 5660 | I915_WRITE(EG1, 0x0000000e); |
| 5661 | I915_WRITE(EG2, 0x000e0000); |
| 5662 | I915_WRITE(EG3, 0x68000300); |
| 5663 | I915_WRITE(EG4, 0x42000000); |
| 5664 | I915_WRITE(EG5, 0x00140031); |
| 5665 | I915_WRITE(EG6, 0); |
| 5666 | I915_WRITE(EG7, 0); |
| 5667 | |
| 5668 | for (i = 0; i < 8; i++) |
| 5669 | I915_WRITE(PXWL + (i * 4), 0); |
| 5670 | |
| 5671 | /* Enable PMON + select events */ |
| 5672 | I915_WRITE(ECR, 0x80000019); |
| 5673 | |
| 5674 | lcfuse = I915_READ(LCFUSE02); |
| 5675 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5676 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5677 | } |
| 5678 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5679 | void intel_init_gt_powersave(struct drm_device *dev) |
| 5680 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5681 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 5682 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5683 | if (IS_CHERRYVIEW(dev)) |
| 5684 | cherryview_init_gt_powersave(dev); |
| 5685 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5686 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5687 | } |
| 5688 | |
| 5689 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 5690 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5691 | if (IS_CHERRYVIEW(dev)) |
| 5692 | return; |
| 5693 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5694 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5695 | } |
| 5696 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5697 | static void gen6_suspend_rps(struct drm_device *dev) |
| 5698 | { |
| 5699 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5700 | |
| 5701 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 5702 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5703 | gen6_disable_rps_interrupts(dev); |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5704 | } |
| 5705 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5706 | /** |
| 5707 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 5708 | * @dev: drm device |
| 5709 | * |
| 5710 | * We don't want to disable RC6 or other features here, we just want |
| 5711 | * to make sure any work we've queued has finished and won't bother |
| 5712 | * us while we're suspended. |
| 5713 | */ |
| 5714 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 5715 | { |
| 5716 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5717 | |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 5718 | if (INTEL_INFO(dev)->gen < 6) |
| 5719 | return; |
| 5720 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5721 | gen6_suspend_rps(dev); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 5722 | |
| 5723 | /* Force GPU to min freq during suspend */ |
| 5724 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5725 | } |
| 5726 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5727 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 5728 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5729 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5730 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5731 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5732 | ironlake_disable_drps(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5733 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5734 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5735 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5736 | mutex_lock(&dev_priv->rps.hw_lock); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5737 | if (INTEL_INFO(dev)->gen >= 9) |
| 5738 | gen9_disable_rps(dev); |
| 5739 | else if (IS_CHERRYVIEW(dev)) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5740 | cherryview_disable_rps(dev); |
| 5741 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5742 | valleyview_disable_rps(dev); |
| 5743 | else |
| 5744 | gen6_disable_rps(dev); |
Imre Deak | e534770 | 2014-11-19 15:30:02 +0200 | [diff] [blame] | 5745 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5746 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5747 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5748 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5749 | } |
| 5750 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5751 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5752 | { |
| 5753 | struct drm_i915_private *dev_priv = |
| 5754 | container_of(work, struct drm_i915_private, |
| 5755 | rps.delayed_resume_work.work); |
| 5756 | struct drm_device *dev = dev_priv->dev; |
| 5757 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5758 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5759 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5760 | gen6_reset_rps_interrupts(dev); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5761 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5762 | if (IS_CHERRYVIEW(dev)) { |
| 5763 | cherryview_enable_rps(dev); |
| 5764 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5765 | valleyview_enable_rps(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5766 | } else if (INTEL_INFO(dev)->gen >= 9) { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5767 | gen9_enable_rc6(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5768 | gen9_enable_rps(dev); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5769 | __gen6_update_ring_freq(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5770 | } else if (IS_BROADWELL(dev)) { |
| 5771 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5772 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5773 | } else { |
| 5774 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5775 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5776 | } |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5777 | |
| 5778 | WARN_ON(dev_priv->rps.max_freq < dev_priv->rps.min_freq); |
| 5779 | WARN_ON(dev_priv->rps.idle_freq > dev_priv->rps.max_freq); |
| 5780 | |
| 5781 | WARN_ON(dev_priv->rps.efficient_freq < dev_priv->rps.min_freq); |
| 5782 | WARN_ON(dev_priv->rps.efficient_freq > dev_priv->rps.max_freq); |
| 5783 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5784 | dev_priv->rps.enabled = true; |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5785 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5786 | gen6_enable_rps_interrupts(dev); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5787 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5788 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5789 | |
| 5790 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5791 | } |
| 5792 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5793 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5794 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5795 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5796 | |
Yu Zhang | f61018b | 2015-02-10 19:05:52 +0800 | [diff] [blame] | 5797 | /* Powersaving is controlled by the host when inside a VM */ |
| 5798 | if (intel_vgpu_active(dev)) |
| 5799 | return; |
| 5800 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5801 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5802 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5803 | ironlake_enable_drps(dev); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5804 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5805 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5806 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5807 | /* |
| 5808 | * PCU communication is slow and this doesn't need to be |
| 5809 | * done at any specific time, so do this out of our fast path |
| 5810 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5811 | * |
| 5812 | * We depend on the HW RC6 power context save/restore |
| 5813 | * mechanism when entering D3 through runtime PM suspend. So |
| 5814 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5815 | * get here via the driver load/system resume/runtime resume |
| 5816 | * paths, so the _noresume version is enough (and in case of |
| 5817 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5818 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5819 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5820 | round_jiffies_up_relative(HZ))) |
| 5821 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5822 | } |
| 5823 | } |
| 5824 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5825 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5826 | { |
| 5827 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5828 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5829 | if (INTEL_INFO(dev)->gen < 6) |
| 5830 | return; |
| 5831 | |
| 5832 | gen6_suspend_rps(dev); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5833 | dev_priv->rps.enabled = false; |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5834 | } |
| 5835 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5836 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5837 | { |
| 5838 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5839 | |
| 5840 | /* |
| 5841 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5842 | * gating for the panel power sequencer or it will fail to |
| 5843 | * start up when no ports are active. |
| 5844 | */ |
| 5845 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5846 | } |
| 5847 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5848 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5849 | { |
| 5850 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5851 | int pipe; |
| 5852 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5853 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5854 | I915_WRITE(DSPCNTR(pipe), |
| 5855 | I915_READ(DSPCNTR(pipe)) | |
| 5856 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5857 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5858 | } |
| 5859 | } |
| 5860 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5861 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5862 | { |
| 5863 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5864 | |
| 5865 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5866 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5867 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5868 | |
| 5869 | /* |
| 5870 | * Don't touch WM1S_LP_EN here. |
| 5871 | * Doing so could cause underruns. |
| 5872 | */ |
| 5873 | } |
| 5874 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5875 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5876 | { |
| 5877 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5878 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5879 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5880 | /* |
| 5881 | * Required for FBC |
| 5882 | * WaFbcDisableDpfcClockGating:ilk |
| 5883 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5884 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5885 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5886 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5887 | |
| 5888 | I915_WRITE(PCH_3DCGDIS0, |
| 5889 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5890 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5891 | I915_WRITE(PCH_3DCGDIS1, |
| 5892 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5893 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5894 | /* |
| 5895 | * According to the spec the following bits should be set in |
| 5896 | * order to enable memory self-refresh |
| 5897 | * The bit 22/21 of 0x42004 |
| 5898 | * The bit 5 of 0x42020 |
| 5899 | * The bit 15 of 0x45000 |
| 5900 | */ |
| 5901 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5902 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5903 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5904 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5905 | I915_WRITE(DISP_ARB_CTL, |
| 5906 | (I915_READ(DISP_ARB_CTL) | |
| 5907 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5908 | |
| 5909 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5910 | |
| 5911 | /* |
| 5912 | * Based on the document from hardware guys the following bits |
| 5913 | * should be set unconditionally in order to enable FBC. |
| 5914 | * The bit 22 of 0x42000 |
| 5915 | * The bit 22 of 0x42004 |
| 5916 | * The bit 7,8,9 of 0x42020. |
| 5917 | */ |
| 5918 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5919 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5920 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5921 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5922 | ILK_FBCQ_DIS); |
| 5923 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5924 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5925 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5926 | } |
| 5927 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5928 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5929 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5930 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5931 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5932 | ILK_ELPIN_409_SELECT); |
| 5933 | I915_WRITE(_3D_CHICKEN2, |
| 5934 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5935 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5936 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5937 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5938 | I915_WRITE(CACHE_MODE_0, |
| 5939 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5940 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5941 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5942 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5943 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5944 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5945 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5946 | ibx_init_clock_gating(dev); |
| 5947 | } |
| 5948 | |
| 5949 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5950 | { |
| 5951 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5952 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5953 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5954 | |
| 5955 | /* |
| 5956 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5957 | * gating for the panel power sequencer or it will fail to |
| 5958 | * start up when no ports are active. |
| 5959 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5960 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5961 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5962 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5963 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5964 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5965 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5966 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5967 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5968 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5969 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5970 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5971 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5972 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5973 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5974 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5975 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5976 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5977 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5978 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5979 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5980 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5981 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5982 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5983 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5984 | } |
| 5985 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5986 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5987 | { |
| 5988 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5989 | uint32_t tmp; |
| 5990 | |
| 5991 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 5992 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5993 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5994 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5995 | } |
| 5996 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5997 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5998 | { |
| 5999 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6000 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6001 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6002 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6003 | |
| 6004 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6005 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6006 | ILK_ELPIN_409_SELECT); |
| 6007 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6008 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 6009 | I915_WRITE(_3D_CHICKEN, |
| 6010 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 6011 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6012 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 6013 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6014 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 6015 | /* |
| 6016 | * BSpec recoomends 8x4 when MSAA is used, |
| 6017 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6018 | * |
| 6019 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6020 | * disable bit, which we don't touch here, but it's good |
| 6021 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 6022 | */ |
| 6023 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6024 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 6025 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6026 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6027 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6028 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 6029 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6030 | |
| 6031 | I915_WRITE(GEN6_UCGCTL1, |
| 6032 | I915_READ(GEN6_UCGCTL1) | |
| 6033 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 6034 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 6035 | |
| 6036 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 6037 | * gating disable must be set. Failure to set it results in |
| 6038 | * flickering pixels due to Z write ordering failures after |
| 6039 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 6040 | * Sanctuary and Tropics, and apparently anything else with |
| 6041 | * alpha test or pixel discard. |
| 6042 | * |
| 6043 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 6044 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6045 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 6046 | * WaDisableRCCUnitClockGating:snb |
| 6047 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6048 | */ |
| 6049 | I915_WRITE(GEN6_UCGCTL2, |
| 6050 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 6051 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 6052 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 6053 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 6054 | I915_WRITE(_3D_CHICKEN3, |
| 6055 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6056 | |
| 6057 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 6058 | * Bspec says: |
| 6059 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 6060 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 6061 | */ |
| 6062 | I915_WRITE(_3D_CHICKEN3, |
| 6063 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 6064 | |
| 6065 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6066 | * According to the spec the following bits should be |
| 6067 | * set in order to enable memory self-refresh and fbc: |
| 6068 | * The bit21 and bit22 of 0x42000 |
| 6069 | * The bit21 and bit22 of 0x42004 |
| 6070 | * The bit5 and bit7 of 0x42020 |
| 6071 | * The bit14 of 0x70180 |
| 6072 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6073 | * |
| 6074 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6075 | */ |
| 6076 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6077 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6078 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 6079 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6080 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6081 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6082 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 6083 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 6084 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 6085 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6086 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6087 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 6088 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6089 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6090 | |
| 6091 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 6095 | { |
| 6096 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 6097 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6098 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6099 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6100 | * |
| 6101 | * This actually overrides the dispatch |
| 6102 | * mode for all thread types. |
| 6103 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6104 | reg &= ~GEN7_FF_SCHED_MASK; |
| 6105 | reg |= GEN7_FF_TS_SCHED_HW; |
| 6106 | reg |= GEN7_FF_VS_SCHED_HW; |
| 6107 | reg |= GEN7_FF_DS_SCHED_HW; |
| 6108 | |
| 6109 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 6110 | } |
| 6111 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6112 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 6113 | { |
| 6114 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6115 | |
| 6116 | /* |
| 6117 | * TODO: this bit should only be enabled when really needed, then |
| 6118 | * disabled when not needed anymore in order to save power. |
| 6119 | */ |
| 6120 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 6121 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 6122 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 6123 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 6124 | |
| 6125 | /* WADPOClockGatingDisable:hsw */ |
| 6126 | I915_WRITE(_TRANSA_CHICKEN1, |
| 6127 | I915_READ(_TRANSA_CHICKEN1) | |
| 6128 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6129 | } |
| 6130 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6131 | static void lpt_suspend_hw(struct drm_device *dev) |
| 6132 | { |
| 6133 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6134 | |
| 6135 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 6136 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 6137 | |
| 6138 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 6139 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 6140 | } |
| 6141 | } |
| 6142 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6143 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6144 | { |
| 6145 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6146 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6147 | |
| 6148 | I915_WRITE(WM3_LP_ILK, 0); |
| 6149 | I915_WRITE(WM2_LP_ILK, 0); |
| 6150 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6151 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6152 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6153 | 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] | 6154 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6155 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6156 | I915_WRITE(CHICKEN_PAR1_1, |
| 6157 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 6158 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6159 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6160 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6161 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 6162 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 6163 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6164 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 6165 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6166 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 6167 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 6168 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6169 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6170 | ~(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] | 6171 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 6172 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6173 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 6174 | |
| 6175 | /* WaDisableSDEUnitClockGating:bdw */ |
| 6176 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6177 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 6178 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 6179 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6180 | } |
| 6181 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6182 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 6183 | { |
| 6184 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6185 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6186 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6187 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 6188 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 6189 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 6190 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 6191 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 6192 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6193 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6194 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6195 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6196 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6197 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 6198 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 6199 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6200 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6201 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6202 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 6203 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6204 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 6205 | /* enable HiZ Raw Stall Optimization */ |
| 6206 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6207 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6208 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6209 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6210 | I915_WRITE(CACHE_MODE_1, |
| 6211 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6212 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6213 | /* |
| 6214 | * BSpec recommends 8x4 when MSAA is used, |
| 6215 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6216 | * |
| 6217 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6218 | * disable bit, which we don't touch here, but it's good |
| 6219 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6220 | */ |
| 6221 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6222 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6223 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 6224 | /* WaSampleCChickenBitEnable:hsw */ |
| 6225 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 6226 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 6227 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6228 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 6229 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 6230 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 6231 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 6232 | I915_WRITE(CHICKEN_PAR1_1, |
| 6233 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6234 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6235 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6236 | } |
| 6237 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6238 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6239 | { |
| 6240 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6241 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6242 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6243 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6244 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6245 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6246 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6247 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6248 | I915_WRITE(_3D_CHICKEN3, |
| 6249 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6250 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6251 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6252 | I915_WRITE(IVB_CHICKEN3, |
| 6253 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6254 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6255 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6256 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6257 | if (IS_IVB_GT1(dev)) |
| 6258 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 6259 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6260 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6261 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 6262 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6263 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6264 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6265 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 6266 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 6267 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6268 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6269 | I915_WRITE(GEN7_L3CNTLREG1, |
| 6270 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 6271 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6272 | GEN7_WA_L3_CHICKEN_MODE); |
| 6273 | if (IS_IVB_GT1(dev)) |
| 6274 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6275 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6276 | else { |
| 6277 | /* must write both registers */ |
| 6278 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6279 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6280 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 6281 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6282 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6283 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6284 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6285 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6286 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6287 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 6288 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6289 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6290 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6291 | */ |
| 6292 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 6293 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6294 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6295 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6296 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6297 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6298 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6299 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6300 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6301 | |
| 6302 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6303 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 6304 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 6305 | /* enable HiZ Raw Stall Optimization */ |
| 6306 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6307 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6308 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 6309 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6310 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6311 | I915_WRITE(CACHE_MODE_1, |
| 6312 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6313 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6314 | /* |
| 6315 | * BSpec recommends 8x4 when MSAA is used, |
| 6316 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6317 | * |
| 6318 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6319 | * disable bit, which we don't touch here, but it's good |
| 6320 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6321 | */ |
| 6322 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6323 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6324 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6325 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 6326 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 6327 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 6328 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6329 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 6330 | if (!HAS_PCH_NOP(dev)) |
| 6331 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6332 | |
| 6333 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6334 | } |
| 6335 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6336 | static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv) |
| 6337 | { |
| 6338 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6339 | |
| 6340 | /* |
| 6341 | * Disable trickle feed and enable pnd deadline calculation |
| 6342 | */ |
| 6343 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
| 6344 | I915_WRITE(CBR1_VLV, 0); |
| 6345 | } |
| 6346 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6347 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6348 | { |
| 6349 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6350 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6351 | vlv_init_display_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6352 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6353 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6354 | I915_WRITE(_3D_CHICKEN3, |
| 6355 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6356 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6357 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6358 | I915_WRITE(IVB_CHICKEN3, |
| 6359 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6360 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6361 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 6362 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6363 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6364 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 6365 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 6366 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6367 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6368 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 6369 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6370 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6371 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6372 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6373 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6374 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6375 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6376 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6377 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 6378 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6379 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6380 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6381 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6382 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6383 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6384 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 6385 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6386 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6387 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6388 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6389 | */ |
| 6390 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6391 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6392 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6393 | /* WaDisableL3Bank2xClockGate:vlv |
| 6394 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6395 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6396 | I915_WRITE(GEN7_UCGCTL4, |
| 6397 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6398 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6399 | /* |
| 6400 | * BSpec says this must be set, even though |
| 6401 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6402 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6403 | I915_WRITE(CACHE_MODE_1, |
| 6404 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6405 | |
| 6406 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 6407 | * BSpec recommends 8x4 when MSAA is used, |
| 6408 | * however in practice 16x4 seems fastest. |
| 6409 | * |
| 6410 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6411 | * disable bit, which we don't touch here, but it's good |
| 6412 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 6413 | */ |
| 6414 | I915_WRITE(GEN7_GT_MODE, |
| 6415 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 6416 | |
| 6417 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6418 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6419 | * This is the hardware default actually. |
| 6420 | */ |
| 6421 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6422 | |
| 6423 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6424 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6425 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6426 | * in the reporting of vblank events. |
| 6427 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6428 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6429 | } |
| 6430 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6431 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6432 | { |
| 6433 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6434 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6435 | vlv_init_display_clock_gating(dev_priv); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6436 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6437 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6438 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6439 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6440 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6441 | ~(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] | 6442 | |
| 6443 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6444 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6445 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6446 | |
| 6447 | /* WaDisableCSUnitClockGating:chv */ |
| 6448 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6449 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6450 | |
| 6451 | /* WaDisableSDEUnitClockGating:chv */ |
| 6452 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6453 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6454 | } |
| 6455 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6456 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6457 | { |
| 6458 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6459 | uint32_t dspclk_gate; |
| 6460 | |
| 6461 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6462 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6463 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6464 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6465 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6466 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6467 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6468 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6469 | if (IS_GM45(dev)) |
| 6470 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6471 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6472 | |
| 6473 | /* WaDisableRenderCachePipelinedFlush */ |
| 6474 | I915_WRITE(CACHE_MODE_0, |
| 6475 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6476 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6477 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6478 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6479 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6480 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6481 | } |
| 6482 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6483 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6484 | { |
| 6485 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6486 | |
| 6487 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6488 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6489 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6490 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6491 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6492 | I915_WRITE(MI_ARB_STATE, |
| 6493 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6494 | |
| 6495 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6496 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6497 | } |
| 6498 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6499 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6500 | { |
| 6501 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6502 | |
| 6503 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6504 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6505 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6506 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6507 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6508 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6509 | I915_WRITE(MI_ARB_STATE, |
| 6510 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6511 | |
| 6512 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6513 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6514 | } |
| 6515 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6516 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6517 | { |
| 6518 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6519 | u32 dstate = I915_READ(D_STATE); |
| 6520 | |
| 6521 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6522 | DSTATE_DOT_CLOCK_GATING; |
| 6523 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6524 | |
| 6525 | if (IS_PINEVIEW(dev)) |
| 6526 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6527 | |
| 6528 | /* IIR "flip pending" means done if this bit is set */ |
| 6529 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6530 | |
| 6531 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6532 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6533 | |
| 6534 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6535 | 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] | 6536 | |
| 6537 | I915_WRITE(MI_ARB_STATE, |
| 6538 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6539 | } |
| 6540 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6541 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6542 | { |
| 6543 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6544 | |
| 6545 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6546 | |
| 6547 | /* interrupts should cause a wake up from C3 */ |
| 6548 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6549 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6550 | |
| 6551 | I915_WRITE(MEM_MODE, |
| 6552 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6553 | } |
| 6554 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6555 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6556 | { |
| 6557 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6558 | |
| 6559 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6560 | |
| 6561 | I915_WRITE(MEM_MODE, |
| 6562 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6563 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6564 | } |
| 6565 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6566 | void intel_init_clock_gating(struct drm_device *dev) |
| 6567 | { |
| 6568 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6569 | |
Damien Lespiau | c57e355 | 2015-02-09 19:33:05 +0000 | [diff] [blame] | 6570 | if (dev_priv->display.init_clock_gating) |
| 6571 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6572 | } |
| 6573 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6574 | void intel_suspend_hw(struct drm_device *dev) |
| 6575 | { |
| 6576 | if (HAS_PCH_LPT(dev)) |
| 6577 | lpt_suspend_hw(dev); |
| 6578 | } |
| 6579 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6580 | /* Set up chip specific power management-related functions */ |
| 6581 | void intel_init_pm(struct drm_device *dev) |
| 6582 | { |
| 6583 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6584 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 6585 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6586 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6587 | /* For cxsr */ |
| 6588 | if (IS_PINEVIEW(dev)) |
| 6589 | i915_pineview_get_mem_freq(dev); |
| 6590 | else if (IS_GEN5(dev)) |
| 6591 | i915_ironlake_get_mem_freq(dev); |
| 6592 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6593 | /* For FIFO watermark updates */ |
Damien Lespiau | f5ed50c | 2014-11-13 17:51:52 +0000 | [diff] [blame] | 6594 | if (INTEL_INFO(dev)->gen >= 9) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 6595 | skl_setup_wm_latency(dev); |
| 6596 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 6597 | if (IS_BROXTON(dev)) |
| 6598 | dev_priv->display.init_clock_gating = |
| 6599 | bxt_init_clock_gating; |
| 6600 | else if (IS_SKYLAKE(dev)) |
| 6601 | dev_priv->display.init_clock_gating = |
| 6602 | skl_init_clock_gating; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 6603 | dev_priv->display.update_wm = skl_update_wm; |
| 6604 | dev_priv->display.update_sprite_wm = skl_update_sprite_wm; |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6605 | } else if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6606 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6607 | |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6608 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6609 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6610 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6611 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6612 | dev_priv->display.update_wm = ilk_update_wm; |
| 6613 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6614 | } else { |
| 6615 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6616 | "Disable CxSR\n"); |
| 6617 | } |
| 6618 | |
| 6619 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6620 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6621 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6622 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6623 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6624 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6625 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6626 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6627 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6628 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6629 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 6630 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6631 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6632 | dev_priv->display.init_clock_gating = |
| 6633 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6634 | } else if (IS_VALLEYVIEW(dev)) { |
| 6635 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6636 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6637 | dev_priv->display.init_clock_gating = |
| 6638 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6639 | } else if (IS_PINEVIEW(dev)) { |
| 6640 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6641 | dev_priv->is_ddr3, |
| 6642 | dev_priv->fsb_freq, |
| 6643 | dev_priv->mem_freq)) { |
| 6644 | DRM_INFO("failed to find known CxSR latency " |
| 6645 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6646 | "disabling CxSR\n", |
| 6647 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6648 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6649 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6650 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6651 | dev_priv->display.update_wm = NULL; |
| 6652 | } else |
| 6653 | dev_priv->display.update_wm = pineview_update_wm; |
| 6654 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6655 | } else if (IS_G4X(dev)) { |
| 6656 | dev_priv->display.update_wm = g4x_update_wm; |
| 6657 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6658 | } else if (IS_GEN4(dev)) { |
| 6659 | dev_priv->display.update_wm = i965_update_wm; |
| 6660 | if (IS_CRESTLINE(dev)) |
| 6661 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6662 | else if (IS_BROADWATER(dev)) |
| 6663 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6664 | } else if (IS_GEN3(dev)) { |
| 6665 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6666 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6667 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6668 | } else if (IS_GEN2(dev)) { |
| 6669 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6670 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6671 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6672 | } else { |
| 6673 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6674 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6675 | } |
| 6676 | |
| 6677 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6678 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6679 | else |
| 6680 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6681 | } else { |
| 6682 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6683 | } |
| 6684 | } |
| 6685 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6686 | 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] | 6687 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6688 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6689 | |
| 6690 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6691 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6692 | return -EAGAIN; |
| 6693 | } |
| 6694 | |
| 6695 | I915_WRITE(GEN6_PCODE_DATA, *val); |
Damien Lespiau | dddab34 | 2014-11-13 17:51:50 +0000 | [diff] [blame] | 6696 | I915_WRITE(GEN6_PCODE_DATA1, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6697 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6698 | |
| 6699 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6700 | 500)) { |
| 6701 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6702 | return -ETIMEDOUT; |
| 6703 | } |
| 6704 | |
| 6705 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6706 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6707 | |
| 6708 | return 0; |
| 6709 | } |
| 6710 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6711 | 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] | 6712 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6713 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6714 | |
| 6715 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6716 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6717 | return -EAGAIN; |
| 6718 | } |
| 6719 | |
| 6720 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6721 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6722 | |
| 6723 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6724 | 500)) { |
| 6725 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6726 | return -ETIMEDOUT; |
| 6727 | } |
| 6728 | |
| 6729 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6730 | |
| 6731 | return 0; |
| 6732 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6733 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6734 | static int vlv_gpu_freq_div(unsigned int czclk_freq) |
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 | switch (czclk_freq) { |
| 6737 | case 200: |
| 6738 | return 10; |
| 6739 | case 267: |
| 6740 | return 12; |
| 6741 | case 320: |
| 6742 | case 333: |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6743 | return 16; |
Ville Syrjälä | ab3fb15 | 2014-11-10 22:55:15 +0200 | [diff] [blame] | 6744 | case 400: |
| 6745 | return 20; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6746 | default: |
| 6747 | return -1; |
| 6748 | } |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6749 | } |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6750 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6751 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6752 | { |
| 6753 | int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
| 6754 | |
| 6755 | div = vlv_gpu_freq_div(czclk_freq); |
| 6756 | if (div < 0) |
| 6757 | return div; |
| 6758 | |
| 6759 | return DIV_ROUND_CLOSEST(czclk_freq * (val + 6 - 0xbd), div); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6760 | } |
| 6761 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6762 | 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] | 6763 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6764 | int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6765 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6766 | mul = vlv_gpu_freq_div(czclk_freq); |
| 6767 | if (mul < 0) |
| 6768 | return mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6769 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6770 | return DIV_ROUND_CLOSEST(mul * val, czclk_freq) + 0xbd - 6; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6771 | } |
| 6772 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6773 | 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] | 6774 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6775 | int div, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6776 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6777 | div = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6778 | if (div < 0) |
| 6779 | return div; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6780 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6781 | return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6782 | } |
| 6783 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6784 | 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] | 6785 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6786 | int mul, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6787 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6788 | mul = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6789 | if (mul < 0) |
| 6790 | return mul; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6791 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 6792 | /* CHV needs even values */ |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6793 | return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6794 | } |
| 6795 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6796 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6797 | { |
Akash Goel | 80b6dda | 2015-03-06 11:07:15 +0530 | [diff] [blame] | 6798 | if (IS_GEN9(dev_priv->dev)) |
| 6799 | return (val * GT_FREQUENCY_MULTIPLIER) / GEN9_FREQ_SCALER; |
| 6800 | else if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6801 | return chv_gpu_freq(dev_priv, val); |
| 6802 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 6803 | return byt_gpu_freq(dev_priv, val); |
| 6804 | else |
| 6805 | return val * GT_FREQUENCY_MULTIPLIER; |
| 6806 | } |
| 6807 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6808 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 6809 | { |
Akash Goel | 80b6dda | 2015-03-06 11:07:15 +0530 | [diff] [blame] | 6810 | if (IS_GEN9(dev_priv->dev)) |
| 6811 | return (val * GEN9_FREQ_SCALER) / GT_FREQUENCY_MULTIPLIER; |
| 6812 | else if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6813 | return chv_freq_opcode(dev_priv, val); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6814 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6815 | return byt_freq_opcode(dev_priv, val); |
| 6816 | else |
| 6817 | return val / GT_FREQUENCY_MULTIPLIER; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6818 | } |
| 6819 | |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 6820 | struct request_boost { |
| 6821 | struct work_struct work; |
| 6822 | struct drm_i915_gem_request *rq; |
| 6823 | }; |
| 6824 | |
| 6825 | static void __intel_rps_boost_work(struct work_struct *work) |
| 6826 | { |
| 6827 | struct request_boost *boost = container_of(work, struct request_boost, work); |
| 6828 | |
| 6829 | if (!i915_gem_request_completed(boost->rq, true)) |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6830 | gen6_rps_boost(to_i915(boost->rq->ring->dev), NULL); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 6831 | |
| 6832 | i915_gem_request_unreference__unlocked(boost->rq); |
| 6833 | kfree(boost); |
| 6834 | } |
| 6835 | |
| 6836 | void intel_queue_rps_boost_for_request(struct drm_device *dev, |
| 6837 | struct drm_i915_gem_request *rq) |
| 6838 | { |
| 6839 | struct request_boost *boost; |
| 6840 | |
| 6841 | if (rq == NULL || INTEL_INFO(dev)->gen < 6) |
| 6842 | return; |
| 6843 | |
| 6844 | boost = kmalloc(sizeof(*boost), GFP_ATOMIC); |
| 6845 | if (boost == NULL) |
| 6846 | return; |
| 6847 | |
| 6848 | i915_gem_request_reference(rq); |
| 6849 | boost->rq = rq; |
| 6850 | |
| 6851 | INIT_WORK(&boost->work, __intel_rps_boost_work); |
| 6852 | queue_work(to_i915(dev)->wq, &boost->work); |
| 6853 | } |
| 6854 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6855 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6856 | { |
| 6857 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6858 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6859 | mutex_init(&dev_priv->rps.hw_lock); |
| 6860 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6861 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 6862 | intel_gen6_powersave_work); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6863 | INIT_LIST_HEAD(&dev_priv->rps.clients); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6864 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 6865 | dev_priv->pm.suspended = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6866 | } |