Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eugeni Dodonov <eugeni.dodonov@intel.com> |
| 25 | * |
| 26 | */ |
| 27 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 28 | #include <linux/cpufreq.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 29 | #include "i915_drv.h" |
| 30 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 31 | #include "../../../platform/x86/intel_ips.h" |
| 32 | #include <linux/module.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 33 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 34 | /** |
| 35 | * RC6 is a special power stage which allows the GPU to enter an very |
| 36 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 37 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 38 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 39 | * |
| 40 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 41 | * among each other with the latency required to enter and leave RC6 and |
| 42 | * voltage consumed by the GPU in different states. |
| 43 | * |
| 44 | * The combination of the following flags define which states GPU is allowed |
| 45 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 46 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 47 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 48 | * which brings the most power savings; deeper states save more power, but |
| 49 | * require higher latency to switch to and wake up. |
| 50 | */ |
| 51 | #define INTEL_RC6_ENABLE (1<<0) |
| 52 | #define INTEL_RC6p_ENABLE (1<<1) |
| 53 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 54 | |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 55 | static void gen9_init_clock_gating(struct drm_device *dev) |
| 56 | { |
Damien Lespiau | acd5c34 | 2014-03-26 16:55:46 +0000 | [diff] [blame] | 57 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 58 | |
Damien Lespiau | 77719d2 | 2015-02-09 19:33:13 +0000 | [diff] [blame] | 59 | /* WaEnableLbsSlaRetryTimerDecrement:skl */ |
| 60 | I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) | |
| 61 | GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE); |
| 62 | } |
Damien Lespiau | 91e41d1 | 2014-03-26 17:42:50 +0000 | [diff] [blame] | 63 | |
Damien Lespiau | 45db219 | 2015-02-09 19:33:09 +0000 | [diff] [blame] | 64 | static void skl_init_clock_gating(struct drm_device *dev) |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 65 | { |
Damien Lespiau | acd5c34 | 2014-03-26 16:55:46 +0000 | [diff] [blame] | 66 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 3ca5da4 | 2014-03-26 18:18:01 +0000 | [diff] [blame] | 67 | |
Damien Lespiau | 77719d2 | 2015-02-09 19:33:13 +0000 | [diff] [blame] | 68 | gen9_init_clock_gating(dev); |
| 69 | |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 70 | if (INTEL_REVID(dev) == SKL_REVID_A0) { |
| 71 | /* |
| 72 | * WaDisableSDEUnitClockGating:skl |
Damien Lespiau | 9253c2e | 2015-02-09 19:33:10 +0000 | [diff] [blame] | 73 | * WaSetGAPSunitClckGateDisable:skl |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 74 | */ |
| 75 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Damien Lespiau | 9253c2e | 2015-02-09 19:33:10 +0000 | [diff] [blame] | 76 | GEN8_GAPSUNIT_CLOCK_GATE_DISABLE | |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 77 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 78 | } |
Damien Lespiau | 8bc0ccf | 2015-02-09 19:33:18 +0000 | [diff] [blame] | 79 | |
Damien Lespiau | 2caa3b2 | 2015-02-09 19:33:20 +0000 | [diff] [blame] | 80 | if (INTEL_REVID(dev) <= SKL_REVID_D0) { |
Damien Lespiau | 81e231a | 2015-02-09 19:33:19 +0000 | [diff] [blame] | 81 | /* WaDisableHDCInvalidation:skl */ |
| 82 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | |
| 83 | BDW_DISABLE_HDC_INVALIDATION); |
| 84 | |
Damien Lespiau | 2caa3b2 | 2015-02-09 19:33:20 +0000 | [diff] [blame] | 85 | /* WaDisableChickenBitTSGBarrierAckForFFSliceCS:skl */ |
| 86 | I915_WRITE(FF_SLICE_CS_CHICKEN2, |
| 87 | I915_READ(FF_SLICE_CS_CHICKEN2) | |
| 88 | GEN9_TSG_BARRIER_ACK_DISABLE); |
| 89 | } |
Damien Lespiau | 81e231a | 2015-02-09 19:33:19 +0000 | [diff] [blame] | 90 | |
Damien Lespiau | 8bc0ccf | 2015-02-09 19:33:18 +0000 | [diff] [blame] | 91 | if (INTEL_REVID(dev) <= SKL_REVID_E0) |
| 92 | /* WaDisableLSQCROPERFforOCL:skl */ |
| 93 | I915_WRITE(GEN8_L3SQCREG4, I915_READ(GEN8_L3SQCREG4) | |
| 94 | GEN8_LQSC_RO_PERF_DIS); |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 97 | static void bxt_init_clock_gating(struct drm_device *dev) |
| 98 | { |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 99 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 100 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 101 | gen9_init_clock_gating(dev); |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * FIXME: |
| 105 | * GEN8_SDEUNIT_CLOCK_GATE_DISABLE applies on A0 only. |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame^] | 106 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 107 | */ |
| 108 | /* WaDisableSDEUnitClockGating:bxt */ |
| 109 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame^] | 110 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE | |
| 111 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 112 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 113 | } |
| 114 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 115 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 116 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 117 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 118 | u32 tmp; |
| 119 | |
| 120 | tmp = I915_READ(CLKCFG); |
| 121 | |
| 122 | switch (tmp & CLKCFG_FSB_MASK) { |
| 123 | case CLKCFG_FSB_533: |
| 124 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 125 | break; |
| 126 | case CLKCFG_FSB_800: |
| 127 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 128 | break; |
| 129 | case CLKCFG_FSB_667: |
| 130 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 131 | break; |
| 132 | case CLKCFG_FSB_400: |
| 133 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | switch (tmp & CLKCFG_MEM_MASK) { |
| 138 | case CLKCFG_MEM_533: |
| 139 | dev_priv->mem_freq = 533; |
| 140 | break; |
| 141 | case CLKCFG_MEM_667: |
| 142 | dev_priv->mem_freq = 667; |
| 143 | break; |
| 144 | case CLKCFG_MEM_800: |
| 145 | dev_priv->mem_freq = 800; |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | /* detect pineview DDR3 setting */ |
| 150 | tmp = I915_READ(CSHRDDR3CTL); |
| 151 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 152 | } |
| 153 | |
| 154 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 155 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 156 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 157 | u16 ddrpll, csipll; |
| 158 | |
| 159 | ddrpll = I915_READ16(DDRMPLL1); |
| 160 | csipll = I915_READ16(CSIPLL0); |
| 161 | |
| 162 | switch (ddrpll & 0xff) { |
| 163 | case 0xc: |
| 164 | dev_priv->mem_freq = 800; |
| 165 | break; |
| 166 | case 0x10: |
| 167 | dev_priv->mem_freq = 1066; |
| 168 | break; |
| 169 | case 0x14: |
| 170 | dev_priv->mem_freq = 1333; |
| 171 | break; |
| 172 | case 0x18: |
| 173 | dev_priv->mem_freq = 1600; |
| 174 | break; |
| 175 | default: |
| 176 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 177 | ddrpll & 0xff); |
| 178 | dev_priv->mem_freq = 0; |
| 179 | break; |
| 180 | } |
| 181 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 182 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 183 | |
| 184 | switch (csipll & 0x3ff) { |
| 185 | case 0x00c: |
| 186 | dev_priv->fsb_freq = 3200; |
| 187 | break; |
| 188 | case 0x00e: |
| 189 | dev_priv->fsb_freq = 3733; |
| 190 | break; |
| 191 | case 0x010: |
| 192 | dev_priv->fsb_freq = 4266; |
| 193 | break; |
| 194 | case 0x012: |
| 195 | dev_priv->fsb_freq = 4800; |
| 196 | break; |
| 197 | case 0x014: |
| 198 | dev_priv->fsb_freq = 5333; |
| 199 | break; |
| 200 | case 0x016: |
| 201 | dev_priv->fsb_freq = 5866; |
| 202 | break; |
| 203 | case 0x018: |
| 204 | dev_priv->fsb_freq = 6400; |
| 205 | break; |
| 206 | default: |
| 207 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 208 | csipll & 0x3ff); |
| 209 | dev_priv->fsb_freq = 0; |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 214 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 215 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 216 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 217 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 218 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 222 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 223 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 224 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 225 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 226 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 227 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 228 | |
| 229 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 230 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 231 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 232 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 233 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 234 | |
| 235 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 236 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 237 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 238 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 239 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 240 | |
| 241 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 242 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 243 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 244 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 245 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 246 | |
| 247 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 248 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 249 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 250 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 251 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 252 | |
| 253 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 254 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 255 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 256 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 257 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 258 | }; |
| 259 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 260 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 261 | int is_ddr3, |
| 262 | int fsb, |
| 263 | int mem) |
| 264 | { |
| 265 | const struct cxsr_latency *latency; |
| 266 | int i; |
| 267 | |
| 268 | if (fsb == 0 || mem == 0) |
| 269 | return NULL; |
| 270 | |
| 271 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 272 | latency = &cxsr_latency_table[i]; |
| 273 | if (is_desktop == latency->is_desktop && |
| 274 | is_ddr3 == latency->is_ddr3 && |
| 275 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 276 | return latency; |
| 277 | } |
| 278 | |
| 279 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 280 | |
| 281 | return NULL; |
| 282 | } |
| 283 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 284 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 285 | { |
| 286 | u32 val; |
| 287 | |
| 288 | mutex_lock(&dev_priv->rps.hw_lock); |
| 289 | |
| 290 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 291 | if (enable) |
| 292 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 293 | else |
| 294 | val |= FORCE_DDR_HIGH_FREQ; |
| 295 | val &= ~FORCE_DDR_LOW_FREQ; |
| 296 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 297 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 298 | |
| 299 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 300 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 301 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 302 | |
| 303 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 304 | } |
| 305 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 306 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 307 | { |
| 308 | u32 val; |
| 309 | |
| 310 | mutex_lock(&dev_priv->rps.hw_lock); |
| 311 | |
| 312 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 313 | if (enable) |
| 314 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 315 | else |
| 316 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
| 317 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 318 | |
| 319 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 320 | } |
| 321 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 322 | #define FW_WM(value, plane) \ |
| 323 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 324 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 325 | 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] | 326 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 327 | struct drm_device *dev = dev_priv->dev; |
| 328 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 329 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 330 | if (IS_VALLEYVIEW(dev)) { |
| 331 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 332 | if (IS_CHERRYVIEW(dev)) |
| 333 | chv_set_memory_pm5(dev_priv, enable); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 334 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 335 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 336 | } else if (IS_PINEVIEW(dev)) { |
| 337 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 338 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 339 | I915_WRITE(DSPFW3, val); |
| 340 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 341 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 342 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 343 | I915_WRITE(FW_BLC_SELF, val); |
| 344 | } else if (IS_I915GM(dev)) { |
| 345 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 346 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 347 | I915_WRITE(INSTPM, val); |
| 348 | } else { |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 353 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 354 | } |
| 355 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 356 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 357 | /* |
| 358 | * Latency for FIFO fetches is dependent on several factors: |
| 359 | * - memory configuration (speed, channels) |
| 360 | * - chipset |
| 361 | * - current MCH state |
| 362 | * It can be fairly high in some situations, so here we assume a fairly |
| 363 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 364 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 365 | * and power consumption (set it too low to save power and we might see |
| 366 | * FIFO underruns and display "flicker"). |
| 367 | * |
| 368 | * A value of 5us seems to be a good balance; safe for very low end |
| 369 | * platforms but not overly aggressive on lower latency configs. |
| 370 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 371 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 372 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 373 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 374 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 375 | |
| 376 | static int vlv_get_fifo_size(struct drm_device *dev, |
| 377 | enum pipe pipe, int plane) |
| 378 | { |
| 379 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 380 | int sprite0_start, sprite1_start, size; |
| 381 | |
| 382 | switch (pipe) { |
| 383 | uint32_t dsparb, dsparb2, dsparb3; |
| 384 | case PIPE_A: |
| 385 | dsparb = I915_READ(DSPARB); |
| 386 | dsparb2 = I915_READ(DSPARB2); |
| 387 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 388 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 389 | break; |
| 390 | case PIPE_B: |
| 391 | dsparb = I915_READ(DSPARB); |
| 392 | dsparb2 = I915_READ(DSPARB2); |
| 393 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 394 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 395 | break; |
| 396 | case PIPE_C: |
| 397 | dsparb2 = I915_READ(DSPARB2); |
| 398 | dsparb3 = I915_READ(DSPARB3); |
| 399 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 400 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 401 | break; |
| 402 | default: |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | switch (plane) { |
| 407 | case 0: |
| 408 | size = sprite0_start; |
| 409 | break; |
| 410 | case 1: |
| 411 | size = sprite1_start - sprite0_start; |
| 412 | break; |
| 413 | case 2: |
| 414 | size = 512 - 1 - sprite1_start; |
| 415 | break; |
| 416 | default: |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | DRM_DEBUG_KMS("Pipe %c %s %c FIFO size: %d\n", |
| 421 | pipe_name(pipe), plane == 0 ? "primary" : "sprite", |
| 422 | plane == 0 ? plane_name(pipe) : sprite_name(pipe, plane - 1), |
| 423 | size); |
| 424 | |
| 425 | return size; |
| 426 | } |
| 427 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 428 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 429 | { |
| 430 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 431 | uint32_t dsparb = I915_READ(DSPARB); |
| 432 | int size; |
| 433 | |
| 434 | size = dsparb & 0x7f; |
| 435 | if (plane) |
| 436 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 437 | |
| 438 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 439 | plane ? "B" : "A", size); |
| 440 | |
| 441 | return size; |
| 442 | } |
| 443 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 444 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 445 | { |
| 446 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 447 | uint32_t dsparb = I915_READ(DSPARB); |
| 448 | int size; |
| 449 | |
| 450 | size = dsparb & 0x1ff; |
| 451 | if (plane) |
| 452 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 453 | size >>= 1; /* Convert to cachelines */ |
| 454 | |
| 455 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 456 | plane ? "B" : "A", size); |
| 457 | |
| 458 | return size; |
| 459 | } |
| 460 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 461 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 462 | { |
| 463 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 464 | uint32_t dsparb = I915_READ(DSPARB); |
| 465 | int size; |
| 466 | |
| 467 | size = dsparb & 0x7f; |
| 468 | size >>= 2; /* Convert to cachelines */ |
| 469 | |
| 470 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 471 | plane ? "B" : "A", |
| 472 | size); |
| 473 | |
| 474 | return size; |
| 475 | } |
| 476 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 477 | /* Pineview has different values for various configs */ |
| 478 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 479 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 480 | .max_wm = PINEVIEW_MAX_WM, |
| 481 | .default_wm = PINEVIEW_DFT_WM, |
| 482 | .guard_size = PINEVIEW_GUARD_WM, |
| 483 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 484 | }; |
| 485 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 486 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 487 | .max_wm = PINEVIEW_MAX_WM, |
| 488 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 489 | .guard_size = PINEVIEW_GUARD_WM, |
| 490 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 491 | }; |
| 492 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 493 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 494 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 495 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 496 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 497 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 498 | }; |
| 499 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 500 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 501 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 502 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 503 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 504 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 505 | }; |
| 506 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 507 | .fifo_size = G4X_FIFO_SIZE, |
| 508 | .max_wm = G4X_MAX_WM, |
| 509 | .default_wm = G4X_MAX_WM, |
| 510 | .guard_size = 2, |
| 511 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 512 | }; |
| 513 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 514 | .fifo_size = I965_CURSOR_FIFO, |
| 515 | .max_wm = I965_CURSOR_MAX_WM, |
| 516 | .default_wm = I965_CURSOR_DFT_WM, |
| 517 | .guard_size = 2, |
| 518 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 519 | }; |
| 520 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 521 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 522 | .max_wm = VALLEYVIEW_MAX_WM, |
| 523 | .default_wm = VALLEYVIEW_MAX_WM, |
| 524 | .guard_size = 2, |
| 525 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 526 | }; |
| 527 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 528 | .fifo_size = I965_CURSOR_FIFO, |
| 529 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 530 | .default_wm = I965_CURSOR_DFT_WM, |
| 531 | .guard_size = 2, |
| 532 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 533 | }; |
| 534 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 535 | .fifo_size = I965_CURSOR_FIFO, |
| 536 | .max_wm = I965_CURSOR_MAX_WM, |
| 537 | .default_wm = I965_CURSOR_DFT_WM, |
| 538 | .guard_size = 2, |
| 539 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 540 | }; |
| 541 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 542 | .fifo_size = I945_FIFO_SIZE, |
| 543 | .max_wm = I915_MAX_WM, |
| 544 | .default_wm = 1, |
| 545 | .guard_size = 2, |
| 546 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 547 | }; |
| 548 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 549 | .fifo_size = I915_FIFO_SIZE, |
| 550 | .max_wm = I915_MAX_WM, |
| 551 | .default_wm = 1, |
| 552 | .guard_size = 2, |
| 553 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 554 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 555 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 556 | .fifo_size = I855GM_FIFO_SIZE, |
| 557 | .max_wm = I915_MAX_WM, |
| 558 | .default_wm = 1, |
| 559 | .guard_size = 2, |
| 560 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 561 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 562 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 563 | .fifo_size = I855GM_FIFO_SIZE, |
| 564 | .max_wm = I915_MAX_WM/2, |
| 565 | .default_wm = 1, |
| 566 | .guard_size = 2, |
| 567 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 568 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 569 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 570 | .fifo_size = I830_FIFO_SIZE, |
| 571 | .max_wm = I915_MAX_WM, |
| 572 | .default_wm = 1, |
| 573 | .guard_size = 2, |
| 574 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 575 | }; |
| 576 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 577 | /** |
| 578 | * intel_calculate_wm - calculate watermark level |
| 579 | * @clock_in_khz: pixel clock |
| 580 | * @wm: chip FIFO params |
| 581 | * @pixel_size: display pixel size |
| 582 | * @latency_ns: memory latency for the platform |
| 583 | * |
| 584 | * Calculate the watermark level (the level at which the display plane will |
| 585 | * start fetching from memory again). Each chip has a different display |
| 586 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 587 | * in the correct intel_watermark_params structure. |
| 588 | * |
| 589 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 590 | * on the pixel size. When it reaches the watermark level, it'll start |
| 591 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 592 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 593 | * will occur, and a display engine hang could result. |
| 594 | */ |
| 595 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 596 | const struct intel_watermark_params *wm, |
| 597 | int fifo_size, |
| 598 | int pixel_size, |
| 599 | unsigned long latency_ns) |
| 600 | { |
| 601 | long entries_required, wm_size; |
| 602 | |
| 603 | /* |
| 604 | * Note: we need to make sure we don't overflow for various clock & |
| 605 | * latency values. |
| 606 | * clocks go from a few thousand to several hundred thousand. |
| 607 | * latency is usually a few thousand |
| 608 | */ |
| 609 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 610 | 1000; |
| 611 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 612 | |
| 613 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 614 | |
| 615 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 616 | |
| 617 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 618 | |
| 619 | /* Don't promote wm_size to unsigned... */ |
| 620 | if (wm_size > (long)wm->max_wm) |
| 621 | wm_size = wm->max_wm; |
| 622 | if (wm_size <= 0) |
| 623 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 624 | |
| 625 | /* |
| 626 | * Bspec seems to indicate that the value shouldn't be lower than |
| 627 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 628 | * Lets go for 8 which is the burst size since certain platforms |
| 629 | * already use a hardcoded 8 (which is what the spec says should be |
| 630 | * done). |
| 631 | */ |
| 632 | if (wm_size <= 8) |
| 633 | wm_size = 8; |
| 634 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 635 | return wm_size; |
| 636 | } |
| 637 | |
| 638 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 639 | { |
| 640 | struct drm_crtc *crtc, *enabled = NULL; |
| 641 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 642 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 643 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 644 | if (enabled) |
| 645 | return NULL; |
| 646 | enabled = crtc; |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | return enabled; |
| 651 | } |
| 652 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 653 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 654 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 655 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 656 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 657 | struct drm_crtc *crtc; |
| 658 | const struct cxsr_latency *latency; |
| 659 | u32 reg; |
| 660 | unsigned long wm; |
| 661 | |
| 662 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 663 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 664 | if (!latency) { |
| 665 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 666 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 667 | return; |
| 668 | } |
| 669 | |
| 670 | crtc = single_enabled_crtc(dev); |
| 671 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 672 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 673 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 674 | int clock; |
| 675 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 676 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 677 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 678 | |
| 679 | /* Display SR */ |
| 680 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 681 | pineview_display_wm.fifo_size, |
| 682 | pixel_size, latency->display_sr); |
| 683 | reg = I915_READ(DSPFW1); |
| 684 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 685 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 686 | I915_WRITE(DSPFW1, reg); |
| 687 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 688 | |
| 689 | /* cursor SR */ |
| 690 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 691 | pineview_display_wm.fifo_size, |
| 692 | pixel_size, latency->cursor_sr); |
| 693 | reg = I915_READ(DSPFW3); |
| 694 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 695 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 696 | I915_WRITE(DSPFW3, reg); |
| 697 | |
| 698 | /* Display HPLL off SR */ |
| 699 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 700 | pineview_display_hplloff_wm.fifo_size, |
| 701 | pixel_size, latency->display_hpll_disable); |
| 702 | reg = I915_READ(DSPFW3); |
| 703 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 704 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 705 | I915_WRITE(DSPFW3, reg); |
| 706 | |
| 707 | /* cursor HPLL off SR */ |
| 708 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 709 | pineview_display_hplloff_wm.fifo_size, |
| 710 | pixel_size, latency->cursor_hpll_disable); |
| 711 | reg = I915_READ(DSPFW3); |
| 712 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 713 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 714 | I915_WRITE(DSPFW3, reg); |
| 715 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 716 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 717 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 718 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 719 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 724 | int plane, |
| 725 | const struct intel_watermark_params *display, |
| 726 | int display_latency_ns, |
| 727 | const struct intel_watermark_params *cursor, |
| 728 | int cursor_latency_ns, |
| 729 | int *plane_wm, |
| 730 | int *cursor_wm) |
| 731 | { |
| 732 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 733 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 734 | int htotal, hdisplay, clock, pixel_size; |
| 735 | int line_time_us, line_count; |
| 736 | int entries, tlb_miss; |
| 737 | |
| 738 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 739 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 740 | *cursor_wm = cursor->guard_size; |
| 741 | *plane_wm = display->guard_size; |
| 742 | return false; |
| 743 | } |
| 744 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 745 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 746 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 747 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 748 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 749 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 750 | |
| 751 | /* Use the small buffer method to calculate plane watermark */ |
| 752 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 753 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 754 | if (tlb_miss > 0) |
| 755 | entries += tlb_miss; |
| 756 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 757 | *plane_wm = entries + display->guard_size; |
| 758 | if (*plane_wm > (int)display->max_wm) |
| 759 | *plane_wm = display->max_wm; |
| 760 | |
| 761 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 762 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 763 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 764 | entries = line_count * crtc->cursor->state->crtc_w * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 765 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 766 | if (tlb_miss > 0) |
| 767 | entries += tlb_miss; |
| 768 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 769 | *cursor_wm = entries + cursor->guard_size; |
| 770 | if (*cursor_wm > (int)cursor->max_wm) |
| 771 | *cursor_wm = (int)cursor->max_wm; |
| 772 | |
| 773 | return true; |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Check the wm result. |
| 778 | * |
| 779 | * If any calculated watermark values is larger than the maximum value that |
| 780 | * can be programmed into the associated watermark register, that watermark |
| 781 | * must be disabled. |
| 782 | */ |
| 783 | static bool g4x_check_srwm(struct drm_device *dev, |
| 784 | int display_wm, int cursor_wm, |
| 785 | const struct intel_watermark_params *display, |
| 786 | const struct intel_watermark_params *cursor) |
| 787 | { |
| 788 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 789 | display_wm, cursor_wm); |
| 790 | |
| 791 | if (display_wm > display->max_wm) { |
| 792 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 793 | display_wm, display->max_wm); |
| 794 | return false; |
| 795 | } |
| 796 | |
| 797 | if (cursor_wm > cursor->max_wm) { |
| 798 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 799 | cursor_wm, cursor->max_wm); |
| 800 | return false; |
| 801 | } |
| 802 | |
| 803 | if (!(display_wm || cursor_wm)) { |
| 804 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 805 | return false; |
| 806 | } |
| 807 | |
| 808 | return true; |
| 809 | } |
| 810 | |
| 811 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 812 | int plane, |
| 813 | int latency_ns, |
| 814 | const struct intel_watermark_params *display, |
| 815 | const struct intel_watermark_params *cursor, |
| 816 | int *display_wm, int *cursor_wm) |
| 817 | { |
| 818 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 819 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 820 | int hdisplay, htotal, pixel_size, clock; |
| 821 | unsigned long line_time_us; |
| 822 | int line_count, line_size; |
| 823 | int small, large; |
| 824 | int entries; |
| 825 | |
| 826 | if (!latency_ns) { |
| 827 | *display_wm = *cursor_wm = 0; |
| 828 | return false; |
| 829 | } |
| 830 | |
| 831 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 832 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 833 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 834 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 835 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 836 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 837 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 838 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 839 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 840 | line_size = hdisplay * pixel_size; |
| 841 | |
| 842 | /* Use the minimum of the small and large buffer method for primary */ |
| 843 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 844 | large = line_count * line_size; |
| 845 | |
| 846 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 847 | *display_wm = entries + display->guard_size; |
| 848 | |
| 849 | /* calculate the self-refresh watermark for display cursor */ |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 850 | entries = line_count * pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 851 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 852 | *cursor_wm = entries + cursor->guard_size; |
| 853 | |
| 854 | return g4x_check_srwm(dev, |
| 855 | *display_wm, *cursor_wm, |
| 856 | display, cursor); |
| 857 | } |
| 858 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 859 | #define FW_WM_VLV(value, plane) \ |
| 860 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 861 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 862 | static void vlv_write_wm_values(struct intel_crtc *crtc, |
| 863 | const struct vlv_wm_values *wm) |
| 864 | { |
| 865 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 866 | enum pipe pipe = crtc->pipe; |
| 867 | |
| 868 | I915_WRITE(VLV_DDL(pipe), |
| 869 | (wm->ddl[pipe].cursor << DDL_CURSOR_SHIFT) | |
| 870 | (wm->ddl[pipe].sprite[1] << DDL_SPRITE_SHIFT(1)) | |
| 871 | (wm->ddl[pipe].sprite[0] << DDL_SPRITE_SHIFT(0)) | |
| 872 | (wm->ddl[pipe].primary << DDL_PLANE_SHIFT)); |
| 873 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 874 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 875 | FW_WM(wm->sr.plane, SR) | |
| 876 | FW_WM(wm->pipe[PIPE_B].cursor, CURSORB) | |
| 877 | FW_WM_VLV(wm->pipe[PIPE_B].primary, PLANEB) | |
| 878 | FW_WM_VLV(wm->pipe[PIPE_A].primary, PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 879 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 880 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[1], SPRITEB) | |
| 881 | FW_WM(wm->pipe[PIPE_A].cursor, CURSORA) | |
| 882 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 883 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 884 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 885 | |
| 886 | if (IS_CHERRYVIEW(dev_priv)) { |
| 887 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 888 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 889 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 890 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 891 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[1], SPRITEF) | |
| 892 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 893 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 894 | FW_WM_VLV(wm->pipe[PIPE_C].primary, PLANEC) | |
| 895 | FW_WM(wm->pipe[PIPE_C].cursor, CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 896 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 897 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 898 | FW_WM(wm->pipe[PIPE_C].sprite[1] >> 8, SPRITEF_HI) | |
| 899 | FW_WM(wm->pipe[PIPE_C].sprite[0] >> 8, SPRITEE_HI) | |
| 900 | FW_WM(wm->pipe[PIPE_C].primary >> 8, PLANEC_HI) | |
| 901 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 902 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 903 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 904 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 905 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 906 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 907 | } else { |
| 908 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 909 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 910 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 911 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 912 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 913 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 914 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 915 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 916 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 917 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 918 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | POSTING_READ(DSPFW1); |
| 922 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 923 | dev_priv->wm.vlv = *wm; |
| 924 | } |
| 925 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 926 | #undef FW_WM_VLV |
| 927 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 928 | static uint8_t vlv_compute_drain_latency(struct drm_crtc *crtc, |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 929 | struct drm_plane *plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 930 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 931 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 932 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 933 | int entries, prec_mult, drain_latency, pixel_size; |
| 934 | int clock = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 935 | const int high_precision = IS_CHERRYVIEW(dev) ? 16 : 64; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 936 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 937 | /* |
| 938 | * FIXME the plane might have an fb |
| 939 | * but be invisible (eg. due to clipping) |
| 940 | */ |
| 941 | if (!intel_crtc->active || !plane->state->fb) |
| 942 | return 0; |
| 943 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 944 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 945 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 946 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 947 | pixel_size = drm_format_plane_cpp(plane->state->fb->pixel_format, 0); |
| 948 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 949 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 950 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 951 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 952 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 953 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 954 | prec_mult = high_precision; |
| 955 | drain_latency = 64 * prec_mult * 4 / entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 956 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 957 | if (drain_latency > DRAIN_LATENCY_MASK) { |
| 958 | prec_mult /= 2; |
| 959 | drain_latency = 64 * prec_mult * 4 / entries; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 960 | } |
| 961 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 962 | if (drain_latency > DRAIN_LATENCY_MASK) |
| 963 | drain_latency = DRAIN_LATENCY_MASK; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 964 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 965 | return drain_latency | (prec_mult == high_precision ? |
| 966 | DDL_PRECISION_HIGH : DDL_PRECISION_LOW); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 967 | } |
| 968 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 969 | static int vlv_compute_wm(struct intel_crtc *crtc, |
| 970 | struct intel_plane *plane, |
| 971 | int fifo_size) |
| 972 | { |
| 973 | int clock, entries, pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 974 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 975 | /* |
| 976 | * FIXME the plane might have an fb |
| 977 | * but be invisible (eg. due to clipping) |
| 978 | */ |
| 979 | if (!crtc->active || !plane->base.state->fb) |
| 980 | return 0; |
| 981 | |
| 982 | pixel_size = drm_format_plane_cpp(plane->base.state->fb->pixel_format, 0); |
| 983 | clock = crtc->config->base.adjusted_mode.crtc_clock; |
| 984 | |
| 985 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
| 986 | |
| 987 | /* |
| 988 | * Set up the watermark such that we don't start issuing memory |
| 989 | * requests until we are within PND's max deadline value (256us). |
| 990 | * Idea being to be idle as long as possible while still taking |
| 991 | * advatange of PND's deadline scheduling. The limit of 8 |
| 992 | * cachelines (used when the FIFO will anyway drain in less time |
| 993 | * than 256us) should match what we would be done if trickle |
| 994 | * feed were enabled. |
| 995 | */ |
| 996 | return fifo_size - clamp(DIV_ROUND_UP(256 * entries, 64), 0, fifo_size - 8); |
| 997 | } |
| 998 | |
| 999 | static bool vlv_compute_sr_wm(struct drm_device *dev, |
| 1000 | struct vlv_wm_values *wm) |
| 1001 | { |
| 1002 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 1003 | struct drm_crtc *crtc; |
| 1004 | enum pipe pipe = INVALID_PIPE; |
| 1005 | int num_planes = 0; |
| 1006 | int fifo_size = 0; |
| 1007 | struct intel_plane *plane; |
| 1008 | |
| 1009 | wm->sr.cursor = wm->sr.plane = 0; |
| 1010 | |
| 1011 | crtc = single_enabled_crtc(dev); |
| 1012 | /* maxfifo not supported on pipe C */ |
| 1013 | if (crtc && to_intel_crtc(crtc)->pipe != PIPE_C) { |
| 1014 | pipe = to_intel_crtc(crtc)->pipe; |
| 1015 | num_planes = !!wm->pipe[pipe].primary + |
| 1016 | !!wm->pipe[pipe].sprite[0] + |
| 1017 | !!wm->pipe[pipe].sprite[1]; |
| 1018 | fifo_size = INTEL_INFO(dev_priv)->num_pipes * 512 - 1; |
| 1019 | } |
| 1020 | |
| 1021 | if (fifo_size == 0 || num_planes > 1) |
| 1022 | return false; |
| 1023 | |
| 1024 | wm->sr.cursor = vlv_compute_wm(to_intel_crtc(crtc), |
| 1025 | to_intel_plane(crtc->cursor), 0x3f); |
| 1026 | |
| 1027 | list_for_each_entry(plane, &dev->mode_config.plane_list, base.head) { |
| 1028 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 1029 | continue; |
| 1030 | |
| 1031 | if (plane->pipe != pipe) |
| 1032 | continue; |
| 1033 | |
| 1034 | wm->sr.plane = vlv_compute_wm(to_intel_crtc(crtc), |
| 1035 | plane, fifo_size); |
| 1036 | if (wm->sr.plane != 0) |
| 1037 | break; |
| 1038 | } |
| 1039 | |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
| 1043 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1044 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1045 | struct drm_device *dev = crtc->dev; |
| 1046 | struct drm_i915_private *dev_priv = dev->dev_private; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1047 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1048 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1049 | bool cxsr_enabled; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1050 | struct vlv_wm_values wm = dev_priv->wm.vlv; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1051 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1052 | wm.ddl[pipe].primary = vlv_compute_drain_latency(crtc, crtc->primary); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1053 | wm.pipe[pipe].primary = vlv_compute_wm(intel_crtc, |
| 1054 | to_intel_plane(crtc->primary), |
| 1055 | vlv_get_fifo_size(dev, pipe, 0)); |
| 1056 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1057 | wm.ddl[pipe].cursor = vlv_compute_drain_latency(crtc, crtc->cursor); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1058 | wm.pipe[pipe].cursor = vlv_compute_wm(intel_crtc, |
| 1059 | to_intel_plane(crtc->cursor), |
| 1060 | 0x3f); |
| 1061 | |
| 1062 | cxsr_enabled = vlv_compute_sr_wm(dev, &wm); |
| 1063 | |
| 1064 | if (memcmp(&wm, &dev_priv->wm.vlv, sizeof(wm)) == 0) |
| 1065 | return; |
| 1066 | |
| 1067 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: plane=%d, cursor=%d, " |
| 1068 | "SR: plane=%d, cursor=%d\n", pipe_name(pipe), |
| 1069 | wm.pipe[pipe].primary, wm.pipe[pipe].cursor, |
| 1070 | wm.sr.plane, wm.sr.cursor); |
| 1071 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 1072 | /* |
| 1073 | * FIXME DDR DVFS introduces massive memory latencies which |
| 1074 | * are not known to system agent so any deadline specified |
| 1075 | * by the display may not be respected. To support DDR DVFS |
| 1076 | * the watermark code needs to be rewritten to essentially |
| 1077 | * bypass deadline mechanism and rely solely on the |
| 1078 | * watermarks. For now disable DDR DVFS. |
| 1079 | */ |
| 1080 | if (IS_CHERRYVIEW(dev_priv)) |
| 1081 | chv_set_memory_dvfs(dev_priv, false); |
| 1082 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1083 | if (!cxsr_enabled) |
| 1084 | intel_set_memory_cxsr(dev_priv, false); |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1085 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1086 | vlv_write_wm_values(intel_crtc, &wm); |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1087 | |
| 1088 | if (cxsr_enabled) |
| 1089 | intel_set_memory_cxsr(dev_priv, true); |
| 1090 | } |
| 1091 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1092 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 1093 | struct drm_crtc *crtc, |
| 1094 | uint32_t sprite_width, |
| 1095 | uint32_t sprite_height, |
| 1096 | int pixel_size, |
| 1097 | bool enabled, bool scaled) |
| 1098 | { |
| 1099 | struct drm_device *dev = crtc->dev; |
| 1100 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1101 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1102 | enum pipe pipe = intel_crtc->pipe; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1103 | int sprite = to_intel_plane(plane)->plane; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1104 | bool cxsr_enabled; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1105 | struct vlv_wm_values wm = dev_priv->wm.vlv; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1106 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1107 | if (enabled) { |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1108 | wm.ddl[pipe].sprite[sprite] = |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1109 | vlv_compute_drain_latency(crtc, plane); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1110 | |
| 1111 | wm.pipe[pipe].sprite[sprite] = |
| 1112 | vlv_compute_wm(intel_crtc, |
| 1113 | to_intel_plane(plane), |
| 1114 | vlv_get_fifo_size(dev, pipe, sprite+1)); |
| 1115 | } else { |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1116 | wm.ddl[pipe].sprite[sprite] = 0; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1117 | wm.pipe[pipe].sprite[sprite] = 0; |
| 1118 | } |
| 1119 | |
| 1120 | cxsr_enabled = vlv_compute_sr_wm(dev, &wm); |
| 1121 | |
| 1122 | if (memcmp(&wm, &dev_priv->wm.vlv, sizeof(wm)) == 0) |
| 1123 | return; |
| 1124 | |
| 1125 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: sprite %c=%d, " |
| 1126 | "SR: plane=%d, cursor=%d\n", pipe_name(pipe), |
| 1127 | sprite_name(pipe, sprite), |
| 1128 | wm.pipe[pipe].sprite[sprite], |
| 1129 | wm.sr.plane, wm.sr.cursor); |
| 1130 | |
| 1131 | if (!cxsr_enabled) |
| 1132 | intel_set_memory_cxsr(dev_priv, false); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1133 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1134 | vlv_write_wm_values(intel_crtc, &wm); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1135 | |
| 1136 | if (cxsr_enabled) |
| 1137 | intel_set_memory_cxsr(dev_priv, true); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1138 | } |
| 1139 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1140 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1141 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1142 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1143 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1144 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1145 | static const int sr_latency_ns = 12000; |
| 1146 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1147 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1148 | int plane_sr, cursor_sr; |
| 1149 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1150 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1151 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1152 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1153 | &g4x_wm_info, pessimal_latency_ns, |
| 1154 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1155 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1156 | enabled |= 1 << PIPE_A; |
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_B, |
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 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1162 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1163 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1164 | if (single_plane_enabled(enabled) && |
| 1165 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1166 | sr_latency_ns, |
| 1167 | &g4x_wm_info, |
| 1168 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1169 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1170 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1171 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1172 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1173 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1174 | plane_sr = cursor_sr = 0; |
| 1175 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1176 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1177 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1178 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1179 | planea_wm, cursora_wm, |
| 1180 | planeb_wm, cursorb_wm, |
| 1181 | plane_sr, cursor_sr); |
| 1182 | |
| 1183 | I915_WRITE(DSPFW1, |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1184 | FW_WM(plane_sr, SR) | |
| 1185 | FW_WM(cursorb_wm, CURSORB) | |
| 1186 | FW_WM(planeb_wm, PLANEB) | |
| 1187 | FW_WM(planea_wm, PLANEA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1188 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1189 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1190 | FW_WM(cursora_wm, CURSORA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1191 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1192 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1193 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1194 | FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1195 | |
| 1196 | if (cxsr_enabled) |
| 1197 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1198 | } |
| 1199 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1200 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1201 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1202 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1203 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1204 | struct drm_crtc *crtc; |
| 1205 | int srwm = 1; |
| 1206 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1207 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1208 | |
| 1209 | /* Calc sr entries for one plane configs */ |
| 1210 | crtc = single_enabled_crtc(dev); |
| 1211 | if (crtc) { |
| 1212 | /* self-refresh has much higher latency */ |
| 1213 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1214 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1215 | &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1216 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1217 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1218 | int hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1219 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1220 | unsigned long line_time_us; |
| 1221 | int entries; |
| 1222 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1223 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1224 | |
| 1225 | /* Use ns/us then divide to preserve precision */ |
| 1226 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1227 | pixel_size * hdisplay; |
| 1228 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1229 | srwm = I965_FIFO_SIZE - entries; |
| 1230 | if (srwm < 0) |
| 1231 | srwm = 1; |
| 1232 | srwm &= 0x1ff; |
| 1233 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1234 | entries, srwm); |
| 1235 | |
| 1236 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 1237 | pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1238 | entries = DIV_ROUND_UP(entries, |
| 1239 | i965_cursor_wm_info.cacheline_size); |
| 1240 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1241 | (entries + i965_cursor_wm_info.guard_size); |
| 1242 | |
| 1243 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1244 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1245 | |
| 1246 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1247 | "cursor %d\n", srwm, cursor_sr); |
| 1248 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1249 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1250 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1251 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1252 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1253 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1257 | srwm); |
| 1258 | |
| 1259 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1260 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 1261 | FW_WM(8, CURSORB) | |
| 1262 | FW_WM(8, PLANEB) | |
| 1263 | FW_WM(8, PLANEA)); |
| 1264 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 1265 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1266 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1267 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1268 | |
| 1269 | if (cxsr_enabled) |
| 1270 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1271 | } |
| 1272 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1273 | #undef FW_WM |
| 1274 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1275 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1276 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1277 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1278 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1279 | const struct intel_watermark_params *wm_info; |
| 1280 | uint32_t fwater_lo; |
| 1281 | uint32_t fwater_hi; |
| 1282 | int cwm, srwm = 1; |
| 1283 | int fifo_size; |
| 1284 | int planea_wm, planeb_wm; |
| 1285 | struct drm_crtc *crtc, *enabled = NULL; |
| 1286 | |
| 1287 | if (IS_I945GM(dev)) |
| 1288 | wm_info = &i945_wm_info; |
| 1289 | else if (!IS_GEN2(dev)) |
| 1290 | wm_info = &i915_wm_info; |
| 1291 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1292 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1293 | |
| 1294 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1295 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1296 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1297 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1298 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1299 | if (IS_GEN2(dev)) |
| 1300 | cpp = 4; |
| 1301 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1302 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1303 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1304 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1305 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1306 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1307 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1308 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1309 | if (planea_wm > (long)wm_info->max_wm) |
| 1310 | planea_wm = wm_info->max_wm; |
| 1311 | } |
| 1312 | |
| 1313 | if (IS_GEN2(dev)) |
| 1314 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1315 | |
| 1316 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1317 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1318 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1319 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1320 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1321 | if (IS_GEN2(dev)) |
| 1322 | cpp = 4; |
| 1323 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1324 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1325 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1326 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1327 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1328 | if (enabled == NULL) |
| 1329 | enabled = crtc; |
| 1330 | else |
| 1331 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1332 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1333 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1334 | if (planeb_wm > (long)wm_info->max_wm) |
| 1335 | planeb_wm = wm_info->max_wm; |
| 1336 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1337 | |
| 1338 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1339 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1340 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1341 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1342 | |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1343 | obj = intel_fb_obj(enabled->primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1344 | |
| 1345 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1346 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1347 | enabled = NULL; |
| 1348 | } |
| 1349 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1350 | /* |
| 1351 | * Overlay gets an aggressive default since video jitter is bad. |
| 1352 | */ |
| 1353 | cwm = 2; |
| 1354 | |
| 1355 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1356 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1357 | |
| 1358 | /* Calc sr entries for one plane configs */ |
| 1359 | if (HAS_FW_BLC(dev) && enabled) { |
| 1360 | /* self-refresh has much higher latency */ |
| 1361 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1362 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1363 | &to_intel_crtc(enabled)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1364 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1365 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1366 | int hdisplay = to_intel_crtc(enabled)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1367 | int pixel_size = enabled->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1368 | unsigned long line_time_us; |
| 1369 | int entries; |
| 1370 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1371 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1372 | |
| 1373 | /* Use ns/us then divide to preserve precision */ |
| 1374 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1375 | pixel_size * hdisplay; |
| 1376 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1377 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1378 | srwm = wm_info->fifo_size - entries; |
| 1379 | if (srwm < 0) |
| 1380 | srwm = 1; |
| 1381 | |
| 1382 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1383 | I915_WRITE(FW_BLC_SELF, |
| 1384 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1385 | else if (IS_I915GM(dev)) |
| 1386 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1387 | } |
| 1388 | |
| 1389 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1390 | planea_wm, planeb_wm, cwm, srwm); |
| 1391 | |
| 1392 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1393 | fwater_hi = (cwm & 0x1f); |
| 1394 | |
| 1395 | /* Set request length to 8 cachelines per fetch */ |
| 1396 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1397 | fwater_hi = fwater_hi | (1 << 8); |
| 1398 | |
| 1399 | I915_WRITE(FW_BLC, fwater_lo); |
| 1400 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1401 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1402 | if (enabled) |
| 1403 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1404 | } |
| 1405 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1406 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1407 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1408 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1409 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1410 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1411 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1412 | uint32_t fwater_lo; |
| 1413 | int planea_wm; |
| 1414 | |
| 1415 | crtc = single_enabled_crtc(dev); |
| 1416 | if (crtc == NULL) |
| 1417 | return; |
| 1418 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1419 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1420 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1421 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1422 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1423 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1424 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1425 | fwater_lo |= (3<<8) | planea_wm; |
| 1426 | |
| 1427 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1428 | |
| 1429 | I915_WRITE(FW_BLC, fwater_lo); |
| 1430 | } |
| 1431 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1432 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1433 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1434 | { |
| 1435 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1436 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1437 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1438 | pixel_rate = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1439 | |
| 1440 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1441 | * adjust the pixel_rate here. */ |
| 1442 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1443 | if (intel_crtc->config->pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1444 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1445 | uint32_t pfit_size = intel_crtc->config->pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1446 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1447 | pipe_w = intel_crtc->config->pipe_src_w; |
| 1448 | pipe_h = intel_crtc->config->pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1449 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1450 | pfit_h = pfit_size & 0xFFFF; |
| 1451 | if (pipe_w < pfit_w) |
| 1452 | pipe_w = pfit_w; |
| 1453 | if (pipe_h < pfit_h) |
| 1454 | pipe_h = pfit_h; |
| 1455 | |
| 1456 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1457 | pfit_w * pfit_h); |
| 1458 | } |
| 1459 | |
| 1460 | return pixel_rate; |
| 1461 | } |
| 1462 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1463 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1464 | 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] | 1465 | uint32_t latency) |
| 1466 | { |
| 1467 | uint64_t ret; |
| 1468 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1469 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1470 | return UINT_MAX; |
| 1471 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1472 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1473 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1474 | |
| 1475 | return ret; |
| 1476 | } |
| 1477 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1478 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1479 | 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] | 1480 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1481 | uint32_t latency) |
| 1482 | { |
| 1483 | uint32_t ret; |
| 1484 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1485 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1486 | return UINT_MAX; |
| 1487 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1488 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1489 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1490 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1491 | return ret; |
| 1492 | } |
| 1493 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1494 | 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] | 1495 | uint8_t bytes_per_pixel) |
| 1496 | { |
| 1497 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1498 | } |
| 1499 | |
Pradeep Bhat | 2ac96d2 | 2014-11-04 17:06:40 +0000 | [diff] [blame] | 1500 | struct skl_pipe_wm_parameters { |
| 1501 | bool active; |
| 1502 | uint32_t pipe_htotal; |
| 1503 | uint32_t pixel_rate; /* in KHz */ |
| 1504 | struct intel_plane_wm_parameters plane[I915_MAX_PLANES]; |
| 1505 | struct intel_plane_wm_parameters cursor; |
| 1506 | }; |
| 1507 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1508 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1509 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1510 | uint32_t pipe_htotal; |
| 1511 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1512 | struct intel_plane_wm_parameters pri; |
| 1513 | struct intel_plane_wm_parameters spr; |
| 1514 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1515 | }; |
| 1516 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1517 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1518 | uint16_t pri; |
| 1519 | uint16_t spr; |
| 1520 | uint16_t cur; |
| 1521 | uint16_t fbc; |
| 1522 | }; |
| 1523 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1524 | /* used in computing the new watermarks state */ |
| 1525 | struct intel_wm_config { |
| 1526 | unsigned int num_pipes_active; |
| 1527 | bool sprites_enabled; |
| 1528 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1529 | }; |
| 1530 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1531 | /* |
| 1532 | * For both WM_PIPE and WM_LP. |
| 1533 | * mem_value must be in 0.1us units. |
| 1534 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1535 | 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] | 1536 | uint32_t mem_value, |
| 1537 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1538 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1539 | uint32_t method1, method2; |
| 1540 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1541 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1542 | return 0; |
| 1543 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1544 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1545 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1546 | mem_value); |
| 1547 | |
| 1548 | if (!is_lp) |
| 1549 | return method1; |
| 1550 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1551 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1552 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1553 | params->pri.horiz_pixels, |
| 1554 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1555 | mem_value); |
| 1556 | |
| 1557 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1558 | } |
| 1559 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1560 | /* |
| 1561 | * For both WM_PIPE and WM_LP. |
| 1562 | * mem_value must be in 0.1us units. |
| 1563 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1564 | 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] | 1565 | uint32_t mem_value) |
| 1566 | { |
| 1567 | uint32_t method1, method2; |
| 1568 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1569 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1570 | return 0; |
| 1571 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1572 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1573 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1574 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1575 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1576 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1577 | params->spr.horiz_pixels, |
| 1578 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1579 | mem_value); |
| 1580 | return min(method1, method2); |
| 1581 | } |
| 1582 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1583 | /* |
| 1584 | * For both WM_PIPE and WM_LP. |
| 1585 | * mem_value must be in 0.1us units. |
| 1586 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1587 | 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] | 1588 | uint32_t mem_value) |
| 1589 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1590 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1591 | return 0; |
| 1592 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1593 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1594 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1595 | params->cur.horiz_pixels, |
| 1596 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1597 | mem_value); |
| 1598 | } |
| 1599 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1600 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1601 | 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] | 1602 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1603 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1604 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1605 | return 0; |
| 1606 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1607 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1608 | params->pri.horiz_pixels, |
| 1609 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1610 | } |
| 1611 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1612 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1613 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1614 | if (INTEL_INFO(dev)->gen >= 8) |
| 1615 | return 3072; |
| 1616 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1617 | return 768; |
| 1618 | else |
| 1619 | return 512; |
| 1620 | } |
| 1621 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1622 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1623 | int level, bool is_sprite) |
| 1624 | { |
| 1625 | if (INTEL_INFO(dev)->gen >= 8) |
| 1626 | /* BDW primary/sprite plane watermarks */ |
| 1627 | return level == 0 ? 255 : 2047; |
| 1628 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1629 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1630 | return level == 0 ? 127 : 1023; |
| 1631 | else if (!is_sprite) |
| 1632 | /* ILK/SNB primary plane watermarks */ |
| 1633 | return level == 0 ? 127 : 511; |
| 1634 | else |
| 1635 | /* ILK/SNB sprite plane watermarks */ |
| 1636 | return level == 0 ? 63 : 255; |
| 1637 | } |
| 1638 | |
| 1639 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1640 | int level) |
| 1641 | { |
| 1642 | if (INTEL_INFO(dev)->gen >= 7) |
| 1643 | return level == 0 ? 63 : 255; |
| 1644 | else |
| 1645 | return level == 0 ? 31 : 63; |
| 1646 | } |
| 1647 | |
| 1648 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1649 | { |
| 1650 | if (INTEL_INFO(dev)->gen >= 8) |
| 1651 | return 31; |
| 1652 | else |
| 1653 | return 15; |
| 1654 | } |
| 1655 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1656 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1657 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1658 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1659 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1660 | enum intel_ddb_partitioning ddb_partitioning, |
| 1661 | bool is_sprite) |
| 1662 | { |
| 1663 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1664 | |
| 1665 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1666 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1667 | return 0; |
| 1668 | |
| 1669 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1670 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1671 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1672 | |
| 1673 | /* |
| 1674 | * For some reason the non self refresh |
| 1675 | * FIFO size is only half of the self |
| 1676 | * refresh FIFO size on ILK/SNB. |
| 1677 | */ |
| 1678 | if (INTEL_INFO(dev)->gen <= 6) |
| 1679 | fifo_size /= 2; |
| 1680 | } |
| 1681 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1682 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1683 | /* level 0 is always calculated with 1:1 split */ |
| 1684 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1685 | if (is_sprite) |
| 1686 | fifo_size *= 5; |
| 1687 | fifo_size /= 6; |
| 1688 | } else { |
| 1689 | fifo_size /= 2; |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1694 | 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] | 1695 | } |
| 1696 | |
| 1697 | /* Calculate the maximum cursor plane watermark */ |
| 1698 | 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] | 1699 | int level, |
| 1700 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1701 | { |
| 1702 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1703 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1704 | return 64; |
| 1705 | |
| 1706 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1707 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1708 | } |
| 1709 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1710 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1711 | int level, |
| 1712 | const struct intel_wm_config *config, |
| 1713 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1714 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1715 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1716 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1717 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1718 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1719 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1720 | } |
| 1721 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1722 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1723 | int level, |
| 1724 | struct ilk_wm_maximums *max) |
| 1725 | { |
| 1726 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1727 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1728 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1729 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1730 | } |
| 1731 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1732 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1733 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1734 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1735 | { |
| 1736 | bool ret; |
| 1737 | |
| 1738 | /* already determined to be invalid? */ |
| 1739 | if (!result->enable) |
| 1740 | return false; |
| 1741 | |
| 1742 | result->enable = result->pri_val <= max->pri && |
| 1743 | result->spr_val <= max->spr && |
| 1744 | result->cur_val <= max->cur; |
| 1745 | |
| 1746 | ret = result->enable; |
| 1747 | |
| 1748 | /* |
| 1749 | * HACK until we can pre-compute everything, |
| 1750 | * and thus fail gracefully if LP0 watermarks |
| 1751 | * are exceeded... |
| 1752 | */ |
| 1753 | if (level == 0 && !result->enable) { |
| 1754 | if (result->pri_val > max->pri) |
| 1755 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 1756 | level, result->pri_val, max->pri); |
| 1757 | if (result->spr_val > max->spr) |
| 1758 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 1759 | level, result->spr_val, max->spr); |
| 1760 | if (result->cur_val > max->cur) |
| 1761 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 1762 | level, result->cur_val, max->cur); |
| 1763 | |
| 1764 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 1765 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 1766 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 1767 | result->enable = true; |
| 1768 | } |
| 1769 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1770 | return ret; |
| 1771 | } |
| 1772 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1773 | 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] | 1774 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1775 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 1776 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1777 | { |
| 1778 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 1779 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 1780 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 1781 | |
| 1782 | /* WM1+ latency values stored in 0.5us units */ |
| 1783 | if (level > 0) { |
| 1784 | pri_latency *= 5; |
| 1785 | spr_latency *= 5; |
| 1786 | cur_latency *= 5; |
| 1787 | } |
| 1788 | |
| 1789 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 1790 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 1791 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 1792 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 1793 | result->enable = true; |
| 1794 | } |
| 1795 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1796 | static uint32_t |
| 1797 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1798 | { |
| 1799 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1800 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1801 | struct drm_display_mode *mode = &intel_crtc->config->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1802 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1803 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 1804 | if (!intel_crtc->active) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1805 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1806 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1807 | /* The WM are computed with base on how long it takes to fill a single |
| 1808 | * row at the given clock rate, multiplied by 8. |
| 1809 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1810 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 1811 | mode->crtc_clock); |
| 1812 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1813 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1814 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1815 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 1816 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1817 | } |
| 1818 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1819 | 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] | 1820 | { |
| 1821 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1822 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1823 | if (IS_GEN9(dev)) { |
| 1824 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1825 | int ret, i; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1826 | int level, max_level = ilk_wm_max_level(dev); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1827 | |
| 1828 | /* read the first set of memory latencies[0:3] */ |
| 1829 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 1830 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1831 | ret = sandybridge_pcode_read(dev_priv, |
| 1832 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1833 | &val); |
| 1834 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1835 | |
| 1836 | if (ret) { |
| 1837 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1838 | return; |
| 1839 | } |
| 1840 | |
| 1841 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1842 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1843 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1844 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1845 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1846 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1847 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1848 | |
| 1849 | /* read the second set of memory latencies[4:7] */ |
| 1850 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 1851 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1852 | ret = sandybridge_pcode_read(dev_priv, |
| 1853 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1854 | &val); |
| 1855 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1856 | if (ret) { |
| 1857 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1858 | return; |
| 1859 | } |
| 1860 | |
| 1861 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1862 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1863 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1864 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1865 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1866 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1867 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1868 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1869 | /* |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 1870 | * WaWmMemoryReadLatency:skl |
| 1871 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1872 | * punit doesn't take into account the read latency so we need |
| 1873 | * to add 2us to the various latency levels we retrieve from |
| 1874 | * the punit. |
| 1875 | * - W0 is a bit special in that it's the only level that |
| 1876 | * can't be disabled if we want to have display working, so |
| 1877 | * we always add 2us there. |
| 1878 | * - For levels >=1, punit returns 0us latency when they are |
| 1879 | * disabled, so we respect that and don't add 2us then |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1880 | * |
| 1881 | * Additionally, if a level n (n > 1) has a 0us latency, all |
| 1882 | * levels m (m >= n) need to be disabled. We make sure to |
| 1883 | * sanitize the values out of the punit to satisfy this |
| 1884 | * requirement. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1885 | */ |
| 1886 | wm[0] += 2; |
| 1887 | for (level = 1; level <= max_level; level++) |
| 1888 | if (wm[level] != 0) |
| 1889 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1890 | else { |
| 1891 | for (i = level + 1; i <= max_level; i++) |
| 1892 | wm[i] = 0; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1893 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1894 | break; |
| 1895 | } |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1896 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1897 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 1898 | |
| 1899 | wm[0] = (sskpd >> 56) & 0xFF; |
| 1900 | if (wm[0] == 0) |
| 1901 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 1902 | wm[1] = (sskpd >> 4) & 0xFF; |
| 1903 | wm[2] = (sskpd >> 12) & 0xFF; |
| 1904 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 1905 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 1906 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 1907 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 1908 | |
| 1909 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 1910 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 1911 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 1912 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 1913 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1914 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 1915 | |
| 1916 | /* ILK primary LP0 latency is 700 ns */ |
| 1917 | wm[0] = 7; |
| 1918 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 1919 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1920 | } |
| 1921 | } |
| 1922 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1923 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1924 | { |
| 1925 | /* ILK sprite LP0 latency is 1300 ns */ |
| 1926 | if (INTEL_INFO(dev)->gen == 5) |
| 1927 | wm[0] = 13; |
| 1928 | } |
| 1929 | |
| 1930 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1931 | { |
| 1932 | /* ILK cursor LP0 latency is 1300 ns */ |
| 1933 | if (INTEL_INFO(dev)->gen == 5) |
| 1934 | wm[0] = 13; |
| 1935 | |
| 1936 | /* WaDoubleCursorLP3Latency:ivb */ |
| 1937 | if (IS_IVYBRIDGE(dev)) |
| 1938 | wm[3] *= 2; |
| 1939 | } |
| 1940 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 1941 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1942 | { |
| 1943 | /* how many WM levels are we expecting */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1944 | if (IS_GEN9(dev)) |
| 1945 | return 7; |
| 1946 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1947 | return 4; |
| 1948 | else if (INTEL_INFO(dev)->gen >= 6) |
| 1949 | return 3; |
| 1950 | else |
| 1951 | return 2; |
| 1952 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 1953 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1954 | static void intel_print_wm_latency(struct drm_device *dev, |
| 1955 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1956 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1957 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1958 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1959 | |
| 1960 | for (level = 0; level <= max_level; level++) { |
| 1961 | unsigned int latency = wm[level]; |
| 1962 | |
| 1963 | if (latency == 0) { |
| 1964 | DRM_ERROR("%s WM%d latency not provided\n", |
| 1965 | name, level); |
| 1966 | continue; |
| 1967 | } |
| 1968 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1969 | /* |
| 1970 | * - latencies are in us on gen9. |
| 1971 | * - before then, WM1+ latency values are in 0.5us units |
| 1972 | */ |
| 1973 | if (IS_GEN9(dev)) |
| 1974 | latency *= 10; |
| 1975 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1976 | latency *= 5; |
| 1977 | |
| 1978 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 1979 | name, level, wm[level], |
| 1980 | latency / 10, latency % 10); |
| 1981 | } |
| 1982 | } |
| 1983 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 1984 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 1985 | uint16_t wm[5], uint16_t min) |
| 1986 | { |
| 1987 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 1988 | |
| 1989 | if (wm[0] >= min) |
| 1990 | return false; |
| 1991 | |
| 1992 | wm[0] = max(wm[0], min); |
| 1993 | for (level = 1; level <= max_level; level++) |
| 1994 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 1995 | |
| 1996 | return true; |
| 1997 | } |
| 1998 | |
| 1999 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 2000 | { |
| 2001 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2002 | bool changed; |
| 2003 | |
| 2004 | /* |
| 2005 | * The BIOS provided WM memory latency values are often |
| 2006 | * inadequate for high resolution displays. Adjust them. |
| 2007 | */ |
| 2008 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2009 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2010 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2011 | |
| 2012 | if (!changed) |
| 2013 | return; |
| 2014 | |
| 2015 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2016 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2017 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2018 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2019 | } |
| 2020 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2021 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2022 | { |
| 2023 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2024 | |
| 2025 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2026 | |
| 2027 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2028 | sizeof(dev_priv->wm.pri_latency)); |
| 2029 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2030 | sizeof(dev_priv->wm.pri_latency)); |
| 2031 | |
| 2032 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2033 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2034 | |
| 2035 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2036 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2037 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2038 | |
| 2039 | if (IS_GEN6(dev)) |
| 2040 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2041 | } |
| 2042 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2043 | static void skl_setup_wm_latency(struct drm_device *dev) |
| 2044 | { |
| 2045 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2046 | |
| 2047 | intel_read_wm_latency(dev, dev_priv->wm.skl_latency); |
| 2048 | intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency); |
| 2049 | } |
| 2050 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2051 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2052 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2053 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2054 | struct drm_device *dev = crtc->dev; |
| 2055 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2056 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2057 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2058 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2059 | if (!intel_crtc->active) |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2060 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2061 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2062 | p->active = true; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2063 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2064 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2065 | |
| 2066 | if (crtc->primary->state->fb) { |
| 2067 | p->pri.enabled = true; |
| 2068 | p->pri.bytes_per_pixel = |
| 2069 | crtc->primary->state->fb->bits_per_pixel / 8; |
| 2070 | } else { |
| 2071 | p->pri.enabled = false; |
| 2072 | p->pri.bytes_per_pixel = 0; |
| 2073 | } |
| 2074 | |
| 2075 | if (crtc->cursor->state->fb) { |
| 2076 | p->cur.enabled = true; |
| 2077 | p->cur.bytes_per_pixel = 4; |
| 2078 | } else { |
| 2079 | p->cur.enabled = false; |
| 2080 | p->cur.bytes_per_pixel = 0; |
| 2081 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2082 | p->pri.horiz_pixels = intel_crtc->config->pipe_src_w; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 2083 | p->cur.horiz_pixels = intel_crtc->base.cursor->state->crtc_w; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2084 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2085 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2086 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2087 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2088 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2089 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2090 | break; |
| 2091 | } |
| 2092 | } |
| 2093 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2094 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2095 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2096 | struct intel_wm_config *config) |
| 2097 | { |
| 2098 | struct intel_crtc *intel_crtc; |
| 2099 | |
| 2100 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2101 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2102 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2103 | |
| 2104 | if (!wm->pipe_enabled) |
| 2105 | continue; |
| 2106 | |
| 2107 | config->sprites_enabled |= wm->sprites_enabled; |
| 2108 | config->sprites_scaled |= wm->sprites_scaled; |
| 2109 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2113 | /* Compute new watermarks for the pipe */ |
| 2114 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2115 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2116 | struct intel_pipe_wm *pipe_wm) |
| 2117 | { |
| 2118 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2119 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2120 | int level, max_level = ilk_wm_max_level(dev); |
| 2121 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2122 | struct intel_wm_config config = { |
| 2123 | .num_pipes_active = 1, |
| 2124 | .sprites_enabled = params->spr.enabled, |
| 2125 | .sprites_scaled = params->spr.scaled, |
| 2126 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2127 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2128 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2129 | pipe_wm->pipe_enabled = params->active; |
| 2130 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2131 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2132 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2133 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2134 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2135 | max_level = 1; |
| 2136 | |
| 2137 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2138 | if (params->spr.scaled) |
| 2139 | max_level = 0; |
| 2140 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2141 | 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] | 2142 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2143 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2144 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2145 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2146 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2147 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2148 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2149 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2150 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2151 | return false; |
| 2152 | |
| 2153 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2154 | |
| 2155 | for (level = 1; level <= max_level; level++) { |
| 2156 | struct intel_wm_level wm = {}; |
| 2157 | |
| 2158 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2159 | |
| 2160 | /* |
| 2161 | * Disable any watermark level that exceeds the |
| 2162 | * register maximums since such watermarks are |
| 2163 | * always invalid. |
| 2164 | */ |
| 2165 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2166 | break; |
| 2167 | |
| 2168 | pipe_wm->wm[level] = wm; |
| 2169 | } |
| 2170 | |
| 2171 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | /* |
| 2175 | * Merge the watermarks from all active pipes for a specific level. |
| 2176 | */ |
| 2177 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2178 | int level, |
| 2179 | struct intel_wm_level *ret_wm) |
| 2180 | { |
| 2181 | const struct intel_crtc *intel_crtc; |
| 2182 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2183 | ret_wm->enable = true; |
| 2184 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2185 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2186 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2187 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2188 | |
| 2189 | if (!active->pipe_enabled) |
| 2190 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2191 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2192 | /* |
| 2193 | * The watermark values may have been used in the past, |
| 2194 | * so we must maintain them in the registers for some |
| 2195 | * time even if the level is now disabled. |
| 2196 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2197 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2198 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2199 | |
| 2200 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2201 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2202 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2203 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2204 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | /* |
| 2208 | * Merge all low power watermarks for all active pipes. |
| 2209 | */ |
| 2210 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2211 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2212 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2213 | struct intel_pipe_wm *merged) |
| 2214 | { |
| 2215 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2216 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2217 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2218 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2219 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2220 | config->num_pipes_active > 1) |
| 2221 | return; |
| 2222 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2223 | /* ILK: FBC WM must be disabled always */ |
| 2224 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2225 | |
| 2226 | /* merge each WM1+ level */ |
| 2227 | for (level = 1; level <= max_level; level++) { |
| 2228 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2229 | |
| 2230 | ilk_merge_wm_level(dev, level, wm); |
| 2231 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2232 | if (level > last_enabled_level) |
| 2233 | wm->enable = false; |
| 2234 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2235 | /* make sure all following levels get disabled */ |
| 2236 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2237 | |
| 2238 | /* |
| 2239 | * The spec says it is preferred to disable |
| 2240 | * FBC WMs instead of disabling a WM level. |
| 2241 | */ |
| 2242 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2243 | if (wm->enable) |
| 2244 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2245 | wm->fbc_val = 0; |
| 2246 | } |
| 2247 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2248 | |
| 2249 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2250 | /* |
| 2251 | * FIXME this is racy. FBC might get enabled later. |
| 2252 | * What we should check here is whether FBC can be |
| 2253 | * enabled sometime later. |
| 2254 | */ |
| 2255 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2256 | for (level = 2; level <= max_level; level++) { |
| 2257 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2258 | |
| 2259 | wm->enable = false; |
| 2260 | } |
| 2261 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2262 | } |
| 2263 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2264 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2265 | { |
| 2266 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2267 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2268 | } |
| 2269 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2270 | /* The value we need to program into the WM_LPx latency field */ |
| 2271 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2272 | { |
| 2273 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2274 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2275 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2276 | return 2 * level; |
| 2277 | else |
| 2278 | return dev_priv->wm.pri_latency[level]; |
| 2279 | } |
| 2280 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2281 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2282 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2283 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2284 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2285 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2286 | struct intel_crtc *intel_crtc; |
| 2287 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2288 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2289 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2290 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2291 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2292 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2293 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2294 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2295 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2296 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2297 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2298 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2299 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2300 | /* |
| 2301 | * Maintain the watermark values even if the level is |
| 2302 | * disabled. Doing otherwise could cause underruns. |
| 2303 | */ |
| 2304 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2305 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2306 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2307 | r->cur_val; |
| 2308 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2309 | if (r->enable) |
| 2310 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2311 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2312 | if (INTEL_INFO(dev)->gen >= 8) |
| 2313 | results->wm_lp[wm_lp - 1] |= |
| 2314 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2315 | else |
| 2316 | results->wm_lp[wm_lp - 1] |= |
| 2317 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2318 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2319 | /* |
| 2320 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2321 | * level is disabled. Doing otherwise could cause underruns. |
| 2322 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2323 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2324 | WARN_ON(wm_lp != 1); |
| 2325 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2326 | } else |
| 2327 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2328 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2329 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2330 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2331 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2332 | enum pipe pipe = intel_crtc->pipe; |
| 2333 | const struct intel_wm_level *r = |
| 2334 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2335 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2336 | if (WARN_ON(!r->enable)) |
| 2337 | continue; |
| 2338 | |
| 2339 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2340 | |
| 2341 | results->wm_pipe[pipe] = |
| 2342 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2343 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2344 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2345 | } |
| 2346 | } |
| 2347 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2348 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2349 | * 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] | 2350 | 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] | 2351 | struct intel_pipe_wm *r1, |
| 2352 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2353 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2354 | int level, max_level = ilk_wm_max_level(dev); |
| 2355 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2356 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2357 | for (level = 1; level <= max_level; level++) { |
| 2358 | if (r1->wm[level].enable) |
| 2359 | level1 = level; |
| 2360 | if (r2->wm[level].enable) |
| 2361 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2362 | } |
| 2363 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2364 | if (level1 == level2) { |
| 2365 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2366 | return r2; |
| 2367 | else |
| 2368 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2369 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2370 | return r1; |
| 2371 | } else { |
| 2372 | return r2; |
| 2373 | } |
| 2374 | } |
| 2375 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2376 | /* dirty bits used to track which watermarks need changes */ |
| 2377 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2378 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2379 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2380 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2381 | #define WM_DIRTY_FBC (1 << 24) |
| 2382 | #define WM_DIRTY_DDB (1 << 25) |
| 2383 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2384 | 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] | 2385 | const struct ilk_wm_values *old, |
| 2386 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2387 | { |
| 2388 | unsigned int dirty = 0; |
| 2389 | enum pipe pipe; |
| 2390 | int wm_lp; |
| 2391 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2392 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2393 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2394 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2395 | /* Must disable LP1+ watermarks too */ |
| 2396 | dirty |= WM_DIRTY_LP_ALL; |
| 2397 | } |
| 2398 | |
| 2399 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2400 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2401 | /* Must disable LP1+ watermarks too */ |
| 2402 | dirty |= WM_DIRTY_LP_ALL; |
| 2403 | } |
| 2404 | } |
| 2405 | |
| 2406 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2407 | dirty |= WM_DIRTY_FBC; |
| 2408 | /* Must disable LP1+ watermarks too */ |
| 2409 | dirty |= WM_DIRTY_LP_ALL; |
| 2410 | } |
| 2411 | |
| 2412 | if (old->partitioning != new->partitioning) { |
| 2413 | dirty |= WM_DIRTY_DDB; |
| 2414 | /* Must disable LP1+ watermarks too */ |
| 2415 | dirty |= WM_DIRTY_LP_ALL; |
| 2416 | } |
| 2417 | |
| 2418 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2419 | if (dirty & WM_DIRTY_LP_ALL) |
| 2420 | return dirty; |
| 2421 | |
| 2422 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2423 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2424 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2425 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2426 | break; |
| 2427 | } |
| 2428 | |
| 2429 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2430 | for (; wm_lp <= 3; wm_lp++) |
| 2431 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2432 | |
| 2433 | return dirty; |
| 2434 | } |
| 2435 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2436 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2437 | unsigned int dirty) |
| 2438 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2439 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2440 | bool changed = false; |
| 2441 | |
| 2442 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2443 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2444 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2445 | changed = true; |
| 2446 | } |
| 2447 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2448 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2449 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2450 | changed = true; |
| 2451 | } |
| 2452 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2453 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2454 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2455 | changed = true; |
| 2456 | } |
| 2457 | |
| 2458 | /* |
| 2459 | * Don't touch WM1S_LP_EN here. |
| 2460 | * Doing so could cause underruns. |
| 2461 | */ |
| 2462 | |
| 2463 | return changed; |
| 2464 | } |
| 2465 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2466 | /* |
| 2467 | * The spec says we shouldn't write when we don't need, because every write |
| 2468 | * causes WMs to be re-evaluated, expending some power. |
| 2469 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2470 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2471 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2472 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2473 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2474 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2475 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2476 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2477 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2478 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2479 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2480 | return; |
| 2481 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2482 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2483 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2484 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2485 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2486 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2487 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2488 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2489 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2490 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2491 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2492 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2493 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2494 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2495 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2496 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2497 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2498 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2499 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2500 | val = I915_READ(WM_MISC); |
| 2501 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2502 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2503 | else |
| 2504 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2505 | I915_WRITE(WM_MISC, val); |
| 2506 | } else { |
| 2507 | val = I915_READ(DISP_ARB_CTL2); |
| 2508 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2509 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2510 | else |
| 2511 | val |= DISP_DATA_PARTITION_5_6; |
| 2512 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2513 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2514 | } |
| 2515 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2516 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2517 | val = I915_READ(DISP_ARB_CTL); |
| 2518 | if (results->enable_fbc_wm) |
| 2519 | val &= ~DISP_FBC_WM_DIS; |
| 2520 | else |
| 2521 | val |= DISP_FBC_WM_DIS; |
| 2522 | I915_WRITE(DISP_ARB_CTL, val); |
| 2523 | } |
| 2524 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2525 | if (dirty & WM_DIRTY_LP(1) && |
| 2526 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2527 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2528 | |
| 2529 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2530 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2531 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2532 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2533 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2534 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2535 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2536 | 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] | 2537 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2538 | 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] | 2539 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2540 | 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] | 2541 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2542 | |
| 2543 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2544 | } |
| 2545 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2546 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2547 | { |
| 2548 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2549 | |
| 2550 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2551 | } |
| 2552 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2553 | /* |
| 2554 | * On gen9, we need to allocate Display Data Buffer (DDB) portions to the |
| 2555 | * different active planes. |
| 2556 | */ |
| 2557 | |
| 2558 | #define SKL_DDB_SIZE 896 /* in blocks */ |
Damien Lespiau | 43d735a | 2015-03-17 11:39:34 +0200 | [diff] [blame] | 2559 | #define BXT_DDB_SIZE 512 |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2560 | |
| 2561 | static void |
| 2562 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
| 2563 | struct drm_crtc *for_crtc, |
| 2564 | const struct intel_wm_config *config, |
| 2565 | const struct skl_pipe_wm_parameters *params, |
| 2566 | struct skl_ddb_entry *alloc /* out */) |
| 2567 | { |
| 2568 | struct drm_crtc *crtc; |
| 2569 | unsigned int pipe_size, ddb_size; |
| 2570 | int nth_active_pipe; |
| 2571 | |
| 2572 | if (!params->active) { |
| 2573 | alloc->start = 0; |
| 2574 | alloc->end = 0; |
| 2575 | return; |
| 2576 | } |
| 2577 | |
Damien Lespiau | 43d735a | 2015-03-17 11:39:34 +0200 | [diff] [blame] | 2578 | if (IS_BROXTON(dev)) |
| 2579 | ddb_size = BXT_DDB_SIZE; |
| 2580 | else |
| 2581 | ddb_size = SKL_DDB_SIZE; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2582 | |
| 2583 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 2584 | |
| 2585 | nth_active_pipe = 0; |
| 2586 | for_each_crtc(dev, crtc) { |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2587 | if (!to_intel_crtc(crtc)->active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2588 | continue; |
| 2589 | |
| 2590 | if (crtc == for_crtc) |
| 2591 | break; |
| 2592 | |
| 2593 | nth_active_pipe++; |
| 2594 | } |
| 2595 | |
| 2596 | pipe_size = ddb_size / config->num_pipes_active; |
| 2597 | alloc->start = nth_active_pipe * ddb_size / config->num_pipes_active; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2598 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | static unsigned int skl_cursor_allocation(const struct intel_wm_config *config) |
| 2602 | { |
| 2603 | if (config->num_pipes_active == 1) |
| 2604 | return 32; |
| 2605 | |
| 2606 | return 8; |
| 2607 | } |
| 2608 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2609 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 2610 | { |
| 2611 | entry->start = reg & 0x3ff; |
| 2612 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2613 | if (entry->end) |
| 2614 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2615 | } |
| 2616 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 2617 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 2618 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2619 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2620 | enum pipe pipe; |
| 2621 | int plane; |
| 2622 | u32 val; |
| 2623 | |
| 2624 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2625 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2626 | val = I915_READ(PLANE_BUF_CFG(pipe, plane)); |
| 2627 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane], |
| 2628 | val); |
| 2629 | } |
| 2630 | |
| 2631 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 2632 | skl_ddb_entry_init_from_hw(&ddb->cursor[pipe], val); |
| 2633 | } |
| 2634 | } |
| 2635 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2636 | static unsigned int |
| 2637 | skl_plane_relative_data_rate(const struct intel_plane_wm_parameters *p) |
| 2638 | { |
| 2639 | return p->horiz_pixels * p->vert_pixels * p->bytes_per_pixel; |
| 2640 | } |
| 2641 | |
| 2642 | /* |
| 2643 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 2644 | * a 8192x4096@32bpp framebuffer: |
| 2645 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 2646 | */ |
| 2647 | static unsigned int |
| 2648 | skl_get_total_relative_data_rate(struct intel_crtc *intel_crtc, |
| 2649 | const struct skl_pipe_wm_parameters *params) |
| 2650 | { |
| 2651 | unsigned int total_data_rate = 0; |
| 2652 | int plane; |
| 2653 | |
| 2654 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2655 | const struct intel_plane_wm_parameters *p; |
| 2656 | |
| 2657 | p = ¶ms->plane[plane]; |
| 2658 | if (!p->enabled) |
| 2659 | continue; |
| 2660 | |
| 2661 | total_data_rate += skl_plane_relative_data_rate(p); |
| 2662 | } |
| 2663 | |
| 2664 | return total_data_rate; |
| 2665 | } |
| 2666 | |
| 2667 | static void |
| 2668 | skl_allocate_pipe_ddb(struct drm_crtc *crtc, |
| 2669 | const struct intel_wm_config *config, |
| 2670 | const struct skl_pipe_wm_parameters *params, |
| 2671 | struct skl_ddb_allocation *ddb /* out */) |
| 2672 | { |
| 2673 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2674 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2675 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2676 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2677 | struct skl_ddb_entry *alloc = &ddb->pipe[pipe]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2678 | uint16_t alloc_size, start, cursor_blocks; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2679 | uint16_t minimum[I915_MAX_PLANES]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2680 | unsigned int total_data_rate; |
| 2681 | int plane; |
| 2682 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2683 | skl_ddb_get_pipe_allocation_limits(dev, crtc, config, params, alloc); |
| 2684 | alloc_size = skl_ddb_entry_size(alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2685 | if (alloc_size == 0) { |
| 2686 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 2687 | memset(&ddb->cursor[pipe], 0, sizeof(ddb->cursor[pipe])); |
| 2688 | return; |
| 2689 | } |
| 2690 | |
| 2691 | cursor_blocks = skl_cursor_allocation(config); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2692 | ddb->cursor[pipe].start = alloc->end - cursor_blocks; |
| 2693 | ddb->cursor[pipe].end = alloc->end; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2694 | |
| 2695 | alloc_size -= cursor_blocks; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2696 | alloc->end -= cursor_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2697 | |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2698 | /* 1. Allocate the mininum required blocks for each active plane */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2699 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2700 | const struct intel_plane_wm_parameters *p; |
| 2701 | |
| 2702 | p = ¶ms->plane[plane]; |
| 2703 | if (!p->enabled) |
| 2704 | continue; |
| 2705 | |
| 2706 | minimum[plane] = 8; |
| 2707 | alloc_size -= minimum[plane]; |
| 2708 | } |
| 2709 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2710 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2711 | * 2. Distribute the remaining space in proportion to the amount of |
| 2712 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2713 | * |
| 2714 | * FIXME: we may not allocate every single block here. |
| 2715 | */ |
| 2716 | total_data_rate = skl_get_total_relative_data_rate(intel_crtc, params); |
| 2717 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2718 | start = alloc->start; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2719 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2720 | const struct intel_plane_wm_parameters *p; |
| 2721 | unsigned int data_rate; |
| 2722 | uint16_t plane_blocks; |
| 2723 | |
| 2724 | p = ¶ms->plane[plane]; |
| 2725 | if (!p->enabled) |
| 2726 | continue; |
| 2727 | |
| 2728 | data_rate = skl_plane_relative_data_rate(p); |
| 2729 | |
| 2730 | /* |
| 2731 | * promote the expression to 64 bits to avoid overflowing, the |
| 2732 | * result is < available as data_rate / total_data_rate < 1 |
| 2733 | */ |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2734 | plane_blocks = minimum[plane]; |
| 2735 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 2736 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2737 | |
| 2738 | ddb->plane[pipe][plane].start = start; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2739 | ddb->plane[pipe][plane].end = start + plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2740 | |
| 2741 | start += plane_blocks; |
| 2742 | } |
| 2743 | |
| 2744 | } |
| 2745 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2746 | 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] | 2747 | { |
| 2748 | /* TODO: Take into account the scalers once we support them */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2749 | return config->base.adjusted_mode.crtc_clock; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | /* |
| 2753 | * The max latency should be 257 (max the punit can code is 255 and we add 2us |
| 2754 | * for the read latency) and bytes_per_pixel should always be <= 8, so that |
| 2755 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 2756 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 2757 | */ |
| 2758 | static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel, |
| 2759 | uint32_t latency) |
| 2760 | { |
| 2761 | uint32_t wm_intermediate_val, ret; |
| 2762 | |
| 2763 | if (latency == 0) |
| 2764 | return UINT_MAX; |
| 2765 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2766 | wm_intermediate_val = latency * pixel_rate * bytes_per_pixel / 512; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2767 | ret = DIV_ROUND_UP(wm_intermediate_val, 1000); |
| 2768 | |
| 2769 | return ret; |
| 2770 | } |
| 2771 | |
| 2772 | static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
| 2773 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2774 | uint64_t tiling, uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2775 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2776 | uint32_t ret; |
| 2777 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2778 | uint32_t wm_intermediate_val; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2779 | |
| 2780 | if (latency == 0) |
| 2781 | return UINT_MAX; |
| 2782 | |
| 2783 | plane_bytes_per_line = horiz_pixels * bytes_per_pixel; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2784 | |
| 2785 | if (tiling == I915_FORMAT_MOD_Y_TILED || |
| 2786 | tiling == I915_FORMAT_MOD_Yf_TILED) { |
| 2787 | plane_bytes_per_line *= 4; |
| 2788 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2789 | plane_blocks_per_line /= 4; |
| 2790 | } else { |
| 2791 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2792 | } |
| 2793 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2794 | wm_intermediate_val = latency * pixel_rate; |
| 2795 | ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) * |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2796 | plane_blocks_per_line; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2797 | |
| 2798 | return ret; |
| 2799 | } |
| 2800 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2801 | static bool skl_ddb_allocation_changed(const struct skl_ddb_allocation *new_ddb, |
| 2802 | const struct intel_crtc *intel_crtc) |
| 2803 | { |
| 2804 | struct drm_device *dev = intel_crtc->base.dev; |
| 2805 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2806 | const struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 2807 | enum pipe pipe = intel_crtc->pipe; |
| 2808 | |
| 2809 | if (memcmp(new_ddb->plane[pipe], cur_ddb->plane[pipe], |
| 2810 | sizeof(new_ddb->plane[pipe]))) |
| 2811 | return true; |
| 2812 | |
| 2813 | if (memcmp(&new_ddb->cursor[pipe], &cur_ddb->cursor[pipe], |
| 2814 | sizeof(new_ddb->cursor[pipe]))) |
| 2815 | return true; |
| 2816 | |
| 2817 | return false; |
| 2818 | } |
| 2819 | |
| 2820 | static void skl_compute_wm_global_parameters(struct drm_device *dev, |
| 2821 | struct intel_wm_config *config) |
| 2822 | { |
| 2823 | struct drm_crtc *crtc; |
| 2824 | struct drm_plane *plane; |
| 2825 | |
| 2826 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2827 | config->num_pipes_active += to_intel_crtc(crtc)->active; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2828 | |
| 2829 | /* FIXME: I don't think we need those two global parameters on SKL */ |
| 2830 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2831 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2832 | |
| 2833 | config->sprites_enabled |= intel_plane->wm.enabled; |
| 2834 | config->sprites_scaled |= intel_plane->wm.scaled; |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | static void skl_compute_wm_pipe_parameters(struct drm_crtc *crtc, |
| 2839 | struct skl_pipe_wm_parameters *p) |
| 2840 | { |
| 2841 | struct drm_device *dev = crtc->dev; |
| 2842 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2843 | enum pipe pipe = intel_crtc->pipe; |
| 2844 | struct drm_plane *plane; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2845 | struct drm_framebuffer *fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2846 | int i = 1; /* Index for sprite planes start */ |
| 2847 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2848 | p->active = intel_crtc->active; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2849 | if (p->active) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2850 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
| 2851 | p->pixel_rate = skl_pipe_pixel_rate(intel_crtc->config); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2852 | |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2853 | fb = crtc->primary->state->fb; |
| 2854 | if (fb) { |
| 2855 | p->plane[0].enabled = true; |
| 2856 | p->plane[0].bytes_per_pixel = fb->bits_per_pixel / 8; |
| 2857 | p->plane[0].tiling = fb->modifier[0]; |
| 2858 | } else { |
| 2859 | p->plane[0].enabled = false; |
| 2860 | p->plane[0].bytes_per_pixel = 0; |
| 2861 | p->plane[0].tiling = DRM_FORMAT_MOD_NONE; |
| 2862 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2863 | p->plane[0].horiz_pixels = intel_crtc->config->pipe_src_w; |
| 2864 | p->plane[0].vert_pixels = intel_crtc->config->pipe_src_h; |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2865 | p->plane[0].rotation = crtc->primary->state->rotation; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2866 | |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2867 | fb = crtc->cursor->state->fb; |
| 2868 | if (fb) { |
| 2869 | p->cursor.enabled = true; |
| 2870 | p->cursor.bytes_per_pixel = fb->bits_per_pixel / 8; |
| 2871 | p->cursor.horiz_pixels = crtc->cursor->state->crtc_w; |
| 2872 | p->cursor.vert_pixels = crtc->cursor->state->crtc_h; |
| 2873 | } else { |
| 2874 | p->cursor.enabled = false; |
| 2875 | p->cursor.bytes_per_pixel = 0; |
| 2876 | p->cursor.horiz_pixels = 64; |
| 2877 | p->cursor.vert_pixels = 64; |
| 2878 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2882 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2883 | |
Sonika Jindal | a712f8e | 2014-12-09 10:59:15 +0530 | [diff] [blame] | 2884 | if (intel_plane->pipe == pipe && |
| 2885 | plane->type == DRM_PLANE_TYPE_OVERLAY) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2886 | p->plane[i++] = intel_plane->wm; |
| 2887 | } |
| 2888 | } |
| 2889 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2890 | static bool skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 2891 | struct skl_pipe_wm_parameters *p, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2892 | struct intel_plane_wm_parameters *p_params, |
| 2893 | uint16_t ddb_allocation, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2894 | int level, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2895 | uint16_t *out_blocks, /* out */ |
| 2896 | uint8_t *out_lines /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2897 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2898 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
| 2899 | uint32_t method1, method2; |
| 2900 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2901 | uint32_t res_blocks, res_lines; |
| 2902 | uint32_t selected_result; |
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 | if (latency == 0 || !p->active || !p_params->enabled) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2905 | return false; |
| 2906 | |
| 2907 | method1 = skl_wm_method1(p->pixel_rate, |
| 2908 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2909 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2910 | method2 = skl_wm_method2(p->pixel_rate, |
| 2911 | p->pipe_htotal, |
| 2912 | p_params->horiz_pixels, |
| 2913 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2914 | p_params->tiling, |
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 | |
| 2917 | plane_bytes_per_line = p_params->horiz_pixels * |
| 2918 | p_params->bytes_per_pixel; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2919 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2920 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2921 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2922 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) { |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2923 | uint32_t min_scanlines = 4; |
| 2924 | uint32_t y_tile_minimum; |
| 2925 | if (intel_rotation_90_or_270(p_params->rotation)) { |
| 2926 | switch (p_params->bytes_per_pixel) { |
| 2927 | case 1: |
| 2928 | min_scanlines = 16; |
| 2929 | break; |
| 2930 | case 2: |
| 2931 | min_scanlines = 8; |
| 2932 | break; |
| 2933 | case 8: |
| 2934 | WARN(1, "Unsupported pixel depth for rotation"); |
kbuild test robot | 2f0b579 | 2015-03-26 22:30:21 +0800 | [diff] [blame] | 2935 | } |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2936 | } |
| 2937 | y_tile_minimum = plane_blocks_per_line * min_scanlines; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2938 | selected_result = max(method2, y_tile_minimum); |
| 2939 | } else { |
| 2940 | if ((ddb_allocation / plane_blocks_per_line) >= 1) |
| 2941 | selected_result = min(method1, method2); |
| 2942 | else |
| 2943 | selected_result = method1; |
| 2944 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2945 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2946 | res_blocks = selected_result + 1; |
| 2947 | res_lines = DIV_ROUND_UP(selected_result, plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2948 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2949 | if (level >= 1 && level <= 7) { |
| 2950 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2951 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) |
| 2952 | res_lines += 4; |
| 2953 | else |
| 2954 | res_blocks++; |
| 2955 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2956 | |
| 2957 | if (res_blocks >= ddb_allocation || res_lines > 31) |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2958 | return false; |
| 2959 | |
| 2960 | *out_blocks = res_blocks; |
| 2961 | *out_lines = res_lines; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2962 | |
| 2963 | return true; |
| 2964 | } |
| 2965 | |
| 2966 | static void skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 2967 | struct skl_ddb_allocation *ddb, |
| 2968 | struct skl_pipe_wm_parameters *p, |
| 2969 | enum pipe pipe, |
| 2970 | int level, |
| 2971 | int num_planes, |
| 2972 | struct skl_wm_level *result) |
| 2973 | { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2974 | uint16_t ddb_blocks; |
| 2975 | int i; |
| 2976 | |
| 2977 | for (i = 0; i < num_planes; i++) { |
| 2978 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]); |
| 2979 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2980 | result->plane_en[i] = skl_compute_plane_wm(dev_priv, |
| 2981 | p, &p->plane[i], |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2982 | ddb_blocks, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2983 | level, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2984 | &result->plane_res_b[i], |
| 2985 | &result->plane_res_l[i]); |
| 2986 | } |
| 2987 | |
| 2988 | ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]); |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2989 | result->cursor_en = skl_compute_plane_wm(dev_priv, p, &p->cursor, |
| 2990 | ddb_blocks, level, |
| 2991 | &result->cursor_res_b, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2992 | &result->cursor_res_l); |
| 2993 | } |
| 2994 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2995 | static uint32_t |
| 2996 | skl_compute_linetime_wm(struct drm_crtc *crtc, struct skl_pipe_wm_parameters *p) |
| 2997 | { |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2998 | if (!to_intel_crtc(crtc)->active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2999 | return 0; |
| 3000 | |
| 3001 | return DIV_ROUND_UP(8 * p->pipe_htotal * 1000, p->pixel_rate); |
| 3002 | |
| 3003 | } |
| 3004 | |
| 3005 | static void skl_compute_transition_wm(struct drm_crtc *crtc, |
| 3006 | struct skl_pipe_wm_parameters *params, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3007 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3008 | { |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3009 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3010 | int i; |
| 3011 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3012 | if (!params->active) |
| 3013 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3014 | |
| 3015 | /* Until we know more, just disable transition WMs */ |
| 3016 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3017 | trans_wm->plane_en[i] = false; |
| 3018 | trans_wm->cursor_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3021 | static void skl_compute_pipe_wm(struct drm_crtc *crtc, |
| 3022 | struct skl_ddb_allocation *ddb, |
| 3023 | struct skl_pipe_wm_parameters *params, |
| 3024 | struct skl_pipe_wm *pipe_wm) |
| 3025 | { |
| 3026 | struct drm_device *dev = crtc->dev; |
| 3027 | const struct drm_i915_private *dev_priv = dev->dev_private; |
| 3028 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3029 | int level, max_level = ilk_wm_max_level(dev); |
| 3030 | |
| 3031 | for (level = 0; level <= max_level; level++) { |
| 3032 | skl_compute_wm_level(dev_priv, ddb, params, intel_crtc->pipe, |
| 3033 | level, intel_num_planes(intel_crtc), |
| 3034 | &pipe_wm->wm[level]); |
| 3035 | } |
| 3036 | pipe_wm->linetime = skl_compute_linetime_wm(crtc, params); |
| 3037 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3038 | skl_compute_transition_wm(crtc, params, &pipe_wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | static void skl_compute_wm_results(struct drm_device *dev, |
| 3042 | struct skl_pipe_wm_parameters *p, |
| 3043 | struct skl_pipe_wm *p_wm, |
| 3044 | struct skl_wm_values *r, |
| 3045 | struct intel_crtc *intel_crtc) |
| 3046 | { |
| 3047 | int level, max_level = ilk_wm_max_level(dev); |
| 3048 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3049 | uint32_t temp; |
| 3050 | int i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3051 | |
| 3052 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3053 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3054 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3055 | |
| 3056 | temp |= p_wm->wm[level].plane_res_l[i] << |
| 3057 | PLANE_WM_LINES_SHIFT; |
| 3058 | temp |= p_wm->wm[level].plane_res_b[i]; |
| 3059 | if (p_wm->wm[level].plane_en[i]) |
| 3060 | temp |= PLANE_WM_EN; |
| 3061 | |
| 3062 | r->plane[pipe][i][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3066 | |
| 3067 | temp |= p_wm->wm[level].cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3068 | temp |= p_wm->wm[level].cursor_res_b; |
| 3069 | |
| 3070 | if (p_wm->wm[level].cursor_en) |
| 3071 | temp |= PLANE_WM_EN; |
| 3072 | |
| 3073 | r->cursor[pipe][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3074 | |
| 3075 | } |
| 3076 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3077 | /* transition WMs */ |
| 3078 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3079 | temp = 0; |
| 3080 | temp |= p_wm->trans_wm.plane_res_l[i] << PLANE_WM_LINES_SHIFT; |
| 3081 | temp |= p_wm->trans_wm.plane_res_b[i]; |
| 3082 | if (p_wm->trans_wm.plane_en[i]) |
| 3083 | temp |= PLANE_WM_EN; |
| 3084 | |
| 3085 | r->plane_trans[pipe][i] = temp; |
| 3086 | } |
| 3087 | |
| 3088 | temp = 0; |
| 3089 | temp |= p_wm->trans_wm.cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3090 | temp |= p_wm->trans_wm.cursor_res_b; |
| 3091 | if (p_wm->trans_wm.cursor_en) |
| 3092 | temp |= PLANE_WM_EN; |
| 3093 | |
| 3094 | r->cursor_trans[pipe] = temp; |
| 3095 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3096 | r->wm_linetime[pipe] = p_wm->linetime; |
| 3097 | } |
| 3098 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3099 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, uint32_t reg, |
| 3100 | const struct skl_ddb_entry *entry) |
| 3101 | { |
| 3102 | if (entry->end) |
| 3103 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 3104 | else |
| 3105 | I915_WRITE(reg, 0); |
| 3106 | } |
| 3107 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3108 | static void skl_write_wm_values(struct drm_i915_private *dev_priv, |
| 3109 | const struct skl_wm_values *new) |
| 3110 | { |
| 3111 | struct drm_device *dev = dev_priv->dev; |
| 3112 | struct intel_crtc *crtc; |
| 3113 | |
| 3114 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
| 3115 | int i, level, max_level = ilk_wm_max_level(dev); |
| 3116 | enum pipe pipe = crtc->pipe; |
| 3117 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3118 | if (!new->dirty[pipe]) |
| 3119 | continue; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3120 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3121 | I915_WRITE(PIPE_WM_LINETIME(pipe), new->wm_linetime[pipe]); |
| 3122 | |
| 3123 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3124 | for (i = 0; i < intel_num_planes(crtc); i++) |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3125 | I915_WRITE(PLANE_WM(pipe, i, level), |
| 3126 | new->plane[pipe][i][level]); |
| 3127 | I915_WRITE(CUR_WM(pipe, level), |
| 3128 | new->cursor[pipe][level]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3129 | } |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3130 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3131 | I915_WRITE(PLANE_WM_TRANS(pipe, i), |
| 3132 | new->plane_trans[pipe][i]); |
| 3133 | I915_WRITE(CUR_WM_TRANS(pipe), new->cursor_trans[pipe]); |
| 3134 | |
| 3135 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3136 | skl_ddb_entry_write(dev_priv, |
| 3137 | PLANE_BUF_CFG(pipe, i), |
| 3138 | &new->ddb.plane[pipe][i]); |
| 3139 | |
| 3140 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
| 3141 | &new->ddb.cursor[pipe]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3142 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3145 | /* |
| 3146 | * When setting up a new DDB allocation arrangement, we need to correctly |
| 3147 | * sequence the times at which the new allocations for the pipes are taken into |
| 3148 | * account or we'll have pipes fetching from space previously allocated to |
| 3149 | * another pipe. |
| 3150 | * |
| 3151 | * Roughly the sequence looks like: |
| 3152 | * 1. re-allocate the pipe(s) with the allocation being reduced and not |
| 3153 | * overlapping with a previous light-up pipe (another way to put it is: |
| 3154 | * pipes with their new allocation strickly included into their old ones). |
| 3155 | * 2. re-allocate the other pipes that get their allocation reduced |
| 3156 | * 3. allocate the pipes having their allocation increased |
| 3157 | * |
| 3158 | * Steps 1. and 2. are here to take care of the following case: |
| 3159 | * - Initially DDB looks like this: |
| 3160 | * | B | C | |
| 3161 | * - enable pipe A. |
| 3162 | * - pipe B has a reduced DDB allocation that overlaps with the old pipe C |
| 3163 | * allocation |
| 3164 | * | A | B | C | |
| 3165 | * |
| 3166 | * We need to sequence the re-allocation: C, B, A (and not B, C, A). |
| 3167 | */ |
| 3168 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3169 | static void |
| 3170 | 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] | 3171 | { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3172 | int plane; |
| 3173 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3174 | DRM_DEBUG_KMS("flush pipe %c (pass %d)\n", pipe_name(pipe), pass); |
| 3175 | |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 3176 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3177 | I915_WRITE(PLANE_SURF(pipe, plane), |
| 3178 | I915_READ(PLANE_SURF(pipe, plane))); |
| 3179 | } |
| 3180 | I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe))); |
| 3181 | } |
| 3182 | |
| 3183 | static bool |
| 3184 | skl_ddb_allocation_included(const struct skl_ddb_allocation *old, |
| 3185 | const struct skl_ddb_allocation *new, |
| 3186 | enum pipe pipe) |
| 3187 | { |
| 3188 | uint16_t old_size, new_size; |
| 3189 | |
| 3190 | old_size = skl_ddb_entry_size(&old->pipe[pipe]); |
| 3191 | new_size = skl_ddb_entry_size(&new->pipe[pipe]); |
| 3192 | |
| 3193 | return old_size != new_size && |
| 3194 | new->pipe[pipe].start >= old->pipe[pipe].start && |
| 3195 | new->pipe[pipe].end <= old->pipe[pipe].end; |
| 3196 | } |
| 3197 | |
| 3198 | static void skl_flush_wm_values(struct drm_i915_private *dev_priv, |
| 3199 | struct skl_wm_values *new_values) |
| 3200 | { |
| 3201 | struct drm_device *dev = dev_priv->dev; |
| 3202 | struct skl_ddb_allocation *cur_ddb, *new_ddb; |
| 3203 | bool reallocated[I915_MAX_PIPES] = {false, false, false}; |
| 3204 | struct intel_crtc *crtc; |
| 3205 | enum pipe pipe; |
| 3206 | |
| 3207 | new_ddb = &new_values->ddb; |
| 3208 | cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 3209 | |
| 3210 | /* |
| 3211 | * First pass: flush the pipes with the new allocation contained into |
| 3212 | * the old space. |
| 3213 | * |
| 3214 | * We'll wait for the vblank on those pipes to ensure we can safely |
| 3215 | * re-allocate the freed space without this pipe fetching from it. |
| 3216 | */ |
| 3217 | for_each_intel_crtc(dev, crtc) { |
| 3218 | if (!crtc->active) |
| 3219 | continue; |
| 3220 | |
| 3221 | pipe = crtc->pipe; |
| 3222 | |
| 3223 | if (!skl_ddb_allocation_included(cur_ddb, new_ddb, pipe)) |
| 3224 | continue; |
| 3225 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3226 | skl_wm_flush_pipe(dev_priv, pipe, 1); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3227 | intel_wait_for_vblank(dev, pipe); |
| 3228 | |
| 3229 | reallocated[pipe] = true; |
| 3230 | } |
| 3231 | |
| 3232 | |
| 3233 | /* |
| 3234 | * Second pass: flush the pipes that are having their allocation |
| 3235 | * reduced, but overlapping with a previous allocation. |
| 3236 | * |
| 3237 | * Here as well we need to wait for the vblank to make sure the freed |
| 3238 | * space is not used anymore. |
| 3239 | */ |
| 3240 | for_each_intel_crtc(dev, crtc) { |
| 3241 | if (!crtc->active) |
| 3242 | continue; |
| 3243 | |
| 3244 | pipe = crtc->pipe; |
| 3245 | |
| 3246 | if (reallocated[pipe]) |
| 3247 | continue; |
| 3248 | |
| 3249 | if (skl_ddb_entry_size(&new_ddb->pipe[pipe]) < |
| 3250 | skl_ddb_entry_size(&cur_ddb->pipe[pipe])) { |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3251 | skl_wm_flush_pipe(dev_priv, pipe, 2); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3252 | intel_wait_for_vblank(dev, pipe); |
Sonika Jindal | d9d8e6b | 2014-12-11 17:58:15 +0530 | [diff] [blame] | 3253 | reallocated[pipe] = true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3254 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | /* |
| 3258 | * Third pass: flush the pipes that got more space allocated. |
| 3259 | * |
| 3260 | * We don't need to actively wait for the update here, next vblank |
| 3261 | * will just get more DDB space with the correct WM values. |
| 3262 | */ |
| 3263 | for_each_intel_crtc(dev, crtc) { |
| 3264 | if (!crtc->active) |
| 3265 | continue; |
| 3266 | |
| 3267 | pipe = crtc->pipe; |
| 3268 | |
| 3269 | /* |
| 3270 | * At this point, only the pipes more space than before are |
| 3271 | * left to re-allocate. |
| 3272 | */ |
| 3273 | if (reallocated[pipe]) |
| 3274 | continue; |
| 3275 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3276 | skl_wm_flush_pipe(dev_priv, pipe, 3); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3277 | } |
| 3278 | } |
| 3279 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3280 | static bool skl_update_pipe_wm(struct drm_crtc *crtc, |
| 3281 | struct skl_pipe_wm_parameters *params, |
| 3282 | struct intel_wm_config *config, |
| 3283 | struct skl_ddb_allocation *ddb, /* out */ |
| 3284 | struct skl_pipe_wm *pipe_wm /* out */) |
| 3285 | { |
| 3286 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3287 | |
| 3288 | skl_compute_wm_pipe_parameters(crtc, params); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3289 | skl_allocate_pipe_ddb(crtc, config, params, ddb); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3290 | skl_compute_pipe_wm(crtc, ddb, params, pipe_wm); |
| 3291 | |
| 3292 | if (!memcmp(&intel_crtc->wm.skl_active, pipe_wm, sizeof(*pipe_wm))) |
| 3293 | return false; |
| 3294 | |
| 3295 | intel_crtc->wm.skl_active = *pipe_wm; |
| 3296 | return true; |
| 3297 | } |
| 3298 | |
| 3299 | static void skl_update_other_pipe_wm(struct drm_device *dev, |
| 3300 | struct drm_crtc *crtc, |
| 3301 | struct intel_wm_config *config, |
| 3302 | struct skl_wm_values *r) |
| 3303 | { |
| 3304 | struct intel_crtc *intel_crtc; |
| 3305 | struct intel_crtc *this_crtc = to_intel_crtc(crtc); |
| 3306 | |
| 3307 | /* |
| 3308 | * If the WM update hasn't changed the allocation for this_crtc (the |
| 3309 | * crtc we are currently computing the new WM values for), other |
| 3310 | * enabled crtcs will keep the same allocation and we don't need to |
| 3311 | * recompute anything for them. |
| 3312 | */ |
| 3313 | if (!skl_ddb_allocation_changed(&r->ddb, this_crtc)) |
| 3314 | return; |
| 3315 | |
| 3316 | /* |
| 3317 | * Otherwise, because of this_crtc being freshly enabled/disabled, the |
| 3318 | * other active pipes need new DDB allocation and WM values. |
| 3319 | */ |
| 3320 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 3321 | base.head) { |
| 3322 | struct skl_pipe_wm_parameters params = {}; |
| 3323 | struct skl_pipe_wm pipe_wm = {}; |
| 3324 | bool wm_changed; |
| 3325 | |
| 3326 | if (this_crtc->pipe == intel_crtc->pipe) |
| 3327 | continue; |
| 3328 | |
| 3329 | if (!intel_crtc->active) |
| 3330 | continue; |
| 3331 | |
| 3332 | wm_changed = skl_update_pipe_wm(&intel_crtc->base, |
| 3333 | ¶ms, config, |
| 3334 | &r->ddb, &pipe_wm); |
| 3335 | |
| 3336 | /* |
| 3337 | * If we end up re-computing the other pipe WM values, it's |
| 3338 | * because it was really needed, so we expect the WM values to |
| 3339 | * be different. |
| 3340 | */ |
| 3341 | WARN_ON(!wm_changed); |
| 3342 | |
| 3343 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, r, intel_crtc); |
| 3344 | r->dirty[intel_crtc->pipe] = true; |
| 3345 | } |
| 3346 | } |
| 3347 | |
| 3348 | static void skl_update_wm(struct drm_crtc *crtc) |
| 3349 | { |
| 3350 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3351 | struct drm_device *dev = crtc->dev; |
| 3352 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3353 | struct skl_pipe_wm_parameters params = {}; |
| 3354 | struct skl_wm_values *results = &dev_priv->wm.skl_results; |
| 3355 | struct skl_pipe_wm pipe_wm = {}; |
| 3356 | struct intel_wm_config config = {}; |
| 3357 | |
| 3358 | memset(results, 0, sizeof(*results)); |
| 3359 | |
| 3360 | skl_compute_wm_global_parameters(dev, &config); |
| 3361 | |
| 3362 | if (!skl_update_pipe_wm(crtc, ¶ms, &config, |
| 3363 | &results->ddb, &pipe_wm)) |
| 3364 | return; |
| 3365 | |
| 3366 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, results, intel_crtc); |
| 3367 | results->dirty[intel_crtc->pipe] = true; |
| 3368 | |
| 3369 | skl_update_other_pipe_wm(dev, crtc, &config, results); |
| 3370 | skl_write_wm_values(dev_priv, results); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3371 | skl_flush_wm_values(dev_priv, results); |
Damien Lespiau | 53b0deb | 2014-11-04 17:06:48 +0000 | [diff] [blame] | 3372 | |
| 3373 | /* store the new configuration */ |
| 3374 | dev_priv->wm.skl_hw = *results; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | static void |
| 3378 | skl_update_sprite_wm(struct drm_plane *plane, struct drm_crtc *crtc, |
| 3379 | uint32_t sprite_width, uint32_t sprite_height, |
| 3380 | int pixel_size, bool enabled, bool scaled) |
| 3381 | { |
| 3382 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3383 | struct drm_framebuffer *fb = plane->state->fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3384 | |
| 3385 | intel_plane->wm.enabled = enabled; |
| 3386 | intel_plane->wm.scaled = scaled; |
| 3387 | intel_plane->wm.horiz_pixels = sprite_width; |
| 3388 | intel_plane->wm.vert_pixels = sprite_height; |
| 3389 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3390 | intel_plane->wm.tiling = DRM_FORMAT_MOD_NONE; |
| 3391 | /* |
| 3392 | * Framebuffer can be NULL on plane disable, but it does not |
| 3393 | * matter for watermarks if we assume no tiling in that case. |
| 3394 | */ |
| 3395 | if (fb) |
| 3396 | intel_plane->wm.tiling = fb->modifier[0]; |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 3397 | intel_plane->wm.rotation = plane->state->rotation; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3398 | |
| 3399 | skl_update_wm(crtc); |
| 3400 | } |
| 3401 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3402 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3403 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3404 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3405 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3406 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3407 | struct ilk_wm_maximums max; |
| 3408 | struct ilk_pipe_wm_parameters params = {}; |
| 3409 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3410 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3411 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3412 | 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] | 3413 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3414 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3415 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3416 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3417 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 3418 | |
| 3419 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 3420 | return; |
| 3421 | |
| 3422 | intel_crtc->wm.active = pipe_wm; |
| 3423 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3424 | ilk_compute_wm_config(dev, &config); |
| 3425 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3426 | 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] | 3427 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3428 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3429 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 3430 | if (INTEL_INFO(dev)->gen >= 7 && |
| 3431 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3432 | 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] | 3433 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3434 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3435 | 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] | 3436 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3437 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3438 | } |
| 3439 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3440 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3441 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3442 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3443 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3444 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3445 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3446 | } |
| 3447 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3448 | static void |
| 3449 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 3450 | struct drm_crtc *crtc, |
| 3451 | uint32_t sprite_width, uint32_t sprite_height, |
| 3452 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3453 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3454 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3455 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3456 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3457 | intel_plane->wm.enabled = enabled; |
| 3458 | intel_plane->wm.scaled = scaled; |
| 3459 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3460 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3461 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3462 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3463 | /* |
| 3464 | * IVB workaround: must disable low power watermarks for at least |
| 3465 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 3466 | * when scaling is disabled. |
| 3467 | * |
| 3468 | * WaCxSRDisabledForSpriteScaling:ivb |
| 3469 | */ |
| 3470 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 3471 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 3472 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3473 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3474 | } |
| 3475 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3476 | static void skl_pipe_wm_active_state(uint32_t val, |
| 3477 | struct skl_pipe_wm *active, |
| 3478 | bool is_transwm, |
| 3479 | bool is_cursor, |
| 3480 | int i, |
| 3481 | int level) |
| 3482 | { |
| 3483 | bool is_enabled = (val & PLANE_WM_EN) != 0; |
| 3484 | |
| 3485 | if (!is_transwm) { |
| 3486 | if (!is_cursor) { |
| 3487 | active->wm[level].plane_en[i] = is_enabled; |
| 3488 | active->wm[level].plane_res_b[i] = |
| 3489 | val & PLANE_WM_BLOCKS_MASK; |
| 3490 | active->wm[level].plane_res_l[i] = |
| 3491 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3492 | PLANE_WM_LINES_MASK; |
| 3493 | } else { |
| 3494 | active->wm[level].cursor_en = is_enabled; |
| 3495 | active->wm[level].cursor_res_b = |
| 3496 | val & PLANE_WM_BLOCKS_MASK; |
| 3497 | active->wm[level].cursor_res_l = |
| 3498 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3499 | PLANE_WM_LINES_MASK; |
| 3500 | } |
| 3501 | } else { |
| 3502 | if (!is_cursor) { |
| 3503 | active->trans_wm.plane_en[i] = is_enabled; |
| 3504 | active->trans_wm.plane_res_b[i] = |
| 3505 | val & PLANE_WM_BLOCKS_MASK; |
| 3506 | active->trans_wm.plane_res_l[i] = |
| 3507 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3508 | PLANE_WM_LINES_MASK; |
| 3509 | } else { |
| 3510 | active->trans_wm.cursor_en = is_enabled; |
| 3511 | active->trans_wm.cursor_res_b = |
| 3512 | val & PLANE_WM_BLOCKS_MASK; |
| 3513 | active->trans_wm.cursor_res_l = |
| 3514 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3515 | PLANE_WM_LINES_MASK; |
| 3516 | } |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3521 | { |
| 3522 | struct drm_device *dev = crtc->dev; |
| 3523 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3524 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
| 3525 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3526 | struct skl_pipe_wm *active = &intel_crtc->wm.skl_active; |
| 3527 | enum pipe pipe = intel_crtc->pipe; |
| 3528 | int level, i, max_level; |
| 3529 | uint32_t temp; |
| 3530 | |
| 3531 | max_level = ilk_wm_max_level(dev); |
| 3532 | |
| 3533 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
| 3534 | |
| 3535 | for (level = 0; level <= max_level; level++) { |
| 3536 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3537 | hw->plane[pipe][i][level] = |
| 3538 | I915_READ(PLANE_WM(pipe, i, level)); |
| 3539 | hw->cursor[pipe][level] = I915_READ(CUR_WM(pipe, level)); |
| 3540 | } |
| 3541 | |
| 3542 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3543 | hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i)); |
| 3544 | hw->cursor_trans[pipe] = I915_READ(CUR_WM_TRANS(pipe)); |
| 3545 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3546 | if (!intel_crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3547 | return; |
| 3548 | |
| 3549 | hw->dirty[pipe] = true; |
| 3550 | |
| 3551 | active->linetime = hw->wm_linetime[pipe]; |
| 3552 | |
| 3553 | for (level = 0; level <= max_level; level++) { |
| 3554 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3555 | temp = hw->plane[pipe][i][level]; |
| 3556 | skl_pipe_wm_active_state(temp, active, false, |
| 3557 | false, i, level); |
| 3558 | } |
| 3559 | temp = hw->cursor[pipe][level]; |
| 3560 | skl_pipe_wm_active_state(temp, active, false, true, i, level); |
| 3561 | } |
| 3562 | |
| 3563 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3564 | temp = hw->plane_trans[pipe][i]; |
| 3565 | skl_pipe_wm_active_state(temp, active, true, false, i, 0); |
| 3566 | } |
| 3567 | |
| 3568 | temp = hw->cursor_trans[pipe]; |
| 3569 | skl_pipe_wm_active_state(temp, active, true, true, i, 0); |
| 3570 | } |
| 3571 | |
| 3572 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 3573 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3574 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3575 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3576 | struct drm_crtc *crtc; |
| 3577 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3578 | skl_ddb_get_hw_state(dev_priv, ddb); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3579 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3580 | skl_pipe_wm_get_hw_state(crtc); |
| 3581 | } |
| 3582 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3583 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3584 | { |
| 3585 | struct drm_device *dev = crtc->dev; |
| 3586 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3587 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3588 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3589 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 3590 | enum pipe pipe = intel_crtc->pipe; |
| 3591 | static const unsigned int wm0_pipe_reg[] = { |
| 3592 | [PIPE_A] = WM0_PIPEA_ILK, |
| 3593 | [PIPE_B] = WM0_PIPEB_ILK, |
| 3594 | [PIPE_C] = WM0_PIPEC_IVB, |
| 3595 | }; |
| 3596 | |
| 3597 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3598 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 3599 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3600 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3601 | active->pipe_enabled = intel_crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3602 | |
| 3603 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3604 | u32 tmp = hw->wm_pipe[pipe]; |
| 3605 | |
| 3606 | /* |
| 3607 | * For active pipes LP0 watermark is marked as |
| 3608 | * enabled, and LP1+ watermaks as disabled since |
| 3609 | * we can't really reverse compute them in case |
| 3610 | * multiple pipes are active. |
| 3611 | */ |
| 3612 | active->wm[0].enable = true; |
| 3613 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 3614 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 3615 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 3616 | active->linetime = hw->wm_linetime[pipe]; |
| 3617 | } else { |
| 3618 | int level, max_level = ilk_wm_max_level(dev); |
| 3619 | |
| 3620 | /* |
| 3621 | * For inactive pipes, all watermark levels |
| 3622 | * should be marked as enabled but zeroed, |
| 3623 | * which is what we'd compute them to. |
| 3624 | */ |
| 3625 | for (level = 0; level <= max_level; level++) |
| 3626 | active->wm[level].enable = true; |
| 3627 | } |
| 3628 | } |
| 3629 | |
| 3630 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 3631 | { |
| 3632 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3633 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3634 | struct drm_crtc *crtc; |
| 3635 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3636 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3637 | ilk_pipe_wm_get_hw_state(crtc); |
| 3638 | |
| 3639 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 3640 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 3641 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 3642 | |
| 3643 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 3644 | if (INTEL_INFO(dev)->gen >= 7) { |
| 3645 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 3646 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 3647 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3648 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3649 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3650 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 3651 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 3652 | else if (IS_IVYBRIDGE(dev)) |
| 3653 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 3654 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3655 | |
| 3656 | hw->enable_fbc_wm = |
| 3657 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3658 | } |
| 3659 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3660 | /** |
| 3661 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3662 | * |
| 3663 | * Calculate watermark values for the various WM regs based on current mode |
| 3664 | * and plane configuration. |
| 3665 | * |
| 3666 | * There are several cases to deal with here: |
| 3667 | * - normal (i.e. non-self-refresh) |
| 3668 | * - self-refresh (SR) mode |
| 3669 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3670 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3671 | * lines), so need to account for TLB latency |
| 3672 | * |
| 3673 | * The normal calculation is: |
| 3674 | * watermark = dotclock * bytes per pixel * latency |
| 3675 | * where latency is platform & configuration dependent (we assume pessimal |
| 3676 | * values here). |
| 3677 | * |
| 3678 | * The SR calculation is: |
| 3679 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3680 | * bytes per pixel |
| 3681 | * where |
| 3682 | * line time = htotal / dotclock |
| 3683 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3684 | * and latency is assumed to be high, as above. |
| 3685 | * |
| 3686 | * The final value programmed to the register should always be rounded up, |
| 3687 | * and include an extra 2 entries to account for clock crossings. |
| 3688 | * |
| 3689 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3690 | * to set the non-SR watermarks to 8. |
| 3691 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3692 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3693 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3694 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3695 | |
| 3696 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3697 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3698 | } |
| 3699 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3700 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3701 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3702 | uint32_t sprite_width, |
| 3703 | uint32_t sprite_height, |
| 3704 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3705 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3706 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3707 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3708 | |
| 3709 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3710 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3711 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3712 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3713 | } |
| 3714 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3715 | /** |
| 3716 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3717 | */ |
| 3718 | DEFINE_SPINLOCK(mchdev_lock); |
| 3719 | |
| 3720 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3721 | * mchdev_lock. */ |
| 3722 | static struct drm_i915_private *i915_mch_dev; |
| 3723 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3724 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3725 | { |
| 3726 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3727 | u16 rgvswctl; |
| 3728 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3729 | assert_spin_locked(&mchdev_lock); |
| 3730 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3731 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3732 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3733 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3734 | return false; /* still busy with another command */ |
| 3735 | } |
| 3736 | |
| 3737 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3738 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3739 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3740 | POSTING_READ16(MEMSWCTL); |
| 3741 | |
| 3742 | rgvswctl |= MEMCTL_CMD_STS; |
| 3743 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3744 | |
| 3745 | return true; |
| 3746 | } |
| 3747 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3748 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3749 | { |
| 3750 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3751 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 3752 | u8 fmax, fmin, fstart, vstart; |
| 3753 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3754 | spin_lock_irq(&mchdev_lock); |
| 3755 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3756 | /* Enable temp reporting */ |
| 3757 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 3758 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 3759 | |
| 3760 | /* 100ms RC evaluation intervals */ |
| 3761 | I915_WRITE(RCUPEI, 100000); |
| 3762 | I915_WRITE(RCDNEI, 100000); |
| 3763 | |
| 3764 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 3765 | I915_WRITE(RCBMAXAVG, 90000); |
| 3766 | I915_WRITE(RCBMINAVG, 80000); |
| 3767 | |
| 3768 | I915_WRITE(MEMIHYST, 1); |
| 3769 | |
| 3770 | /* Set up min, max, and cur for interrupt handling */ |
| 3771 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 3772 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3773 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3774 | MEMMODE_FSTART_SHIFT; |
| 3775 | |
| 3776 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3777 | PXVFREQ_PX_SHIFT; |
| 3778 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3779 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3780 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3781 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3782 | dev_priv->ips.max_delay = fstart; |
| 3783 | dev_priv->ips.min_delay = fmin; |
| 3784 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3785 | |
| 3786 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3787 | fmax, fmin, fstart); |
| 3788 | |
| 3789 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3790 | |
| 3791 | /* |
| 3792 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3793 | */ |
| 3794 | |
| 3795 | I915_WRITE(VIDSTART, vstart); |
| 3796 | POSTING_READ(VIDSTART); |
| 3797 | |
| 3798 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3799 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3800 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3801 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3802 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3803 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3804 | |
| 3805 | ironlake_set_drps(dev, fstart); |
| 3806 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3807 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3808 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3809 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3810 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 3811 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3812 | |
| 3813 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3814 | } |
| 3815 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3816 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3817 | { |
| 3818 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3819 | u16 rgvswctl; |
| 3820 | |
| 3821 | spin_lock_irq(&mchdev_lock); |
| 3822 | |
| 3823 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3824 | |
| 3825 | /* Ack interrupts, disable EFC interrupt */ |
| 3826 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3827 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3828 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3829 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3830 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3831 | |
| 3832 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3833 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3834 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3835 | rgvswctl |= MEMCTL_CMD_STS; |
| 3836 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3837 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3838 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3839 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3840 | } |
| 3841 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3842 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3843 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3844 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3845 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3846 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3847 | 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] | 3848 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3849 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3850 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3851 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3852 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3853 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3854 | * the hw runs at the minimal clock before selecting the desired |
| 3855 | * frequency, if the down threshold expires in that window we will not |
| 3856 | * receive a down interrupt. */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3857 | if (IS_GEN9(dev_priv->dev)) { |
| 3858 | limits = (dev_priv->rps.max_freq_softlimit) << 23; |
| 3859 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3860 | limits |= (dev_priv->rps.min_freq_softlimit) << 14; |
| 3861 | } else { |
| 3862 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3863 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3864 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
| 3865 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3866 | |
| 3867 | return limits; |
| 3868 | } |
| 3869 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3870 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3871 | { |
| 3872 | int new_power; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3873 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 3874 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3875 | |
| 3876 | new_power = dev_priv->rps.power; |
| 3877 | switch (dev_priv->rps.power) { |
| 3878 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3879 | 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] | 3880 | new_power = BETWEEN; |
| 3881 | break; |
| 3882 | |
| 3883 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3884 | 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] | 3885 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3886 | 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] | 3887 | new_power = HIGH_POWER; |
| 3888 | break; |
| 3889 | |
| 3890 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3891 | 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] | 3892 | new_power = BETWEEN; |
| 3893 | break; |
| 3894 | } |
| 3895 | /* Max/min bins are special */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3896 | if (val <= dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3897 | new_power = LOW_POWER; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3898 | if (val >= dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3899 | new_power = HIGH_POWER; |
| 3900 | if (new_power == dev_priv->rps.power) |
| 3901 | return; |
| 3902 | |
| 3903 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3904 | switch (new_power) { |
| 3905 | case LOW_POWER: |
| 3906 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3907 | ei_up = 16000; |
| 3908 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3909 | |
| 3910 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3911 | ei_down = 32000; |
| 3912 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3913 | break; |
| 3914 | |
| 3915 | case BETWEEN: |
| 3916 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3917 | ei_up = 13000; |
| 3918 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3919 | |
| 3920 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3921 | ei_down = 32000; |
| 3922 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3923 | break; |
| 3924 | |
| 3925 | case HIGH_POWER: |
| 3926 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3927 | ei_up = 10000; |
| 3928 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3929 | |
| 3930 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3931 | ei_down = 32000; |
| 3932 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3933 | break; |
| 3934 | } |
| 3935 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3936 | I915_WRITE(GEN6_RP_UP_EI, |
| 3937 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
| 3938 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
| 3939 | GT_INTERVAL_FROM_US(dev_priv, (ei_up * threshold_up / 100))); |
| 3940 | |
| 3941 | I915_WRITE(GEN6_RP_DOWN_EI, |
| 3942 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
| 3943 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
| 3944 | GT_INTERVAL_FROM_US(dev_priv, (ei_down * threshold_down / 100))); |
| 3945 | |
| 3946 | I915_WRITE(GEN6_RP_CONTROL, |
| 3947 | GEN6_RP_MEDIA_TURBO | |
| 3948 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3949 | GEN6_RP_MEDIA_IS_GFX | |
| 3950 | GEN6_RP_ENABLE | |
| 3951 | GEN6_RP_UP_BUSY_AVG | |
| 3952 | GEN6_RP_DOWN_IDLE_AVG); |
| 3953 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3954 | dev_priv->rps.power = new_power; |
| 3955 | dev_priv->rps.last_adj = 0; |
| 3956 | } |
| 3957 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3958 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3959 | { |
| 3960 | u32 mask = 0; |
| 3961 | |
| 3962 | if (val > dev_priv->rps.min_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 3963 | 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] | 3964 | if (val < dev_priv->rps.max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 3965 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3966 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3967 | mask &= dev_priv->pm_rps_events; |
| 3968 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 3969 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3970 | } |
| 3971 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3972 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3973 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3974 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3975 | static void gen6_set_rps(struct drm_device *dev, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3976 | { |
| 3977 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3978 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3979 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3980 | WARN_ON(val > dev_priv->rps.max_freq); |
| 3981 | WARN_ON(val < dev_priv->rps.min_freq); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3982 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3983 | /* min/max delay may still have been modified so be sure to |
| 3984 | * write the limits value. |
| 3985 | */ |
| 3986 | if (val != dev_priv->rps.cur_freq) { |
| 3987 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3988 | |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 3989 | if (IS_GEN9(dev)) |
| 3990 | I915_WRITE(GEN6_RPNSWREQ, |
| 3991 | GEN9_FREQUENCY(val)); |
| 3992 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3993 | I915_WRITE(GEN6_RPNSWREQ, |
| 3994 | HSW_FREQUENCY(val)); |
| 3995 | else |
| 3996 | I915_WRITE(GEN6_RPNSWREQ, |
| 3997 | GEN6_FREQUENCY(val) | |
| 3998 | GEN6_OFFSET(0) | |
| 3999 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 4000 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4001 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4002 | /* Make sure we continue to get interrupts |
| 4003 | * until we hit the minimum or maximum frequencies. |
| 4004 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 4005 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4006 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4007 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 4008 | POSTING_READ(GEN6_RPNSWREQ); |
| 4009 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4010 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 4011 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4012 | } |
| 4013 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4014 | static void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 4015 | { |
| 4016 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4017 | |
| 4018 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4019 | WARN_ON(val > dev_priv->rps.max_freq); |
| 4020 | WARN_ON(val < dev_priv->rps.min_freq); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4021 | |
| 4022 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 4023 | "Odd GPU freq value\n")) |
| 4024 | val &= ~1; |
| 4025 | |
| 4026 | if (val != dev_priv->rps.cur_freq) |
| 4027 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 4028 | |
| 4029 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 4030 | |
| 4031 | dev_priv->rps.cur_freq = val; |
| 4032 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
| 4033 | } |
| 4034 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4035 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 4036 | * |
| 4037 | * * If Gfx is Idle, then |
| 4038 | * 1. Mask Turbo interrupts |
| 4039 | * 2. Bring up Gfx clock |
| 4040 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 4041 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 4042 | * 5. Unmask Turbo interrupts |
| 4043 | */ |
| 4044 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 4045 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4046 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4047 | u32 val = dev_priv->rps.idle_freq; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4048 | |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 4049 | /* CHV and latest VLV don't need to force the gfx clock */ |
| 4050 | if (IS_CHERRYVIEW(dev) || dev->pdev->revision >= 0xd) { |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4051 | valleyview_set_rps(dev_priv->dev, val); |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4052 | return; |
| 4053 | } |
| 4054 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4055 | /* |
| 4056 | * When we are idle. Drop to min voltage state. |
| 4057 | */ |
| 4058 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4059 | if (dev_priv->rps.cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4060 | return; |
| 4061 | |
| 4062 | /* Mask turbo interrupt so that they will not come in between */ |
Imre Deak | f24eeb1 | 2014-12-19 19:33:27 +0200 | [diff] [blame] | 4063 | I915_WRITE(GEN6_PMINTRMSK, |
| 4064 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4065 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4066 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4067 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4068 | dev_priv->rps.cur_freq = val; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4069 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4070 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4071 | |
| 4072 | 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] | 4073 | & GENFREQSTATUS) == 0, 100)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4074 | DRM_ERROR("timed out waiting for Punit\n"); |
| 4075 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4076 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4077 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4078 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4079 | } |
| 4080 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4081 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 4082 | { |
| 4083 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4084 | if (dev_priv->rps.enabled) { |
| 4085 | if (dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) |
| 4086 | gen6_rps_reset_ei(dev_priv); |
| 4087 | I915_WRITE(GEN6_PMINTRMSK, |
| 4088 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
| 4089 | } |
| 4090 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4091 | } |
| 4092 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4093 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 4094 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 4095 | struct drm_device *dev = dev_priv->dev; |
| 4096 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4097 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4098 | if (dev_priv->rps.enabled) { |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 4099 | if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4100 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4101 | else |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4102 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4103 | dev_priv->rps.last_adj = 0; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4104 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4105 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4106 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4107 | } |
| 4108 | |
| 4109 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 4110 | { |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4111 | u32 val; |
| 4112 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4113 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4114 | val = dev_priv->rps.max_freq_softlimit; |
| 4115 | if (dev_priv->rps.enabled && |
| 4116 | dev_priv->mm.busy && |
| 4117 | dev_priv->rps.cur_freq < val) { |
| 4118 | intel_set_rps(dev_priv->dev, val); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4119 | dev_priv->rps.last_adj = 0; |
| 4120 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4121 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4122 | } |
| 4123 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4124 | void intel_set_rps(struct drm_device *dev, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4125 | { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4126 | if (IS_VALLEYVIEW(dev)) |
| 4127 | valleyview_set_rps(dev, val); |
| 4128 | else |
| 4129 | gen6_set_rps(dev, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4130 | } |
| 4131 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4132 | static void gen9_disable_rps(struct drm_device *dev) |
| 4133 | { |
| 4134 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4135 | |
| 4136 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4137 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4138 | } |
| 4139 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4140 | static void gen6_disable_rps(struct drm_device *dev) |
| 4141 | { |
| 4142 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4143 | |
| 4144 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4145 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4146 | } |
| 4147 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4148 | static void cherryview_disable_rps(struct drm_device *dev) |
| 4149 | { |
| 4150 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4151 | |
| 4152 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4153 | } |
| 4154 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4155 | static void valleyview_disable_rps(struct drm_device *dev) |
| 4156 | { |
| 4157 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4158 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4159 | /* we're doing forcewake before Disabling RC6, |
| 4160 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4161 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4162 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4163 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4164 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4165 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4166 | } |
| 4167 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4168 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 4169 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4170 | if (IS_VALLEYVIEW(dev)) { |
| 4171 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 4172 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 4173 | else |
| 4174 | mode = 0; |
| 4175 | } |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4176 | if (HAS_RC6p(dev)) |
| 4177 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s RC6p %s RC6pp %s\n", |
| 4178 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 4179 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 4180 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
| 4181 | |
| 4182 | else |
| 4183 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s\n", |
| 4184 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4187 | 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] | 4188 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 4189 | /* No RC6 before Ironlake */ |
| 4190 | if (INTEL_INFO(dev)->gen < 5) |
| 4191 | return 0; |
| 4192 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4193 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 4194 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 4195 | return 0; |
| 4196 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 4197 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4198 | if (enable_rc6 >= 0) { |
| 4199 | int mask; |
| 4200 | |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4201 | if (HAS_RC6p(dev)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4202 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 4203 | INTEL_RC6pp_ENABLE; |
| 4204 | else |
| 4205 | mask = INTEL_RC6_ENABLE; |
| 4206 | |
| 4207 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 4208 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 4209 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4210 | |
| 4211 | return enable_rc6 & mask; |
| 4212 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4213 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 4214 | /* Disable RC6 on Ironlake */ |
| 4215 | if (INTEL_INFO(dev)->gen == 5) |
| 4216 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4217 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4218 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 4219 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4220 | |
| 4221 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4222 | } |
| 4223 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4224 | int intel_enable_rc6(const struct drm_device *dev) |
| 4225 | { |
| 4226 | return i915.enable_rc6; |
| 4227 | } |
| 4228 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4229 | static void gen6_init_rps_frequencies(struct drm_device *dev) |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4230 | { |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4231 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4232 | uint32_t rp_state_cap; |
| 4233 | u32 ddcc_status = 0; |
| 4234 | int ret; |
| 4235 | |
| 4236 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4237 | /* All of these values are in units of 50MHz */ |
| 4238 | dev_priv->rps.cur_freq = 0; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4239 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4240 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4241 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4242 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
Akash Goel | cee991c | 2015-03-06 11:07:16 +0530 | [diff] [blame] | 4243 | if (IS_SKYLAKE(dev)) { |
| 4244 | /* Store the frequency values in 16.66 MHZ units, which is |
| 4245 | the natural hardware unit for SKL */ |
| 4246 | dev_priv->rps.rp0_freq *= GEN9_FREQ_SCALER; |
| 4247 | dev_priv->rps.rp1_freq *= GEN9_FREQ_SCALER; |
| 4248 | dev_priv->rps.min_freq *= GEN9_FREQ_SCALER; |
| 4249 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4250 | /* hw_max = RP0 until we check for overclocking */ |
| 4251 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 4252 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4253 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 4254 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
| 4255 | ret = sandybridge_pcode_read(dev_priv, |
| 4256 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 4257 | &ddcc_status); |
| 4258 | if (0 == ret) |
| 4259 | dev_priv->rps.efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 4260 | clamp_t(u8, |
| 4261 | ((ddcc_status >> 8) & 0xff), |
| 4262 | dev_priv->rps.min_freq, |
| 4263 | dev_priv->rps.max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4264 | } |
| 4265 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4266 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4267 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4268 | /* Preserve min/max settings in case of re-init */ |
| 4269 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4270 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4271 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4272 | if (dev_priv->rps.min_freq_softlimit == 0) { |
| 4273 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 4274 | dev_priv->rps.min_freq_softlimit = |
Tom O'Rourke | f4ab408 | 2014-11-19 14:21:53 -0800 | [diff] [blame] | 4275 | /* max(RPe, 450 MHz) */ |
| 4276 | max(dev_priv->rps.efficient_freq, (u8) 9); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4277 | else |
| 4278 | dev_priv->rps.min_freq_softlimit = |
| 4279 | dev_priv->rps.min_freq; |
| 4280 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4281 | } |
| 4282 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4283 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4284 | static void gen9_enable_rps(struct drm_device *dev) |
| 4285 | { |
| 4286 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4287 | |
| 4288 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 4289 | |
Damien Lespiau | ba1c554 | 2015-01-16 18:07:26 +0000 | [diff] [blame] | 4290 | gen6_init_rps_frequencies(dev); |
| 4291 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4292 | /* Program defaults and thresholds for RPS*/ |
| 4293 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4294 | GEN9_FREQUENCY(dev_priv->rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4295 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4296 | /* 1 second timeout*/ |
| 4297 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 4298 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 4299 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4300 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4301 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4302 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 4303 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 4304 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
| 4305 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
| 4306 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4307 | |
| 4308 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 4309 | } |
| 4310 | |
| 4311 | static void gen9_enable_rc6(struct drm_device *dev) |
| 4312 | { |
| 4313 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4314 | struct intel_engine_cs *ring; |
| 4315 | uint32_t rc6_mask = 0; |
| 4316 | int unused; |
| 4317 | |
| 4318 | /* 1a: Software RC state - RC0 */ |
| 4319 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4320 | |
| 4321 | /* 1b: Get forcewake during program sequence. Although the driver |
| 4322 | * 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] | 4323 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4324 | |
| 4325 | /* 2a: Disable RC states. */ |
| 4326 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4327 | |
| 4328 | /* 2b: Program RC6 thresholds.*/ |
| 4329 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
| 4330 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4331 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4332 | for_each_ring(ring, dev_priv, unused) |
| 4333 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4334 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4335 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
| 4336 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4337 | /* 2c: Program Coarse Power Gating Policies. */ |
| 4338 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 4339 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 4340 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4341 | /* 3a: Enable RC6 */ |
| 4342 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4343 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 4344 | DRM_INFO("RC6 %s\n", (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 4345 | "on" : "off"); |
| 4346 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4347 | GEN6_RC_CTL_EI_MODE(1) | |
| 4348 | rc6_mask); |
| 4349 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4350 | /* 3b: Enable Coarse Power Gating only when RC6 is enabled */ |
| 4351 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? 3 : 0); |
| 4352 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4353 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4354 | |
| 4355 | } |
| 4356 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4357 | static void gen8_enable_rps(struct drm_device *dev) |
| 4358 | { |
| 4359 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4360 | struct intel_engine_cs *ring; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4361 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4362 | int unused; |
| 4363 | |
| 4364 | /* 1a: Software RC state - RC0 */ |
| 4365 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4366 | |
| 4367 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 4368 | * 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] | 4369 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4370 | |
| 4371 | /* 2a: Disable RC states. */ |
| 4372 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4373 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4374 | /* Initialize rps frequencies */ |
| 4375 | gen6_init_rps_frequencies(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4376 | |
| 4377 | /* 2b: Program RC6 thresholds.*/ |
| 4378 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4379 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4380 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4381 | for_each_ring(ring, dev_priv, unused) |
| 4382 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4383 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4384 | if (IS_BROADWELL(dev)) |
| 4385 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 4386 | else |
| 4387 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4388 | |
| 4389 | /* 3: Enable RC6 */ |
| 4390 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4391 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 4392 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4393 | if (IS_BROADWELL(dev)) |
| 4394 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4395 | GEN7_RC_CTL_TO_MODE | |
| 4396 | rc6_mask); |
| 4397 | else |
| 4398 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4399 | GEN6_RC_CTL_EI_MODE(1) | |
| 4400 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4401 | |
| 4402 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 4403 | I915_WRITE(GEN6_RPNSWREQ, |
| 4404 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 4405 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4406 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4407 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 4408 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4409 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4410 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 4411 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 4412 | dev_priv->rps.max_freq_softlimit << 24 | |
| 4413 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4414 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4415 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 4416 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 4417 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 4418 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4419 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4420 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4421 | |
| 4422 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4423 | I915_WRITE(GEN6_RP_CONTROL, |
| 4424 | GEN6_RP_MEDIA_TURBO | |
| 4425 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4426 | GEN6_RP_MEDIA_IS_GFX | |
| 4427 | GEN6_RP_ENABLE | |
| 4428 | GEN6_RP_UP_BUSY_AVG | |
| 4429 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4430 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4431 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4432 | |
Tom O'Rourke | c7f3153 | 2014-11-19 14:21:54 -0800 | [diff] [blame] | 4433 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4434 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4435 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4436 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4437 | } |
| 4438 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4439 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4440 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4441 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4442 | struct intel_engine_cs *ring; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4443 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4444 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4445 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4446 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4447 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4448 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4449 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4450 | /* Here begins a magic sequence of register writes to enable |
| 4451 | * auto-downclocking. |
| 4452 | * |
| 4453 | * Perhaps there might be some value in exposing these to |
| 4454 | * userspace... |
| 4455 | */ |
| 4456 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4457 | |
| 4458 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 4459 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 4460 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 4461 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4462 | } |
| 4463 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4464 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4465 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4466 | /* Initialize rps frequencies */ |
| 4467 | gen6_init_rps_frequencies(dev); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 4468 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4469 | /* disable the counters and set deterministic thresholds */ |
| 4470 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4471 | |
| 4472 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 4473 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 4474 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 4475 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4476 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4477 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 4478 | for_each_ring(ring, dev_priv, i) |
| 4479 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4480 | |
| 4481 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4482 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 4483 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 4484 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 4485 | else |
| 4486 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 4487 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4488 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 4489 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4490 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4491 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 4492 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 4493 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 4494 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4495 | /* We don't use those on Haswell */ |
| 4496 | if (!IS_HASWELL(dev)) { |
| 4497 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 4498 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4499 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4500 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 4501 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 4502 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4503 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4504 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4505 | |
| 4506 | I915_WRITE(GEN6_RC_CONTROL, |
| 4507 | rc6_mask | |
| 4508 | GEN6_RC_CTL_EI_MODE(1) | |
| 4509 | GEN6_RC_CTL_HW_ENABLE); |
| 4510 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4511 | /* Power down if completely idle for over 50ms */ |
| 4512 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4513 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4514 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4515 | 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] | 4516 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4517 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4518 | |
| 4519 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 4520 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 4521 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4522 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4523 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4524 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4525 | } |
| 4526 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4527 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4528 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4529 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4530 | rc6vids = 0; |
| 4531 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4532 | if (IS_GEN6(dev) && ret) { |
| 4533 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4534 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4535 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4536 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4537 | rc6vids &= 0xffff00; |
| 4538 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4539 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4540 | if (ret) |
| 4541 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4542 | } |
| 4543 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4544 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4545 | } |
| 4546 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4547 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4548 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4549 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4550 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4551 | unsigned int gpu_freq; |
| 4552 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4553 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4554 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4555 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4556 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4557 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4558 | policy = cpufreq_cpu_get(0); |
| 4559 | if (policy) { |
| 4560 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4561 | cpufreq_cpu_put(policy); |
| 4562 | } else { |
| 4563 | /* |
| 4564 | * Default to measured freq if none found, PCU will ensure we |
| 4565 | * don't go over |
| 4566 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4567 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4568 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4569 | |
| 4570 | /* Convert from kHz to MHz */ |
| 4571 | max_ia_freq /= 1000; |
| 4572 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4573 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4574 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4575 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4576 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4577 | /* |
| 4578 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4579 | * to use for memory access. We do this by specifying the IA frequency |
| 4580 | * the PCU should use as a reference to determine the ring frequency. |
| 4581 | */ |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4582 | 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] | 4583 | gpu_freq--) { |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4584 | int diff = dev_priv->rps.max_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4585 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4586 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4587 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4588 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4589 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4590 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4591 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4592 | ring_freq = max(min_ring_freq, ring_freq); |
| 4593 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4594 | } else { |
| 4595 | /* On older processors, there is no separate ring |
| 4596 | * clock domain, so in order to boost the bandwidth |
| 4597 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4598 | * |
| 4599 | * For GPU frequencies less than 750MHz, |
| 4600 | * just use the lowest ring freq. |
| 4601 | */ |
| 4602 | if (gpu_freq < min_freq) |
| 4603 | ia_freq = 800; |
| 4604 | else |
| 4605 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4606 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4607 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4608 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4609 | sandybridge_pcode_write(dev_priv, |
| 4610 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4611 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4612 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4613 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4614 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4615 | } |
| 4616 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4617 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4618 | { |
| 4619 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4620 | |
| 4621 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4622 | return; |
| 4623 | |
| 4624 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4625 | __gen6_update_ring_freq(dev); |
| 4626 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4627 | } |
| 4628 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4629 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4630 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4631 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4632 | u32 val, rp0; |
| 4633 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4634 | if (dev->pdev->revision >= 0x20) { |
| 4635 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4636 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4637 | switch (INTEL_INFO(dev)->eu_total) { |
| 4638 | case 8: |
| 4639 | /* (2 * 4) config */ |
| 4640 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 4641 | break; |
| 4642 | case 12: |
| 4643 | /* (2 * 6) config */ |
| 4644 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 4645 | break; |
| 4646 | case 16: |
| 4647 | /* (2 * 8) config */ |
| 4648 | default: |
| 4649 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 4650 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 4651 | break; |
| 4652 | } |
| 4653 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 4654 | } else { |
| 4655 | /* For pre-production hardware */ |
| 4656 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4657 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4658 | PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4659 | } |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4660 | return rp0; |
| 4661 | } |
| 4662 | |
| 4663 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4664 | { |
| 4665 | u32 val, rpe; |
| 4666 | |
| 4667 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4668 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4669 | |
| 4670 | return rpe; |
| 4671 | } |
| 4672 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4673 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4674 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4675 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4676 | u32 val, rp1; |
| 4677 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4678 | if (dev->pdev->revision >= 0x20) { |
| 4679 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 4680 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 4681 | } else { |
| 4682 | /* For pre-production hardware */ |
| 4683 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4684 | rp1 = ((val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4685 | PUNIT_GPU_STATUS_MAX_FREQ_MASK); |
| 4686 | } |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4687 | return rp1; |
| 4688 | } |
| 4689 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4690 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4691 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4692 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4693 | u32 val, rpn; |
| 4694 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4695 | if (dev->pdev->revision >= 0x20) { |
| 4696 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 4697 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 4698 | FB_GFX_FREQ_FUSE_MASK); |
| 4699 | } else { /* For pre-production hardware */ |
| 4700 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4701 | rpn = ((val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & |
| 4702 | PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK); |
| 4703 | } |
| 4704 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4705 | return rpn; |
| 4706 | } |
| 4707 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4708 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4709 | { |
| 4710 | u32 val, rp1; |
| 4711 | |
| 4712 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4713 | |
| 4714 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4715 | |
| 4716 | return rp1; |
| 4717 | } |
| 4718 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4719 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4720 | { |
| 4721 | u32 val, rp0; |
| 4722 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4723 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4724 | |
| 4725 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4726 | /* Clamp to max */ |
| 4727 | rp0 = min_t(u32, rp0, 0xea); |
| 4728 | |
| 4729 | return rp0; |
| 4730 | } |
| 4731 | |
| 4732 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4733 | { |
| 4734 | u32 val, rpe; |
| 4735 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4736 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_LO); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4737 | 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] | 4738 | 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] | 4739 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4740 | |
| 4741 | return rpe; |
| 4742 | } |
| 4743 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4744 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4745 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4746 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4749 | /* Check that the pctx buffer wasn't move under us. */ |
| 4750 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4751 | { |
| 4752 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4753 | |
| 4754 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4755 | dev_priv->vlv_pctx->stolen->start); |
| 4756 | } |
| 4757 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4758 | |
| 4759 | /* Check that the pcbr address is not empty. */ |
| 4760 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4761 | { |
| 4762 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4763 | |
| 4764 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4765 | } |
| 4766 | |
| 4767 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4768 | { |
| 4769 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4770 | unsigned long pctx_paddr, paddr; |
| 4771 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4772 | u32 pcbr; |
| 4773 | int pctx_size = 32*1024; |
| 4774 | |
| 4775 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4776 | |
| 4777 | pcbr = I915_READ(VLV_PCBR); |
| 4778 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4779 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4780 | paddr = (dev_priv->mm.stolen_base + |
| 4781 | (gtt->stolen_size - pctx_size)); |
| 4782 | |
| 4783 | pctx_paddr = (paddr & (~4095)); |
| 4784 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4785 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4786 | |
| 4787 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4788 | } |
| 4789 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4790 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4791 | { |
| 4792 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4793 | struct drm_i915_gem_object *pctx; |
| 4794 | unsigned long pctx_paddr; |
| 4795 | u32 pcbr; |
| 4796 | int pctx_size = 24*1024; |
| 4797 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4798 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4799 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4800 | pcbr = I915_READ(VLV_PCBR); |
| 4801 | if (pcbr) { |
| 4802 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4803 | int pcbr_offset; |
| 4804 | |
| 4805 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4806 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4807 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4808 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4809 | pctx_size); |
| 4810 | goto out; |
| 4811 | } |
| 4812 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4813 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 4814 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4815 | /* |
| 4816 | * From the Gunit register HAS: |
| 4817 | * The Gfx driver is expected to program this register and ensure |
| 4818 | * proper allocation within Gfx stolen memory. For example, this |
| 4819 | * register should be programmed such than the PCBR range does not |
| 4820 | * overlap with other ranges, such as the frame buffer, protected |
| 4821 | * memory, or any other relevant ranges. |
| 4822 | */ |
| 4823 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4824 | if (!pctx) { |
| 4825 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4826 | return; |
| 4827 | } |
| 4828 | |
| 4829 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4830 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4831 | |
| 4832 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4833 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4834 | dev_priv->vlv_pctx = pctx; |
| 4835 | } |
| 4836 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4837 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4838 | { |
| 4839 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4840 | |
| 4841 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4842 | return; |
| 4843 | |
| 4844 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 4845 | dev_priv->vlv_pctx = NULL; |
| 4846 | } |
| 4847 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4848 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 4849 | { |
| 4850 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4851 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4852 | |
| 4853 | valleyview_setup_pctx(dev); |
| 4854 | |
| 4855 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4856 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4857 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4858 | switch ((val >> 6) & 3) { |
| 4859 | case 0: |
| 4860 | case 1: |
| 4861 | dev_priv->mem_freq = 800; |
| 4862 | break; |
| 4863 | case 2: |
| 4864 | dev_priv->mem_freq = 1066; |
| 4865 | break; |
| 4866 | case 3: |
| 4867 | dev_priv->mem_freq = 1333; |
| 4868 | break; |
| 4869 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4870 | 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] | 4871 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4872 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 4873 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4874 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4875 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4876 | dev_priv->rps.max_freq); |
| 4877 | |
| 4878 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 4879 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4880 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4881 | dev_priv->rps.efficient_freq); |
| 4882 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4883 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 4884 | 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] | 4885 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4886 | dev_priv->rps.rp1_freq); |
| 4887 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4888 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 4889 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4890 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4891 | dev_priv->rps.min_freq); |
| 4892 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4893 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4894 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4895 | /* Preserve min/max settings in case of re-init */ |
| 4896 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4897 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4898 | |
| 4899 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4900 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4901 | |
| 4902 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4903 | } |
| 4904 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4905 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4906 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4907 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4908 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4909 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4910 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4911 | |
| 4912 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4913 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 4914 | mutex_lock(&dev_priv->dpio_lock); |
| 4915 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
| 4916 | mutex_unlock(&dev_priv->dpio_lock); |
| 4917 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4918 | switch ((val >> 2) & 0x7) { |
| 4919 | case 0: |
| 4920 | case 1: |
| 4921 | dev_priv->rps.cz_freq = 200; |
| 4922 | dev_priv->mem_freq = 1600; |
| 4923 | break; |
| 4924 | case 2: |
| 4925 | dev_priv->rps.cz_freq = 267; |
| 4926 | dev_priv->mem_freq = 1600; |
| 4927 | break; |
| 4928 | case 3: |
| 4929 | dev_priv->rps.cz_freq = 333; |
| 4930 | dev_priv->mem_freq = 2000; |
| 4931 | break; |
| 4932 | case 4: |
| 4933 | dev_priv->rps.cz_freq = 320; |
| 4934 | dev_priv->mem_freq = 1600; |
| 4935 | break; |
| 4936 | case 5: |
| 4937 | dev_priv->rps.cz_freq = 400; |
| 4938 | dev_priv->mem_freq = 1600; |
| 4939 | break; |
| 4940 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4941 | 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] | 4942 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4943 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4944 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4945 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4946 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4947 | dev_priv->rps.max_freq); |
| 4948 | |
| 4949 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4950 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4951 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4952 | dev_priv->rps.efficient_freq); |
| 4953 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4954 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4955 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4956 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4957 | dev_priv->rps.rp1_freq); |
| 4958 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4959 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4960 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4961 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4962 | dev_priv->rps.min_freq); |
| 4963 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4964 | WARN_ONCE((dev_priv->rps.max_freq | |
| 4965 | dev_priv->rps.efficient_freq | |
| 4966 | dev_priv->rps.rp1_freq | |
| 4967 | dev_priv->rps.min_freq) & 1, |
| 4968 | "Odd GPU freq values\n"); |
| 4969 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4970 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4971 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4972 | /* Preserve min/max settings in case of re-init */ |
| 4973 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4974 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4975 | |
| 4976 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4977 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4978 | |
| 4979 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4980 | } |
| 4981 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4982 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4983 | { |
| 4984 | valleyview_cleanup_pctx(dev); |
| 4985 | } |
| 4986 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4987 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4988 | { |
| 4989 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4990 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4991 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4992 | int i; |
| 4993 | |
| 4994 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4995 | |
| 4996 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4997 | if (gtfifodbg) { |
| 4998 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4999 | gtfifodbg); |
| 5000 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5001 | } |
| 5002 | |
| 5003 | cherryview_check_pctx(dev_priv); |
| 5004 | |
| 5005 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 5006 | * 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] | 5007 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5008 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 5009 | /* Disable RC states. */ |
| 5010 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5011 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5012 | /* 2a: Program RC6 thresholds.*/ |
| 5013 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 5014 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 5015 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 5016 | |
| 5017 | for_each_ring(ring, dev_priv, i) |
| 5018 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5019 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 5020 | |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 5021 | /* TO threshold set to 1750 us ( 0x557 * 1.28 us) */ |
| 5022 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5023 | |
| 5024 | /* allows RC6 residency counter to work */ |
| 5025 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 5026 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 5027 | VLV_MEDIA_RC6_COUNT_EN | |
| 5028 | VLV_RENDER_RC6_COUNT_EN)); |
| 5029 | |
| 5030 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 5031 | pcbr = I915_READ(VLV_PCBR); |
| 5032 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5033 | /* 3: Enable RC6 */ |
| 5034 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 5035 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 5036 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5037 | |
| 5038 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 5039 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5040 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 5041 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5042 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5043 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5044 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5045 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5046 | |
| 5047 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5048 | |
| 5049 | /* 5: Enable RPS */ |
| 5050 | I915_WRITE(GEN6_RP_CONTROL, |
| 5051 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 5052 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5053 | GEN6_RP_ENABLE | |
| 5054 | GEN6_RP_UP_BUSY_AVG | |
| 5055 | GEN6_RP_DOWN_IDLE_AVG); |
| 5056 | |
| 5057 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5058 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 5059 | /* RPS code assumes GPLL is used */ |
| 5060 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 5061 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 5062 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5063 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5064 | |
| 5065 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 5066 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5067 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5068 | dev_priv->rps.cur_freq); |
| 5069 | |
| 5070 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5071 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5072 | dev_priv->rps.efficient_freq); |
| 5073 | |
| 5074 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 5075 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5076 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5077 | } |
| 5078 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5079 | static void valleyview_enable_rps(struct drm_device *dev) |
| 5080 | { |
| 5081 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5082 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 5083 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5084 | int i; |
| 5085 | |
| 5086 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 5087 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5088 | valleyview_check_pctx(dev_priv); |
| 5089 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5090 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 5091 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 5092 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5093 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5094 | } |
| 5095 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 5096 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5097 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5098 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 5099 | /* Disable RC states. */ |
| 5100 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5101 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 5102 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5103 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5104 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5105 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5106 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5107 | |
| 5108 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5109 | |
| 5110 | I915_WRITE(GEN6_RP_CONTROL, |
| 5111 | GEN6_RP_MEDIA_TURBO | |
| 5112 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 5113 | GEN6_RP_MEDIA_IS_GFX | |
| 5114 | GEN6_RP_ENABLE | |
| 5115 | GEN6_RP_UP_BUSY_AVG | |
| 5116 | GEN6_RP_DOWN_IDLE_CONT); |
| 5117 | |
| 5118 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 5119 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 5120 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 5121 | |
| 5122 | for_each_ring(ring, dev_priv, i) |
| 5123 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5124 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 5125 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5126 | |
| 5127 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5128 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5129 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 5130 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5131 | VLV_MEDIA_RC6_COUNT_EN | |
| 5132 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5133 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5134 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 5135 | 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] | 5136 | |
| 5137 | intel_print_rc6_info(dev, rc6_mode); |
| 5138 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5139 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5140 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 5141 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5142 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 5143 | /* RPS code assumes GPLL is used */ |
| 5144 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 5145 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 5146 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5147 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5148 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5149 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5150 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5151 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5152 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5153 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5154 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5155 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5156 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5157 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5158 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5159 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5160 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5163 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 5164 | { |
| 5165 | unsigned long freq; |
| 5166 | int div = (vidfreq & 0x3f0000) >> 16; |
| 5167 | int post = (vidfreq & 0x3000) >> 12; |
| 5168 | int pre = (vidfreq & 0x7); |
| 5169 | |
| 5170 | if (!pre) |
| 5171 | return 0; |
| 5172 | |
| 5173 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 5174 | |
| 5175 | return freq; |
| 5176 | } |
| 5177 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5178 | static const struct cparams { |
| 5179 | u16 i; |
| 5180 | u16 t; |
| 5181 | u16 m; |
| 5182 | u16 c; |
| 5183 | } cparams[] = { |
| 5184 | { 1, 1333, 301, 28664 }, |
| 5185 | { 1, 1066, 294, 24460 }, |
| 5186 | { 1, 800, 294, 25192 }, |
| 5187 | { 0, 1333, 276, 27605 }, |
| 5188 | { 0, 1066, 276, 27605 }, |
| 5189 | { 0, 800, 231, 23784 }, |
| 5190 | }; |
| 5191 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5192 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5193 | { |
| 5194 | u64 total_count, diff, ret; |
| 5195 | u32 count1, count2, count3, m = 0, c = 0; |
| 5196 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 5197 | int i; |
| 5198 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5199 | assert_spin_locked(&mchdev_lock); |
| 5200 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5201 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5202 | |
| 5203 | /* Prevent division-by-zero if we are asking too fast. |
| 5204 | * Also, we don't get interesting results if we are polling |
| 5205 | * faster than once in 10ms, so just return the saved value |
| 5206 | * in such cases. |
| 5207 | */ |
| 5208 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5209 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5210 | |
| 5211 | count1 = I915_READ(DMIEC); |
| 5212 | count2 = I915_READ(DDREC); |
| 5213 | count3 = I915_READ(CSIEC); |
| 5214 | |
| 5215 | total_count = count1 + count2 + count3; |
| 5216 | |
| 5217 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5218 | if (total_count < dev_priv->ips.last_count1) { |
| 5219 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5220 | diff += total_count; |
| 5221 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5222 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5226 | if (cparams[i].i == dev_priv->ips.c_m && |
| 5227 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5228 | m = cparams[i].m; |
| 5229 | c = cparams[i].c; |
| 5230 | break; |
| 5231 | } |
| 5232 | } |
| 5233 | |
| 5234 | diff = div_u64(diff, diff1); |
| 5235 | ret = ((m * diff) + c); |
| 5236 | ret = div_u64(ret, 10); |
| 5237 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5238 | dev_priv->ips.last_count1 = total_count; |
| 5239 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5240 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5241 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5242 | |
| 5243 | return ret; |
| 5244 | } |
| 5245 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5246 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 5247 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5248 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5249 | unsigned long val; |
| 5250 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5251 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5252 | return 0; |
| 5253 | |
| 5254 | spin_lock_irq(&mchdev_lock); |
| 5255 | |
| 5256 | val = __i915_chipset_val(dev_priv); |
| 5257 | |
| 5258 | spin_unlock_irq(&mchdev_lock); |
| 5259 | |
| 5260 | return val; |
| 5261 | } |
| 5262 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5263 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 5264 | { |
| 5265 | unsigned long m, x, b; |
| 5266 | u32 tsfs; |
| 5267 | |
| 5268 | tsfs = I915_READ(TSFS); |
| 5269 | |
| 5270 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 5271 | x = I915_READ8(TR1); |
| 5272 | |
| 5273 | b = tsfs & TSFS_INTR_MASK; |
| 5274 | |
| 5275 | return ((m * x) / 127) - b; |
| 5276 | } |
| 5277 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5278 | static int _pxvid_to_vd(u8 pxvid) |
| 5279 | { |
| 5280 | if (pxvid == 0) |
| 5281 | return 0; |
| 5282 | |
| 5283 | if (pxvid >= 8 && pxvid < 31) |
| 5284 | pxvid = 31; |
| 5285 | |
| 5286 | return (pxvid + 2) * 125; |
| 5287 | } |
| 5288 | |
| 5289 | 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] | 5290 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5291 | struct drm_device *dev = dev_priv->dev; |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5292 | const int vd = _pxvid_to_vd(pxvid); |
| 5293 | const int vm = vd - 1125; |
| 5294 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5295 | if (INTEL_INFO(dev)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5296 | return vm > 0 ? vm : 0; |
| 5297 | |
| 5298 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5299 | } |
| 5300 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5301 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5302 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5303 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5304 | u32 count; |
| 5305 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5306 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5307 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5308 | now = ktime_get_raw_ns(); |
| 5309 | diffms = now - dev_priv->ips.last_time2; |
| 5310 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5311 | |
| 5312 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5313 | if (!diffms) |
| 5314 | return; |
| 5315 | |
| 5316 | count = I915_READ(GFXEC); |
| 5317 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5318 | if (count < dev_priv->ips.last_count2) { |
| 5319 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5320 | diff += count; |
| 5321 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5322 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5323 | } |
| 5324 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5325 | dev_priv->ips.last_count2 = count; |
| 5326 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5327 | |
| 5328 | /* More magic constants... */ |
| 5329 | diff = diff * 1181; |
| 5330 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5331 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5332 | } |
| 5333 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5334 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 5335 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5336 | struct drm_device *dev = dev_priv->dev; |
| 5337 | |
| 5338 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5339 | return; |
| 5340 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5341 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5342 | |
| 5343 | __i915_update_gfx_val(dev_priv); |
| 5344 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5345 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5346 | } |
| 5347 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5348 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5349 | { |
| 5350 | unsigned long t, corr, state1, corr2, state2; |
| 5351 | u32 pxvid, ext_v; |
| 5352 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5353 | assert_spin_locked(&mchdev_lock); |
| 5354 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5355 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5356 | pxvid = (pxvid >> 24) & 0x7f; |
| 5357 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5358 | |
| 5359 | state1 = ext_v; |
| 5360 | |
| 5361 | t = i915_mch_val(dev_priv); |
| 5362 | |
| 5363 | /* Revel in the empirically derived constants */ |
| 5364 | |
| 5365 | /* Correction factor in 1/100000 units */ |
| 5366 | if (t > 80) |
| 5367 | corr = ((t * 2349) + 135940); |
| 5368 | else if (t >= 50) |
| 5369 | corr = ((t * 964) + 29317); |
| 5370 | else /* < 50 */ |
| 5371 | corr = ((t * 301) + 1004); |
| 5372 | |
| 5373 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5374 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5375 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5376 | |
| 5377 | state2 = (corr2 * state1) / 10000; |
| 5378 | state2 /= 100; /* convert to mW */ |
| 5379 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5380 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5381 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5382 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5383 | } |
| 5384 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5385 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5386 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5387 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5388 | unsigned long val; |
| 5389 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5390 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5391 | return 0; |
| 5392 | |
| 5393 | spin_lock_irq(&mchdev_lock); |
| 5394 | |
| 5395 | val = __i915_gfx_val(dev_priv); |
| 5396 | |
| 5397 | spin_unlock_irq(&mchdev_lock); |
| 5398 | |
| 5399 | return val; |
| 5400 | } |
| 5401 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5402 | /** |
| 5403 | * i915_read_mch_val - return value for IPS use |
| 5404 | * |
| 5405 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5406 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5407 | */ |
| 5408 | unsigned long i915_read_mch_val(void) |
| 5409 | { |
| 5410 | struct drm_i915_private *dev_priv; |
| 5411 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5412 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5413 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5414 | if (!i915_mch_dev) |
| 5415 | goto out_unlock; |
| 5416 | dev_priv = i915_mch_dev; |
| 5417 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5418 | chipset_val = __i915_chipset_val(dev_priv); |
| 5419 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5420 | |
| 5421 | ret = chipset_val + graphics_val; |
| 5422 | |
| 5423 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5424 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5425 | |
| 5426 | return ret; |
| 5427 | } |
| 5428 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5429 | |
| 5430 | /** |
| 5431 | * i915_gpu_raise - raise GPU frequency limit |
| 5432 | * |
| 5433 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5434 | */ |
| 5435 | bool i915_gpu_raise(void) |
| 5436 | { |
| 5437 | struct drm_i915_private *dev_priv; |
| 5438 | bool ret = true; |
| 5439 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5440 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5441 | if (!i915_mch_dev) { |
| 5442 | ret = false; |
| 5443 | goto out_unlock; |
| 5444 | } |
| 5445 | dev_priv = i915_mch_dev; |
| 5446 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5447 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5448 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5449 | |
| 5450 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5451 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5452 | |
| 5453 | return ret; |
| 5454 | } |
| 5455 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5456 | |
| 5457 | /** |
| 5458 | * i915_gpu_lower - lower GPU frequency limit |
| 5459 | * |
| 5460 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5461 | * frequency maximum. |
| 5462 | */ |
| 5463 | bool i915_gpu_lower(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.min_delay) |
| 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_lower); |
| 5484 | |
| 5485 | /** |
| 5486 | * i915_gpu_busy - indicate GPU business to IPS |
| 5487 | * |
| 5488 | * Tell the IPS driver whether or not the GPU is busy. |
| 5489 | */ |
| 5490 | bool i915_gpu_busy(void) |
| 5491 | { |
| 5492 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5493 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5494 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5495 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5496 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5497 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5498 | if (!i915_mch_dev) |
| 5499 | goto out_unlock; |
| 5500 | dev_priv = i915_mch_dev; |
| 5501 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5502 | for_each_ring(ring, dev_priv, i) |
| 5503 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5504 | |
| 5505 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5506 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5507 | |
| 5508 | return ret; |
| 5509 | } |
| 5510 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 5511 | |
| 5512 | /** |
| 5513 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5514 | * |
| 5515 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5516 | * current frequency to the default. |
| 5517 | */ |
| 5518 | bool i915_gpu_turbo_disable(void) |
| 5519 | { |
| 5520 | struct drm_i915_private *dev_priv; |
| 5521 | bool ret = true; |
| 5522 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5523 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5524 | if (!i915_mch_dev) { |
| 5525 | ret = false; |
| 5526 | goto out_unlock; |
| 5527 | } |
| 5528 | dev_priv = i915_mch_dev; |
| 5529 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5530 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5531 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5532 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5533 | ret = false; |
| 5534 | |
| 5535 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5536 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5537 | |
| 5538 | return ret; |
| 5539 | } |
| 5540 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5541 | |
| 5542 | /** |
| 5543 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5544 | * IPS got loaded first. |
| 5545 | * |
| 5546 | * This awkward dance is so that neither module has to depend on the |
| 5547 | * other in order for IPS to do the appropriate communication of |
| 5548 | * GPU turbo limits to i915. |
| 5549 | */ |
| 5550 | static void |
| 5551 | ips_ping_for_i915_load(void) |
| 5552 | { |
| 5553 | void (*link)(void); |
| 5554 | |
| 5555 | link = symbol_get(ips_link_to_i915_driver); |
| 5556 | if (link) { |
| 5557 | link(); |
| 5558 | symbol_put(ips_link_to_i915_driver); |
| 5559 | } |
| 5560 | } |
| 5561 | |
| 5562 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5563 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5564 | /* We only register the i915 ips part with intel-ips once everything is |
| 5565 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5566 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5567 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5568 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5569 | |
| 5570 | ips_ping_for_i915_load(); |
| 5571 | } |
| 5572 | |
| 5573 | void intel_gpu_ips_teardown(void) |
| 5574 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5575 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5576 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5577 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5578 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5579 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5580 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5581 | { |
| 5582 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5583 | u32 lcfuse; |
| 5584 | u8 pxw[16]; |
| 5585 | int i; |
| 5586 | |
| 5587 | /* Disable to program */ |
| 5588 | I915_WRITE(ECR, 0); |
| 5589 | POSTING_READ(ECR); |
| 5590 | |
| 5591 | /* Program energy weights for various events */ |
| 5592 | I915_WRITE(SDEW, 0x15040d00); |
| 5593 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5594 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5595 | I915_WRITE(CSIEW2, 0x04000004); |
| 5596 | |
| 5597 | for (i = 0; i < 5; i++) |
| 5598 | I915_WRITE(PEW + (i * 4), 0); |
| 5599 | for (i = 0; i < 3; i++) |
| 5600 | I915_WRITE(DEW + (i * 4), 0); |
| 5601 | |
| 5602 | /* Program P-state weights to account for frequency power adjustment */ |
| 5603 | for (i = 0; i < 16; i++) { |
| 5604 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5605 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5606 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5607 | PXVFREQ_PX_SHIFT; |
| 5608 | unsigned long val; |
| 5609 | |
| 5610 | val = vid * vid; |
| 5611 | val *= (freq / 1000); |
| 5612 | val *= 255; |
| 5613 | val /= (127*127*900); |
| 5614 | if (val > 0xff) |
| 5615 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5616 | pxw[i] = val; |
| 5617 | } |
| 5618 | /* Render standby states get 0 weight */ |
| 5619 | pxw[14] = 0; |
| 5620 | pxw[15] = 0; |
| 5621 | |
| 5622 | for (i = 0; i < 4; i++) { |
| 5623 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 5624 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 5625 | I915_WRITE(PXW + (i * 4), val); |
| 5626 | } |
| 5627 | |
| 5628 | /* Adjust magic regs to magic values (more experimental results) */ |
| 5629 | I915_WRITE(OGW0, 0); |
| 5630 | I915_WRITE(OGW1, 0); |
| 5631 | I915_WRITE(EG0, 0x00007f00); |
| 5632 | I915_WRITE(EG1, 0x0000000e); |
| 5633 | I915_WRITE(EG2, 0x000e0000); |
| 5634 | I915_WRITE(EG3, 0x68000300); |
| 5635 | I915_WRITE(EG4, 0x42000000); |
| 5636 | I915_WRITE(EG5, 0x00140031); |
| 5637 | I915_WRITE(EG6, 0); |
| 5638 | I915_WRITE(EG7, 0); |
| 5639 | |
| 5640 | for (i = 0; i < 8; i++) |
| 5641 | I915_WRITE(PXWL + (i * 4), 0); |
| 5642 | |
| 5643 | /* Enable PMON + select events */ |
| 5644 | I915_WRITE(ECR, 0x80000019); |
| 5645 | |
| 5646 | lcfuse = I915_READ(LCFUSE02); |
| 5647 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5648 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5649 | } |
| 5650 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5651 | void intel_init_gt_powersave(struct drm_device *dev) |
| 5652 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5653 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 5654 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5655 | if (IS_CHERRYVIEW(dev)) |
| 5656 | cherryview_init_gt_powersave(dev); |
| 5657 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5658 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 5662 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5663 | if (IS_CHERRYVIEW(dev)) |
| 5664 | return; |
| 5665 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5666 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5667 | } |
| 5668 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5669 | static void gen6_suspend_rps(struct drm_device *dev) |
| 5670 | { |
| 5671 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5672 | |
| 5673 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 5674 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5675 | gen6_disable_rps_interrupts(dev); |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5676 | } |
| 5677 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5678 | /** |
| 5679 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 5680 | * @dev: drm device |
| 5681 | * |
| 5682 | * We don't want to disable RC6 or other features here, we just want |
| 5683 | * to make sure any work we've queued has finished and won't bother |
| 5684 | * us while we're suspended. |
| 5685 | */ |
| 5686 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 5687 | { |
| 5688 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5689 | |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 5690 | if (INTEL_INFO(dev)->gen < 6) |
| 5691 | return; |
| 5692 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5693 | gen6_suspend_rps(dev); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 5694 | |
| 5695 | /* Force GPU to min freq during suspend */ |
| 5696 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5697 | } |
| 5698 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5699 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 5700 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5701 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5702 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5703 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5704 | ironlake_disable_drps(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5705 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5706 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5707 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5708 | mutex_lock(&dev_priv->rps.hw_lock); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5709 | if (INTEL_INFO(dev)->gen >= 9) |
| 5710 | gen9_disable_rps(dev); |
| 5711 | else if (IS_CHERRYVIEW(dev)) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5712 | cherryview_disable_rps(dev); |
| 5713 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5714 | valleyview_disable_rps(dev); |
| 5715 | else |
| 5716 | gen6_disable_rps(dev); |
Imre Deak | e534770 | 2014-11-19 15:30:02 +0200 | [diff] [blame] | 5717 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5718 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5719 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5720 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5721 | } |
| 5722 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5723 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5724 | { |
| 5725 | struct drm_i915_private *dev_priv = |
| 5726 | container_of(work, struct drm_i915_private, |
| 5727 | rps.delayed_resume_work.work); |
| 5728 | struct drm_device *dev = dev_priv->dev; |
| 5729 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5730 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5731 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5732 | gen6_reset_rps_interrupts(dev); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5733 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5734 | if (IS_CHERRYVIEW(dev)) { |
| 5735 | cherryview_enable_rps(dev); |
| 5736 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5737 | valleyview_enable_rps(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5738 | } else if (INTEL_INFO(dev)->gen >= 9) { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5739 | gen9_enable_rc6(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5740 | gen9_enable_rps(dev); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5741 | __gen6_update_ring_freq(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5742 | } else if (IS_BROADWELL(dev)) { |
| 5743 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5744 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5745 | } else { |
| 5746 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5747 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5748 | } |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5749 | |
| 5750 | WARN_ON(dev_priv->rps.max_freq < dev_priv->rps.min_freq); |
| 5751 | WARN_ON(dev_priv->rps.idle_freq > dev_priv->rps.max_freq); |
| 5752 | |
| 5753 | WARN_ON(dev_priv->rps.efficient_freq < dev_priv->rps.min_freq); |
| 5754 | WARN_ON(dev_priv->rps.efficient_freq > dev_priv->rps.max_freq); |
| 5755 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5756 | dev_priv->rps.enabled = true; |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5757 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5758 | gen6_enable_rps_interrupts(dev); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5759 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5760 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5761 | |
| 5762 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5763 | } |
| 5764 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5765 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5766 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5767 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5768 | |
Yu Zhang | f61018b | 2015-02-10 19:05:52 +0800 | [diff] [blame] | 5769 | /* Powersaving is controlled by the host when inside a VM */ |
| 5770 | if (intel_vgpu_active(dev)) |
| 5771 | return; |
| 5772 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5773 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5774 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5775 | ironlake_enable_drps(dev); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5776 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5777 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5778 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5779 | /* |
| 5780 | * PCU communication is slow and this doesn't need to be |
| 5781 | * done at any specific time, so do this out of our fast path |
| 5782 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5783 | * |
| 5784 | * We depend on the HW RC6 power context save/restore |
| 5785 | * mechanism when entering D3 through runtime PM suspend. So |
| 5786 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5787 | * get here via the driver load/system resume/runtime resume |
| 5788 | * paths, so the _noresume version is enough (and in case of |
| 5789 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5790 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5791 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5792 | round_jiffies_up_relative(HZ))) |
| 5793 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5794 | } |
| 5795 | } |
| 5796 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5797 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5798 | { |
| 5799 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5800 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5801 | if (INTEL_INFO(dev)->gen < 6) |
| 5802 | return; |
| 5803 | |
| 5804 | gen6_suspend_rps(dev); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5805 | dev_priv->rps.enabled = false; |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5806 | } |
| 5807 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5808 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5809 | { |
| 5810 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5811 | |
| 5812 | /* |
| 5813 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5814 | * gating for the panel power sequencer or it will fail to |
| 5815 | * start up when no ports are active. |
| 5816 | */ |
| 5817 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5818 | } |
| 5819 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5820 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5821 | { |
| 5822 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5823 | int pipe; |
| 5824 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5825 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5826 | I915_WRITE(DSPCNTR(pipe), |
| 5827 | I915_READ(DSPCNTR(pipe)) | |
| 5828 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5829 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5830 | } |
| 5831 | } |
| 5832 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5833 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5834 | { |
| 5835 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5836 | |
| 5837 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5838 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5839 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5840 | |
| 5841 | /* |
| 5842 | * Don't touch WM1S_LP_EN here. |
| 5843 | * Doing so could cause underruns. |
| 5844 | */ |
| 5845 | } |
| 5846 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5847 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5848 | { |
| 5849 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5850 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5851 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5852 | /* |
| 5853 | * Required for FBC |
| 5854 | * WaFbcDisableDpfcClockGating:ilk |
| 5855 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5856 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5857 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5858 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5859 | |
| 5860 | I915_WRITE(PCH_3DCGDIS0, |
| 5861 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5862 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5863 | I915_WRITE(PCH_3DCGDIS1, |
| 5864 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5865 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5866 | /* |
| 5867 | * According to the spec the following bits should be set in |
| 5868 | * order to enable memory self-refresh |
| 5869 | * The bit 22/21 of 0x42004 |
| 5870 | * The bit 5 of 0x42020 |
| 5871 | * The bit 15 of 0x45000 |
| 5872 | */ |
| 5873 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5874 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5875 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5876 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5877 | I915_WRITE(DISP_ARB_CTL, |
| 5878 | (I915_READ(DISP_ARB_CTL) | |
| 5879 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5880 | |
| 5881 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5882 | |
| 5883 | /* |
| 5884 | * Based on the document from hardware guys the following bits |
| 5885 | * should be set unconditionally in order to enable FBC. |
| 5886 | * The bit 22 of 0x42000 |
| 5887 | * The bit 22 of 0x42004 |
| 5888 | * The bit 7,8,9 of 0x42020. |
| 5889 | */ |
| 5890 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5891 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5892 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5893 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5894 | ILK_FBCQ_DIS); |
| 5895 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5896 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5897 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5898 | } |
| 5899 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5900 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5901 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5902 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5903 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5904 | ILK_ELPIN_409_SELECT); |
| 5905 | I915_WRITE(_3D_CHICKEN2, |
| 5906 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5907 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5908 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5909 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5910 | I915_WRITE(CACHE_MODE_0, |
| 5911 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5912 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5913 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5914 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5915 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5916 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5917 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5918 | ibx_init_clock_gating(dev); |
| 5919 | } |
| 5920 | |
| 5921 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5922 | { |
| 5923 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5924 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5925 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5926 | |
| 5927 | /* |
| 5928 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5929 | * gating for the panel power sequencer or it will fail to |
| 5930 | * start up when no ports are active. |
| 5931 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5932 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5933 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5934 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5935 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5936 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5937 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5938 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5939 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5940 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5941 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5942 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5943 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5944 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5945 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5946 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5947 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5948 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5949 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5950 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5951 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5952 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5953 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5954 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5955 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5956 | } |
| 5957 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5958 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5959 | { |
| 5960 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5961 | uint32_t tmp; |
| 5962 | |
| 5963 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 5964 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5965 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5966 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5967 | } |
| 5968 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5969 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5970 | { |
| 5971 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5972 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5973 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5974 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5975 | |
| 5976 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5977 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5978 | ILK_ELPIN_409_SELECT); |
| 5979 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5980 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5981 | I915_WRITE(_3D_CHICKEN, |
| 5982 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5983 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5984 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5985 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5986 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5987 | /* |
| 5988 | * BSpec recoomends 8x4 when MSAA is used, |
| 5989 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5990 | * |
| 5991 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5992 | * disable bit, which we don't touch here, but it's good |
| 5993 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5994 | */ |
| 5995 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 5996 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5997 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5998 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5999 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6000 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 6001 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6002 | |
| 6003 | I915_WRITE(GEN6_UCGCTL1, |
| 6004 | I915_READ(GEN6_UCGCTL1) | |
| 6005 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 6006 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 6007 | |
| 6008 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 6009 | * gating disable must be set. Failure to set it results in |
| 6010 | * flickering pixels due to Z write ordering failures after |
| 6011 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 6012 | * Sanctuary and Tropics, and apparently anything else with |
| 6013 | * alpha test or pixel discard. |
| 6014 | * |
| 6015 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 6016 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6017 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 6018 | * WaDisableRCCUnitClockGating:snb |
| 6019 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6020 | */ |
| 6021 | I915_WRITE(GEN6_UCGCTL2, |
| 6022 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 6023 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 6024 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 6025 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 6026 | I915_WRITE(_3D_CHICKEN3, |
| 6027 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6028 | |
| 6029 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 6030 | * Bspec says: |
| 6031 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 6032 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 6033 | */ |
| 6034 | I915_WRITE(_3D_CHICKEN3, |
| 6035 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 6036 | |
| 6037 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6038 | * According to the spec the following bits should be |
| 6039 | * set in order to enable memory self-refresh and fbc: |
| 6040 | * The bit21 and bit22 of 0x42000 |
| 6041 | * The bit21 and bit22 of 0x42004 |
| 6042 | * The bit5 and bit7 of 0x42020 |
| 6043 | * The bit14 of 0x70180 |
| 6044 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6045 | * |
| 6046 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6047 | */ |
| 6048 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6049 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6050 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 6051 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6052 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6053 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6054 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 6055 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 6056 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 6057 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6058 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6059 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 6060 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6061 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6062 | |
| 6063 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 6067 | { |
| 6068 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 6069 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6070 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6071 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6072 | * |
| 6073 | * This actually overrides the dispatch |
| 6074 | * mode for all thread types. |
| 6075 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6076 | reg &= ~GEN7_FF_SCHED_MASK; |
| 6077 | reg |= GEN7_FF_TS_SCHED_HW; |
| 6078 | reg |= GEN7_FF_VS_SCHED_HW; |
| 6079 | reg |= GEN7_FF_DS_SCHED_HW; |
| 6080 | |
| 6081 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 6082 | } |
| 6083 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6084 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 6085 | { |
| 6086 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6087 | |
| 6088 | /* |
| 6089 | * TODO: this bit should only be enabled when really needed, then |
| 6090 | * disabled when not needed anymore in order to save power. |
| 6091 | */ |
| 6092 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 6093 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 6094 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 6095 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 6096 | |
| 6097 | /* WADPOClockGatingDisable:hsw */ |
| 6098 | I915_WRITE(_TRANSA_CHICKEN1, |
| 6099 | I915_READ(_TRANSA_CHICKEN1) | |
| 6100 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6101 | } |
| 6102 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6103 | static void lpt_suspend_hw(struct drm_device *dev) |
| 6104 | { |
| 6105 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6106 | |
| 6107 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 6108 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 6109 | |
| 6110 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 6111 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 6112 | } |
| 6113 | } |
| 6114 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6115 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6116 | { |
| 6117 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6118 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6119 | |
| 6120 | I915_WRITE(WM3_LP_ILK, 0); |
| 6121 | I915_WRITE(WM2_LP_ILK, 0); |
| 6122 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6123 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6124 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6125 | 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] | 6126 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6127 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6128 | I915_WRITE(CHICKEN_PAR1_1, |
| 6129 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 6130 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6131 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6132 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6133 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 6134 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 6135 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6136 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 6137 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6138 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 6139 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 6140 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6141 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6142 | ~(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] | 6143 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 6144 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6145 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 6146 | |
| 6147 | /* WaDisableSDEUnitClockGating:bdw */ |
| 6148 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6149 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 6150 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 6151 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6152 | } |
| 6153 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6154 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 6155 | { |
| 6156 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6157 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6158 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6159 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 6160 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 6161 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 6162 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 6163 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 6164 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6165 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6166 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6167 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6168 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6169 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 6170 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 6171 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6172 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6173 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6174 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 6175 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6176 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 6177 | /* enable HiZ Raw Stall Optimization */ |
| 6178 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6179 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6180 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6181 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6182 | I915_WRITE(CACHE_MODE_1, |
| 6183 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6184 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6185 | /* |
| 6186 | * BSpec recommends 8x4 when MSAA is used, |
| 6187 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6188 | * |
| 6189 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6190 | * disable bit, which we don't touch here, but it's good |
| 6191 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6192 | */ |
| 6193 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6194 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6195 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 6196 | /* WaSampleCChickenBitEnable:hsw */ |
| 6197 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 6198 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 6199 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6200 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 6201 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 6202 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 6203 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 6204 | I915_WRITE(CHICKEN_PAR1_1, |
| 6205 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6206 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6207 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6208 | } |
| 6209 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6210 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6211 | { |
| 6212 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6213 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6214 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6215 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6216 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6217 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6218 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6219 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6220 | I915_WRITE(_3D_CHICKEN3, |
| 6221 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6222 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6223 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6224 | I915_WRITE(IVB_CHICKEN3, |
| 6225 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6226 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6227 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6228 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6229 | if (IS_IVB_GT1(dev)) |
| 6230 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 6231 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6232 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6233 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 6234 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6235 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6236 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6237 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 6238 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 6239 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6240 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6241 | I915_WRITE(GEN7_L3CNTLREG1, |
| 6242 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 6243 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6244 | GEN7_WA_L3_CHICKEN_MODE); |
| 6245 | if (IS_IVB_GT1(dev)) |
| 6246 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6247 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6248 | else { |
| 6249 | /* must write both registers */ |
| 6250 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6251 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6252 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 6253 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6254 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6255 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6256 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6257 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6258 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6259 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 6260 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6261 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6262 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6263 | */ |
| 6264 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 6265 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6266 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6267 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6268 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6269 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6270 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6271 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6272 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6273 | |
| 6274 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6275 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 6276 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 6277 | /* enable HiZ Raw Stall Optimization */ |
| 6278 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6279 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6280 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 6281 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6282 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6283 | I915_WRITE(CACHE_MODE_1, |
| 6284 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6285 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6286 | /* |
| 6287 | * BSpec recommends 8x4 when MSAA is used, |
| 6288 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6289 | * |
| 6290 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6291 | * disable bit, which we don't touch here, but it's good |
| 6292 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6293 | */ |
| 6294 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6295 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6296 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6297 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 6298 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 6299 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 6300 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6301 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 6302 | if (!HAS_PCH_NOP(dev)) |
| 6303 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6304 | |
| 6305 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6306 | } |
| 6307 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6308 | static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv) |
| 6309 | { |
| 6310 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6311 | |
| 6312 | /* |
| 6313 | * Disable trickle feed and enable pnd deadline calculation |
| 6314 | */ |
| 6315 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
| 6316 | I915_WRITE(CBR1_VLV, 0); |
| 6317 | } |
| 6318 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6319 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6320 | { |
| 6321 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6322 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6323 | vlv_init_display_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6324 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6325 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6326 | I915_WRITE(_3D_CHICKEN3, |
| 6327 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6328 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6329 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6330 | I915_WRITE(IVB_CHICKEN3, |
| 6331 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6332 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6333 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 6334 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6335 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6336 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 6337 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 6338 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6339 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6340 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 6341 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6342 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6343 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6344 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6345 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6346 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6347 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6348 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6349 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 6350 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6351 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6352 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6353 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6354 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6355 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6356 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 6357 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6358 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6359 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6360 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6361 | */ |
| 6362 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6363 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6364 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6365 | /* WaDisableL3Bank2xClockGate:vlv |
| 6366 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6367 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6368 | I915_WRITE(GEN7_UCGCTL4, |
| 6369 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6370 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6371 | /* |
| 6372 | * BSpec says this must be set, even though |
| 6373 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6374 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6375 | I915_WRITE(CACHE_MODE_1, |
| 6376 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6377 | |
| 6378 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 6379 | * BSpec recommends 8x4 when MSAA is used, |
| 6380 | * however in practice 16x4 seems fastest. |
| 6381 | * |
| 6382 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6383 | * disable bit, which we don't touch here, but it's good |
| 6384 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 6385 | */ |
| 6386 | I915_WRITE(GEN7_GT_MODE, |
| 6387 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 6388 | |
| 6389 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6390 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6391 | * This is the hardware default actually. |
| 6392 | */ |
| 6393 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6394 | |
| 6395 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6396 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6397 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6398 | * in the reporting of vblank events. |
| 6399 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6400 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6401 | } |
| 6402 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6403 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6404 | { |
| 6405 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6406 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6407 | vlv_init_display_clock_gating(dev_priv); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6408 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6409 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6410 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6411 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6412 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6413 | ~(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] | 6414 | |
| 6415 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6416 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6417 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6418 | |
| 6419 | /* WaDisableCSUnitClockGating:chv */ |
| 6420 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6421 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6422 | |
| 6423 | /* WaDisableSDEUnitClockGating:chv */ |
| 6424 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6425 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6426 | } |
| 6427 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6428 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6429 | { |
| 6430 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6431 | uint32_t dspclk_gate; |
| 6432 | |
| 6433 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6434 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6435 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6436 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6437 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6438 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6439 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6440 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6441 | if (IS_GM45(dev)) |
| 6442 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6443 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6444 | |
| 6445 | /* WaDisableRenderCachePipelinedFlush */ |
| 6446 | I915_WRITE(CACHE_MODE_0, |
| 6447 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6448 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6449 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6450 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6451 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6452 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6453 | } |
| 6454 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6455 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6456 | { |
| 6457 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6458 | |
| 6459 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6460 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6461 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6462 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6463 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6464 | I915_WRITE(MI_ARB_STATE, |
| 6465 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6466 | |
| 6467 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6468 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6469 | } |
| 6470 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6471 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6472 | { |
| 6473 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6474 | |
| 6475 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6476 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6477 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6478 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6479 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6480 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6481 | I915_WRITE(MI_ARB_STATE, |
| 6482 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6483 | |
| 6484 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6485 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6486 | } |
| 6487 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6488 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6489 | { |
| 6490 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6491 | u32 dstate = I915_READ(D_STATE); |
| 6492 | |
| 6493 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6494 | DSTATE_DOT_CLOCK_GATING; |
| 6495 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6496 | |
| 6497 | if (IS_PINEVIEW(dev)) |
| 6498 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6499 | |
| 6500 | /* IIR "flip pending" means done if this bit is set */ |
| 6501 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6502 | |
| 6503 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6504 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6505 | |
| 6506 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6507 | 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] | 6508 | |
| 6509 | I915_WRITE(MI_ARB_STATE, |
| 6510 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6511 | } |
| 6512 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6513 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6514 | { |
| 6515 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6516 | |
| 6517 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6518 | |
| 6519 | /* interrupts should cause a wake up from C3 */ |
| 6520 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6521 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6522 | |
| 6523 | I915_WRITE(MEM_MODE, |
| 6524 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6525 | } |
| 6526 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6527 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6528 | { |
| 6529 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6530 | |
| 6531 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6532 | |
| 6533 | I915_WRITE(MEM_MODE, |
| 6534 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6535 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6536 | } |
| 6537 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6538 | void intel_init_clock_gating(struct drm_device *dev) |
| 6539 | { |
| 6540 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6541 | |
Damien Lespiau | c57e355 | 2015-02-09 19:33:05 +0000 | [diff] [blame] | 6542 | if (dev_priv->display.init_clock_gating) |
| 6543 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6544 | } |
| 6545 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6546 | void intel_suspend_hw(struct drm_device *dev) |
| 6547 | { |
| 6548 | if (HAS_PCH_LPT(dev)) |
| 6549 | lpt_suspend_hw(dev); |
| 6550 | } |
| 6551 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6552 | /* Set up chip specific power management-related functions */ |
| 6553 | void intel_init_pm(struct drm_device *dev) |
| 6554 | { |
| 6555 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6556 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 6557 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6558 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6559 | /* For cxsr */ |
| 6560 | if (IS_PINEVIEW(dev)) |
| 6561 | i915_pineview_get_mem_freq(dev); |
| 6562 | else if (IS_GEN5(dev)) |
| 6563 | i915_ironlake_get_mem_freq(dev); |
| 6564 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6565 | /* For FIFO watermark updates */ |
Damien Lespiau | f5ed50c | 2014-11-13 17:51:52 +0000 | [diff] [blame] | 6566 | if (INTEL_INFO(dev)->gen >= 9) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 6567 | skl_setup_wm_latency(dev); |
| 6568 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 6569 | if (IS_BROXTON(dev)) |
| 6570 | dev_priv->display.init_clock_gating = |
| 6571 | bxt_init_clock_gating; |
| 6572 | else if (IS_SKYLAKE(dev)) |
| 6573 | dev_priv->display.init_clock_gating = |
| 6574 | skl_init_clock_gating; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 6575 | dev_priv->display.update_wm = skl_update_wm; |
| 6576 | dev_priv->display.update_sprite_wm = skl_update_sprite_wm; |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6577 | } else if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6578 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6579 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6580 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6581 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6582 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6583 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6584 | dev_priv->display.update_wm = ilk_update_wm; |
| 6585 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6586 | } else { |
| 6587 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6588 | "Disable CxSR\n"); |
| 6589 | } |
| 6590 | |
| 6591 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6592 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6593 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6594 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6595 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6596 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6597 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6598 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6599 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6600 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6601 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 6602 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6603 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6604 | dev_priv->display.init_clock_gating = |
| 6605 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6606 | } else if (IS_VALLEYVIEW(dev)) { |
| 6607 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6608 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6609 | dev_priv->display.init_clock_gating = |
| 6610 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6611 | } else if (IS_PINEVIEW(dev)) { |
| 6612 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6613 | dev_priv->is_ddr3, |
| 6614 | dev_priv->fsb_freq, |
| 6615 | dev_priv->mem_freq)) { |
| 6616 | DRM_INFO("failed to find known CxSR latency " |
| 6617 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6618 | "disabling CxSR\n", |
| 6619 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6620 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6621 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6622 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6623 | dev_priv->display.update_wm = NULL; |
| 6624 | } else |
| 6625 | dev_priv->display.update_wm = pineview_update_wm; |
| 6626 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6627 | } else if (IS_G4X(dev)) { |
| 6628 | dev_priv->display.update_wm = g4x_update_wm; |
| 6629 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6630 | } else if (IS_GEN4(dev)) { |
| 6631 | dev_priv->display.update_wm = i965_update_wm; |
| 6632 | if (IS_CRESTLINE(dev)) |
| 6633 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6634 | else if (IS_BROADWATER(dev)) |
| 6635 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6636 | } else if (IS_GEN3(dev)) { |
| 6637 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6638 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6639 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6640 | } else if (IS_GEN2(dev)) { |
| 6641 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6642 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6643 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6644 | } else { |
| 6645 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6646 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6650 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6651 | else |
| 6652 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6653 | } else { |
| 6654 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6655 | } |
| 6656 | } |
| 6657 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6658 | 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] | 6659 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6660 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6661 | |
| 6662 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6663 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6664 | return -EAGAIN; |
| 6665 | } |
| 6666 | |
| 6667 | I915_WRITE(GEN6_PCODE_DATA, *val); |
Damien Lespiau | dddab34 | 2014-11-13 17:51:50 +0000 | [diff] [blame] | 6668 | I915_WRITE(GEN6_PCODE_DATA1, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6669 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6670 | |
| 6671 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6672 | 500)) { |
| 6673 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6674 | return -ETIMEDOUT; |
| 6675 | } |
| 6676 | |
| 6677 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6678 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6679 | |
| 6680 | return 0; |
| 6681 | } |
| 6682 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6683 | 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] | 6684 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6685 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6686 | |
| 6687 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6688 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6689 | return -EAGAIN; |
| 6690 | } |
| 6691 | |
| 6692 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6693 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6694 | |
| 6695 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6696 | 500)) { |
| 6697 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6698 | return -ETIMEDOUT; |
| 6699 | } |
| 6700 | |
| 6701 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6702 | |
| 6703 | return 0; |
| 6704 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6705 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6706 | static int vlv_gpu_freq_div(unsigned int czclk_freq) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6707 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6708 | switch (czclk_freq) { |
| 6709 | case 200: |
| 6710 | return 10; |
| 6711 | case 267: |
| 6712 | return 12; |
| 6713 | case 320: |
| 6714 | case 333: |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6715 | return 16; |
Ville Syrjälä | ab3fb15 | 2014-11-10 22:55:15 +0200 | [diff] [blame] | 6716 | case 400: |
| 6717 | return 20; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6718 | default: |
| 6719 | return -1; |
| 6720 | } |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6721 | } |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6722 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6723 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6724 | { |
| 6725 | int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
| 6726 | |
| 6727 | div = vlv_gpu_freq_div(czclk_freq); |
| 6728 | if (div < 0) |
| 6729 | return div; |
| 6730 | |
| 6731 | return DIV_ROUND_CLOSEST(czclk_freq * (val + 6 - 0xbd), div); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6732 | } |
| 6733 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6734 | 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] | 6735 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6736 | int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6737 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6738 | mul = vlv_gpu_freq_div(czclk_freq); |
| 6739 | if (mul < 0) |
| 6740 | return mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6741 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6742 | return DIV_ROUND_CLOSEST(mul * val, czclk_freq) + 0xbd - 6; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6743 | } |
| 6744 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6745 | 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] | 6746 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6747 | int div, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6748 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6749 | div = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6750 | if (div < 0) |
| 6751 | return div; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6752 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6753 | return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6754 | } |
| 6755 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6756 | 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] | 6757 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6758 | int mul, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6759 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6760 | mul = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6761 | if (mul < 0) |
| 6762 | return mul; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6763 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 6764 | /* CHV needs even values */ |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6765 | return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6766 | } |
| 6767 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6768 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6769 | { |
Akash Goel | 80b6dda | 2015-03-06 11:07:15 +0530 | [diff] [blame] | 6770 | if (IS_GEN9(dev_priv->dev)) |
| 6771 | return (val * GT_FREQUENCY_MULTIPLIER) / GEN9_FREQ_SCALER; |
| 6772 | else if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6773 | return chv_gpu_freq(dev_priv, val); |
| 6774 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 6775 | return byt_gpu_freq(dev_priv, val); |
| 6776 | else |
| 6777 | return val * GT_FREQUENCY_MULTIPLIER; |
| 6778 | } |
| 6779 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6780 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 6781 | { |
Akash Goel | 80b6dda | 2015-03-06 11:07:15 +0530 | [diff] [blame] | 6782 | if (IS_GEN9(dev_priv->dev)) |
| 6783 | return (val * GEN9_FREQ_SCALER) / GT_FREQUENCY_MULTIPLIER; |
| 6784 | else if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6785 | return chv_freq_opcode(dev_priv, val); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6786 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6787 | return byt_freq_opcode(dev_priv, val); |
| 6788 | else |
| 6789 | return val / GT_FREQUENCY_MULTIPLIER; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6790 | } |
| 6791 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6792 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6793 | { |
| 6794 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6795 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6796 | mutex_init(&dev_priv->rps.hw_lock); |
| 6797 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6798 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 6799 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6800 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 6801 | dev_priv->pm.suspended = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6802 | } |