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 | 77719d2 | 2015-02-09 19:33:13 +0000 | [diff] [blame] | 55 | static void gen9_init_clock_gating(struct drm_device *dev) |
| 56 | { |
| 57 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 58 | |
| 59 | /* WaEnableLbsSlaRetryTimerDecrement:skl */ |
| 60 | I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) | |
| 61 | GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE); |
| 62 | } |
| 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; |
| 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 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 97 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 98 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 99 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 100 | u32 tmp; |
| 101 | |
| 102 | tmp = I915_READ(CLKCFG); |
| 103 | |
| 104 | switch (tmp & CLKCFG_FSB_MASK) { |
| 105 | case CLKCFG_FSB_533: |
| 106 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 107 | break; |
| 108 | case CLKCFG_FSB_800: |
| 109 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 110 | break; |
| 111 | case CLKCFG_FSB_667: |
| 112 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 113 | break; |
| 114 | case CLKCFG_FSB_400: |
| 115 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 116 | break; |
| 117 | } |
| 118 | |
| 119 | switch (tmp & CLKCFG_MEM_MASK) { |
| 120 | case CLKCFG_MEM_533: |
| 121 | dev_priv->mem_freq = 533; |
| 122 | break; |
| 123 | case CLKCFG_MEM_667: |
| 124 | dev_priv->mem_freq = 667; |
| 125 | break; |
| 126 | case CLKCFG_MEM_800: |
| 127 | dev_priv->mem_freq = 800; |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | /* detect pineview DDR3 setting */ |
| 132 | tmp = I915_READ(CSHRDDR3CTL); |
| 133 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 134 | } |
| 135 | |
| 136 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 137 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 138 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 139 | u16 ddrpll, csipll; |
| 140 | |
| 141 | ddrpll = I915_READ16(DDRMPLL1); |
| 142 | csipll = I915_READ16(CSIPLL0); |
| 143 | |
| 144 | switch (ddrpll & 0xff) { |
| 145 | case 0xc: |
| 146 | dev_priv->mem_freq = 800; |
| 147 | break; |
| 148 | case 0x10: |
| 149 | dev_priv->mem_freq = 1066; |
| 150 | break; |
| 151 | case 0x14: |
| 152 | dev_priv->mem_freq = 1333; |
| 153 | break; |
| 154 | case 0x18: |
| 155 | dev_priv->mem_freq = 1600; |
| 156 | break; |
| 157 | default: |
| 158 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 159 | ddrpll & 0xff); |
| 160 | dev_priv->mem_freq = 0; |
| 161 | break; |
| 162 | } |
| 163 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 164 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 165 | |
| 166 | switch (csipll & 0x3ff) { |
| 167 | case 0x00c: |
| 168 | dev_priv->fsb_freq = 3200; |
| 169 | break; |
| 170 | case 0x00e: |
| 171 | dev_priv->fsb_freq = 3733; |
| 172 | break; |
| 173 | case 0x010: |
| 174 | dev_priv->fsb_freq = 4266; |
| 175 | break; |
| 176 | case 0x012: |
| 177 | dev_priv->fsb_freq = 4800; |
| 178 | break; |
| 179 | case 0x014: |
| 180 | dev_priv->fsb_freq = 5333; |
| 181 | break; |
| 182 | case 0x016: |
| 183 | dev_priv->fsb_freq = 5866; |
| 184 | break; |
| 185 | case 0x018: |
| 186 | dev_priv->fsb_freq = 6400; |
| 187 | break; |
| 188 | default: |
| 189 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 190 | csipll & 0x3ff); |
| 191 | dev_priv->fsb_freq = 0; |
| 192 | break; |
| 193 | } |
| 194 | |
| 195 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 196 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 197 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 198 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 199 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 200 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 204 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 205 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 206 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 207 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 208 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 209 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 210 | |
| 211 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 212 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 213 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 214 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 215 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 216 | |
| 217 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 218 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 219 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 220 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 221 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 222 | |
| 223 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 224 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 225 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 226 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 227 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 228 | |
| 229 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 230 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 231 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 232 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 233 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 234 | |
| 235 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 236 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 237 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 238 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 239 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 240 | }; |
| 241 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 242 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 243 | int is_ddr3, |
| 244 | int fsb, |
| 245 | int mem) |
| 246 | { |
| 247 | const struct cxsr_latency *latency; |
| 248 | int i; |
| 249 | |
| 250 | if (fsb == 0 || mem == 0) |
| 251 | return NULL; |
| 252 | |
| 253 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 254 | latency = &cxsr_latency_table[i]; |
| 255 | if (is_desktop == latency->is_desktop && |
| 256 | is_ddr3 == latency->is_ddr3 && |
| 257 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 258 | return latency; |
| 259 | } |
| 260 | |
| 261 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 262 | |
| 263 | return NULL; |
| 264 | } |
| 265 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 266 | 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] | 267 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 268 | struct drm_device *dev = dev_priv->dev; |
| 269 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 270 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 271 | if (IS_VALLEYVIEW(dev)) { |
| 272 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 273 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 274 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 275 | } else if (IS_PINEVIEW(dev)) { |
| 276 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 277 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 278 | I915_WRITE(DSPFW3, val); |
| 279 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 280 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 281 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 282 | I915_WRITE(FW_BLC_SELF, val); |
| 283 | } else if (IS_I915GM(dev)) { |
| 284 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 285 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 286 | I915_WRITE(INSTPM, val); |
| 287 | } else { |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 292 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* |
| 296 | * Latency for FIFO fetches is dependent on several factors: |
| 297 | * - memory configuration (speed, channels) |
| 298 | * - chipset |
| 299 | * - current MCH state |
| 300 | * It can be fairly high in some situations, so here we assume a fairly |
| 301 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 302 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 303 | * and power consumption (set it too low to save power and we might see |
| 304 | * FIFO underruns and display "flicker"). |
| 305 | * |
| 306 | * A value of 5us seems to be a good balance; safe for very low end |
| 307 | * platforms but not overly aggressive on lower latency configs. |
| 308 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 309 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 310 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 311 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 312 | { |
| 313 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 314 | uint32_t dsparb = I915_READ(DSPARB); |
| 315 | int size; |
| 316 | |
| 317 | size = dsparb & 0x7f; |
| 318 | if (plane) |
| 319 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 320 | |
| 321 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 322 | plane ? "B" : "A", size); |
| 323 | |
| 324 | return size; |
| 325 | } |
| 326 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 327 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 328 | { |
| 329 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 330 | uint32_t dsparb = I915_READ(DSPARB); |
| 331 | int size; |
| 332 | |
| 333 | size = dsparb & 0x1ff; |
| 334 | if (plane) |
| 335 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 336 | size >>= 1; /* Convert to cachelines */ |
| 337 | |
| 338 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 339 | plane ? "B" : "A", size); |
| 340 | |
| 341 | return size; |
| 342 | } |
| 343 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 344 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 345 | { |
| 346 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 347 | uint32_t dsparb = I915_READ(DSPARB); |
| 348 | int size; |
| 349 | |
| 350 | size = dsparb & 0x7f; |
| 351 | size >>= 2; /* Convert to cachelines */ |
| 352 | |
| 353 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 354 | plane ? "B" : "A", |
| 355 | size); |
| 356 | |
| 357 | return size; |
| 358 | } |
| 359 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 360 | /* Pineview has different values for various configs */ |
| 361 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 362 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 363 | .max_wm = PINEVIEW_MAX_WM, |
| 364 | .default_wm = PINEVIEW_DFT_WM, |
| 365 | .guard_size = PINEVIEW_GUARD_WM, |
| 366 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 367 | }; |
| 368 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 369 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 370 | .max_wm = PINEVIEW_MAX_WM, |
| 371 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 372 | .guard_size = PINEVIEW_GUARD_WM, |
| 373 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 374 | }; |
| 375 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 376 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 377 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 378 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 379 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 380 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 381 | }; |
| 382 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 383 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 384 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 385 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 386 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 387 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 388 | }; |
| 389 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 390 | .fifo_size = G4X_FIFO_SIZE, |
| 391 | .max_wm = G4X_MAX_WM, |
| 392 | .default_wm = G4X_MAX_WM, |
| 393 | .guard_size = 2, |
| 394 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 395 | }; |
| 396 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 397 | .fifo_size = I965_CURSOR_FIFO, |
| 398 | .max_wm = I965_CURSOR_MAX_WM, |
| 399 | .default_wm = I965_CURSOR_DFT_WM, |
| 400 | .guard_size = 2, |
| 401 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 402 | }; |
| 403 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 404 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 405 | .max_wm = VALLEYVIEW_MAX_WM, |
| 406 | .default_wm = VALLEYVIEW_MAX_WM, |
| 407 | .guard_size = 2, |
| 408 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 409 | }; |
| 410 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 411 | .fifo_size = I965_CURSOR_FIFO, |
| 412 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 413 | .default_wm = I965_CURSOR_DFT_WM, |
| 414 | .guard_size = 2, |
| 415 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 416 | }; |
| 417 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 418 | .fifo_size = I965_CURSOR_FIFO, |
| 419 | .max_wm = I965_CURSOR_MAX_WM, |
| 420 | .default_wm = I965_CURSOR_DFT_WM, |
| 421 | .guard_size = 2, |
| 422 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 423 | }; |
| 424 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 425 | .fifo_size = I945_FIFO_SIZE, |
| 426 | .max_wm = I915_MAX_WM, |
| 427 | .default_wm = 1, |
| 428 | .guard_size = 2, |
| 429 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 430 | }; |
| 431 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 432 | .fifo_size = I915_FIFO_SIZE, |
| 433 | .max_wm = I915_MAX_WM, |
| 434 | .default_wm = 1, |
| 435 | .guard_size = 2, |
| 436 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 437 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 438 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 439 | .fifo_size = I855GM_FIFO_SIZE, |
| 440 | .max_wm = I915_MAX_WM, |
| 441 | .default_wm = 1, |
| 442 | .guard_size = 2, |
| 443 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 444 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 445 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 446 | .fifo_size = I855GM_FIFO_SIZE, |
| 447 | .max_wm = I915_MAX_WM/2, |
| 448 | .default_wm = 1, |
| 449 | .guard_size = 2, |
| 450 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 451 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 452 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 453 | .fifo_size = I830_FIFO_SIZE, |
| 454 | .max_wm = I915_MAX_WM, |
| 455 | .default_wm = 1, |
| 456 | .guard_size = 2, |
| 457 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 458 | }; |
| 459 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 460 | /** |
| 461 | * intel_calculate_wm - calculate watermark level |
| 462 | * @clock_in_khz: pixel clock |
| 463 | * @wm: chip FIFO params |
| 464 | * @pixel_size: display pixel size |
| 465 | * @latency_ns: memory latency for the platform |
| 466 | * |
| 467 | * Calculate the watermark level (the level at which the display plane will |
| 468 | * start fetching from memory again). Each chip has a different display |
| 469 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 470 | * in the correct intel_watermark_params structure. |
| 471 | * |
| 472 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 473 | * on the pixel size. When it reaches the watermark level, it'll start |
| 474 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 475 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 476 | * will occur, and a display engine hang could result. |
| 477 | */ |
| 478 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 479 | const struct intel_watermark_params *wm, |
| 480 | int fifo_size, |
| 481 | int pixel_size, |
| 482 | unsigned long latency_ns) |
| 483 | { |
| 484 | long entries_required, wm_size; |
| 485 | |
| 486 | /* |
| 487 | * Note: we need to make sure we don't overflow for various clock & |
| 488 | * latency values. |
| 489 | * clocks go from a few thousand to several hundred thousand. |
| 490 | * latency is usually a few thousand |
| 491 | */ |
| 492 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 493 | 1000; |
| 494 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 495 | |
| 496 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 497 | |
| 498 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 499 | |
| 500 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 501 | |
| 502 | /* Don't promote wm_size to unsigned... */ |
| 503 | if (wm_size > (long)wm->max_wm) |
| 504 | wm_size = wm->max_wm; |
| 505 | if (wm_size <= 0) |
| 506 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 507 | |
| 508 | /* |
| 509 | * Bspec seems to indicate that the value shouldn't be lower than |
| 510 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 511 | * Lets go for 8 which is the burst size since certain platforms |
| 512 | * already use a hardcoded 8 (which is what the spec says should be |
| 513 | * done). |
| 514 | */ |
| 515 | if (wm_size <= 8) |
| 516 | wm_size = 8; |
| 517 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 518 | return wm_size; |
| 519 | } |
| 520 | |
| 521 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 522 | { |
| 523 | struct drm_crtc *crtc, *enabled = NULL; |
| 524 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 525 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 526 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 527 | if (enabled) |
| 528 | return NULL; |
| 529 | enabled = crtc; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | return enabled; |
| 534 | } |
| 535 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 536 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 537 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 538 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 539 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 540 | struct drm_crtc *crtc; |
| 541 | const struct cxsr_latency *latency; |
| 542 | u32 reg; |
| 543 | unsigned long wm; |
| 544 | |
| 545 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 546 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 547 | if (!latency) { |
| 548 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 549 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 550 | return; |
| 551 | } |
| 552 | |
| 553 | crtc = single_enabled_crtc(dev); |
| 554 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 555 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 556 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 557 | int clock; |
| 558 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 559 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 560 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 561 | |
| 562 | /* Display SR */ |
| 563 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 564 | pineview_display_wm.fifo_size, |
| 565 | pixel_size, latency->display_sr); |
| 566 | reg = I915_READ(DSPFW1); |
| 567 | reg &= ~DSPFW_SR_MASK; |
| 568 | reg |= wm << DSPFW_SR_SHIFT; |
| 569 | I915_WRITE(DSPFW1, reg); |
| 570 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 571 | |
| 572 | /* cursor SR */ |
| 573 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 574 | pineview_display_wm.fifo_size, |
| 575 | pixel_size, latency->cursor_sr); |
| 576 | reg = I915_READ(DSPFW3); |
| 577 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 578 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 579 | I915_WRITE(DSPFW3, reg); |
| 580 | |
| 581 | /* Display HPLL off SR */ |
| 582 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 583 | pineview_display_hplloff_wm.fifo_size, |
| 584 | pixel_size, latency->display_hpll_disable); |
| 585 | reg = I915_READ(DSPFW3); |
| 586 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 587 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 588 | I915_WRITE(DSPFW3, reg); |
| 589 | |
| 590 | /* cursor HPLL off SR */ |
| 591 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 592 | pineview_display_hplloff_wm.fifo_size, |
| 593 | pixel_size, latency->cursor_hpll_disable); |
| 594 | reg = I915_READ(DSPFW3); |
| 595 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 596 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 597 | I915_WRITE(DSPFW3, reg); |
| 598 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 599 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 600 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 601 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 602 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 607 | int plane, |
| 608 | const struct intel_watermark_params *display, |
| 609 | int display_latency_ns, |
| 610 | const struct intel_watermark_params *cursor, |
| 611 | int cursor_latency_ns, |
| 612 | int *plane_wm, |
| 613 | int *cursor_wm) |
| 614 | { |
| 615 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 616 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 617 | int htotal, hdisplay, clock, pixel_size; |
| 618 | int line_time_us, line_count; |
| 619 | int entries, tlb_miss; |
| 620 | |
| 621 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 622 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 623 | *cursor_wm = cursor->guard_size; |
| 624 | *plane_wm = display->guard_size; |
| 625 | return false; |
| 626 | } |
| 627 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 628 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 629 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 630 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 631 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 632 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 633 | |
| 634 | /* Use the small buffer method to calculate plane watermark */ |
| 635 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 636 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 637 | if (tlb_miss > 0) |
| 638 | entries += tlb_miss; |
| 639 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 640 | *plane_wm = entries + display->guard_size; |
| 641 | if (*plane_wm > (int)display->max_wm) |
| 642 | *plane_wm = display->max_wm; |
| 643 | |
| 644 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 645 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 646 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 647 | entries = line_count * to_intel_crtc(crtc)->cursor_width * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 648 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 649 | if (tlb_miss > 0) |
| 650 | entries += tlb_miss; |
| 651 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 652 | *cursor_wm = entries + cursor->guard_size; |
| 653 | if (*cursor_wm > (int)cursor->max_wm) |
| 654 | *cursor_wm = (int)cursor->max_wm; |
| 655 | |
| 656 | return true; |
| 657 | } |
| 658 | |
| 659 | /* |
| 660 | * Check the wm result. |
| 661 | * |
| 662 | * If any calculated watermark values is larger than the maximum value that |
| 663 | * can be programmed into the associated watermark register, that watermark |
| 664 | * must be disabled. |
| 665 | */ |
| 666 | static bool g4x_check_srwm(struct drm_device *dev, |
| 667 | int display_wm, int cursor_wm, |
| 668 | const struct intel_watermark_params *display, |
| 669 | const struct intel_watermark_params *cursor) |
| 670 | { |
| 671 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 672 | display_wm, cursor_wm); |
| 673 | |
| 674 | if (display_wm > display->max_wm) { |
| 675 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 676 | display_wm, display->max_wm); |
| 677 | return false; |
| 678 | } |
| 679 | |
| 680 | if (cursor_wm > cursor->max_wm) { |
| 681 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 682 | cursor_wm, cursor->max_wm); |
| 683 | return false; |
| 684 | } |
| 685 | |
| 686 | if (!(display_wm || cursor_wm)) { |
| 687 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | return true; |
| 692 | } |
| 693 | |
| 694 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 695 | int plane, |
| 696 | int latency_ns, |
| 697 | const struct intel_watermark_params *display, |
| 698 | const struct intel_watermark_params *cursor, |
| 699 | int *display_wm, int *cursor_wm) |
| 700 | { |
| 701 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 702 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 703 | int hdisplay, htotal, pixel_size, clock; |
| 704 | unsigned long line_time_us; |
| 705 | int line_count, line_size; |
| 706 | int small, large; |
| 707 | int entries; |
| 708 | |
| 709 | if (!latency_ns) { |
| 710 | *display_wm = *cursor_wm = 0; |
| 711 | return false; |
| 712 | } |
| 713 | |
| 714 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 715 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 716 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 717 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 718 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 719 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 720 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 721 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 722 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 723 | line_size = hdisplay * pixel_size; |
| 724 | |
| 725 | /* Use the minimum of the small and large buffer method for primary */ |
| 726 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 727 | large = line_count * line_size; |
| 728 | |
| 729 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 730 | *display_wm = entries + display->guard_size; |
| 731 | |
| 732 | /* calculate the self-refresh watermark for display cursor */ |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 733 | entries = line_count * pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 734 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 735 | *cursor_wm = entries + cursor->guard_size; |
| 736 | |
| 737 | return g4x_check_srwm(dev, |
| 738 | *display_wm, *cursor_wm, |
| 739 | display, cursor); |
| 740 | } |
| 741 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 742 | static bool vlv_compute_drain_latency(struct drm_crtc *crtc, |
| 743 | int pixel_size, |
| 744 | int *prec_mult, |
| 745 | int *drain_latency) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 746 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 747 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 748 | int entries; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 749 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 750 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 751 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 752 | return false; |
| 753 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 754 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
| 755 | return false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 756 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 757 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 758 | if (IS_CHERRYVIEW(dev)) |
| 759 | *prec_mult = (entries > 128) ? DRAIN_LATENCY_PRECISION_32 : |
| 760 | DRAIN_LATENCY_PRECISION_16; |
| 761 | else |
| 762 | *prec_mult = (entries > 128) ? DRAIN_LATENCY_PRECISION_64 : |
| 763 | DRAIN_LATENCY_PRECISION_32; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 764 | *drain_latency = (64 * (*prec_mult) * 4) / entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 765 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 766 | if (*drain_latency > DRAIN_LATENCY_MASK) |
| 767 | *drain_latency = DRAIN_LATENCY_MASK; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 768 | |
| 769 | return true; |
| 770 | } |
| 771 | |
| 772 | /* |
| 773 | * Update drain latency registers of memory arbiter |
| 774 | * |
| 775 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 776 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 777 | * latency value. |
| 778 | */ |
| 779 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 780 | static void vlv_update_drain_latency(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 781 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 782 | struct drm_device *dev = crtc->dev; |
| 783 | struct drm_i915_private *dev_priv = dev->dev_private; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 784 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 785 | int pixel_size; |
| 786 | int drain_latency; |
| 787 | enum pipe pipe = intel_crtc->pipe; |
| 788 | int plane_prec, prec_mult, plane_dl; |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 789 | const int high_precision = IS_CHERRYVIEW(dev) ? |
| 790 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_64; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 791 | |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 792 | plane_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_PLANE_PRECISION_HIGH | |
| 793 | DRAIN_LATENCY_MASK | DDL_CURSOR_PRECISION_HIGH | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 794 | (DRAIN_LATENCY_MASK << DDL_CURSOR_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 795 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 796 | if (!intel_crtc_active(crtc)) { |
| 797 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
| 798 | return; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 799 | } |
| 800 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 801 | /* Primary plane Drain Latency */ |
| 802 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; /* BPP */ |
| 803 | if (vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 804 | plane_prec = (prec_mult == high_precision) ? |
| 805 | DDL_PLANE_PRECISION_HIGH : |
| 806 | DDL_PLANE_PRECISION_LOW; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 807 | plane_dl |= plane_prec | drain_latency; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 808 | } |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 809 | |
| 810 | /* Cursor Drain Latency |
| 811 | * BPP is always 4 for cursor |
| 812 | */ |
| 813 | pixel_size = 4; |
| 814 | |
| 815 | /* Program cursor DL only if it is enabled */ |
| 816 | if (intel_crtc->cursor_base && |
| 817 | vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 818 | plane_prec = (prec_mult == high_precision) ? |
| 819 | DDL_CURSOR_PRECISION_HIGH : |
| 820 | DDL_CURSOR_PRECISION_LOW; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 821 | plane_dl |= plane_prec | (drain_latency << DDL_CURSOR_SHIFT); |
| 822 | } |
| 823 | |
| 824 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 828 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 829 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 830 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 831 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 832 | static const int sr_latency_ns = 12000; |
| 833 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 834 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 835 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 836 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 837 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 838 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 839 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 840 | vlv_update_drain_latency(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 841 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 842 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 843 | &valleyview_wm_info, pessimal_latency_ns, |
| 844 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 845 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 846 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 847 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 848 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 849 | &valleyview_wm_info, pessimal_latency_ns, |
| 850 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 851 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 852 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 853 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 854 | if (single_plane_enabled(enabled) && |
| 855 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 856 | sr_latency_ns, |
| 857 | &valleyview_wm_info, |
| 858 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 859 | &plane_sr, &ignore_cursor_sr) && |
| 860 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 861 | 2*sr_latency_ns, |
| 862 | &valleyview_wm_info, |
| 863 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 864 | &ignore_plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 865 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 866 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 867 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 868 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 869 | plane_sr = cursor_sr = 0; |
| 870 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 871 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 872 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 873 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 874 | planea_wm, cursora_wm, |
| 875 | planeb_wm, cursorb_wm, |
| 876 | plane_sr, cursor_sr); |
| 877 | |
| 878 | I915_WRITE(DSPFW1, |
| 879 | (plane_sr << DSPFW_SR_SHIFT) | |
| 880 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 881 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 882 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 883 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 884 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 885 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 886 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 887 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 888 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 889 | |
| 890 | if (cxsr_enabled) |
| 891 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 892 | } |
| 893 | |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 894 | static void cherryview_update_wm(struct drm_crtc *crtc) |
| 895 | { |
| 896 | struct drm_device *dev = crtc->dev; |
| 897 | static const int sr_latency_ns = 12000; |
| 898 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 899 | int planea_wm, planeb_wm, planec_wm; |
| 900 | int cursora_wm, cursorb_wm, cursorc_wm; |
| 901 | int plane_sr, cursor_sr; |
| 902 | int ignore_plane_sr, ignore_cursor_sr; |
| 903 | unsigned int enabled = 0; |
| 904 | bool cxsr_enabled; |
| 905 | |
| 906 | vlv_update_drain_latency(crtc); |
| 907 | |
| 908 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 909 | &valleyview_wm_info, pessimal_latency_ns, |
| 910 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 911 | &planea_wm, &cursora_wm)) |
| 912 | enabled |= 1 << PIPE_A; |
| 913 | |
| 914 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 915 | &valleyview_wm_info, pessimal_latency_ns, |
| 916 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 917 | &planeb_wm, &cursorb_wm)) |
| 918 | enabled |= 1 << PIPE_B; |
| 919 | |
| 920 | if (g4x_compute_wm0(dev, PIPE_C, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 921 | &valleyview_wm_info, pessimal_latency_ns, |
| 922 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 923 | &planec_wm, &cursorc_wm)) |
| 924 | enabled |= 1 << PIPE_C; |
| 925 | |
| 926 | if (single_plane_enabled(enabled) && |
| 927 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 928 | sr_latency_ns, |
| 929 | &valleyview_wm_info, |
| 930 | &valleyview_cursor_wm_info, |
| 931 | &plane_sr, &ignore_cursor_sr) && |
| 932 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 933 | 2*sr_latency_ns, |
| 934 | &valleyview_wm_info, |
| 935 | &valleyview_cursor_wm_info, |
| 936 | &ignore_plane_sr, &cursor_sr)) { |
| 937 | cxsr_enabled = true; |
| 938 | } else { |
| 939 | cxsr_enabled = false; |
| 940 | intel_set_memory_cxsr(dev_priv, false); |
| 941 | plane_sr = cursor_sr = 0; |
| 942 | } |
| 943 | |
| 944 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 945 | "B: plane=%d, cursor=%d, C: plane=%d, cursor=%d, " |
| 946 | "SR: plane=%d, cursor=%d\n", |
| 947 | planea_wm, cursora_wm, |
| 948 | planeb_wm, cursorb_wm, |
| 949 | planec_wm, cursorc_wm, |
| 950 | plane_sr, cursor_sr); |
| 951 | |
| 952 | I915_WRITE(DSPFW1, |
| 953 | (plane_sr << DSPFW_SR_SHIFT) | |
| 954 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 955 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 956 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
| 957 | I915_WRITE(DSPFW2, |
| 958 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
| 959 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 960 | I915_WRITE(DSPFW3, |
| 961 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 962 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 963 | I915_WRITE(DSPFW9_CHV, |
| 964 | (I915_READ(DSPFW9_CHV) & ~(DSPFW_PLANEC_MASK | |
| 965 | DSPFW_CURSORC_MASK)) | |
| 966 | (planec_wm << DSPFW_PLANEC_SHIFT) | |
| 967 | (cursorc_wm << DSPFW_CURSORC_SHIFT)); |
| 968 | |
| 969 | if (cxsr_enabled) |
| 970 | intel_set_memory_cxsr(dev_priv, true); |
| 971 | } |
| 972 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 973 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 974 | struct drm_crtc *crtc, |
| 975 | uint32_t sprite_width, |
| 976 | uint32_t sprite_height, |
| 977 | int pixel_size, |
| 978 | bool enabled, bool scaled) |
| 979 | { |
| 980 | struct drm_device *dev = crtc->dev; |
| 981 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 982 | int pipe = to_intel_plane(plane)->pipe; |
| 983 | int sprite = to_intel_plane(plane)->plane; |
| 984 | int drain_latency; |
| 985 | int plane_prec; |
| 986 | int sprite_dl; |
| 987 | int prec_mult; |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 988 | const int high_precision = IS_CHERRYVIEW(dev) ? |
| 989 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_64; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 990 | |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 991 | sprite_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_SPRITE_PRECISION_HIGH(sprite) | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 992 | (DRAIN_LATENCY_MASK << DDL_SPRITE_SHIFT(sprite))); |
| 993 | |
| 994 | if (enabled && vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, |
| 995 | &drain_latency)) { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 996 | plane_prec = (prec_mult == high_precision) ? |
| 997 | DDL_SPRITE_PRECISION_HIGH(sprite) : |
| 998 | DDL_SPRITE_PRECISION_LOW(sprite); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 999 | sprite_dl |= plane_prec | |
| 1000 | (drain_latency << DDL_SPRITE_SHIFT(sprite)); |
| 1001 | } |
| 1002 | |
| 1003 | I915_WRITE(VLV_DDL(pipe), sprite_dl); |
| 1004 | } |
| 1005 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1006 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1007 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1008 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1009 | static const int sr_latency_ns = 12000; |
| 1010 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1011 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1012 | int plane_sr, cursor_sr; |
| 1013 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1014 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1015 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1016 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1017 | &g4x_wm_info, pessimal_latency_ns, |
| 1018 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1019 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1020 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1021 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1022 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1023 | &g4x_wm_info, pessimal_latency_ns, |
| 1024 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1025 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1026 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1027 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1028 | if (single_plane_enabled(enabled) && |
| 1029 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1030 | sr_latency_ns, |
| 1031 | &g4x_wm_info, |
| 1032 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1033 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1034 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1035 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1036 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1037 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1038 | plane_sr = cursor_sr = 0; |
| 1039 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1040 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1041 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1042 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1043 | planea_wm, cursora_wm, |
| 1044 | planeb_wm, cursorb_wm, |
| 1045 | plane_sr, cursor_sr); |
| 1046 | |
| 1047 | I915_WRITE(DSPFW1, |
| 1048 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1049 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1050 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1051 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1052 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1053 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1054 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1055 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1056 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1057 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1058 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1059 | |
| 1060 | if (cxsr_enabled) |
| 1061 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1062 | } |
| 1063 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1064 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1065 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1066 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1067 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1068 | struct drm_crtc *crtc; |
| 1069 | int srwm = 1; |
| 1070 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1071 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1072 | |
| 1073 | /* Calc sr entries for one plane configs */ |
| 1074 | crtc = single_enabled_crtc(dev); |
| 1075 | if (crtc) { |
| 1076 | /* self-refresh has much higher latency */ |
| 1077 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1078 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1079 | &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1080 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1081 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1082 | int hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1083 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1084 | unsigned long line_time_us; |
| 1085 | int entries; |
| 1086 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1087 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1088 | |
| 1089 | /* Use ns/us then divide to preserve precision */ |
| 1090 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1091 | pixel_size * hdisplay; |
| 1092 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1093 | srwm = I965_FIFO_SIZE - entries; |
| 1094 | if (srwm < 0) |
| 1095 | srwm = 1; |
| 1096 | srwm &= 0x1ff; |
| 1097 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1098 | entries, srwm); |
| 1099 | |
| 1100 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1101 | pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1102 | entries = DIV_ROUND_UP(entries, |
| 1103 | i965_cursor_wm_info.cacheline_size); |
| 1104 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1105 | (entries + i965_cursor_wm_info.guard_size); |
| 1106 | |
| 1107 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1108 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1109 | |
| 1110 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1111 | "cursor %d\n", srwm, cursor_sr); |
| 1112 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1113 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1114 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1115 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1116 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1117 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1121 | srwm); |
| 1122 | |
| 1123 | /* 965 has limitations... */ |
| 1124 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1125 | (8 << DSPFW_CURSORB_SHIFT) | |
| 1126 | (8 << DSPFW_PLANEB_SHIFT) | |
| 1127 | (8 << DSPFW_PLANEA_SHIFT)); |
| 1128 | I915_WRITE(DSPFW2, (8 << DSPFW_CURSORA_SHIFT) | |
| 1129 | (8 << DSPFW_PLANEC_SHIFT_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1130 | /* update cursor SR watermark */ |
| 1131 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1132 | |
| 1133 | if (cxsr_enabled) |
| 1134 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1135 | } |
| 1136 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1137 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1138 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1139 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1140 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1141 | const struct intel_watermark_params *wm_info; |
| 1142 | uint32_t fwater_lo; |
| 1143 | uint32_t fwater_hi; |
| 1144 | int cwm, srwm = 1; |
| 1145 | int fifo_size; |
| 1146 | int planea_wm, planeb_wm; |
| 1147 | struct drm_crtc *crtc, *enabled = NULL; |
| 1148 | |
| 1149 | if (IS_I945GM(dev)) |
| 1150 | wm_info = &i945_wm_info; |
| 1151 | else if (!IS_GEN2(dev)) |
| 1152 | wm_info = &i915_wm_info; |
| 1153 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1154 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1155 | |
| 1156 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1157 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1158 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1159 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1160 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1161 | if (IS_GEN2(dev)) |
| 1162 | cpp = 4; |
| 1163 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1164 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1165 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1166 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1167 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1168 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1169 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1170 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1171 | if (planea_wm > (long)wm_info->max_wm) |
| 1172 | planea_wm = wm_info->max_wm; |
| 1173 | } |
| 1174 | |
| 1175 | if (IS_GEN2(dev)) |
| 1176 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1177 | |
| 1178 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1179 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1180 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1181 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1182 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1183 | if (IS_GEN2(dev)) |
| 1184 | cpp = 4; |
| 1185 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1186 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1187 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1188 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1189 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1190 | if (enabled == NULL) |
| 1191 | enabled = crtc; |
| 1192 | else |
| 1193 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1194 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1195 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1196 | if (planeb_wm > (long)wm_info->max_wm) |
| 1197 | planeb_wm = wm_info->max_wm; |
| 1198 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1199 | |
| 1200 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1201 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1202 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1203 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1204 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1205 | obj = intel_fb_obj(enabled->primary->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1206 | |
| 1207 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1208 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1209 | enabled = NULL; |
| 1210 | } |
| 1211 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1212 | /* |
| 1213 | * Overlay gets an aggressive default since video jitter is bad. |
| 1214 | */ |
| 1215 | cwm = 2; |
| 1216 | |
| 1217 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1218 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1219 | |
| 1220 | /* Calc sr entries for one plane configs */ |
| 1221 | if (HAS_FW_BLC(dev) && enabled) { |
| 1222 | /* self-refresh has much higher latency */ |
| 1223 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1224 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1225 | &to_intel_crtc(enabled)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1226 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1227 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1228 | int hdisplay = to_intel_crtc(enabled)->config->pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1229 | int pixel_size = enabled->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1230 | unsigned long line_time_us; |
| 1231 | int entries; |
| 1232 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1233 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1234 | |
| 1235 | /* Use ns/us then divide to preserve precision */ |
| 1236 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1237 | pixel_size * hdisplay; |
| 1238 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1239 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1240 | srwm = wm_info->fifo_size - entries; |
| 1241 | if (srwm < 0) |
| 1242 | srwm = 1; |
| 1243 | |
| 1244 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1245 | I915_WRITE(FW_BLC_SELF, |
| 1246 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1247 | else if (IS_I915GM(dev)) |
| 1248 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1249 | } |
| 1250 | |
| 1251 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1252 | planea_wm, planeb_wm, cwm, srwm); |
| 1253 | |
| 1254 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1255 | fwater_hi = (cwm & 0x1f); |
| 1256 | |
| 1257 | /* Set request length to 8 cachelines per fetch */ |
| 1258 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1259 | fwater_hi = fwater_hi | (1 << 8); |
| 1260 | |
| 1261 | I915_WRITE(FW_BLC, fwater_lo); |
| 1262 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1263 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1264 | if (enabled) |
| 1265 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1266 | } |
| 1267 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1268 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1269 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1270 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1271 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1272 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1273 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1274 | uint32_t fwater_lo; |
| 1275 | int planea_wm; |
| 1276 | |
| 1277 | crtc = single_enabled_crtc(dev); |
| 1278 | if (crtc == NULL) |
| 1279 | return; |
| 1280 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1281 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1282 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1283 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1284 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1285 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1286 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1287 | fwater_lo |= (3<<8) | planea_wm; |
| 1288 | |
| 1289 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1290 | |
| 1291 | I915_WRITE(FW_BLC, fwater_lo); |
| 1292 | } |
| 1293 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1294 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1295 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1296 | { |
| 1297 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1298 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1299 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1300 | pixel_rate = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1301 | |
| 1302 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1303 | * adjust the pixel_rate here. */ |
| 1304 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1305 | if (intel_crtc->config->pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1306 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1307 | uint32_t pfit_size = intel_crtc->config->pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1308 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1309 | pipe_w = intel_crtc->config->pipe_src_w; |
| 1310 | pipe_h = intel_crtc->config->pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1311 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1312 | pfit_h = pfit_size & 0xFFFF; |
| 1313 | if (pipe_w < pfit_w) |
| 1314 | pipe_w = pfit_w; |
| 1315 | if (pipe_h < pfit_h) |
| 1316 | pipe_h = pfit_h; |
| 1317 | |
| 1318 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1319 | pfit_w * pfit_h); |
| 1320 | } |
| 1321 | |
| 1322 | return pixel_rate; |
| 1323 | } |
| 1324 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1325 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1326 | 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] | 1327 | uint32_t latency) |
| 1328 | { |
| 1329 | uint64_t ret; |
| 1330 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1331 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1332 | return UINT_MAX; |
| 1333 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1334 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1335 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1336 | |
| 1337 | return ret; |
| 1338 | } |
| 1339 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1340 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1341 | 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] | 1342 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1343 | uint32_t latency) |
| 1344 | { |
| 1345 | uint32_t ret; |
| 1346 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1347 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1348 | return UINT_MAX; |
| 1349 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1350 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1351 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1352 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1353 | return ret; |
| 1354 | } |
| 1355 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1356 | 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] | 1357 | uint8_t bytes_per_pixel) |
| 1358 | { |
| 1359 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1360 | } |
| 1361 | |
Pradeep Bhat | 2ac96d2 | 2014-11-04 17:06:40 +0000 | [diff] [blame] | 1362 | struct skl_pipe_wm_parameters { |
| 1363 | bool active; |
| 1364 | uint32_t pipe_htotal; |
| 1365 | uint32_t pixel_rate; /* in KHz */ |
| 1366 | struct intel_plane_wm_parameters plane[I915_MAX_PLANES]; |
| 1367 | struct intel_plane_wm_parameters cursor; |
| 1368 | }; |
| 1369 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1370 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1371 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1372 | uint32_t pipe_htotal; |
| 1373 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1374 | struct intel_plane_wm_parameters pri; |
| 1375 | struct intel_plane_wm_parameters spr; |
| 1376 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1377 | }; |
| 1378 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1379 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1380 | uint16_t pri; |
| 1381 | uint16_t spr; |
| 1382 | uint16_t cur; |
| 1383 | uint16_t fbc; |
| 1384 | }; |
| 1385 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1386 | /* used in computing the new watermarks state */ |
| 1387 | struct intel_wm_config { |
| 1388 | unsigned int num_pipes_active; |
| 1389 | bool sprites_enabled; |
| 1390 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1391 | }; |
| 1392 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1393 | /* |
| 1394 | * For both WM_PIPE and WM_LP. |
| 1395 | * mem_value must be in 0.1us units. |
| 1396 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1397 | 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] | 1398 | uint32_t mem_value, |
| 1399 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1400 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1401 | uint32_t method1, method2; |
| 1402 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1403 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1404 | return 0; |
| 1405 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1406 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1407 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1408 | mem_value); |
| 1409 | |
| 1410 | if (!is_lp) |
| 1411 | return method1; |
| 1412 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1413 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1414 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1415 | params->pri.horiz_pixels, |
| 1416 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1417 | mem_value); |
| 1418 | |
| 1419 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1420 | } |
| 1421 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1422 | /* |
| 1423 | * For both WM_PIPE and WM_LP. |
| 1424 | * mem_value must be in 0.1us units. |
| 1425 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1426 | 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] | 1427 | uint32_t mem_value) |
| 1428 | { |
| 1429 | uint32_t method1, method2; |
| 1430 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1431 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1432 | return 0; |
| 1433 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1434 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1435 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1436 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1437 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1438 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1439 | params->spr.horiz_pixels, |
| 1440 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1441 | mem_value); |
| 1442 | return min(method1, method2); |
| 1443 | } |
| 1444 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1445 | /* |
| 1446 | * For both WM_PIPE and WM_LP. |
| 1447 | * mem_value must be in 0.1us units. |
| 1448 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1449 | 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] | 1450 | uint32_t mem_value) |
| 1451 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1452 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1453 | return 0; |
| 1454 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1455 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1456 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1457 | params->cur.horiz_pixels, |
| 1458 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1459 | mem_value); |
| 1460 | } |
| 1461 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1462 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1463 | 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] | 1464 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1465 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1466 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1467 | return 0; |
| 1468 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1469 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1470 | params->pri.horiz_pixels, |
| 1471 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1472 | } |
| 1473 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1474 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1475 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1476 | if (INTEL_INFO(dev)->gen >= 8) |
| 1477 | return 3072; |
| 1478 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1479 | return 768; |
| 1480 | else |
| 1481 | return 512; |
| 1482 | } |
| 1483 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1484 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1485 | int level, bool is_sprite) |
| 1486 | { |
| 1487 | if (INTEL_INFO(dev)->gen >= 8) |
| 1488 | /* BDW primary/sprite plane watermarks */ |
| 1489 | return level == 0 ? 255 : 2047; |
| 1490 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1491 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1492 | return level == 0 ? 127 : 1023; |
| 1493 | else if (!is_sprite) |
| 1494 | /* ILK/SNB primary plane watermarks */ |
| 1495 | return level == 0 ? 127 : 511; |
| 1496 | else |
| 1497 | /* ILK/SNB sprite plane watermarks */ |
| 1498 | return level == 0 ? 63 : 255; |
| 1499 | } |
| 1500 | |
| 1501 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1502 | int level) |
| 1503 | { |
| 1504 | if (INTEL_INFO(dev)->gen >= 7) |
| 1505 | return level == 0 ? 63 : 255; |
| 1506 | else |
| 1507 | return level == 0 ? 31 : 63; |
| 1508 | } |
| 1509 | |
| 1510 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1511 | { |
| 1512 | if (INTEL_INFO(dev)->gen >= 8) |
| 1513 | return 31; |
| 1514 | else |
| 1515 | return 15; |
| 1516 | } |
| 1517 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1518 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1519 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1520 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1521 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1522 | enum intel_ddb_partitioning ddb_partitioning, |
| 1523 | bool is_sprite) |
| 1524 | { |
| 1525 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1526 | |
| 1527 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1528 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1529 | return 0; |
| 1530 | |
| 1531 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1532 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1533 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1534 | |
| 1535 | /* |
| 1536 | * For some reason the non self refresh |
| 1537 | * FIFO size is only half of the self |
| 1538 | * refresh FIFO size on ILK/SNB. |
| 1539 | */ |
| 1540 | if (INTEL_INFO(dev)->gen <= 6) |
| 1541 | fifo_size /= 2; |
| 1542 | } |
| 1543 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1544 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1545 | /* level 0 is always calculated with 1:1 split */ |
| 1546 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1547 | if (is_sprite) |
| 1548 | fifo_size *= 5; |
| 1549 | fifo_size /= 6; |
| 1550 | } else { |
| 1551 | fifo_size /= 2; |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1556 | 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] | 1557 | } |
| 1558 | |
| 1559 | /* Calculate the maximum cursor plane watermark */ |
| 1560 | 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] | 1561 | int level, |
| 1562 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1563 | { |
| 1564 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1565 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1566 | return 64; |
| 1567 | |
| 1568 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1569 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1570 | } |
| 1571 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1572 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1573 | int level, |
| 1574 | const struct intel_wm_config *config, |
| 1575 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1576 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1577 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1578 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1579 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1580 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1581 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1582 | } |
| 1583 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1584 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1585 | int level, |
| 1586 | struct ilk_wm_maximums *max) |
| 1587 | { |
| 1588 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1589 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1590 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1591 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1592 | } |
| 1593 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1594 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1595 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1596 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1597 | { |
| 1598 | bool ret; |
| 1599 | |
| 1600 | /* already determined to be invalid? */ |
| 1601 | if (!result->enable) |
| 1602 | return false; |
| 1603 | |
| 1604 | result->enable = result->pri_val <= max->pri && |
| 1605 | result->spr_val <= max->spr && |
| 1606 | result->cur_val <= max->cur; |
| 1607 | |
| 1608 | ret = result->enable; |
| 1609 | |
| 1610 | /* |
| 1611 | * HACK until we can pre-compute everything, |
| 1612 | * and thus fail gracefully if LP0 watermarks |
| 1613 | * are exceeded... |
| 1614 | */ |
| 1615 | if (level == 0 && !result->enable) { |
| 1616 | if (result->pri_val > max->pri) |
| 1617 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 1618 | level, result->pri_val, max->pri); |
| 1619 | if (result->spr_val > max->spr) |
| 1620 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 1621 | level, result->spr_val, max->spr); |
| 1622 | if (result->cur_val > max->cur) |
| 1623 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 1624 | level, result->cur_val, max->cur); |
| 1625 | |
| 1626 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 1627 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 1628 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 1629 | result->enable = true; |
| 1630 | } |
| 1631 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1632 | return ret; |
| 1633 | } |
| 1634 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1635 | 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] | 1636 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1637 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 1638 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1639 | { |
| 1640 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 1641 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 1642 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 1643 | |
| 1644 | /* WM1+ latency values stored in 0.5us units */ |
| 1645 | if (level > 0) { |
| 1646 | pri_latency *= 5; |
| 1647 | spr_latency *= 5; |
| 1648 | cur_latency *= 5; |
| 1649 | } |
| 1650 | |
| 1651 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 1652 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 1653 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 1654 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 1655 | result->enable = true; |
| 1656 | } |
| 1657 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1658 | static uint32_t |
| 1659 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1660 | { |
| 1661 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1662 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1663 | struct drm_display_mode *mode = &intel_crtc->config->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1664 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1665 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1666 | if (!intel_crtc_active(crtc)) |
| 1667 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1668 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1669 | /* The WM are computed with base on how long it takes to fill a single |
| 1670 | * row at the given clock rate, multiplied by 8. |
| 1671 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1672 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 1673 | mode->crtc_clock); |
| 1674 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1675 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1676 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1677 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 1678 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1679 | } |
| 1680 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1681 | 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] | 1682 | { |
| 1683 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1684 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1685 | if (IS_GEN9(dev)) { |
| 1686 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1687 | int ret, i; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1688 | int level, max_level = ilk_wm_max_level(dev); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1689 | |
| 1690 | /* read the first set of memory latencies[0:3] */ |
| 1691 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 1692 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1693 | ret = sandybridge_pcode_read(dev_priv, |
| 1694 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1695 | &val); |
| 1696 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1697 | |
| 1698 | if (ret) { |
| 1699 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1700 | return; |
| 1701 | } |
| 1702 | |
| 1703 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1704 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1705 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1706 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1707 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1708 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1709 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1710 | |
| 1711 | /* read the second set of memory latencies[4:7] */ |
| 1712 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 1713 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1714 | ret = sandybridge_pcode_read(dev_priv, |
| 1715 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1716 | &val); |
| 1717 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1718 | if (ret) { |
| 1719 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1720 | return; |
| 1721 | } |
| 1722 | |
| 1723 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1724 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1725 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1726 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1727 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1728 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1729 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1730 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1731 | /* |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 1732 | * WaWmMemoryReadLatency:skl |
| 1733 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1734 | * punit doesn't take into account the read latency so we need |
| 1735 | * to add 2us to the various latency levels we retrieve from |
| 1736 | * the punit. |
| 1737 | * - W0 is a bit special in that it's the only level that |
| 1738 | * can't be disabled if we want to have display working, so |
| 1739 | * we always add 2us there. |
| 1740 | * - For levels >=1, punit returns 0us latency when they are |
| 1741 | * disabled, so we respect that and don't add 2us then |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1742 | * |
| 1743 | * Additionally, if a level n (n > 1) has a 0us latency, all |
| 1744 | * levels m (m >= n) need to be disabled. We make sure to |
| 1745 | * sanitize the values out of the punit to satisfy this |
| 1746 | * requirement. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1747 | */ |
| 1748 | wm[0] += 2; |
| 1749 | for (level = 1; level <= max_level; level++) |
| 1750 | if (wm[level] != 0) |
| 1751 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1752 | else { |
| 1753 | for (i = level + 1; i <= max_level; i++) |
| 1754 | wm[i] = 0; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1755 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1756 | break; |
| 1757 | } |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1758 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1759 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 1760 | |
| 1761 | wm[0] = (sskpd >> 56) & 0xFF; |
| 1762 | if (wm[0] == 0) |
| 1763 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 1764 | wm[1] = (sskpd >> 4) & 0xFF; |
| 1765 | wm[2] = (sskpd >> 12) & 0xFF; |
| 1766 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 1767 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 1768 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 1769 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 1770 | |
| 1771 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 1772 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 1773 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 1774 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 1775 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1776 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 1777 | |
| 1778 | /* ILK primary LP0 latency is 700 ns */ |
| 1779 | wm[0] = 7; |
| 1780 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 1781 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1782 | } |
| 1783 | } |
| 1784 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1785 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1786 | { |
| 1787 | /* ILK sprite LP0 latency is 1300 ns */ |
| 1788 | if (INTEL_INFO(dev)->gen == 5) |
| 1789 | wm[0] = 13; |
| 1790 | } |
| 1791 | |
| 1792 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1793 | { |
| 1794 | /* ILK cursor LP0 latency is 1300 ns */ |
| 1795 | if (INTEL_INFO(dev)->gen == 5) |
| 1796 | wm[0] = 13; |
| 1797 | |
| 1798 | /* WaDoubleCursorLP3Latency:ivb */ |
| 1799 | if (IS_IVYBRIDGE(dev)) |
| 1800 | wm[3] *= 2; |
| 1801 | } |
| 1802 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 1803 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1804 | { |
| 1805 | /* how many WM levels are we expecting */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1806 | if (IS_GEN9(dev)) |
| 1807 | return 7; |
| 1808 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1809 | return 4; |
| 1810 | else if (INTEL_INFO(dev)->gen >= 6) |
| 1811 | return 3; |
| 1812 | else |
| 1813 | return 2; |
| 1814 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 1815 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1816 | static void intel_print_wm_latency(struct drm_device *dev, |
| 1817 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1818 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1819 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1820 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1821 | |
| 1822 | for (level = 0; level <= max_level; level++) { |
| 1823 | unsigned int latency = wm[level]; |
| 1824 | |
| 1825 | if (latency == 0) { |
| 1826 | DRM_ERROR("%s WM%d latency not provided\n", |
| 1827 | name, level); |
| 1828 | continue; |
| 1829 | } |
| 1830 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1831 | /* |
| 1832 | * - latencies are in us on gen9. |
| 1833 | * - before then, WM1+ latency values are in 0.5us units |
| 1834 | */ |
| 1835 | if (IS_GEN9(dev)) |
| 1836 | latency *= 10; |
| 1837 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1838 | latency *= 5; |
| 1839 | |
| 1840 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 1841 | name, level, wm[level], |
| 1842 | latency / 10, latency % 10); |
| 1843 | } |
| 1844 | } |
| 1845 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 1846 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 1847 | uint16_t wm[5], uint16_t min) |
| 1848 | { |
| 1849 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 1850 | |
| 1851 | if (wm[0] >= min) |
| 1852 | return false; |
| 1853 | |
| 1854 | wm[0] = max(wm[0], min); |
| 1855 | for (level = 1; level <= max_level; level++) |
| 1856 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 1857 | |
| 1858 | return true; |
| 1859 | } |
| 1860 | |
| 1861 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 1862 | { |
| 1863 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1864 | bool changed; |
| 1865 | |
| 1866 | /* |
| 1867 | * The BIOS provided WM memory latency values are often |
| 1868 | * inadequate for high resolution displays. Adjust them. |
| 1869 | */ |
| 1870 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 1871 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 1872 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 1873 | |
| 1874 | if (!changed) |
| 1875 | return; |
| 1876 | |
| 1877 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 1878 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 1879 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 1880 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 1881 | } |
| 1882 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 1883 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1884 | { |
| 1885 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1886 | |
| 1887 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 1888 | |
| 1889 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 1890 | sizeof(dev_priv->wm.pri_latency)); |
| 1891 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 1892 | sizeof(dev_priv->wm.pri_latency)); |
| 1893 | |
| 1894 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 1895 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1896 | |
| 1897 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 1898 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 1899 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 1900 | |
| 1901 | if (IS_GEN6(dev)) |
| 1902 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1903 | } |
| 1904 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1905 | static void skl_setup_wm_latency(struct drm_device *dev) |
| 1906 | { |
| 1907 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1908 | |
| 1909 | intel_read_wm_latency(dev, dev_priv->wm.skl_latency); |
| 1910 | intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency); |
| 1911 | } |
| 1912 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1913 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1914 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1915 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 1916 | struct drm_device *dev = crtc->dev; |
| 1917 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1918 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 1919 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1920 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1921 | if (!intel_crtc_active(crtc)) |
| 1922 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1923 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1924 | p->active = true; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1925 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1926 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
| 1927 | p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8; |
| 1928 | p->cur.bytes_per_pixel = 4; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1929 | p->pri.horiz_pixels = intel_crtc->config->pipe_src_w; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1930 | p->cur.horiz_pixels = intel_crtc->cursor_width; |
| 1931 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 1932 | p->pri.enabled = true; |
| 1933 | p->cur.enabled = true; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 1934 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 1935 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1936 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1937 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1938 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 1939 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1940 | break; |
| 1941 | } |
| 1942 | } |
| 1943 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1944 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1945 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 1946 | struct intel_wm_config *config) |
| 1947 | { |
| 1948 | struct intel_crtc *intel_crtc; |
| 1949 | |
| 1950 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 1951 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1952 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 1953 | |
| 1954 | if (!wm->pipe_enabled) |
| 1955 | continue; |
| 1956 | |
| 1957 | config->sprites_enabled |= wm->sprites_enabled; |
| 1958 | config->sprites_scaled |= wm->sprites_scaled; |
| 1959 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1963 | /* Compute new watermarks for the pipe */ |
| 1964 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1965 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1966 | struct intel_pipe_wm *pipe_wm) |
| 1967 | { |
| 1968 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1969 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1970 | int level, max_level = ilk_wm_max_level(dev); |
| 1971 | /* LP0 watermark maximums depend on this pipe alone */ |
| 1972 | struct intel_wm_config config = { |
| 1973 | .num_pipes_active = 1, |
| 1974 | .sprites_enabled = params->spr.enabled, |
| 1975 | .sprites_scaled = params->spr.scaled, |
| 1976 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1977 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1978 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1979 | pipe_wm->pipe_enabled = params->active; |
| 1980 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 1981 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 1982 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 1983 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 1984 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 1985 | max_level = 1; |
| 1986 | |
| 1987 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 1988 | if (params->spr.scaled) |
| 1989 | max_level = 0; |
| 1990 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1991 | 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] | 1992 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 1993 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 1994 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1995 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1996 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 1997 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 1998 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1999 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2000 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2001 | return false; |
| 2002 | |
| 2003 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2004 | |
| 2005 | for (level = 1; level <= max_level; level++) { |
| 2006 | struct intel_wm_level wm = {}; |
| 2007 | |
| 2008 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2009 | |
| 2010 | /* |
| 2011 | * Disable any watermark level that exceeds the |
| 2012 | * register maximums since such watermarks are |
| 2013 | * always invalid. |
| 2014 | */ |
| 2015 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2016 | break; |
| 2017 | |
| 2018 | pipe_wm->wm[level] = wm; |
| 2019 | } |
| 2020 | |
| 2021 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | /* |
| 2025 | * Merge the watermarks from all active pipes for a specific level. |
| 2026 | */ |
| 2027 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2028 | int level, |
| 2029 | struct intel_wm_level *ret_wm) |
| 2030 | { |
| 2031 | const struct intel_crtc *intel_crtc; |
| 2032 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2033 | ret_wm->enable = true; |
| 2034 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2035 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2036 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2037 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2038 | |
| 2039 | if (!active->pipe_enabled) |
| 2040 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2041 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2042 | /* |
| 2043 | * The watermark values may have been used in the past, |
| 2044 | * so we must maintain them in the registers for some |
| 2045 | * time even if the level is now disabled. |
| 2046 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2047 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2048 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2049 | |
| 2050 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2051 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2052 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2053 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2054 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | /* |
| 2058 | * Merge all low power watermarks for all active pipes. |
| 2059 | */ |
| 2060 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2061 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2062 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2063 | struct intel_pipe_wm *merged) |
| 2064 | { |
| 2065 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2066 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2067 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2068 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2069 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2070 | config->num_pipes_active > 1) |
| 2071 | return; |
| 2072 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2073 | /* ILK: FBC WM must be disabled always */ |
| 2074 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2075 | |
| 2076 | /* merge each WM1+ level */ |
| 2077 | for (level = 1; level <= max_level; level++) { |
| 2078 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2079 | |
| 2080 | ilk_merge_wm_level(dev, level, wm); |
| 2081 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2082 | if (level > last_enabled_level) |
| 2083 | wm->enable = false; |
| 2084 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2085 | /* make sure all following levels get disabled */ |
| 2086 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2087 | |
| 2088 | /* |
| 2089 | * The spec says it is preferred to disable |
| 2090 | * FBC WMs instead of disabling a WM level. |
| 2091 | */ |
| 2092 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2093 | if (wm->enable) |
| 2094 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2095 | wm->fbc_val = 0; |
| 2096 | } |
| 2097 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2098 | |
| 2099 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2100 | /* |
| 2101 | * FIXME this is racy. FBC might get enabled later. |
| 2102 | * What we should check here is whether FBC can be |
| 2103 | * enabled sometime later. |
| 2104 | */ |
| 2105 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2106 | for (level = 2; level <= max_level; level++) { |
| 2107 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2108 | |
| 2109 | wm->enable = false; |
| 2110 | } |
| 2111 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2112 | } |
| 2113 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2114 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2115 | { |
| 2116 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2117 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2118 | } |
| 2119 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2120 | /* The value we need to program into the WM_LPx latency field */ |
| 2121 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2122 | { |
| 2123 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2124 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2125 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2126 | return 2 * level; |
| 2127 | else |
| 2128 | return dev_priv->wm.pri_latency[level]; |
| 2129 | } |
| 2130 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2131 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2132 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2133 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2134 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2135 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2136 | struct intel_crtc *intel_crtc; |
| 2137 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2138 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2139 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2140 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2141 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2142 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2143 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2144 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2145 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2146 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2147 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2148 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2149 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2150 | /* |
| 2151 | * Maintain the watermark values even if the level is |
| 2152 | * disabled. Doing otherwise could cause underruns. |
| 2153 | */ |
| 2154 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2155 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2156 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2157 | r->cur_val; |
| 2158 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2159 | if (r->enable) |
| 2160 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2161 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2162 | if (INTEL_INFO(dev)->gen >= 8) |
| 2163 | results->wm_lp[wm_lp - 1] |= |
| 2164 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2165 | else |
| 2166 | results->wm_lp[wm_lp - 1] |= |
| 2167 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2168 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2169 | /* |
| 2170 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2171 | * level is disabled. Doing otherwise could cause underruns. |
| 2172 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2173 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2174 | WARN_ON(wm_lp != 1); |
| 2175 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2176 | } else |
| 2177 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2178 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2179 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2180 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2181 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2182 | enum pipe pipe = intel_crtc->pipe; |
| 2183 | const struct intel_wm_level *r = |
| 2184 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2185 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2186 | if (WARN_ON(!r->enable)) |
| 2187 | continue; |
| 2188 | |
| 2189 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2190 | |
| 2191 | results->wm_pipe[pipe] = |
| 2192 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2193 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2194 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2198 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2199 | * 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] | 2200 | 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] | 2201 | struct intel_pipe_wm *r1, |
| 2202 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2203 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2204 | int level, max_level = ilk_wm_max_level(dev); |
| 2205 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2206 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2207 | for (level = 1; level <= max_level; level++) { |
| 2208 | if (r1->wm[level].enable) |
| 2209 | level1 = level; |
| 2210 | if (r2->wm[level].enable) |
| 2211 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2212 | } |
| 2213 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2214 | if (level1 == level2) { |
| 2215 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2216 | return r2; |
| 2217 | else |
| 2218 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2219 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2220 | return r1; |
| 2221 | } else { |
| 2222 | return r2; |
| 2223 | } |
| 2224 | } |
| 2225 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2226 | /* dirty bits used to track which watermarks need changes */ |
| 2227 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2228 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2229 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2230 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2231 | #define WM_DIRTY_FBC (1 << 24) |
| 2232 | #define WM_DIRTY_DDB (1 << 25) |
| 2233 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2234 | 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] | 2235 | const struct ilk_wm_values *old, |
| 2236 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2237 | { |
| 2238 | unsigned int dirty = 0; |
| 2239 | enum pipe pipe; |
| 2240 | int wm_lp; |
| 2241 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2242 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2243 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2244 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2245 | /* Must disable LP1+ watermarks too */ |
| 2246 | dirty |= WM_DIRTY_LP_ALL; |
| 2247 | } |
| 2248 | |
| 2249 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2250 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2251 | /* Must disable LP1+ watermarks too */ |
| 2252 | dirty |= WM_DIRTY_LP_ALL; |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2257 | dirty |= WM_DIRTY_FBC; |
| 2258 | /* Must disable LP1+ watermarks too */ |
| 2259 | dirty |= WM_DIRTY_LP_ALL; |
| 2260 | } |
| 2261 | |
| 2262 | if (old->partitioning != new->partitioning) { |
| 2263 | dirty |= WM_DIRTY_DDB; |
| 2264 | /* Must disable LP1+ watermarks too */ |
| 2265 | dirty |= WM_DIRTY_LP_ALL; |
| 2266 | } |
| 2267 | |
| 2268 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2269 | if (dirty & WM_DIRTY_LP_ALL) |
| 2270 | return dirty; |
| 2271 | |
| 2272 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2273 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2274 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2275 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2276 | break; |
| 2277 | } |
| 2278 | |
| 2279 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2280 | for (; wm_lp <= 3; wm_lp++) |
| 2281 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2282 | |
| 2283 | return dirty; |
| 2284 | } |
| 2285 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2286 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2287 | unsigned int dirty) |
| 2288 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2289 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2290 | bool changed = false; |
| 2291 | |
| 2292 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2293 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2294 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2295 | changed = true; |
| 2296 | } |
| 2297 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2298 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2299 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2300 | changed = true; |
| 2301 | } |
| 2302 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2303 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2304 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2305 | changed = true; |
| 2306 | } |
| 2307 | |
| 2308 | /* |
| 2309 | * Don't touch WM1S_LP_EN here. |
| 2310 | * Doing so could cause underruns. |
| 2311 | */ |
| 2312 | |
| 2313 | return changed; |
| 2314 | } |
| 2315 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2316 | /* |
| 2317 | * The spec says we shouldn't write when we don't need, because every write |
| 2318 | * causes WMs to be re-evaluated, expending some power. |
| 2319 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2320 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2321 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2322 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2323 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2324 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2325 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2326 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2327 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2328 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2329 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2330 | return; |
| 2331 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2332 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2333 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2334 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2335 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2336 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2337 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2338 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2339 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2340 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2341 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2342 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2343 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2344 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2345 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2346 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2347 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2348 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2349 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2350 | val = I915_READ(WM_MISC); |
| 2351 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2352 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2353 | else |
| 2354 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2355 | I915_WRITE(WM_MISC, val); |
| 2356 | } else { |
| 2357 | val = I915_READ(DISP_ARB_CTL2); |
| 2358 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2359 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2360 | else |
| 2361 | val |= DISP_DATA_PARTITION_5_6; |
| 2362 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2363 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2364 | } |
| 2365 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2366 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2367 | val = I915_READ(DISP_ARB_CTL); |
| 2368 | if (results->enable_fbc_wm) |
| 2369 | val &= ~DISP_FBC_WM_DIS; |
| 2370 | else |
| 2371 | val |= DISP_FBC_WM_DIS; |
| 2372 | I915_WRITE(DISP_ARB_CTL, val); |
| 2373 | } |
| 2374 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2375 | if (dirty & WM_DIRTY_LP(1) && |
| 2376 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2377 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2378 | |
| 2379 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2380 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2381 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2382 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2383 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2384 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2385 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2386 | 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] | 2387 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2388 | 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] | 2389 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2390 | 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] | 2391 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2392 | |
| 2393 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2394 | } |
| 2395 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2396 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2397 | { |
| 2398 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2399 | |
| 2400 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2401 | } |
| 2402 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2403 | /* |
| 2404 | * On gen9, we need to allocate Display Data Buffer (DDB) portions to the |
| 2405 | * different active planes. |
| 2406 | */ |
| 2407 | |
| 2408 | #define SKL_DDB_SIZE 896 /* in blocks */ |
| 2409 | |
| 2410 | static void |
| 2411 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
| 2412 | struct drm_crtc *for_crtc, |
| 2413 | const struct intel_wm_config *config, |
| 2414 | const struct skl_pipe_wm_parameters *params, |
| 2415 | struct skl_ddb_entry *alloc /* out */) |
| 2416 | { |
| 2417 | struct drm_crtc *crtc; |
| 2418 | unsigned int pipe_size, ddb_size; |
| 2419 | int nth_active_pipe; |
| 2420 | |
| 2421 | if (!params->active) { |
| 2422 | alloc->start = 0; |
| 2423 | alloc->end = 0; |
| 2424 | return; |
| 2425 | } |
| 2426 | |
| 2427 | ddb_size = SKL_DDB_SIZE; |
| 2428 | |
| 2429 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 2430 | |
| 2431 | nth_active_pipe = 0; |
| 2432 | for_each_crtc(dev, crtc) { |
| 2433 | if (!intel_crtc_active(crtc)) |
| 2434 | continue; |
| 2435 | |
| 2436 | if (crtc == for_crtc) |
| 2437 | break; |
| 2438 | |
| 2439 | nth_active_pipe++; |
| 2440 | } |
| 2441 | |
| 2442 | pipe_size = ddb_size / config->num_pipes_active; |
| 2443 | alloc->start = nth_active_pipe * ddb_size / config->num_pipes_active; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2444 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | static unsigned int skl_cursor_allocation(const struct intel_wm_config *config) |
| 2448 | { |
| 2449 | if (config->num_pipes_active == 1) |
| 2450 | return 32; |
| 2451 | |
| 2452 | return 8; |
| 2453 | } |
| 2454 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2455 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 2456 | { |
| 2457 | entry->start = reg & 0x3ff; |
| 2458 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2459 | if (entry->end) |
| 2460 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 2463 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 2464 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2465 | { |
| 2466 | struct drm_device *dev = dev_priv->dev; |
| 2467 | enum pipe pipe; |
| 2468 | int plane; |
| 2469 | u32 val; |
| 2470 | |
| 2471 | for_each_pipe(dev_priv, pipe) { |
| 2472 | for_each_plane(pipe, plane) { |
| 2473 | val = I915_READ(PLANE_BUF_CFG(pipe, plane)); |
| 2474 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane], |
| 2475 | val); |
| 2476 | } |
| 2477 | |
| 2478 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 2479 | skl_ddb_entry_init_from_hw(&ddb->cursor[pipe], val); |
| 2480 | } |
| 2481 | } |
| 2482 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2483 | static unsigned int |
| 2484 | skl_plane_relative_data_rate(const struct intel_plane_wm_parameters *p) |
| 2485 | { |
| 2486 | return p->horiz_pixels * p->vert_pixels * p->bytes_per_pixel; |
| 2487 | } |
| 2488 | |
| 2489 | /* |
| 2490 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 2491 | * a 8192x4096@32bpp framebuffer: |
| 2492 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 2493 | */ |
| 2494 | static unsigned int |
| 2495 | skl_get_total_relative_data_rate(struct intel_crtc *intel_crtc, |
| 2496 | const struct skl_pipe_wm_parameters *params) |
| 2497 | { |
| 2498 | unsigned int total_data_rate = 0; |
| 2499 | int plane; |
| 2500 | |
| 2501 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2502 | const struct intel_plane_wm_parameters *p; |
| 2503 | |
| 2504 | p = ¶ms->plane[plane]; |
| 2505 | if (!p->enabled) |
| 2506 | continue; |
| 2507 | |
| 2508 | total_data_rate += skl_plane_relative_data_rate(p); |
| 2509 | } |
| 2510 | |
| 2511 | return total_data_rate; |
| 2512 | } |
| 2513 | |
| 2514 | static void |
| 2515 | skl_allocate_pipe_ddb(struct drm_crtc *crtc, |
| 2516 | const struct intel_wm_config *config, |
| 2517 | const struct skl_pipe_wm_parameters *params, |
| 2518 | struct skl_ddb_allocation *ddb /* out */) |
| 2519 | { |
| 2520 | struct drm_device *dev = crtc->dev; |
| 2521 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2522 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2523 | struct skl_ddb_entry *alloc = &ddb->pipe[pipe]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2524 | uint16_t alloc_size, start, cursor_blocks; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame^] | 2525 | uint16_t minimum[I915_MAX_PLANES]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2526 | unsigned int total_data_rate; |
| 2527 | int plane; |
| 2528 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2529 | skl_ddb_get_pipe_allocation_limits(dev, crtc, config, params, alloc); |
| 2530 | alloc_size = skl_ddb_entry_size(alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2531 | if (alloc_size == 0) { |
| 2532 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 2533 | memset(&ddb->cursor[pipe], 0, sizeof(ddb->cursor[pipe])); |
| 2534 | return; |
| 2535 | } |
| 2536 | |
| 2537 | cursor_blocks = skl_cursor_allocation(config); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2538 | ddb->cursor[pipe].start = alloc->end - cursor_blocks; |
| 2539 | ddb->cursor[pipe].end = alloc->end; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2540 | |
| 2541 | alloc_size -= cursor_blocks; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2542 | alloc->end -= cursor_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2543 | |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame^] | 2544 | /* 1. Allocate the mininum required blocks for each active plane */ |
| 2545 | for_each_plane(pipe, plane) { |
| 2546 | const struct intel_plane_wm_parameters *p; |
| 2547 | |
| 2548 | p = ¶ms->plane[plane]; |
| 2549 | if (!p->enabled) |
| 2550 | continue; |
| 2551 | |
| 2552 | minimum[plane] = 8; |
| 2553 | alloc_size -= minimum[plane]; |
| 2554 | } |
| 2555 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2556 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame^] | 2557 | * 2. Distribute the remaining space in proportion to the amount of |
| 2558 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2559 | * |
| 2560 | * FIXME: we may not allocate every single block here. |
| 2561 | */ |
| 2562 | total_data_rate = skl_get_total_relative_data_rate(intel_crtc, params); |
| 2563 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2564 | start = alloc->start; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2565 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2566 | const struct intel_plane_wm_parameters *p; |
| 2567 | unsigned int data_rate; |
| 2568 | uint16_t plane_blocks; |
| 2569 | |
| 2570 | p = ¶ms->plane[plane]; |
| 2571 | if (!p->enabled) |
| 2572 | continue; |
| 2573 | |
| 2574 | data_rate = skl_plane_relative_data_rate(p); |
| 2575 | |
| 2576 | /* |
| 2577 | * promote the expression to 64 bits to avoid overflowing, the |
| 2578 | * result is < available as data_rate / total_data_rate < 1 |
| 2579 | */ |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame^] | 2580 | plane_blocks = minimum[plane]; |
| 2581 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 2582 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2583 | |
| 2584 | ddb->plane[pipe][plane].start = start; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2585 | ddb->plane[pipe][plane].end = start + plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2586 | |
| 2587 | start += plane_blocks; |
| 2588 | } |
| 2589 | |
| 2590 | } |
| 2591 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2592 | 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] | 2593 | { |
| 2594 | /* TODO: Take into account the scalers once we support them */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2595 | return config->base.adjusted_mode.crtc_clock; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | /* |
| 2599 | * The max latency should be 257 (max the punit can code is 255 and we add 2us |
| 2600 | * for the read latency) and bytes_per_pixel should always be <= 8, so that |
| 2601 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 2602 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 2603 | */ |
| 2604 | static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel, |
| 2605 | uint32_t latency) |
| 2606 | { |
| 2607 | uint32_t wm_intermediate_val, ret; |
| 2608 | |
| 2609 | if (latency == 0) |
| 2610 | return UINT_MAX; |
| 2611 | |
| 2612 | wm_intermediate_val = latency * pixel_rate * bytes_per_pixel; |
| 2613 | ret = DIV_ROUND_UP(wm_intermediate_val, 1000); |
| 2614 | |
| 2615 | return ret; |
| 2616 | } |
| 2617 | |
| 2618 | static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
| 2619 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 2620 | uint32_t latency) |
| 2621 | { |
| 2622 | uint32_t ret, plane_bytes_per_line, wm_intermediate_val; |
| 2623 | |
| 2624 | if (latency == 0) |
| 2625 | return UINT_MAX; |
| 2626 | |
| 2627 | plane_bytes_per_line = horiz_pixels * bytes_per_pixel; |
| 2628 | wm_intermediate_val = latency * pixel_rate; |
| 2629 | ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) * |
| 2630 | plane_bytes_per_line; |
| 2631 | |
| 2632 | return ret; |
| 2633 | } |
| 2634 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2635 | static bool skl_ddb_allocation_changed(const struct skl_ddb_allocation *new_ddb, |
| 2636 | const struct intel_crtc *intel_crtc) |
| 2637 | { |
| 2638 | struct drm_device *dev = intel_crtc->base.dev; |
| 2639 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2640 | const struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 2641 | enum pipe pipe = intel_crtc->pipe; |
| 2642 | |
| 2643 | if (memcmp(new_ddb->plane[pipe], cur_ddb->plane[pipe], |
| 2644 | sizeof(new_ddb->plane[pipe]))) |
| 2645 | return true; |
| 2646 | |
| 2647 | if (memcmp(&new_ddb->cursor[pipe], &cur_ddb->cursor[pipe], |
| 2648 | sizeof(new_ddb->cursor[pipe]))) |
| 2649 | return true; |
| 2650 | |
| 2651 | return false; |
| 2652 | } |
| 2653 | |
| 2654 | static void skl_compute_wm_global_parameters(struct drm_device *dev, |
| 2655 | struct intel_wm_config *config) |
| 2656 | { |
| 2657 | struct drm_crtc *crtc; |
| 2658 | struct drm_plane *plane; |
| 2659 | |
| 2660 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 2661 | config->num_pipes_active += intel_crtc_active(crtc); |
| 2662 | |
| 2663 | /* FIXME: I don't think we need those two global parameters on SKL */ |
| 2664 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2665 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2666 | |
| 2667 | config->sprites_enabled |= intel_plane->wm.enabled; |
| 2668 | config->sprites_scaled |= intel_plane->wm.scaled; |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | static void skl_compute_wm_pipe_parameters(struct drm_crtc *crtc, |
| 2673 | struct skl_pipe_wm_parameters *p) |
| 2674 | { |
| 2675 | struct drm_device *dev = crtc->dev; |
| 2676 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2677 | enum pipe pipe = intel_crtc->pipe; |
| 2678 | struct drm_plane *plane; |
| 2679 | int i = 1; /* Index for sprite planes start */ |
| 2680 | |
| 2681 | p->active = intel_crtc_active(crtc); |
| 2682 | if (p->active) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2683 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
| 2684 | p->pixel_rate = skl_pipe_pixel_rate(intel_crtc->config); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2685 | |
| 2686 | /* |
| 2687 | * For now, assume primary and cursor planes are always enabled. |
| 2688 | */ |
| 2689 | p->plane[0].enabled = true; |
| 2690 | p->plane[0].bytes_per_pixel = |
| 2691 | crtc->primary->fb->bits_per_pixel / 8; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2692 | p->plane[0].horiz_pixels = intel_crtc->config->pipe_src_w; |
| 2693 | p->plane[0].vert_pixels = intel_crtc->config->pipe_src_h; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2694 | |
| 2695 | p->cursor.enabled = true; |
| 2696 | p->cursor.bytes_per_pixel = 4; |
| 2697 | p->cursor.horiz_pixels = intel_crtc->cursor_width ? |
| 2698 | intel_crtc->cursor_width : 64; |
| 2699 | } |
| 2700 | |
| 2701 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2702 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2703 | |
Sonika Jindal | a712f8e | 2014-12-09 10:59:15 +0530 | [diff] [blame] | 2704 | if (intel_plane->pipe == pipe && |
| 2705 | plane->type == DRM_PLANE_TYPE_OVERLAY) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2706 | p->plane[i++] = intel_plane->wm; |
| 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | static bool skl_compute_plane_wm(struct skl_pipe_wm_parameters *p, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2711 | struct intel_plane_wm_parameters *p_params, |
| 2712 | uint16_t ddb_allocation, |
| 2713 | uint32_t mem_value, |
| 2714 | uint16_t *out_blocks, /* out */ |
| 2715 | uint8_t *out_lines /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2716 | { |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2717 | uint32_t method1, method2, plane_bytes_per_line, res_blocks, res_lines; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2718 | uint32_t result_bytes; |
| 2719 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2720 | if (mem_value == 0 || !p->active || !p_params->enabled) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2721 | return false; |
| 2722 | |
| 2723 | method1 = skl_wm_method1(p->pixel_rate, |
| 2724 | p_params->bytes_per_pixel, |
| 2725 | mem_value); |
| 2726 | method2 = skl_wm_method2(p->pixel_rate, |
| 2727 | p->pipe_htotal, |
| 2728 | p_params->horiz_pixels, |
| 2729 | p_params->bytes_per_pixel, |
| 2730 | mem_value); |
| 2731 | |
| 2732 | plane_bytes_per_line = p_params->horiz_pixels * |
| 2733 | p_params->bytes_per_pixel; |
| 2734 | |
| 2735 | /* For now xtile and linear */ |
Damien Lespiau | 21fca25 | 2014-11-04 17:06:54 +0000 | [diff] [blame] | 2736 | if (((ddb_allocation * 512) / plane_bytes_per_line) >= 1) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2737 | result_bytes = min(method1, method2); |
| 2738 | else |
| 2739 | result_bytes = method1; |
| 2740 | |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2741 | res_blocks = DIV_ROUND_UP(result_bytes, 512) + 1; |
| 2742 | res_lines = DIV_ROUND_UP(result_bytes, plane_bytes_per_line); |
| 2743 | |
| 2744 | if (res_blocks > ddb_allocation || res_lines > 31) |
| 2745 | return false; |
| 2746 | |
| 2747 | *out_blocks = res_blocks; |
| 2748 | *out_lines = res_lines; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2749 | |
| 2750 | return true; |
| 2751 | } |
| 2752 | |
| 2753 | static void skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 2754 | struct skl_ddb_allocation *ddb, |
| 2755 | struct skl_pipe_wm_parameters *p, |
| 2756 | enum pipe pipe, |
| 2757 | int level, |
| 2758 | int num_planes, |
| 2759 | struct skl_wm_level *result) |
| 2760 | { |
| 2761 | uint16_t latency = dev_priv->wm.skl_latency[level]; |
| 2762 | uint16_t ddb_blocks; |
| 2763 | int i; |
| 2764 | |
| 2765 | for (i = 0; i < num_planes; i++) { |
| 2766 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]); |
| 2767 | |
| 2768 | result->plane_en[i] = skl_compute_plane_wm(p, &p->plane[i], |
| 2769 | ddb_blocks, |
| 2770 | latency, |
| 2771 | &result->plane_res_b[i], |
| 2772 | &result->plane_res_l[i]); |
| 2773 | } |
| 2774 | |
| 2775 | ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]); |
| 2776 | result->cursor_en = skl_compute_plane_wm(p, &p->cursor, ddb_blocks, |
| 2777 | latency, &result->cursor_res_b, |
| 2778 | &result->cursor_res_l); |
| 2779 | } |
| 2780 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2781 | static uint32_t |
| 2782 | skl_compute_linetime_wm(struct drm_crtc *crtc, struct skl_pipe_wm_parameters *p) |
| 2783 | { |
| 2784 | if (!intel_crtc_active(crtc)) |
| 2785 | return 0; |
| 2786 | |
| 2787 | return DIV_ROUND_UP(8 * p->pipe_htotal * 1000, p->pixel_rate); |
| 2788 | |
| 2789 | } |
| 2790 | |
| 2791 | static void skl_compute_transition_wm(struct drm_crtc *crtc, |
| 2792 | struct skl_pipe_wm_parameters *params, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2793 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2794 | { |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2795 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2796 | int i; |
| 2797 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2798 | if (!params->active) |
| 2799 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2800 | |
| 2801 | /* Until we know more, just disable transition WMs */ |
| 2802 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 2803 | trans_wm->plane_en[i] = false; |
| 2804 | trans_wm->cursor_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2807 | static void skl_compute_pipe_wm(struct drm_crtc *crtc, |
| 2808 | struct skl_ddb_allocation *ddb, |
| 2809 | struct skl_pipe_wm_parameters *params, |
| 2810 | struct skl_pipe_wm *pipe_wm) |
| 2811 | { |
| 2812 | struct drm_device *dev = crtc->dev; |
| 2813 | const struct drm_i915_private *dev_priv = dev->dev_private; |
| 2814 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2815 | int level, max_level = ilk_wm_max_level(dev); |
| 2816 | |
| 2817 | for (level = 0; level <= max_level; level++) { |
| 2818 | skl_compute_wm_level(dev_priv, ddb, params, intel_crtc->pipe, |
| 2819 | level, intel_num_planes(intel_crtc), |
| 2820 | &pipe_wm->wm[level]); |
| 2821 | } |
| 2822 | pipe_wm->linetime = skl_compute_linetime_wm(crtc, params); |
| 2823 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2824 | skl_compute_transition_wm(crtc, params, &pipe_wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | static void skl_compute_wm_results(struct drm_device *dev, |
| 2828 | struct skl_pipe_wm_parameters *p, |
| 2829 | struct skl_pipe_wm *p_wm, |
| 2830 | struct skl_wm_values *r, |
| 2831 | struct intel_crtc *intel_crtc) |
| 2832 | { |
| 2833 | int level, max_level = ilk_wm_max_level(dev); |
| 2834 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2835 | uint32_t temp; |
| 2836 | int i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2837 | |
| 2838 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2839 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 2840 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2841 | |
| 2842 | temp |= p_wm->wm[level].plane_res_l[i] << |
| 2843 | PLANE_WM_LINES_SHIFT; |
| 2844 | temp |= p_wm->wm[level].plane_res_b[i]; |
| 2845 | if (p_wm->wm[level].plane_en[i]) |
| 2846 | temp |= PLANE_WM_EN; |
| 2847 | |
| 2848 | r->plane[pipe][i][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2852 | |
| 2853 | temp |= p_wm->wm[level].cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 2854 | temp |= p_wm->wm[level].cursor_res_b; |
| 2855 | |
| 2856 | if (p_wm->wm[level].cursor_en) |
| 2857 | temp |= PLANE_WM_EN; |
| 2858 | |
| 2859 | r->cursor[pipe][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2860 | |
| 2861 | } |
| 2862 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2863 | /* transition WMs */ |
| 2864 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 2865 | temp = 0; |
| 2866 | temp |= p_wm->trans_wm.plane_res_l[i] << PLANE_WM_LINES_SHIFT; |
| 2867 | temp |= p_wm->trans_wm.plane_res_b[i]; |
| 2868 | if (p_wm->trans_wm.plane_en[i]) |
| 2869 | temp |= PLANE_WM_EN; |
| 2870 | |
| 2871 | r->plane_trans[pipe][i] = temp; |
| 2872 | } |
| 2873 | |
| 2874 | temp = 0; |
| 2875 | temp |= p_wm->trans_wm.cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 2876 | temp |= p_wm->trans_wm.cursor_res_b; |
| 2877 | if (p_wm->trans_wm.cursor_en) |
| 2878 | temp |= PLANE_WM_EN; |
| 2879 | |
| 2880 | r->cursor_trans[pipe] = temp; |
| 2881 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2882 | r->wm_linetime[pipe] = p_wm->linetime; |
| 2883 | } |
| 2884 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2885 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, uint32_t reg, |
| 2886 | const struct skl_ddb_entry *entry) |
| 2887 | { |
| 2888 | if (entry->end) |
| 2889 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 2890 | else |
| 2891 | I915_WRITE(reg, 0); |
| 2892 | } |
| 2893 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2894 | static void skl_write_wm_values(struct drm_i915_private *dev_priv, |
| 2895 | const struct skl_wm_values *new) |
| 2896 | { |
| 2897 | struct drm_device *dev = dev_priv->dev; |
| 2898 | struct intel_crtc *crtc; |
| 2899 | |
| 2900 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
| 2901 | int i, level, max_level = ilk_wm_max_level(dev); |
| 2902 | enum pipe pipe = crtc->pipe; |
| 2903 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 2904 | if (!new->dirty[pipe]) |
| 2905 | continue; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2906 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 2907 | I915_WRITE(PIPE_WM_LINETIME(pipe), new->wm_linetime[pipe]); |
| 2908 | |
| 2909 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2910 | for (i = 0; i < intel_num_planes(crtc); i++) |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 2911 | I915_WRITE(PLANE_WM(pipe, i, level), |
| 2912 | new->plane[pipe][i][level]); |
| 2913 | I915_WRITE(CUR_WM(pipe, level), |
| 2914 | new->cursor[pipe][level]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2915 | } |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 2916 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 2917 | I915_WRITE(PLANE_WM_TRANS(pipe, i), |
| 2918 | new->plane_trans[pipe][i]); |
| 2919 | I915_WRITE(CUR_WM_TRANS(pipe), new->cursor_trans[pipe]); |
| 2920 | |
| 2921 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 2922 | skl_ddb_entry_write(dev_priv, |
| 2923 | PLANE_BUF_CFG(pipe, i), |
| 2924 | &new->ddb.plane[pipe][i]); |
| 2925 | |
| 2926 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
| 2927 | &new->ddb.cursor[pipe]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2928 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 2931 | /* |
| 2932 | * When setting up a new DDB allocation arrangement, we need to correctly |
| 2933 | * sequence the times at which the new allocations for the pipes are taken into |
| 2934 | * account or we'll have pipes fetching from space previously allocated to |
| 2935 | * another pipe. |
| 2936 | * |
| 2937 | * Roughly the sequence looks like: |
| 2938 | * 1. re-allocate the pipe(s) with the allocation being reduced and not |
| 2939 | * overlapping with a previous light-up pipe (another way to put it is: |
| 2940 | * pipes with their new allocation strickly included into their old ones). |
| 2941 | * 2. re-allocate the other pipes that get their allocation reduced |
| 2942 | * 3. allocate the pipes having their allocation increased |
| 2943 | * |
| 2944 | * Steps 1. and 2. are here to take care of the following case: |
| 2945 | * - Initially DDB looks like this: |
| 2946 | * | B | C | |
| 2947 | * - enable pipe A. |
| 2948 | * - pipe B has a reduced DDB allocation that overlaps with the old pipe C |
| 2949 | * allocation |
| 2950 | * | A | B | C | |
| 2951 | * |
| 2952 | * We need to sequence the re-allocation: C, B, A (and not B, C, A). |
| 2953 | */ |
| 2954 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 2955 | static void |
| 2956 | 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] | 2957 | { |
| 2958 | struct drm_device *dev = dev_priv->dev; |
| 2959 | int plane; |
| 2960 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 2961 | DRM_DEBUG_KMS("flush pipe %c (pass %d)\n", pipe_name(pipe), pass); |
| 2962 | |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 2963 | for_each_plane(pipe, plane) { |
| 2964 | I915_WRITE(PLANE_SURF(pipe, plane), |
| 2965 | I915_READ(PLANE_SURF(pipe, plane))); |
| 2966 | } |
| 2967 | I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe))); |
| 2968 | } |
| 2969 | |
| 2970 | static bool |
| 2971 | skl_ddb_allocation_included(const struct skl_ddb_allocation *old, |
| 2972 | const struct skl_ddb_allocation *new, |
| 2973 | enum pipe pipe) |
| 2974 | { |
| 2975 | uint16_t old_size, new_size; |
| 2976 | |
| 2977 | old_size = skl_ddb_entry_size(&old->pipe[pipe]); |
| 2978 | new_size = skl_ddb_entry_size(&new->pipe[pipe]); |
| 2979 | |
| 2980 | return old_size != new_size && |
| 2981 | new->pipe[pipe].start >= old->pipe[pipe].start && |
| 2982 | new->pipe[pipe].end <= old->pipe[pipe].end; |
| 2983 | } |
| 2984 | |
| 2985 | static void skl_flush_wm_values(struct drm_i915_private *dev_priv, |
| 2986 | struct skl_wm_values *new_values) |
| 2987 | { |
| 2988 | struct drm_device *dev = dev_priv->dev; |
| 2989 | struct skl_ddb_allocation *cur_ddb, *new_ddb; |
| 2990 | bool reallocated[I915_MAX_PIPES] = {false, false, false}; |
| 2991 | struct intel_crtc *crtc; |
| 2992 | enum pipe pipe; |
| 2993 | |
| 2994 | new_ddb = &new_values->ddb; |
| 2995 | cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 2996 | |
| 2997 | /* |
| 2998 | * First pass: flush the pipes with the new allocation contained into |
| 2999 | * the old space. |
| 3000 | * |
| 3001 | * We'll wait for the vblank on those pipes to ensure we can safely |
| 3002 | * re-allocate the freed space without this pipe fetching from it. |
| 3003 | */ |
| 3004 | for_each_intel_crtc(dev, crtc) { |
| 3005 | if (!crtc->active) |
| 3006 | continue; |
| 3007 | |
| 3008 | pipe = crtc->pipe; |
| 3009 | |
| 3010 | if (!skl_ddb_allocation_included(cur_ddb, new_ddb, pipe)) |
| 3011 | continue; |
| 3012 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3013 | skl_wm_flush_pipe(dev_priv, pipe, 1); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3014 | intel_wait_for_vblank(dev, pipe); |
| 3015 | |
| 3016 | reallocated[pipe] = true; |
| 3017 | } |
| 3018 | |
| 3019 | |
| 3020 | /* |
| 3021 | * Second pass: flush the pipes that are having their allocation |
| 3022 | * reduced, but overlapping with a previous allocation. |
| 3023 | * |
| 3024 | * Here as well we need to wait for the vblank to make sure the freed |
| 3025 | * space is not used anymore. |
| 3026 | */ |
| 3027 | for_each_intel_crtc(dev, crtc) { |
| 3028 | if (!crtc->active) |
| 3029 | continue; |
| 3030 | |
| 3031 | pipe = crtc->pipe; |
| 3032 | |
| 3033 | if (reallocated[pipe]) |
| 3034 | continue; |
| 3035 | |
| 3036 | if (skl_ddb_entry_size(&new_ddb->pipe[pipe]) < |
| 3037 | skl_ddb_entry_size(&cur_ddb->pipe[pipe])) { |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3038 | skl_wm_flush_pipe(dev_priv, pipe, 2); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3039 | intel_wait_for_vblank(dev, pipe); |
Sonika Jindal | d9d8e6b | 2014-12-11 17:58:15 +0530 | [diff] [blame] | 3040 | reallocated[pipe] = true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3041 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | /* |
| 3045 | * Third pass: flush the pipes that got more space allocated. |
| 3046 | * |
| 3047 | * We don't need to actively wait for the update here, next vblank |
| 3048 | * will just get more DDB space with the correct WM values. |
| 3049 | */ |
| 3050 | for_each_intel_crtc(dev, crtc) { |
| 3051 | if (!crtc->active) |
| 3052 | continue; |
| 3053 | |
| 3054 | pipe = crtc->pipe; |
| 3055 | |
| 3056 | /* |
| 3057 | * At this point, only the pipes more space than before are |
| 3058 | * left to re-allocate. |
| 3059 | */ |
| 3060 | if (reallocated[pipe]) |
| 3061 | continue; |
| 3062 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3063 | skl_wm_flush_pipe(dev_priv, pipe, 3); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3064 | } |
| 3065 | } |
| 3066 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3067 | static bool skl_update_pipe_wm(struct drm_crtc *crtc, |
| 3068 | struct skl_pipe_wm_parameters *params, |
| 3069 | struct intel_wm_config *config, |
| 3070 | struct skl_ddb_allocation *ddb, /* out */ |
| 3071 | struct skl_pipe_wm *pipe_wm /* out */) |
| 3072 | { |
| 3073 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3074 | |
| 3075 | skl_compute_wm_pipe_parameters(crtc, params); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3076 | skl_allocate_pipe_ddb(crtc, config, params, ddb); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3077 | skl_compute_pipe_wm(crtc, ddb, params, pipe_wm); |
| 3078 | |
| 3079 | if (!memcmp(&intel_crtc->wm.skl_active, pipe_wm, sizeof(*pipe_wm))) |
| 3080 | return false; |
| 3081 | |
| 3082 | intel_crtc->wm.skl_active = *pipe_wm; |
| 3083 | return true; |
| 3084 | } |
| 3085 | |
| 3086 | static void skl_update_other_pipe_wm(struct drm_device *dev, |
| 3087 | struct drm_crtc *crtc, |
| 3088 | struct intel_wm_config *config, |
| 3089 | struct skl_wm_values *r) |
| 3090 | { |
| 3091 | struct intel_crtc *intel_crtc; |
| 3092 | struct intel_crtc *this_crtc = to_intel_crtc(crtc); |
| 3093 | |
| 3094 | /* |
| 3095 | * If the WM update hasn't changed the allocation for this_crtc (the |
| 3096 | * crtc we are currently computing the new WM values for), other |
| 3097 | * enabled crtcs will keep the same allocation and we don't need to |
| 3098 | * recompute anything for them. |
| 3099 | */ |
| 3100 | if (!skl_ddb_allocation_changed(&r->ddb, this_crtc)) |
| 3101 | return; |
| 3102 | |
| 3103 | /* |
| 3104 | * Otherwise, because of this_crtc being freshly enabled/disabled, the |
| 3105 | * other active pipes need new DDB allocation and WM values. |
| 3106 | */ |
| 3107 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 3108 | base.head) { |
| 3109 | struct skl_pipe_wm_parameters params = {}; |
| 3110 | struct skl_pipe_wm pipe_wm = {}; |
| 3111 | bool wm_changed; |
| 3112 | |
| 3113 | if (this_crtc->pipe == intel_crtc->pipe) |
| 3114 | continue; |
| 3115 | |
| 3116 | if (!intel_crtc->active) |
| 3117 | continue; |
| 3118 | |
| 3119 | wm_changed = skl_update_pipe_wm(&intel_crtc->base, |
| 3120 | ¶ms, config, |
| 3121 | &r->ddb, &pipe_wm); |
| 3122 | |
| 3123 | /* |
| 3124 | * If we end up re-computing the other pipe WM values, it's |
| 3125 | * because it was really needed, so we expect the WM values to |
| 3126 | * be different. |
| 3127 | */ |
| 3128 | WARN_ON(!wm_changed); |
| 3129 | |
| 3130 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, r, intel_crtc); |
| 3131 | r->dirty[intel_crtc->pipe] = true; |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | static void skl_update_wm(struct drm_crtc *crtc) |
| 3136 | { |
| 3137 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3138 | struct drm_device *dev = crtc->dev; |
| 3139 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3140 | struct skl_pipe_wm_parameters params = {}; |
| 3141 | struct skl_wm_values *results = &dev_priv->wm.skl_results; |
| 3142 | struct skl_pipe_wm pipe_wm = {}; |
| 3143 | struct intel_wm_config config = {}; |
| 3144 | |
| 3145 | memset(results, 0, sizeof(*results)); |
| 3146 | |
| 3147 | skl_compute_wm_global_parameters(dev, &config); |
| 3148 | |
| 3149 | if (!skl_update_pipe_wm(crtc, ¶ms, &config, |
| 3150 | &results->ddb, &pipe_wm)) |
| 3151 | return; |
| 3152 | |
| 3153 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, results, intel_crtc); |
| 3154 | results->dirty[intel_crtc->pipe] = true; |
| 3155 | |
| 3156 | skl_update_other_pipe_wm(dev, crtc, &config, results); |
| 3157 | skl_write_wm_values(dev_priv, results); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3158 | skl_flush_wm_values(dev_priv, results); |
Damien Lespiau | 53b0deb | 2014-11-04 17:06:48 +0000 | [diff] [blame] | 3159 | |
| 3160 | /* store the new configuration */ |
| 3161 | dev_priv->wm.skl_hw = *results; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | static void |
| 3165 | skl_update_sprite_wm(struct drm_plane *plane, struct drm_crtc *crtc, |
| 3166 | uint32_t sprite_width, uint32_t sprite_height, |
| 3167 | int pixel_size, bool enabled, bool scaled) |
| 3168 | { |
| 3169 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 3170 | |
| 3171 | intel_plane->wm.enabled = enabled; |
| 3172 | intel_plane->wm.scaled = scaled; |
| 3173 | intel_plane->wm.horiz_pixels = sprite_width; |
| 3174 | intel_plane->wm.vert_pixels = sprite_height; |
| 3175 | intel_plane->wm.bytes_per_pixel = pixel_size; |
| 3176 | |
| 3177 | skl_update_wm(crtc); |
| 3178 | } |
| 3179 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3180 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3181 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3182 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3183 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3184 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3185 | struct ilk_wm_maximums max; |
| 3186 | struct ilk_pipe_wm_parameters params = {}; |
| 3187 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3188 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3189 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3190 | 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] | 3191 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3192 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3193 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3194 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3195 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 3196 | |
| 3197 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 3198 | return; |
| 3199 | |
| 3200 | intel_crtc->wm.active = pipe_wm; |
| 3201 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3202 | ilk_compute_wm_config(dev, &config); |
| 3203 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3204 | 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] | 3205 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3206 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3207 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 3208 | if (INTEL_INFO(dev)->gen >= 7 && |
| 3209 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3210 | 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] | 3211 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3212 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3213 | 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] | 3214 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3215 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3216 | } |
| 3217 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3218 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3219 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3220 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3221 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3222 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3223 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3224 | } |
| 3225 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3226 | static void |
| 3227 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 3228 | struct drm_crtc *crtc, |
| 3229 | uint32_t sprite_width, uint32_t sprite_height, |
| 3230 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3231 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3232 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3233 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3234 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3235 | intel_plane->wm.enabled = enabled; |
| 3236 | intel_plane->wm.scaled = scaled; |
| 3237 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3238 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3239 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3240 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3241 | /* |
| 3242 | * IVB workaround: must disable low power watermarks for at least |
| 3243 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 3244 | * when scaling is disabled. |
| 3245 | * |
| 3246 | * WaCxSRDisabledForSpriteScaling:ivb |
| 3247 | */ |
| 3248 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 3249 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 3250 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3251 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3252 | } |
| 3253 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3254 | static void skl_pipe_wm_active_state(uint32_t val, |
| 3255 | struct skl_pipe_wm *active, |
| 3256 | bool is_transwm, |
| 3257 | bool is_cursor, |
| 3258 | int i, |
| 3259 | int level) |
| 3260 | { |
| 3261 | bool is_enabled = (val & PLANE_WM_EN) != 0; |
| 3262 | |
| 3263 | if (!is_transwm) { |
| 3264 | if (!is_cursor) { |
| 3265 | active->wm[level].plane_en[i] = is_enabled; |
| 3266 | active->wm[level].plane_res_b[i] = |
| 3267 | val & PLANE_WM_BLOCKS_MASK; |
| 3268 | active->wm[level].plane_res_l[i] = |
| 3269 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3270 | PLANE_WM_LINES_MASK; |
| 3271 | } else { |
| 3272 | active->wm[level].cursor_en = is_enabled; |
| 3273 | active->wm[level].cursor_res_b = |
| 3274 | val & PLANE_WM_BLOCKS_MASK; |
| 3275 | active->wm[level].cursor_res_l = |
| 3276 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3277 | PLANE_WM_LINES_MASK; |
| 3278 | } |
| 3279 | } else { |
| 3280 | if (!is_cursor) { |
| 3281 | active->trans_wm.plane_en[i] = is_enabled; |
| 3282 | active->trans_wm.plane_res_b[i] = |
| 3283 | val & PLANE_WM_BLOCKS_MASK; |
| 3284 | active->trans_wm.plane_res_l[i] = |
| 3285 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3286 | PLANE_WM_LINES_MASK; |
| 3287 | } else { |
| 3288 | active->trans_wm.cursor_en = is_enabled; |
| 3289 | active->trans_wm.cursor_res_b = |
| 3290 | val & PLANE_WM_BLOCKS_MASK; |
| 3291 | active->trans_wm.cursor_res_l = |
| 3292 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3293 | PLANE_WM_LINES_MASK; |
| 3294 | } |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3299 | { |
| 3300 | struct drm_device *dev = crtc->dev; |
| 3301 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3302 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
| 3303 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3304 | struct skl_pipe_wm *active = &intel_crtc->wm.skl_active; |
| 3305 | enum pipe pipe = intel_crtc->pipe; |
| 3306 | int level, i, max_level; |
| 3307 | uint32_t temp; |
| 3308 | |
| 3309 | max_level = ilk_wm_max_level(dev); |
| 3310 | |
| 3311 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
| 3312 | |
| 3313 | for (level = 0; level <= max_level; level++) { |
| 3314 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3315 | hw->plane[pipe][i][level] = |
| 3316 | I915_READ(PLANE_WM(pipe, i, level)); |
| 3317 | hw->cursor[pipe][level] = I915_READ(CUR_WM(pipe, level)); |
| 3318 | } |
| 3319 | |
| 3320 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3321 | hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i)); |
| 3322 | hw->cursor_trans[pipe] = I915_READ(CUR_WM_TRANS(pipe)); |
| 3323 | |
| 3324 | if (!intel_crtc_active(crtc)) |
| 3325 | return; |
| 3326 | |
| 3327 | hw->dirty[pipe] = true; |
| 3328 | |
| 3329 | active->linetime = hw->wm_linetime[pipe]; |
| 3330 | |
| 3331 | for (level = 0; level <= max_level; level++) { |
| 3332 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3333 | temp = hw->plane[pipe][i][level]; |
| 3334 | skl_pipe_wm_active_state(temp, active, false, |
| 3335 | false, i, level); |
| 3336 | } |
| 3337 | temp = hw->cursor[pipe][level]; |
| 3338 | skl_pipe_wm_active_state(temp, active, false, true, i, level); |
| 3339 | } |
| 3340 | |
| 3341 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3342 | temp = hw->plane_trans[pipe][i]; |
| 3343 | skl_pipe_wm_active_state(temp, active, true, false, i, 0); |
| 3344 | } |
| 3345 | |
| 3346 | temp = hw->cursor_trans[pipe]; |
| 3347 | skl_pipe_wm_active_state(temp, active, true, true, i, 0); |
| 3348 | } |
| 3349 | |
| 3350 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 3351 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3352 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3353 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3354 | struct drm_crtc *crtc; |
| 3355 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3356 | skl_ddb_get_hw_state(dev_priv, ddb); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3357 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3358 | skl_pipe_wm_get_hw_state(crtc); |
| 3359 | } |
| 3360 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3361 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3362 | { |
| 3363 | struct drm_device *dev = crtc->dev; |
| 3364 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3365 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3366 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3367 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 3368 | enum pipe pipe = intel_crtc->pipe; |
| 3369 | static const unsigned int wm0_pipe_reg[] = { |
| 3370 | [PIPE_A] = WM0_PIPEA_ILK, |
| 3371 | [PIPE_B] = WM0_PIPEB_ILK, |
| 3372 | [PIPE_C] = WM0_PIPEC_IVB, |
| 3373 | }; |
| 3374 | |
| 3375 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3376 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 3377 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3378 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3379 | active->pipe_enabled = intel_crtc_active(crtc); |
| 3380 | |
| 3381 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3382 | u32 tmp = hw->wm_pipe[pipe]; |
| 3383 | |
| 3384 | /* |
| 3385 | * For active pipes LP0 watermark is marked as |
| 3386 | * enabled, and LP1+ watermaks as disabled since |
| 3387 | * we can't really reverse compute them in case |
| 3388 | * multiple pipes are active. |
| 3389 | */ |
| 3390 | active->wm[0].enable = true; |
| 3391 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 3392 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 3393 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 3394 | active->linetime = hw->wm_linetime[pipe]; |
| 3395 | } else { |
| 3396 | int level, max_level = ilk_wm_max_level(dev); |
| 3397 | |
| 3398 | /* |
| 3399 | * For inactive pipes, all watermark levels |
| 3400 | * should be marked as enabled but zeroed, |
| 3401 | * which is what we'd compute them to. |
| 3402 | */ |
| 3403 | for (level = 0; level <= max_level; level++) |
| 3404 | active->wm[level].enable = true; |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 3409 | { |
| 3410 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3411 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3412 | struct drm_crtc *crtc; |
| 3413 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3414 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3415 | ilk_pipe_wm_get_hw_state(crtc); |
| 3416 | |
| 3417 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 3418 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 3419 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 3420 | |
| 3421 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 3422 | if (INTEL_INFO(dev)->gen >= 7) { |
| 3423 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 3424 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 3425 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3426 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3427 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3428 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 3429 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 3430 | else if (IS_IVYBRIDGE(dev)) |
| 3431 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 3432 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3433 | |
| 3434 | hw->enable_fbc_wm = |
| 3435 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3436 | } |
| 3437 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3438 | /** |
| 3439 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3440 | * |
| 3441 | * Calculate watermark values for the various WM regs based on current mode |
| 3442 | * and plane configuration. |
| 3443 | * |
| 3444 | * There are several cases to deal with here: |
| 3445 | * - normal (i.e. non-self-refresh) |
| 3446 | * - self-refresh (SR) mode |
| 3447 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3448 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3449 | * lines), so need to account for TLB latency |
| 3450 | * |
| 3451 | * The normal calculation is: |
| 3452 | * watermark = dotclock * bytes per pixel * latency |
| 3453 | * where latency is platform & configuration dependent (we assume pessimal |
| 3454 | * values here). |
| 3455 | * |
| 3456 | * The SR calculation is: |
| 3457 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3458 | * bytes per pixel |
| 3459 | * where |
| 3460 | * line time = htotal / dotclock |
| 3461 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3462 | * and latency is assumed to be high, as above. |
| 3463 | * |
| 3464 | * The final value programmed to the register should always be rounded up, |
| 3465 | * and include an extra 2 entries to account for clock crossings. |
| 3466 | * |
| 3467 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3468 | * to set the non-SR watermarks to 8. |
| 3469 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3470 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3471 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3472 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3473 | |
| 3474 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3475 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3476 | } |
| 3477 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3478 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3479 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3480 | uint32_t sprite_width, |
| 3481 | uint32_t sprite_height, |
| 3482 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3483 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3484 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3485 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3486 | |
| 3487 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3488 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3489 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3490 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3491 | } |
| 3492 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3493 | static struct drm_i915_gem_object * |
| 3494 | intel_alloc_context_page(struct drm_device *dev) |
| 3495 | { |
| 3496 | struct drm_i915_gem_object *ctx; |
| 3497 | int ret; |
| 3498 | |
| 3499 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3500 | |
| 3501 | ctx = i915_gem_alloc_object(dev, 4096); |
| 3502 | if (!ctx) { |
| 3503 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 3504 | return NULL; |
| 3505 | } |
| 3506 | |
Daniel Vetter | c69766f | 2014-02-14 14:01:17 +0100 | [diff] [blame] | 3507 | ret = i915_gem_obj_ggtt_pin(ctx, 4096, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3508 | if (ret) { |
| 3509 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 3510 | goto err_unref; |
| 3511 | } |
| 3512 | |
| 3513 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
| 3514 | if (ret) { |
| 3515 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 3516 | goto err_unpin; |
| 3517 | } |
| 3518 | |
| 3519 | return ctx; |
| 3520 | |
| 3521 | err_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 3522 | i915_gem_object_ggtt_unpin(ctx); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3523 | err_unref: |
| 3524 | drm_gem_object_unreference(&ctx->base); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3525 | return NULL; |
| 3526 | } |
| 3527 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3528 | /** |
| 3529 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3530 | */ |
| 3531 | DEFINE_SPINLOCK(mchdev_lock); |
| 3532 | |
| 3533 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3534 | * mchdev_lock. */ |
| 3535 | static struct drm_i915_private *i915_mch_dev; |
| 3536 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3537 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3538 | { |
| 3539 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3540 | u16 rgvswctl; |
| 3541 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3542 | assert_spin_locked(&mchdev_lock); |
| 3543 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3544 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3545 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3546 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3547 | return false; /* still busy with another command */ |
| 3548 | } |
| 3549 | |
| 3550 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3551 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3552 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3553 | POSTING_READ16(MEMSWCTL); |
| 3554 | |
| 3555 | rgvswctl |= MEMCTL_CMD_STS; |
| 3556 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3557 | |
| 3558 | return true; |
| 3559 | } |
| 3560 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3561 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3562 | { |
| 3563 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3564 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 3565 | u8 fmax, fmin, fstart, vstart; |
| 3566 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3567 | spin_lock_irq(&mchdev_lock); |
| 3568 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3569 | /* Enable temp reporting */ |
| 3570 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 3571 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 3572 | |
| 3573 | /* 100ms RC evaluation intervals */ |
| 3574 | I915_WRITE(RCUPEI, 100000); |
| 3575 | I915_WRITE(RCDNEI, 100000); |
| 3576 | |
| 3577 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 3578 | I915_WRITE(RCBMAXAVG, 90000); |
| 3579 | I915_WRITE(RCBMINAVG, 80000); |
| 3580 | |
| 3581 | I915_WRITE(MEMIHYST, 1); |
| 3582 | |
| 3583 | /* Set up min, max, and cur for interrupt handling */ |
| 3584 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 3585 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3586 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3587 | MEMMODE_FSTART_SHIFT; |
| 3588 | |
| 3589 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3590 | PXVFREQ_PX_SHIFT; |
| 3591 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3592 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3593 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3594 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3595 | dev_priv->ips.max_delay = fstart; |
| 3596 | dev_priv->ips.min_delay = fmin; |
| 3597 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3598 | |
| 3599 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3600 | fmax, fmin, fstart); |
| 3601 | |
| 3602 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3603 | |
| 3604 | /* |
| 3605 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3606 | */ |
| 3607 | |
| 3608 | I915_WRITE(VIDSTART, vstart); |
| 3609 | POSTING_READ(VIDSTART); |
| 3610 | |
| 3611 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3612 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3613 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3614 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3615 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3616 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3617 | |
| 3618 | ironlake_set_drps(dev, fstart); |
| 3619 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3620 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3621 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3622 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3623 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 3624 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3625 | |
| 3626 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3627 | } |
| 3628 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3629 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3630 | { |
| 3631 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3632 | u16 rgvswctl; |
| 3633 | |
| 3634 | spin_lock_irq(&mchdev_lock); |
| 3635 | |
| 3636 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3637 | |
| 3638 | /* Ack interrupts, disable EFC interrupt */ |
| 3639 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3640 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3641 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3642 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3643 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3644 | |
| 3645 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3646 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3647 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3648 | rgvswctl |= MEMCTL_CMD_STS; |
| 3649 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3650 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3651 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3652 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3653 | } |
| 3654 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3655 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3656 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3657 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3658 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3659 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 3660 | static u32 gen6_rps_limits(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3661 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3662 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3663 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3664 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3665 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3666 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3667 | * the hw runs at the minimal clock before selecting the desired |
| 3668 | * frequency, if the down threshold expires in that window we will not |
| 3669 | * receive a down interrupt. */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3670 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3671 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3672 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3673 | |
| 3674 | return limits; |
| 3675 | } |
| 3676 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3677 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3678 | { |
| 3679 | int new_power; |
| 3680 | |
| 3681 | new_power = dev_priv->rps.power; |
| 3682 | switch (dev_priv->rps.power) { |
| 3683 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3684 | 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] | 3685 | new_power = BETWEEN; |
| 3686 | break; |
| 3687 | |
| 3688 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3689 | 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] | 3690 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3691 | 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] | 3692 | new_power = HIGH_POWER; |
| 3693 | break; |
| 3694 | |
| 3695 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3696 | 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] | 3697 | new_power = BETWEEN; |
| 3698 | break; |
| 3699 | } |
| 3700 | /* Max/min bins are special */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3701 | if (val == dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3702 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3703 | if (val == dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3704 | new_power = HIGH_POWER; |
| 3705 | if (new_power == dev_priv->rps.power) |
| 3706 | return; |
| 3707 | |
| 3708 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3709 | switch (new_power) { |
| 3710 | case LOW_POWER: |
| 3711 | /* Upclock if more than 95% busy over 16ms */ |
| 3712 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 3713 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 3714 | |
| 3715 | /* Downclock if less than 85% busy over 32ms */ |
| 3716 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3717 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 3718 | |
| 3719 | I915_WRITE(GEN6_RP_CONTROL, |
| 3720 | GEN6_RP_MEDIA_TURBO | |
| 3721 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3722 | GEN6_RP_MEDIA_IS_GFX | |
| 3723 | GEN6_RP_ENABLE | |
| 3724 | GEN6_RP_UP_BUSY_AVG | |
| 3725 | GEN6_RP_DOWN_IDLE_AVG); |
| 3726 | break; |
| 3727 | |
| 3728 | case BETWEEN: |
| 3729 | /* Upclock if more than 90% busy over 13ms */ |
| 3730 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 3731 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 3732 | |
| 3733 | /* Downclock if less than 75% busy over 32ms */ |
| 3734 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3735 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 3736 | |
| 3737 | I915_WRITE(GEN6_RP_CONTROL, |
| 3738 | GEN6_RP_MEDIA_TURBO | |
| 3739 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3740 | GEN6_RP_MEDIA_IS_GFX | |
| 3741 | GEN6_RP_ENABLE | |
| 3742 | GEN6_RP_UP_BUSY_AVG | |
| 3743 | GEN6_RP_DOWN_IDLE_AVG); |
| 3744 | break; |
| 3745 | |
| 3746 | case HIGH_POWER: |
| 3747 | /* Upclock if more than 85% busy over 10ms */ |
| 3748 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 3749 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 3750 | |
| 3751 | /* Downclock if less than 60% busy over 32ms */ |
| 3752 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3753 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 3754 | |
| 3755 | I915_WRITE(GEN6_RP_CONTROL, |
| 3756 | GEN6_RP_MEDIA_TURBO | |
| 3757 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3758 | GEN6_RP_MEDIA_IS_GFX | |
| 3759 | GEN6_RP_ENABLE | |
| 3760 | GEN6_RP_UP_BUSY_AVG | |
| 3761 | GEN6_RP_DOWN_IDLE_AVG); |
| 3762 | break; |
| 3763 | } |
| 3764 | |
| 3765 | dev_priv->rps.power = new_power; |
| 3766 | dev_priv->rps.last_adj = 0; |
| 3767 | } |
| 3768 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3769 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3770 | { |
| 3771 | u32 mask = 0; |
| 3772 | |
| 3773 | if (val > dev_priv->rps.min_freq_softlimit) |
| 3774 | mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
| 3775 | if (val < dev_priv->rps.max_freq_softlimit) |
| 3776 | mask |= GEN6_PM_RP_UP_THRESHOLD; |
| 3777 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3778 | mask |= dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED); |
| 3779 | mask &= dev_priv->pm_rps_events; |
| 3780 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 3781 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3784 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3785 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3786 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3787 | static void gen6_set_rps(struct drm_device *dev, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3788 | { |
| 3789 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3790 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3791 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3792 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3793 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3794 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3795 | /* min/max delay may still have been modified so be sure to |
| 3796 | * write the limits value. |
| 3797 | */ |
| 3798 | if (val != dev_priv->rps.cur_freq) { |
| 3799 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3800 | |
Ben Widawsky | 50e6a2a | 2014-03-31 17:16:43 -0700 | [diff] [blame] | 3801 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3802 | I915_WRITE(GEN6_RPNSWREQ, |
| 3803 | HSW_FREQUENCY(val)); |
| 3804 | else |
| 3805 | I915_WRITE(GEN6_RPNSWREQ, |
| 3806 | GEN6_FREQUENCY(val) | |
| 3807 | GEN6_OFFSET(0) | |
| 3808 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3809 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3810 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3811 | /* Make sure we continue to get interrupts |
| 3812 | * until we hit the minimum or maximum frequencies. |
| 3813 | */ |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3814 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3815 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3816 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3817 | POSTING_READ(GEN6_RPNSWREQ); |
| 3818 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3819 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3820 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3821 | } |
| 3822 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3823 | static void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 3824 | { |
| 3825 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3826 | |
| 3827 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 3828 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3829 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
| 3830 | |
| 3831 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 3832 | "Odd GPU freq value\n")) |
| 3833 | val &= ~1; |
| 3834 | |
| 3835 | if (val != dev_priv->rps.cur_freq) |
| 3836 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 3837 | |
| 3838 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 3839 | |
| 3840 | dev_priv->rps.cur_freq = val; |
| 3841 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
| 3842 | } |
| 3843 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3844 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 3845 | * |
| 3846 | * * If Gfx is Idle, then |
| 3847 | * 1. Mask Turbo interrupts |
| 3848 | * 2. Bring up Gfx clock |
| 3849 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 3850 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 3851 | * 5. Unmask Turbo interrupts |
| 3852 | */ |
| 3853 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 3854 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 3855 | struct drm_device *dev = dev_priv->dev; |
| 3856 | |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 3857 | /* CHV and latest VLV don't need to force the gfx clock */ |
| 3858 | if (IS_CHERRYVIEW(dev) || dev->pdev->revision >= 0xd) { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 3859 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3860 | return; |
| 3861 | } |
| 3862 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3863 | /* |
| 3864 | * When we are idle. Drop to min voltage state. |
| 3865 | */ |
| 3866 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3867 | if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3868 | return; |
| 3869 | |
| 3870 | /* Mask turbo interrupt so that they will not come in between */ |
Imre Deak | f24eeb1 | 2014-12-19 19:33:27 +0200 | [diff] [blame] | 3871 | I915_WRITE(GEN6_PMINTRMSK, |
| 3872 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3873 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3874 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3875 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3876 | dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3877 | |
| 3878 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3879 | dev_priv->rps.min_freq_softlimit); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3880 | |
| 3881 | 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] | 3882 | & GENFREQSTATUS) == 0, 100)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3883 | DRM_ERROR("timed out waiting for Punit\n"); |
| 3884 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3885 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3886 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3887 | I915_WRITE(GEN6_PMINTRMSK, |
| 3888 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3889 | } |
| 3890 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3891 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 3892 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3893 | struct drm_device *dev = dev_priv->dev; |
| 3894 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3895 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3896 | if (dev_priv->rps.enabled) { |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 3897 | if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3898 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 3899 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3900 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3901 | dev_priv->rps.last_adj = 0; |
| 3902 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3903 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3904 | } |
| 3905 | |
| 3906 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 3907 | { |
| 3908 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3909 | if (dev_priv->rps.enabled) { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3910 | intel_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3911 | dev_priv->rps.last_adj = 0; |
| 3912 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3913 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3914 | } |
| 3915 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3916 | void intel_set_rps(struct drm_device *dev, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3917 | { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3918 | if (IS_VALLEYVIEW(dev)) |
| 3919 | valleyview_set_rps(dev, val); |
| 3920 | else |
| 3921 | gen6_set_rps(dev, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3922 | } |
| 3923 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 3924 | static void gen9_disable_rps(struct drm_device *dev) |
| 3925 | { |
| 3926 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3927 | |
| 3928 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 3929 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3932 | static void gen6_disable_rps(struct drm_device *dev) |
| 3933 | { |
| 3934 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3935 | |
| 3936 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3937 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3938 | } |
| 3939 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3940 | static void cherryview_disable_rps(struct drm_device *dev) |
| 3941 | { |
| 3942 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3943 | |
| 3944 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3945 | } |
| 3946 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3947 | static void valleyview_disable_rps(struct drm_device *dev) |
| 3948 | { |
| 3949 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3950 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 3951 | /* we're doing forcewake before Disabling RC6, |
| 3952 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 3953 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 3954 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3955 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3956 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 3957 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3960 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 3961 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 3962 | if (IS_VALLEYVIEW(dev)) { |
| 3963 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 3964 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 3965 | else |
| 3966 | mode = 0; |
| 3967 | } |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 3968 | if (HAS_RC6p(dev)) |
| 3969 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s RC6p %s RC6pp %s\n", |
| 3970 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 3971 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 3972 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
| 3973 | |
| 3974 | else |
| 3975 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s\n", |
| 3976 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3979 | 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] | 3980 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 3981 | /* No RC6 before Ironlake */ |
| 3982 | if (INTEL_INFO(dev)->gen < 5) |
| 3983 | return 0; |
| 3984 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3985 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 3986 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 3987 | return 0; |
| 3988 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3989 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3990 | if (enable_rc6 >= 0) { |
| 3991 | int mask; |
| 3992 | |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 3993 | if (HAS_RC6p(dev)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3994 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 3995 | INTEL_RC6pp_ENABLE; |
| 3996 | else |
| 3997 | mask = INTEL_RC6_ENABLE; |
| 3998 | |
| 3999 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 4000 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 4001 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4002 | |
| 4003 | return enable_rc6 & mask; |
| 4004 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4005 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 4006 | /* Disable RC6 on Ironlake */ |
| 4007 | if (INTEL_INFO(dev)->gen == 5) |
| 4008 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4009 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4010 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 4011 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4012 | |
| 4013 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4014 | } |
| 4015 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4016 | int intel_enable_rc6(const struct drm_device *dev) |
| 4017 | { |
| 4018 | return i915.enable_rc6; |
| 4019 | } |
| 4020 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4021 | static void gen6_init_rps_frequencies(struct drm_device *dev) |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4022 | { |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4023 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4024 | uint32_t rp_state_cap; |
| 4025 | u32 ddcc_status = 0; |
| 4026 | int ret; |
| 4027 | |
| 4028 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4029 | /* All of these values are in units of 50MHz */ |
| 4030 | dev_priv->rps.cur_freq = 0; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4031 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4032 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4033 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4034 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4035 | /* hw_max = RP0 until we check for overclocking */ |
| 4036 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 4037 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4038 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 4039 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
| 4040 | ret = sandybridge_pcode_read(dev_priv, |
| 4041 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 4042 | &ddcc_status); |
| 4043 | if (0 == ret) |
| 4044 | dev_priv->rps.efficient_freq = |
| 4045 | (ddcc_status >> 8) & 0xff; |
| 4046 | } |
| 4047 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4048 | /* Preserve min/max settings in case of re-init */ |
| 4049 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4050 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4051 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4052 | if (dev_priv->rps.min_freq_softlimit == 0) { |
| 4053 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 4054 | dev_priv->rps.min_freq_softlimit = |
Tom O'Rourke | f4ab408 | 2014-11-19 14:21:53 -0800 | [diff] [blame] | 4055 | /* max(RPe, 450 MHz) */ |
| 4056 | max(dev_priv->rps.efficient_freq, (u8) 9); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4057 | else |
| 4058 | dev_priv->rps.min_freq_softlimit = |
| 4059 | dev_priv->rps.min_freq; |
| 4060 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4063 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4064 | static void gen9_enable_rps(struct drm_device *dev) |
| 4065 | { |
| 4066 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4067 | |
| 4068 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 4069 | |
Damien Lespiau | ba1c554 | 2015-01-16 18:07:26 +0000 | [diff] [blame] | 4070 | gen6_init_rps_frequencies(dev); |
| 4071 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4072 | I915_WRITE(GEN6_RPNSWREQ, 0xc800000); |
| 4073 | I915_WRITE(GEN6_RC_VIDEO_FREQ, 0xc800000); |
| 4074 | |
| 4075 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 0xf4240); |
| 4076 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, 0x12060000); |
| 4077 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 0xe808); |
| 4078 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 0x3bd08); |
| 4079 | I915_WRITE(GEN6_RP_UP_EI, 0x101d0); |
| 4080 | I915_WRITE(GEN6_RP_DOWN_EI, 0x55730); |
| 4081 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
| 4082 | I915_WRITE(GEN6_PMINTRMSK, 0x6); |
| 4083 | I915_WRITE(GEN6_RP_CONTROL, GEN6_RP_MEDIA_TURBO | |
| 4084 | GEN6_RP_MEDIA_HW_MODE | GEN6_RP_MEDIA_IS_GFX | |
| 4085 | GEN6_RP_ENABLE | GEN6_RP_UP_BUSY_AVG | |
| 4086 | GEN6_RP_DOWN_IDLE_AVG); |
| 4087 | |
| 4088 | gen6_enable_rps_interrupts(dev); |
| 4089 | |
| 4090 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 4091 | } |
| 4092 | |
| 4093 | static void gen9_enable_rc6(struct drm_device *dev) |
| 4094 | { |
| 4095 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4096 | struct intel_engine_cs *ring; |
| 4097 | uint32_t rc6_mask = 0; |
| 4098 | int unused; |
| 4099 | |
| 4100 | /* 1a: Software RC state - RC0 */ |
| 4101 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4102 | |
| 4103 | /* 1b: Get forcewake during program sequence. Although the driver |
| 4104 | * 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] | 4105 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4106 | |
| 4107 | /* 2a: Disable RC states. */ |
| 4108 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4109 | |
| 4110 | /* 2b: Program RC6 thresholds.*/ |
| 4111 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
| 4112 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4113 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4114 | for_each_ring(ring, dev_priv, unused) |
| 4115 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4116 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4117 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
| 4118 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4119 | /* 2c: Program Coarse Power Gating Policies. */ |
| 4120 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 4121 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 4122 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4123 | /* 3a: Enable RC6 */ |
| 4124 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4125 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 4126 | DRM_INFO("RC6 %s\n", (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 4127 | "on" : "off"); |
| 4128 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4129 | GEN6_RC_CTL_EI_MODE(1) | |
| 4130 | rc6_mask); |
| 4131 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4132 | /* 3b: Enable Coarse Power Gating only when RC6 is enabled */ |
| 4133 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? 3 : 0); |
| 4134 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4135 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4136 | |
| 4137 | } |
| 4138 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4139 | static void gen8_enable_rps(struct drm_device *dev) |
| 4140 | { |
| 4141 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4142 | struct intel_engine_cs *ring; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4143 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4144 | int unused; |
| 4145 | |
| 4146 | /* 1a: Software RC state - RC0 */ |
| 4147 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4148 | |
| 4149 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 4150 | * 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] | 4151 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4152 | |
| 4153 | /* 2a: Disable RC states. */ |
| 4154 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4155 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4156 | /* Initialize rps frequencies */ |
| 4157 | gen6_init_rps_frequencies(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4158 | |
| 4159 | /* 2b: Program RC6 thresholds.*/ |
| 4160 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4161 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4162 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4163 | for_each_ring(ring, dev_priv, unused) |
| 4164 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4165 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4166 | if (IS_BROADWELL(dev)) |
| 4167 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 4168 | else |
| 4169 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4170 | |
| 4171 | /* 3: Enable RC6 */ |
| 4172 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4173 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 4174 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4175 | if (IS_BROADWELL(dev)) |
| 4176 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4177 | GEN7_RC_CTL_TO_MODE | |
| 4178 | rc6_mask); |
| 4179 | else |
| 4180 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4181 | GEN6_RC_CTL_EI_MODE(1) | |
| 4182 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4183 | |
| 4184 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 4185 | I915_WRITE(GEN6_RPNSWREQ, |
| 4186 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 4187 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4188 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4189 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 4190 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4191 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4192 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 4193 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 4194 | dev_priv->rps.max_freq_softlimit << 24 | |
| 4195 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4196 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4197 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 4198 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 4199 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 4200 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4201 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4202 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4203 | |
| 4204 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4205 | I915_WRITE(GEN6_RP_CONTROL, |
| 4206 | GEN6_RP_MEDIA_TURBO | |
| 4207 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4208 | GEN6_RP_MEDIA_IS_GFX | |
| 4209 | GEN6_RP_ENABLE | |
| 4210 | GEN6_RP_UP_BUSY_AVG | |
| 4211 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4212 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4213 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4214 | |
Tom O'Rourke | c7f3153 | 2014-11-19 14:21:54 -0800 | [diff] [blame] | 4215 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
| 4216 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4217 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4218 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4219 | } |
| 4220 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4221 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4222 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4223 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4224 | struct intel_engine_cs *ring; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4225 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4226 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4227 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4228 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4229 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4230 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4231 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4232 | /* Here begins a magic sequence of register writes to enable |
| 4233 | * auto-downclocking. |
| 4234 | * |
| 4235 | * Perhaps there might be some value in exposing these to |
| 4236 | * userspace... |
| 4237 | */ |
| 4238 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4239 | |
| 4240 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 4241 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 4242 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 4243 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4244 | } |
| 4245 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4246 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4247 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4248 | /* Initialize rps frequencies */ |
| 4249 | gen6_init_rps_frequencies(dev); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 4250 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4251 | /* disable the counters and set deterministic thresholds */ |
| 4252 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4253 | |
| 4254 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 4255 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 4256 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 4257 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4258 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4259 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 4260 | for_each_ring(ring, dev_priv, i) |
| 4261 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4262 | |
| 4263 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4264 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 4265 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 4266 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 4267 | else |
| 4268 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 4269 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4270 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 4271 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4272 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4273 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 4274 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 4275 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 4276 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4277 | /* We don't use those on Haswell */ |
| 4278 | if (!IS_HASWELL(dev)) { |
| 4279 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 4280 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4281 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4282 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 4283 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 4284 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4285 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4286 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4287 | |
| 4288 | I915_WRITE(GEN6_RC_CONTROL, |
| 4289 | rc6_mask | |
| 4290 | GEN6_RC_CTL_EI_MODE(1) | |
| 4291 | GEN6_RC_CTL_HW_ENABLE); |
| 4292 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4293 | /* Power down if completely idle for over 50ms */ |
| 4294 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4295 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4296 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4297 | 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] | 4298 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4299 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4300 | |
| 4301 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 4302 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 4303 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4304 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4305 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4306 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4307 | } |
| 4308 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4309 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4310 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4311 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4312 | rc6vids = 0; |
| 4313 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4314 | if (IS_GEN6(dev) && ret) { |
| 4315 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4316 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4317 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4318 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4319 | rc6vids &= 0xffff00; |
| 4320 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4321 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4322 | if (ret) |
| 4323 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4324 | } |
| 4325 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4326 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4327 | } |
| 4328 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4329 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4330 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4331 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4332 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4333 | unsigned int gpu_freq; |
| 4334 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4335 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4336 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4337 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4338 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4339 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4340 | policy = cpufreq_cpu_get(0); |
| 4341 | if (policy) { |
| 4342 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4343 | cpufreq_cpu_put(policy); |
| 4344 | } else { |
| 4345 | /* |
| 4346 | * Default to measured freq if none found, PCU will ensure we |
| 4347 | * don't go over |
| 4348 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4349 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4350 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4351 | |
| 4352 | /* Convert from kHz to MHz */ |
| 4353 | max_ia_freq /= 1000; |
| 4354 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4355 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4356 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4357 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4358 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4359 | /* |
| 4360 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4361 | * to use for memory access. We do this by specifying the IA frequency |
| 4362 | * the PCU should use as a reference to determine the ring frequency. |
| 4363 | */ |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4364 | 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] | 4365 | gpu_freq--) { |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4366 | int diff = dev_priv->rps.max_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4367 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4368 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4369 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4370 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4371 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4372 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4373 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4374 | ring_freq = max(min_ring_freq, ring_freq); |
| 4375 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4376 | } else { |
| 4377 | /* On older processors, there is no separate ring |
| 4378 | * clock domain, so in order to boost the bandwidth |
| 4379 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4380 | * |
| 4381 | * For GPU frequencies less than 750MHz, |
| 4382 | * just use the lowest ring freq. |
| 4383 | */ |
| 4384 | if (gpu_freq < min_freq) |
| 4385 | ia_freq = 800; |
| 4386 | else |
| 4387 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4388 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4389 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4390 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4391 | sandybridge_pcode_write(dev_priv, |
| 4392 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4393 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4394 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4395 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4396 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4397 | } |
| 4398 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4399 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4400 | { |
| 4401 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4402 | |
| 4403 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4404 | return; |
| 4405 | |
| 4406 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4407 | __gen6_update_ring_freq(dev); |
| 4408 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4409 | } |
| 4410 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4411 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4412 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4413 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4414 | u32 val, rp0; |
| 4415 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4416 | if (dev->pdev->revision >= 0x20) { |
| 4417 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4418 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4419 | switch (INTEL_INFO(dev)->eu_total) { |
| 4420 | case 8: |
| 4421 | /* (2 * 4) config */ |
| 4422 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 4423 | break; |
| 4424 | case 12: |
| 4425 | /* (2 * 6) config */ |
| 4426 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 4427 | break; |
| 4428 | case 16: |
| 4429 | /* (2 * 8) config */ |
| 4430 | default: |
| 4431 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 4432 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 4433 | break; |
| 4434 | } |
| 4435 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 4436 | } else { |
| 4437 | /* For pre-production hardware */ |
| 4438 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4439 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4440 | PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4441 | } |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4442 | return rp0; |
| 4443 | } |
| 4444 | |
| 4445 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4446 | { |
| 4447 | u32 val, rpe; |
| 4448 | |
| 4449 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4450 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4451 | |
| 4452 | return rpe; |
| 4453 | } |
| 4454 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4455 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4456 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4457 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4458 | u32 val, rp1; |
| 4459 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4460 | if (dev->pdev->revision >= 0x20) { |
| 4461 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 4462 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 4463 | } else { |
| 4464 | /* For pre-production hardware */ |
| 4465 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4466 | rp1 = ((val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4467 | PUNIT_GPU_STATUS_MAX_FREQ_MASK); |
| 4468 | } |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4469 | return rp1; |
| 4470 | } |
| 4471 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4472 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4473 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4474 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4475 | u32 val, rpn; |
| 4476 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4477 | if (dev->pdev->revision >= 0x20) { |
| 4478 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 4479 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 4480 | FB_GFX_FREQ_FUSE_MASK); |
| 4481 | } else { /* For pre-production hardware */ |
| 4482 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4483 | rpn = ((val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & |
| 4484 | PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK); |
| 4485 | } |
| 4486 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4487 | return rpn; |
| 4488 | } |
| 4489 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4490 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4491 | { |
| 4492 | u32 val, rp1; |
| 4493 | |
| 4494 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4495 | |
| 4496 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4497 | |
| 4498 | return rp1; |
| 4499 | } |
| 4500 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4501 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4502 | { |
| 4503 | u32 val, rp0; |
| 4504 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4505 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4506 | |
| 4507 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4508 | /* Clamp to max */ |
| 4509 | rp0 = min_t(u32, rp0, 0xea); |
| 4510 | |
| 4511 | return rp0; |
| 4512 | } |
| 4513 | |
| 4514 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4515 | { |
| 4516 | u32 val, rpe; |
| 4517 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4518 | 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] | 4519 | 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] | 4520 | 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] | 4521 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4522 | |
| 4523 | return rpe; |
| 4524 | } |
| 4525 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4526 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4527 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4528 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4529 | } |
| 4530 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4531 | /* Check that the pctx buffer wasn't move under us. */ |
| 4532 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4533 | { |
| 4534 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4535 | |
| 4536 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4537 | dev_priv->vlv_pctx->stolen->start); |
| 4538 | } |
| 4539 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4540 | |
| 4541 | /* Check that the pcbr address is not empty. */ |
| 4542 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4543 | { |
| 4544 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4545 | |
| 4546 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4547 | } |
| 4548 | |
| 4549 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4550 | { |
| 4551 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4552 | unsigned long pctx_paddr, paddr; |
| 4553 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4554 | u32 pcbr; |
| 4555 | int pctx_size = 32*1024; |
| 4556 | |
| 4557 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4558 | |
| 4559 | pcbr = I915_READ(VLV_PCBR); |
| 4560 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4561 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4562 | paddr = (dev_priv->mm.stolen_base + |
| 4563 | (gtt->stolen_size - pctx_size)); |
| 4564 | |
| 4565 | pctx_paddr = (paddr & (~4095)); |
| 4566 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4567 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4568 | |
| 4569 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4570 | } |
| 4571 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4572 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4573 | { |
| 4574 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4575 | struct drm_i915_gem_object *pctx; |
| 4576 | unsigned long pctx_paddr; |
| 4577 | u32 pcbr; |
| 4578 | int pctx_size = 24*1024; |
| 4579 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4580 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4581 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4582 | pcbr = I915_READ(VLV_PCBR); |
| 4583 | if (pcbr) { |
| 4584 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4585 | int pcbr_offset; |
| 4586 | |
| 4587 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4588 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4589 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4590 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4591 | pctx_size); |
| 4592 | goto out; |
| 4593 | } |
| 4594 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4595 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 4596 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4597 | /* |
| 4598 | * From the Gunit register HAS: |
| 4599 | * The Gfx driver is expected to program this register and ensure |
| 4600 | * proper allocation within Gfx stolen memory. For example, this |
| 4601 | * register should be programmed such than the PCBR range does not |
| 4602 | * overlap with other ranges, such as the frame buffer, protected |
| 4603 | * memory, or any other relevant ranges. |
| 4604 | */ |
| 4605 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4606 | if (!pctx) { |
| 4607 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4608 | return; |
| 4609 | } |
| 4610 | |
| 4611 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4612 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4613 | |
| 4614 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4615 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4616 | dev_priv->vlv_pctx = pctx; |
| 4617 | } |
| 4618 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4619 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4620 | { |
| 4621 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4622 | |
| 4623 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4624 | return; |
| 4625 | |
| 4626 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 4627 | dev_priv->vlv_pctx = NULL; |
| 4628 | } |
| 4629 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4630 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 4631 | { |
| 4632 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4633 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4634 | |
| 4635 | valleyview_setup_pctx(dev); |
| 4636 | |
| 4637 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4638 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4639 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4640 | switch ((val >> 6) & 3) { |
| 4641 | case 0: |
| 4642 | case 1: |
| 4643 | dev_priv->mem_freq = 800; |
| 4644 | break; |
| 4645 | case 2: |
| 4646 | dev_priv->mem_freq = 1066; |
| 4647 | break; |
| 4648 | case 3: |
| 4649 | dev_priv->mem_freq = 1333; |
| 4650 | break; |
| 4651 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4652 | 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] | 4653 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4654 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 4655 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4656 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4657 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4658 | dev_priv->rps.max_freq); |
| 4659 | |
| 4660 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 4661 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4662 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4663 | dev_priv->rps.efficient_freq); |
| 4664 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4665 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 4666 | 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] | 4667 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4668 | dev_priv->rps.rp1_freq); |
| 4669 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4670 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 4671 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4672 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4673 | dev_priv->rps.min_freq); |
| 4674 | |
| 4675 | /* Preserve min/max settings in case of re-init */ |
| 4676 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4677 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4678 | |
| 4679 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4680 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4681 | |
| 4682 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4683 | } |
| 4684 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4685 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4686 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4687 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4688 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4689 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4690 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4691 | |
| 4692 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4693 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 4694 | mutex_lock(&dev_priv->dpio_lock); |
| 4695 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
| 4696 | mutex_unlock(&dev_priv->dpio_lock); |
| 4697 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4698 | switch ((val >> 2) & 0x7) { |
| 4699 | case 0: |
| 4700 | case 1: |
| 4701 | dev_priv->rps.cz_freq = 200; |
| 4702 | dev_priv->mem_freq = 1600; |
| 4703 | break; |
| 4704 | case 2: |
| 4705 | dev_priv->rps.cz_freq = 267; |
| 4706 | dev_priv->mem_freq = 1600; |
| 4707 | break; |
| 4708 | case 3: |
| 4709 | dev_priv->rps.cz_freq = 333; |
| 4710 | dev_priv->mem_freq = 2000; |
| 4711 | break; |
| 4712 | case 4: |
| 4713 | dev_priv->rps.cz_freq = 320; |
| 4714 | dev_priv->mem_freq = 1600; |
| 4715 | break; |
| 4716 | case 5: |
| 4717 | dev_priv->rps.cz_freq = 400; |
| 4718 | dev_priv->mem_freq = 1600; |
| 4719 | break; |
| 4720 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4721 | 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] | 4722 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4723 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4724 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4725 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4726 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4727 | dev_priv->rps.max_freq); |
| 4728 | |
| 4729 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4730 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4731 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4732 | dev_priv->rps.efficient_freq); |
| 4733 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4734 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4735 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4736 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4737 | dev_priv->rps.rp1_freq); |
| 4738 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4739 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4740 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4741 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4742 | dev_priv->rps.min_freq); |
| 4743 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4744 | WARN_ONCE((dev_priv->rps.max_freq | |
| 4745 | dev_priv->rps.efficient_freq | |
| 4746 | dev_priv->rps.rp1_freq | |
| 4747 | dev_priv->rps.min_freq) & 1, |
| 4748 | "Odd GPU freq values\n"); |
| 4749 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4750 | /* Preserve min/max settings in case of re-init */ |
| 4751 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4752 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4753 | |
| 4754 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4755 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4756 | |
| 4757 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4758 | } |
| 4759 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4760 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4761 | { |
| 4762 | valleyview_cleanup_pctx(dev); |
| 4763 | } |
| 4764 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4765 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4766 | { |
| 4767 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4768 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4769 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4770 | int i; |
| 4771 | |
| 4772 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4773 | |
| 4774 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4775 | if (gtfifodbg) { |
| 4776 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4777 | gtfifodbg); |
| 4778 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4779 | } |
| 4780 | |
| 4781 | cherryview_check_pctx(dev_priv); |
| 4782 | |
| 4783 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 4784 | * 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] | 4785 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4786 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 4787 | /* Disable RC states. */ |
| 4788 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4789 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4790 | /* 2a: Program RC6 thresholds.*/ |
| 4791 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4792 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4793 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4794 | |
| 4795 | for_each_ring(ring, dev_priv, i) |
| 4796 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4797 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4798 | |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 4799 | /* TO threshold set to 1750 us ( 0x557 * 1.28 us) */ |
| 4800 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4801 | |
| 4802 | /* allows RC6 residency counter to work */ |
| 4803 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 4804 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 4805 | VLV_MEDIA_RC6_COUNT_EN | |
| 4806 | VLV_RENDER_RC6_COUNT_EN)); |
| 4807 | |
| 4808 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 4809 | pcbr = I915_READ(VLV_PCBR); |
| 4810 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4811 | /* 3: Enable RC6 */ |
| 4812 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 4813 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 4814 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4815 | |
| 4816 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 4817 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4818 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 4819 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4820 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4821 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4822 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4823 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4824 | |
| 4825 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4826 | |
| 4827 | /* 5: Enable RPS */ |
| 4828 | I915_WRITE(GEN6_RP_CONTROL, |
| 4829 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 4830 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4831 | GEN6_RP_ENABLE | |
| 4832 | GEN6_RP_UP_BUSY_AVG | |
| 4833 | GEN6_RP_DOWN_IDLE_AVG); |
| 4834 | |
| 4835 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4836 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 4837 | /* RPS code assumes GPLL is used */ |
| 4838 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 4839 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 4840 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4841 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4842 | |
| 4843 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 4844 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4845 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4846 | dev_priv->rps.cur_freq); |
| 4847 | |
| 4848 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4849 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4850 | dev_priv->rps.efficient_freq); |
| 4851 | |
| 4852 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 4853 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4854 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4855 | } |
| 4856 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4857 | static void valleyview_enable_rps(struct drm_device *dev) |
| 4858 | { |
| 4859 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4860 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 4861 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4862 | int i; |
| 4863 | |
| 4864 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4865 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4866 | valleyview_check_pctx(dev_priv); |
| 4867 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4868 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 4869 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4870 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4871 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4872 | } |
| 4873 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4874 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4875 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4876 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 4877 | /* Disable RC states. */ |
| 4878 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4879 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 4880 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4881 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4882 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4883 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4884 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4885 | |
| 4886 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4887 | |
| 4888 | I915_WRITE(GEN6_RP_CONTROL, |
| 4889 | GEN6_RP_MEDIA_TURBO | |
| 4890 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4891 | GEN6_RP_MEDIA_IS_GFX | |
| 4892 | GEN6_RP_ENABLE | |
| 4893 | GEN6_RP_UP_BUSY_AVG | |
| 4894 | GEN6_RP_DOWN_IDLE_CONT); |
| 4895 | |
| 4896 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 4897 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4898 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4899 | |
| 4900 | for_each_ring(ring, dev_priv, i) |
| 4901 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4902 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 4903 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4904 | |
| 4905 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4906 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4907 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 4908 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4909 | VLV_MEDIA_RC6_COUNT_EN | |
| 4910 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4911 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4912 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 4913 | 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] | 4914 | |
| 4915 | intel_print_rc6_info(dev, rc6_mode); |
| 4916 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4917 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4918 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4919 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4920 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 4921 | /* RPS code assumes GPLL is used */ |
| 4922 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 4923 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 4924 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4925 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4926 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4927 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4928 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4929 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4930 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4931 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4932 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4933 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4934 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4935 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4936 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4937 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4938 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4939 | } |
| 4940 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4941 | void ironlake_teardown_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4942 | { |
| 4943 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4944 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4945 | if (dev_priv->ips.renderctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4946 | i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4947 | drm_gem_object_unreference(&dev_priv->ips.renderctx->base); |
| 4948 | dev_priv->ips.renderctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4949 | } |
| 4950 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4951 | if (dev_priv->ips.pwrctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4952 | i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4953 | drm_gem_object_unreference(&dev_priv->ips.pwrctx->base); |
| 4954 | dev_priv->ips.pwrctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4955 | } |
| 4956 | } |
| 4957 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4958 | static void ironlake_disable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4959 | { |
| 4960 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4961 | |
| 4962 | if (I915_READ(PWRCTXA)) { |
| 4963 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 4964 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 4965 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 4966 | 50); |
| 4967 | |
| 4968 | I915_WRITE(PWRCTXA, 0); |
| 4969 | POSTING_READ(PWRCTXA); |
| 4970 | |
| 4971 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 4972 | POSTING_READ(RSTDBYCTL); |
| 4973 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 4977 | { |
| 4978 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4979 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4980 | if (dev_priv->ips.renderctx == NULL) |
| 4981 | dev_priv->ips.renderctx = intel_alloc_context_page(dev); |
| 4982 | if (!dev_priv->ips.renderctx) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4983 | return -ENOMEM; |
| 4984 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4985 | if (dev_priv->ips.pwrctx == NULL) |
| 4986 | dev_priv->ips.pwrctx = intel_alloc_context_page(dev); |
| 4987 | if (!dev_priv->ips.pwrctx) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4988 | ironlake_teardown_rc6(dev); |
| 4989 | return -ENOMEM; |
| 4990 | } |
| 4991 | |
| 4992 | return 0; |
| 4993 | } |
| 4994 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4995 | static void ironlake_enable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4996 | { |
| 4997 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4998 | struct intel_engine_cs *ring = &dev_priv->ring[RCS]; |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4999 | bool was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5000 | int ret; |
| 5001 | |
| 5002 | /* rc6 disabled by default due to repeated reports of hanging during |
| 5003 | * boot and resume. |
| 5004 | */ |
| 5005 | if (!intel_enable_rc6(dev)) |
| 5006 | return; |
| 5007 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 5008 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 5009 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5010 | ret = ironlake_setup_rc6(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 5011 | if (ret) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5012 | return; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5013 | |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 5014 | was_interruptible = dev_priv->mm.interruptible; |
| 5015 | dev_priv->mm.interruptible = false; |
| 5016 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5017 | /* |
| 5018 | * GPU can automatically power down the render unit if given a page |
| 5019 | * to save state. |
| 5020 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 5021 | ret = intel_ring_begin(ring, 6); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5022 | if (ret) { |
| 5023 | ironlake_teardown_rc6(dev); |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 5024 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5025 | return; |
| 5026 | } |
| 5027 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 5028 | intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 5029 | intel_ring_emit(ring, MI_SET_CONTEXT); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 5030 | intel_ring_emit(ring, i915_gem_obj_ggtt_offset(dev_priv->ips.renderctx) | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 5031 | MI_MM_SPACE_GTT | |
| 5032 | MI_SAVE_EXT_STATE_EN | |
| 5033 | MI_RESTORE_EXT_STATE_EN | |
| 5034 | MI_RESTORE_INHIBIT); |
| 5035 | intel_ring_emit(ring, MI_SUSPEND_FLUSH); |
| 5036 | intel_ring_emit(ring, MI_NOOP); |
| 5037 | intel_ring_emit(ring, MI_FLUSH); |
| 5038 | intel_ring_advance(ring); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5039 | |
| 5040 | /* |
| 5041 | * Wait for the command parser to advance past MI_SET_CONTEXT. The HW |
| 5042 | * does an implicit flush, combined with MI_FLUSH above, it should be |
| 5043 | * safe to assume that renderctx is valid |
| 5044 | */ |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 5045 | ret = intel_ring_idle(ring); |
| 5046 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5047 | if (ret) { |
Jani Nikula | def27a5 | 2013-03-12 10:49:19 +0200 | [diff] [blame] | 5048 | DRM_ERROR("failed to enable ironlake power savings\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5049 | ironlake_teardown_rc6(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5050 | return; |
| 5051 | } |
| 5052 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 5053 | I915_WRITE(PWRCTXA, i915_gem_obj_ggtt_offset(dev_priv->ips.pwrctx) | PWRCTX_EN); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5054 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 5055 | |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 5056 | intel_print_rc6_info(dev, GEN6_RC_CTL_RC6_ENABLE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5057 | } |
| 5058 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5059 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 5060 | { |
| 5061 | unsigned long freq; |
| 5062 | int div = (vidfreq & 0x3f0000) >> 16; |
| 5063 | int post = (vidfreq & 0x3000) >> 12; |
| 5064 | int pre = (vidfreq & 0x7); |
| 5065 | |
| 5066 | if (!pre) |
| 5067 | return 0; |
| 5068 | |
| 5069 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 5070 | |
| 5071 | return freq; |
| 5072 | } |
| 5073 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5074 | static const struct cparams { |
| 5075 | u16 i; |
| 5076 | u16 t; |
| 5077 | u16 m; |
| 5078 | u16 c; |
| 5079 | } cparams[] = { |
| 5080 | { 1, 1333, 301, 28664 }, |
| 5081 | { 1, 1066, 294, 24460 }, |
| 5082 | { 1, 800, 294, 25192 }, |
| 5083 | { 0, 1333, 276, 27605 }, |
| 5084 | { 0, 1066, 276, 27605 }, |
| 5085 | { 0, 800, 231, 23784 }, |
| 5086 | }; |
| 5087 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5088 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5089 | { |
| 5090 | u64 total_count, diff, ret; |
| 5091 | u32 count1, count2, count3, m = 0, c = 0; |
| 5092 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 5093 | int i; |
| 5094 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5095 | assert_spin_locked(&mchdev_lock); |
| 5096 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5097 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5098 | |
| 5099 | /* Prevent division-by-zero if we are asking too fast. |
| 5100 | * Also, we don't get interesting results if we are polling |
| 5101 | * faster than once in 10ms, so just return the saved value |
| 5102 | * in such cases. |
| 5103 | */ |
| 5104 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5105 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5106 | |
| 5107 | count1 = I915_READ(DMIEC); |
| 5108 | count2 = I915_READ(DDREC); |
| 5109 | count3 = I915_READ(CSIEC); |
| 5110 | |
| 5111 | total_count = count1 + count2 + count3; |
| 5112 | |
| 5113 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5114 | if (total_count < dev_priv->ips.last_count1) { |
| 5115 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5116 | diff += total_count; |
| 5117 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5118 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5122 | if (cparams[i].i == dev_priv->ips.c_m && |
| 5123 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5124 | m = cparams[i].m; |
| 5125 | c = cparams[i].c; |
| 5126 | break; |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | diff = div_u64(diff, diff1); |
| 5131 | ret = ((m * diff) + c); |
| 5132 | ret = div_u64(ret, 10); |
| 5133 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5134 | dev_priv->ips.last_count1 = total_count; |
| 5135 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5136 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5137 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5138 | |
| 5139 | return ret; |
| 5140 | } |
| 5141 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5142 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 5143 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5144 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5145 | unsigned long val; |
| 5146 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5147 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5148 | return 0; |
| 5149 | |
| 5150 | spin_lock_irq(&mchdev_lock); |
| 5151 | |
| 5152 | val = __i915_chipset_val(dev_priv); |
| 5153 | |
| 5154 | spin_unlock_irq(&mchdev_lock); |
| 5155 | |
| 5156 | return val; |
| 5157 | } |
| 5158 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5159 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 5160 | { |
| 5161 | unsigned long m, x, b; |
| 5162 | u32 tsfs; |
| 5163 | |
| 5164 | tsfs = I915_READ(TSFS); |
| 5165 | |
| 5166 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 5167 | x = I915_READ8(TR1); |
| 5168 | |
| 5169 | b = tsfs & TSFS_INTR_MASK; |
| 5170 | |
| 5171 | return ((m * x) / 127) - b; |
| 5172 | } |
| 5173 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5174 | static int _pxvid_to_vd(u8 pxvid) |
| 5175 | { |
| 5176 | if (pxvid == 0) |
| 5177 | return 0; |
| 5178 | |
| 5179 | if (pxvid >= 8 && pxvid < 31) |
| 5180 | pxvid = 31; |
| 5181 | |
| 5182 | return (pxvid + 2) * 125; |
| 5183 | } |
| 5184 | |
| 5185 | 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] | 5186 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5187 | struct drm_device *dev = dev_priv->dev; |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5188 | const int vd = _pxvid_to_vd(pxvid); |
| 5189 | const int vm = vd - 1125; |
| 5190 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5191 | if (INTEL_INFO(dev)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5192 | return vm > 0 ? vm : 0; |
| 5193 | |
| 5194 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5195 | } |
| 5196 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5197 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5198 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5199 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5200 | u32 count; |
| 5201 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5202 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5203 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5204 | now = ktime_get_raw_ns(); |
| 5205 | diffms = now - dev_priv->ips.last_time2; |
| 5206 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5207 | |
| 5208 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5209 | if (!diffms) |
| 5210 | return; |
| 5211 | |
| 5212 | count = I915_READ(GFXEC); |
| 5213 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5214 | if (count < dev_priv->ips.last_count2) { |
| 5215 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5216 | diff += count; |
| 5217 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5218 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5219 | } |
| 5220 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5221 | dev_priv->ips.last_count2 = count; |
| 5222 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5223 | |
| 5224 | /* More magic constants... */ |
| 5225 | diff = diff * 1181; |
| 5226 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5227 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5228 | } |
| 5229 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5230 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 5231 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5232 | struct drm_device *dev = dev_priv->dev; |
| 5233 | |
| 5234 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5235 | return; |
| 5236 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5237 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5238 | |
| 5239 | __i915_update_gfx_val(dev_priv); |
| 5240 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5241 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5242 | } |
| 5243 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5244 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5245 | { |
| 5246 | unsigned long t, corr, state1, corr2, state2; |
| 5247 | u32 pxvid, ext_v; |
| 5248 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5249 | assert_spin_locked(&mchdev_lock); |
| 5250 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5251 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5252 | pxvid = (pxvid >> 24) & 0x7f; |
| 5253 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5254 | |
| 5255 | state1 = ext_v; |
| 5256 | |
| 5257 | t = i915_mch_val(dev_priv); |
| 5258 | |
| 5259 | /* Revel in the empirically derived constants */ |
| 5260 | |
| 5261 | /* Correction factor in 1/100000 units */ |
| 5262 | if (t > 80) |
| 5263 | corr = ((t * 2349) + 135940); |
| 5264 | else if (t >= 50) |
| 5265 | corr = ((t * 964) + 29317); |
| 5266 | else /* < 50 */ |
| 5267 | corr = ((t * 301) + 1004); |
| 5268 | |
| 5269 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5270 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5271 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5272 | |
| 5273 | state2 = (corr2 * state1) / 10000; |
| 5274 | state2 /= 100; /* convert to mW */ |
| 5275 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5276 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5277 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5278 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5279 | } |
| 5280 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5281 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5282 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5283 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5284 | unsigned long val; |
| 5285 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5286 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5287 | return 0; |
| 5288 | |
| 5289 | spin_lock_irq(&mchdev_lock); |
| 5290 | |
| 5291 | val = __i915_gfx_val(dev_priv); |
| 5292 | |
| 5293 | spin_unlock_irq(&mchdev_lock); |
| 5294 | |
| 5295 | return val; |
| 5296 | } |
| 5297 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5298 | /** |
| 5299 | * i915_read_mch_val - return value for IPS use |
| 5300 | * |
| 5301 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5302 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5303 | */ |
| 5304 | unsigned long i915_read_mch_val(void) |
| 5305 | { |
| 5306 | struct drm_i915_private *dev_priv; |
| 5307 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5308 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5309 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5310 | if (!i915_mch_dev) |
| 5311 | goto out_unlock; |
| 5312 | dev_priv = i915_mch_dev; |
| 5313 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5314 | chipset_val = __i915_chipset_val(dev_priv); |
| 5315 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5316 | |
| 5317 | ret = chipset_val + graphics_val; |
| 5318 | |
| 5319 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5320 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5321 | |
| 5322 | return ret; |
| 5323 | } |
| 5324 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5325 | |
| 5326 | /** |
| 5327 | * i915_gpu_raise - raise GPU frequency limit |
| 5328 | * |
| 5329 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5330 | */ |
| 5331 | bool i915_gpu_raise(void) |
| 5332 | { |
| 5333 | struct drm_i915_private *dev_priv; |
| 5334 | bool ret = true; |
| 5335 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5336 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5337 | if (!i915_mch_dev) { |
| 5338 | ret = false; |
| 5339 | goto out_unlock; |
| 5340 | } |
| 5341 | dev_priv = i915_mch_dev; |
| 5342 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5343 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5344 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5345 | |
| 5346 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5347 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5348 | |
| 5349 | return ret; |
| 5350 | } |
| 5351 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5352 | |
| 5353 | /** |
| 5354 | * i915_gpu_lower - lower GPU frequency limit |
| 5355 | * |
| 5356 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5357 | * frequency maximum. |
| 5358 | */ |
| 5359 | bool i915_gpu_lower(void) |
| 5360 | { |
| 5361 | struct drm_i915_private *dev_priv; |
| 5362 | bool ret = true; |
| 5363 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5364 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5365 | if (!i915_mch_dev) { |
| 5366 | ret = false; |
| 5367 | goto out_unlock; |
| 5368 | } |
| 5369 | dev_priv = i915_mch_dev; |
| 5370 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5371 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 5372 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5373 | |
| 5374 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5375 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5376 | |
| 5377 | return ret; |
| 5378 | } |
| 5379 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 5380 | |
| 5381 | /** |
| 5382 | * i915_gpu_busy - indicate GPU business to IPS |
| 5383 | * |
| 5384 | * Tell the IPS driver whether or not the GPU is busy. |
| 5385 | */ |
| 5386 | bool i915_gpu_busy(void) |
| 5387 | { |
| 5388 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5389 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5390 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5391 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5392 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5393 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5394 | if (!i915_mch_dev) |
| 5395 | goto out_unlock; |
| 5396 | dev_priv = i915_mch_dev; |
| 5397 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5398 | for_each_ring(ring, dev_priv, i) |
| 5399 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5400 | |
| 5401 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5402 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5403 | |
| 5404 | return ret; |
| 5405 | } |
| 5406 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 5407 | |
| 5408 | /** |
| 5409 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5410 | * |
| 5411 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5412 | * current frequency to the default. |
| 5413 | */ |
| 5414 | bool i915_gpu_turbo_disable(void) |
| 5415 | { |
| 5416 | struct drm_i915_private *dev_priv; |
| 5417 | bool ret = true; |
| 5418 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5419 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5420 | if (!i915_mch_dev) { |
| 5421 | ret = false; |
| 5422 | goto out_unlock; |
| 5423 | } |
| 5424 | dev_priv = i915_mch_dev; |
| 5425 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5426 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5427 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5428 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5429 | ret = false; |
| 5430 | |
| 5431 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5432 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5433 | |
| 5434 | return ret; |
| 5435 | } |
| 5436 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5437 | |
| 5438 | /** |
| 5439 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5440 | * IPS got loaded first. |
| 5441 | * |
| 5442 | * This awkward dance is so that neither module has to depend on the |
| 5443 | * other in order for IPS to do the appropriate communication of |
| 5444 | * GPU turbo limits to i915. |
| 5445 | */ |
| 5446 | static void |
| 5447 | ips_ping_for_i915_load(void) |
| 5448 | { |
| 5449 | void (*link)(void); |
| 5450 | |
| 5451 | link = symbol_get(ips_link_to_i915_driver); |
| 5452 | if (link) { |
| 5453 | link(); |
| 5454 | symbol_put(ips_link_to_i915_driver); |
| 5455 | } |
| 5456 | } |
| 5457 | |
| 5458 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5459 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5460 | /* We only register the i915 ips part with intel-ips once everything is |
| 5461 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5462 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5463 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5464 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5465 | |
| 5466 | ips_ping_for_i915_load(); |
| 5467 | } |
| 5468 | |
| 5469 | void intel_gpu_ips_teardown(void) |
| 5470 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5471 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5472 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5473 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5474 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5475 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5476 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5477 | { |
| 5478 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5479 | u32 lcfuse; |
| 5480 | u8 pxw[16]; |
| 5481 | int i; |
| 5482 | |
| 5483 | /* Disable to program */ |
| 5484 | I915_WRITE(ECR, 0); |
| 5485 | POSTING_READ(ECR); |
| 5486 | |
| 5487 | /* Program energy weights for various events */ |
| 5488 | I915_WRITE(SDEW, 0x15040d00); |
| 5489 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5490 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5491 | I915_WRITE(CSIEW2, 0x04000004); |
| 5492 | |
| 5493 | for (i = 0; i < 5; i++) |
| 5494 | I915_WRITE(PEW + (i * 4), 0); |
| 5495 | for (i = 0; i < 3; i++) |
| 5496 | I915_WRITE(DEW + (i * 4), 0); |
| 5497 | |
| 5498 | /* Program P-state weights to account for frequency power adjustment */ |
| 5499 | for (i = 0; i < 16; i++) { |
| 5500 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5501 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5502 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5503 | PXVFREQ_PX_SHIFT; |
| 5504 | unsigned long val; |
| 5505 | |
| 5506 | val = vid * vid; |
| 5507 | val *= (freq / 1000); |
| 5508 | val *= 255; |
| 5509 | val /= (127*127*900); |
| 5510 | if (val > 0xff) |
| 5511 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5512 | pxw[i] = val; |
| 5513 | } |
| 5514 | /* Render standby states get 0 weight */ |
| 5515 | pxw[14] = 0; |
| 5516 | pxw[15] = 0; |
| 5517 | |
| 5518 | for (i = 0; i < 4; i++) { |
| 5519 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 5520 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 5521 | I915_WRITE(PXW + (i * 4), val); |
| 5522 | } |
| 5523 | |
| 5524 | /* Adjust magic regs to magic values (more experimental results) */ |
| 5525 | I915_WRITE(OGW0, 0); |
| 5526 | I915_WRITE(OGW1, 0); |
| 5527 | I915_WRITE(EG0, 0x00007f00); |
| 5528 | I915_WRITE(EG1, 0x0000000e); |
| 5529 | I915_WRITE(EG2, 0x000e0000); |
| 5530 | I915_WRITE(EG3, 0x68000300); |
| 5531 | I915_WRITE(EG4, 0x42000000); |
| 5532 | I915_WRITE(EG5, 0x00140031); |
| 5533 | I915_WRITE(EG6, 0); |
| 5534 | I915_WRITE(EG7, 0); |
| 5535 | |
| 5536 | for (i = 0; i < 8; i++) |
| 5537 | I915_WRITE(PXWL + (i * 4), 0); |
| 5538 | |
| 5539 | /* Enable PMON + select events */ |
| 5540 | I915_WRITE(ECR, 0x80000019); |
| 5541 | |
| 5542 | lcfuse = I915_READ(LCFUSE02); |
| 5543 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5544 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5545 | } |
| 5546 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5547 | void intel_init_gt_powersave(struct drm_device *dev) |
| 5548 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5549 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 5550 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5551 | if (IS_CHERRYVIEW(dev)) |
| 5552 | cherryview_init_gt_powersave(dev); |
| 5553 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5554 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 5558 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5559 | if (IS_CHERRYVIEW(dev)) |
| 5560 | return; |
| 5561 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5562 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5563 | } |
| 5564 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5565 | static void gen6_suspend_rps(struct drm_device *dev) |
| 5566 | { |
| 5567 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5568 | |
| 5569 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 5570 | |
| 5571 | /* |
| 5572 | * TODO: disable RPS interrupts on GEN9+ too once RPS support |
| 5573 | * is added for it. |
| 5574 | */ |
| 5575 | if (INTEL_INFO(dev)->gen < 9) |
| 5576 | gen6_disable_rps_interrupts(dev); |
| 5577 | } |
| 5578 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5579 | /** |
| 5580 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 5581 | * @dev: drm device |
| 5582 | * |
| 5583 | * We don't want to disable RC6 or other features here, we just want |
| 5584 | * to make sure any work we've queued has finished and won't bother |
| 5585 | * us while we're suspended. |
| 5586 | */ |
| 5587 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 5588 | { |
| 5589 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5590 | |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 5591 | if (INTEL_INFO(dev)->gen < 6) |
| 5592 | return; |
| 5593 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5594 | gen6_suspend_rps(dev); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 5595 | |
| 5596 | /* Force GPU to min freq during suspend */ |
| 5597 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5598 | } |
| 5599 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5600 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 5601 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5602 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5603 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5604 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5605 | ironlake_disable_drps(dev); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5606 | ironlake_disable_rc6(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5607 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5608 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5609 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5610 | mutex_lock(&dev_priv->rps.hw_lock); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5611 | if (INTEL_INFO(dev)->gen >= 9) |
| 5612 | gen9_disable_rps(dev); |
| 5613 | else if (IS_CHERRYVIEW(dev)) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5614 | cherryview_disable_rps(dev); |
| 5615 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5616 | valleyview_disable_rps(dev); |
| 5617 | else |
| 5618 | gen6_disable_rps(dev); |
Imre Deak | e534770 | 2014-11-19 15:30:02 +0200 | [diff] [blame] | 5619 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5620 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5621 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5622 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5623 | } |
| 5624 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5625 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5626 | { |
| 5627 | struct drm_i915_private *dev_priv = |
| 5628 | container_of(work, struct drm_i915_private, |
| 5629 | rps.delayed_resume_work.work); |
| 5630 | struct drm_device *dev = dev_priv->dev; |
| 5631 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5632 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5633 | |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5634 | /* |
| 5635 | * TODO: reset/enable RPS interrupts on GEN9+ too, once RPS support is |
| 5636 | * added for it. |
| 5637 | */ |
| 5638 | if (INTEL_INFO(dev)->gen < 9) |
| 5639 | gen6_reset_rps_interrupts(dev); |
| 5640 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5641 | if (IS_CHERRYVIEW(dev)) { |
| 5642 | cherryview_enable_rps(dev); |
| 5643 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5644 | valleyview_enable_rps(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5645 | } else if (INTEL_INFO(dev)->gen >= 9) { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5646 | gen9_enable_rc6(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5647 | gen9_enable_rps(dev); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5648 | __gen6_update_ring_freq(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5649 | } else if (IS_BROADWELL(dev)) { |
| 5650 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5651 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5652 | } else { |
| 5653 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5654 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5655 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5656 | dev_priv->rps.enabled = true; |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5657 | |
| 5658 | if (INTEL_INFO(dev)->gen < 9) |
| 5659 | gen6_enable_rps_interrupts(dev); |
| 5660 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5661 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5662 | |
| 5663 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5664 | } |
| 5665 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5666 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5667 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5668 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5669 | |
Yu Zhang | f61018b | 2015-02-10 19:05:52 +0800 | [diff] [blame] | 5670 | /* Powersaving is controlled by the host when inside a VM */ |
| 5671 | if (intel_vgpu_active(dev)) |
| 5672 | return; |
| 5673 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5674 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5675 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5676 | ironlake_enable_drps(dev); |
| 5677 | ironlake_enable_rc6(dev); |
| 5678 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5679 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5680 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5681 | /* |
| 5682 | * PCU communication is slow and this doesn't need to be |
| 5683 | * done at any specific time, so do this out of our fast path |
| 5684 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5685 | * |
| 5686 | * We depend on the HW RC6 power context save/restore |
| 5687 | * mechanism when entering D3 through runtime PM suspend. So |
| 5688 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5689 | * get here via the driver load/system resume/runtime resume |
| 5690 | * paths, so the _noresume version is enough (and in case of |
| 5691 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5692 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5693 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5694 | round_jiffies_up_relative(HZ))) |
| 5695 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5696 | } |
| 5697 | } |
| 5698 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5699 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5700 | { |
| 5701 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5702 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5703 | if (INTEL_INFO(dev)->gen < 6) |
| 5704 | return; |
| 5705 | |
| 5706 | gen6_suspend_rps(dev); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5707 | dev_priv->rps.enabled = false; |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5708 | } |
| 5709 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5710 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5711 | { |
| 5712 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5713 | |
| 5714 | /* |
| 5715 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5716 | * gating for the panel power sequencer or it will fail to |
| 5717 | * start up when no ports are active. |
| 5718 | */ |
| 5719 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5720 | } |
| 5721 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5722 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5723 | { |
| 5724 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5725 | int pipe; |
| 5726 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5727 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5728 | I915_WRITE(DSPCNTR(pipe), |
| 5729 | I915_READ(DSPCNTR(pipe)) | |
| 5730 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5731 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5732 | } |
| 5733 | } |
| 5734 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5735 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5736 | { |
| 5737 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5738 | |
| 5739 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5740 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5741 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5742 | |
| 5743 | /* |
| 5744 | * Don't touch WM1S_LP_EN here. |
| 5745 | * Doing so could cause underruns. |
| 5746 | */ |
| 5747 | } |
| 5748 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5749 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5750 | { |
| 5751 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5752 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5753 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5754 | /* |
| 5755 | * Required for FBC |
| 5756 | * WaFbcDisableDpfcClockGating:ilk |
| 5757 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5758 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5759 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5760 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5761 | |
| 5762 | I915_WRITE(PCH_3DCGDIS0, |
| 5763 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5764 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5765 | I915_WRITE(PCH_3DCGDIS1, |
| 5766 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5767 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5768 | /* |
| 5769 | * According to the spec the following bits should be set in |
| 5770 | * order to enable memory self-refresh |
| 5771 | * The bit 22/21 of 0x42004 |
| 5772 | * The bit 5 of 0x42020 |
| 5773 | * The bit 15 of 0x45000 |
| 5774 | */ |
| 5775 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5776 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5777 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5778 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5779 | I915_WRITE(DISP_ARB_CTL, |
| 5780 | (I915_READ(DISP_ARB_CTL) | |
| 5781 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5782 | |
| 5783 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5784 | |
| 5785 | /* |
| 5786 | * Based on the document from hardware guys the following bits |
| 5787 | * should be set unconditionally in order to enable FBC. |
| 5788 | * The bit 22 of 0x42000 |
| 5789 | * The bit 22 of 0x42004 |
| 5790 | * The bit 7,8,9 of 0x42020. |
| 5791 | */ |
| 5792 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5793 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5794 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5795 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5796 | ILK_FBCQ_DIS); |
| 5797 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5798 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5799 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5800 | } |
| 5801 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5802 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5803 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5804 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5805 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5806 | ILK_ELPIN_409_SELECT); |
| 5807 | I915_WRITE(_3D_CHICKEN2, |
| 5808 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5809 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5810 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5811 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5812 | I915_WRITE(CACHE_MODE_0, |
| 5813 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5814 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5815 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5816 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5817 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5818 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5819 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5820 | ibx_init_clock_gating(dev); |
| 5821 | } |
| 5822 | |
| 5823 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5824 | { |
| 5825 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5826 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5827 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5828 | |
| 5829 | /* |
| 5830 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5831 | * gating for the panel power sequencer or it will fail to |
| 5832 | * start up when no ports are active. |
| 5833 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5834 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5835 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5836 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5837 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5838 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5839 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5840 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5841 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5842 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5843 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5844 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5845 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5846 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5847 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5848 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5849 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5850 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5851 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5852 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5853 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5854 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5855 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5856 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5857 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5858 | } |
| 5859 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5860 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5861 | { |
| 5862 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5863 | uint32_t tmp; |
| 5864 | |
| 5865 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 5866 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5867 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5868 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5869 | } |
| 5870 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5871 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5872 | { |
| 5873 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5874 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5875 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5876 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5877 | |
| 5878 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5879 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5880 | ILK_ELPIN_409_SELECT); |
| 5881 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5882 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5883 | I915_WRITE(_3D_CHICKEN, |
| 5884 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5885 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5886 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5887 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5888 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5889 | /* |
| 5890 | * BSpec recoomends 8x4 when MSAA is used, |
| 5891 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5892 | * |
| 5893 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5894 | * disable bit, which we don't touch here, but it's good |
| 5895 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5896 | */ |
| 5897 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 5898 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5899 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5900 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5901 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5902 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 5903 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5904 | |
| 5905 | I915_WRITE(GEN6_UCGCTL1, |
| 5906 | I915_READ(GEN6_UCGCTL1) | |
| 5907 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 5908 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 5909 | |
| 5910 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 5911 | * gating disable must be set. Failure to set it results in |
| 5912 | * flickering pixels due to Z write ordering failures after |
| 5913 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 5914 | * Sanctuary and Tropics, and apparently anything else with |
| 5915 | * alpha test or pixel discard. |
| 5916 | * |
| 5917 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 5918 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5919 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 5920 | * WaDisableRCCUnitClockGating:snb |
| 5921 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5922 | */ |
| 5923 | I915_WRITE(GEN6_UCGCTL2, |
| 5924 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 5925 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 5926 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 5927 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 5928 | I915_WRITE(_3D_CHICKEN3, |
| 5929 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5930 | |
| 5931 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 5932 | * Bspec says: |
| 5933 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 5934 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 5935 | */ |
| 5936 | I915_WRITE(_3D_CHICKEN3, |
| 5937 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 5938 | |
| 5939 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5940 | * According to the spec the following bits should be |
| 5941 | * set in order to enable memory self-refresh and fbc: |
| 5942 | * The bit21 and bit22 of 0x42000 |
| 5943 | * The bit21 and bit22 of 0x42004 |
| 5944 | * The bit5 and bit7 of 0x42020 |
| 5945 | * The bit14 of 0x70180 |
| 5946 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5947 | * |
| 5948 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5949 | */ |
| 5950 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5951 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5952 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 5953 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5954 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5955 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5956 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 5957 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 5958 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 5959 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5960 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5961 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 5962 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5963 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5964 | |
| 5965 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 5969 | { |
| 5970 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 5971 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5972 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5973 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5974 | * |
| 5975 | * This actually overrides the dispatch |
| 5976 | * mode for all thread types. |
| 5977 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5978 | reg &= ~GEN7_FF_SCHED_MASK; |
| 5979 | reg |= GEN7_FF_TS_SCHED_HW; |
| 5980 | reg |= GEN7_FF_VS_SCHED_HW; |
| 5981 | reg |= GEN7_FF_DS_SCHED_HW; |
| 5982 | |
| 5983 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 5984 | } |
| 5985 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5986 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 5987 | { |
| 5988 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5989 | |
| 5990 | /* |
| 5991 | * TODO: this bit should only be enabled when really needed, then |
| 5992 | * disabled when not needed anymore in order to save power. |
| 5993 | */ |
| 5994 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 5995 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 5996 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 5997 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 5998 | |
| 5999 | /* WADPOClockGatingDisable:hsw */ |
| 6000 | I915_WRITE(_TRANSA_CHICKEN1, |
| 6001 | I915_READ(_TRANSA_CHICKEN1) | |
| 6002 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6003 | } |
| 6004 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6005 | static void lpt_suspend_hw(struct drm_device *dev) |
| 6006 | { |
| 6007 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6008 | |
| 6009 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 6010 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 6011 | |
| 6012 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 6013 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 6014 | } |
| 6015 | } |
| 6016 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6017 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6018 | { |
| 6019 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6020 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6021 | |
| 6022 | I915_WRITE(WM3_LP_ILK, 0); |
| 6023 | I915_WRITE(WM2_LP_ILK, 0); |
| 6024 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6025 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6026 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6027 | 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] | 6028 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6029 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6030 | I915_WRITE(CHICKEN_PAR1_1, |
| 6031 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 6032 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6033 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6034 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6035 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 6036 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 6037 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6038 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 6039 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6040 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 6041 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 6042 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6043 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6044 | ~(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] | 6045 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 6046 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6047 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 6048 | |
| 6049 | /* WaDisableSDEUnitClockGating:bdw */ |
| 6050 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6051 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 6052 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 6053 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6054 | } |
| 6055 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6056 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 6057 | { |
| 6058 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6059 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6060 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6061 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 6062 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 6063 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 6064 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 6065 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 6066 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6067 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6068 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6069 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6070 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6071 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 6072 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 6073 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6074 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6075 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6076 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 6077 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6078 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 6079 | /* enable HiZ Raw Stall Optimization */ |
| 6080 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6081 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6082 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6083 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6084 | I915_WRITE(CACHE_MODE_1, |
| 6085 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6086 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6087 | /* |
| 6088 | * BSpec recommends 8x4 when MSAA is used, |
| 6089 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6090 | * |
| 6091 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6092 | * disable bit, which we don't touch here, but it's good |
| 6093 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6094 | */ |
| 6095 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6096 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6097 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 6098 | /* WaSampleCChickenBitEnable:hsw */ |
| 6099 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 6100 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 6101 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6102 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 6103 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 6104 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 6105 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 6106 | I915_WRITE(CHICKEN_PAR1_1, |
| 6107 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6108 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6109 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6110 | } |
| 6111 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6112 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6113 | { |
| 6114 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6115 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6116 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6117 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6118 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6119 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6120 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6121 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6122 | I915_WRITE(_3D_CHICKEN3, |
| 6123 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6124 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6125 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6126 | I915_WRITE(IVB_CHICKEN3, |
| 6127 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6128 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6129 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6130 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6131 | if (IS_IVB_GT1(dev)) |
| 6132 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 6133 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6134 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6135 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 6136 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6137 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6138 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6139 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 6140 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 6141 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6142 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6143 | I915_WRITE(GEN7_L3CNTLREG1, |
| 6144 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 6145 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6146 | GEN7_WA_L3_CHICKEN_MODE); |
| 6147 | if (IS_IVB_GT1(dev)) |
| 6148 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6149 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6150 | else { |
| 6151 | /* must write both registers */ |
| 6152 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6153 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6154 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 6155 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6156 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6157 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6158 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6159 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6160 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6161 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 6162 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6163 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6164 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6165 | */ |
| 6166 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 6167 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6168 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6169 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6170 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6171 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6172 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6173 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6174 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6175 | |
| 6176 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6177 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 6178 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 6179 | /* enable HiZ Raw Stall Optimization */ |
| 6180 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6181 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6182 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 6183 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6184 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6185 | I915_WRITE(CACHE_MODE_1, |
| 6186 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6187 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6188 | /* |
| 6189 | * BSpec recommends 8x4 when MSAA is used, |
| 6190 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6191 | * |
| 6192 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6193 | * disable bit, which we don't touch here, but it's good |
| 6194 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6195 | */ |
| 6196 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6197 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6198 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6199 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 6200 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 6201 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 6202 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6203 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 6204 | if (!HAS_PCH_NOP(dev)) |
| 6205 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6206 | |
| 6207 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6208 | } |
| 6209 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6210 | static void valleyview_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; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6213 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 6214 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6215 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6216 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6217 | I915_WRITE(_3D_CHICKEN3, |
| 6218 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6219 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6220 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6221 | I915_WRITE(IVB_CHICKEN3, |
| 6222 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6223 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6224 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 6225 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6226 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6227 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 6228 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 6229 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6230 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6231 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 6232 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6233 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6234 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6235 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6236 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6237 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6238 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6239 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6240 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 6241 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6242 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6243 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6244 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6245 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6246 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6247 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 6248 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6249 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6250 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6251 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6252 | */ |
| 6253 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6254 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6255 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6256 | /* WaDisableL3Bank2xClockGate:vlv |
| 6257 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6258 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6259 | I915_WRITE(GEN7_UCGCTL4, |
| 6260 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6261 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 6262 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6263 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6264 | /* |
| 6265 | * BSpec says this must be set, even though |
| 6266 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6267 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6268 | I915_WRITE(CACHE_MODE_1, |
| 6269 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6270 | |
| 6271 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 6272 | * BSpec recommends 8x4 when MSAA is used, |
| 6273 | * however in practice 16x4 seems fastest. |
| 6274 | * |
| 6275 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6276 | * disable bit, which we don't touch here, but it's good |
| 6277 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 6278 | */ |
| 6279 | I915_WRITE(GEN7_GT_MODE, |
| 6280 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 6281 | |
| 6282 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6283 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6284 | * This is the hardware default actually. |
| 6285 | */ |
| 6286 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6287 | |
| 6288 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6289 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6290 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6291 | * in the reporting of vblank events. |
| 6292 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6293 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6294 | } |
| 6295 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6296 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6297 | { |
| 6298 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6299 | |
| 6300 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6301 | |
| 6302 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6303 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6304 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6305 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6306 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6307 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6308 | ~(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] | 6309 | |
| 6310 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6311 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6312 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6313 | |
| 6314 | /* WaDisableCSUnitClockGating:chv */ |
| 6315 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6316 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6317 | |
| 6318 | /* WaDisableSDEUnitClockGating:chv */ |
| 6319 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6320 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6321 | } |
| 6322 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6323 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6324 | { |
| 6325 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6326 | uint32_t dspclk_gate; |
| 6327 | |
| 6328 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6329 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6330 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6331 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6332 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6333 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6334 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6335 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6336 | if (IS_GM45(dev)) |
| 6337 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6338 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6339 | |
| 6340 | /* WaDisableRenderCachePipelinedFlush */ |
| 6341 | I915_WRITE(CACHE_MODE_0, |
| 6342 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6343 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6344 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6345 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6346 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6347 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6348 | } |
| 6349 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6350 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6351 | { |
| 6352 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6353 | |
| 6354 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6355 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6356 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6357 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6358 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6359 | I915_WRITE(MI_ARB_STATE, |
| 6360 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6361 | |
| 6362 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6363 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6364 | } |
| 6365 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6366 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6367 | { |
| 6368 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6369 | |
| 6370 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6371 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6372 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6373 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6374 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6375 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6376 | I915_WRITE(MI_ARB_STATE, |
| 6377 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6378 | |
| 6379 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6380 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6381 | } |
| 6382 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6383 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6384 | { |
| 6385 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6386 | u32 dstate = I915_READ(D_STATE); |
| 6387 | |
| 6388 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6389 | DSTATE_DOT_CLOCK_GATING; |
| 6390 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6391 | |
| 6392 | if (IS_PINEVIEW(dev)) |
| 6393 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6394 | |
| 6395 | /* IIR "flip pending" means done if this bit is set */ |
| 6396 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6397 | |
| 6398 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6399 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6400 | |
| 6401 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6402 | 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] | 6403 | |
| 6404 | I915_WRITE(MI_ARB_STATE, |
| 6405 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6406 | } |
| 6407 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6408 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6409 | { |
| 6410 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6411 | |
| 6412 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6413 | |
| 6414 | /* interrupts should cause a wake up from C3 */ |
| 6415 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6416 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6417 | |
| 6418 | I915_WRITE(MEM_MODE, |
| 6419 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6420 | } |
| 6421 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6422 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6423 | { |
| 6424 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6425 | |
| 6426 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6427 | |
| 6428 | I915_WRITE(MEM_MODE, |
| 6429 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6430 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6431 | } |
| 6432 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6433 | void intel_init_clock_gating(struct drm_device *dev) |
| 6434 | { |
| 6435 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6436 | |
Damien Lespiau | c57e355 | 2015-02-09 19:33:05 +0000 | [diff] [blame] | 6437 | if (dev_priv->display.init_clock_gating) |
| 6438 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6439 | } |
| 6440 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6441 | void intel_suspend_hw(struct drm_device *dev) |
| 6442 | { |
| 6443 | if (HAS_PCH_LPT(dev)) |
| 6444 | lpt_suspend_hw(dev); |
| 6445 | } |
| 6446 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6447 | /* Set up chip specific power management-related functions */ |
| 6448 | void intel_init_pm(struct drm_device *dev) |
| 6449 | { |
| 6450 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6451 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 6452 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6453 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6454 | /* For cxsr */ |
| 6455 | if (IS_PINEVIEW(dev)) |
| 6456 | i915_pineview_get_mem_freq(dev); |
| 6457 | else if (IS_GEN5(dev)) |
| 6458 | i915_ironlake_get_mem_freq(dev); |
| 6459 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6460 | /* For FIFO watermark updates */ |
Damien Lespiau | f5ed50c | 2014-11-13 17:51:52 +0000 | [diff] [blame] | 6461 | if (INTEL_INFO(dev)->gen >= 9) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 6462 | skl_setup_wm_latency(dev); |
| 6463 | |
Damien Lespiau | 45db219 | 2015-02-09 19:33:09 +0000 | [diff] [blame] | 6464 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 6465 | dev_priv->display.update_wm = skl_update_wm; |
| 6466 | dev_priv->display.update_sprite_wm = skl_update_sprite_wm; |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6467 | } else if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6468 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6469 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6470 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6471 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6472 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6473 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6474 | dev_priv->display.update_wm = ilk_update_wm; |
| 6475 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6476 | } else { |
| 6477 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6478 | "Disable CxSR\n"); |
| 6479 | } |
| 6480 | |
| 6481 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6482 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6483 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6484 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6485 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6486 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6487 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6488 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6489 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6490 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6491 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 6492 | dev_priv->display.update_wm = cherryview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6493 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6494 | dev_priv->display.init_clock_gating = |
| 6495 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6496 | } else if (IS_VALLEYVIEW(dev)) { |
| 6497 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6498 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6499 | dev_priv->display.init_clock_gating = |
| 6500 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6501 | } else if (IS_PINEVIEW(dev)) { |
| 6502 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6503 | dev_priv->is_ddr3, |
| 6504 | dev_priv->fsb_freq, |
| 6505 | dev_priv->mem_freq)) { |
| 6506 | DRM_INFO("failed to find known CxSR latency " |
| 6507 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6508 | "disabling CxSR\n", |
| 6509 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6510 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6511 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6512 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6513 | dev_priv->display.update_wm = NULL; |
| 6514 | } else |
| 6515 | dev_priv->display.update_wm = pineview_update_wm; |
| 6516 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6517 | } else if (IS_G4X(dev)) { |
| 6518 | dev_priv->display.update_wm = g4x_update_wm; |
| 6519 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6520 | } else if (IS_GEN4(dev)) { |
| 6521 | dev_priv->display.update_wm = i965_update_wm; |
| 6522 | if (IS_CRESTLINE(dev)) |
| 6523 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6524 | else if (IS_BROADWATER(dev)) |
| 6525 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6526 | } else if (IS_GEN3(dev)) { |
| 6527 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6528 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6529 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6530 | } else if (IS_GEN2(dev)) { |
| 6531 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6532 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6533 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6534 | } else { |
| 6535 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6536 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6540 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6541 | else |
| 6542 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6543 | } else { |
| 6544 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6545 | } |
| 6546 | } |
| 6547 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6548 | 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] | 6549 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6550 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6551 | |
| 6552 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6553 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6554 | return -EAGAIN; |
| 6555 | } |
| 6556 | |
| 6557 | I915_WRITE(GEN6_PCODE_DATA, *val); |
Damien Lespiau | dddab34 | 2014-11-13 17:51:50 +0000 | [diff] [blame] | 6558 | I915_WRITE(GEN6_PCODE_DATA1, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6559 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6560 | |
| 6561 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6562 | 500)) { |
| 6563 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6564 | return -ETIMEDOUT; |
| 6565 | } |
| 6566 | |
| 6567 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6568 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6569 | |
| 6570 | return 0; |
| 6571 | } |
| 6572 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6573 | 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] | 6574 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6575 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6576 | |
| 6577 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6578 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6579 | return -EAGAIN; |
| 6580 | } |
| 6581 | |
| 6582 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6583 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6584 | |
| 6585 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6586 | 500)) { |
| 6587 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6588 | return -ETIMEDOUT; |
| 6589 | } |
| 6590 | |
| 6591 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6592 | |
| 6593 | return 0; |
| 6594 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6595 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6596 | static int vlv_gpu_freq_div(unsigned int czclk_freq) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6597 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6598 | switch (czclk_freq) { |
| 6599 | case 200: |
| 6600 | return 10; |
| 6601 | case 267: |
| 6602 | return 12; |
| 6603 | case 320: |
| 6604 | case 333: |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6605 | return 16; |
Ville Syrjälä | ab3fb15 | 2014-11-10 22:55:15 +0200 | [diff] [blame] | 6606 | case 400: |
| 6607 | return 20; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6608 | default: |
| 6609 | return -1; |
| 6610 | } |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6611 | } |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6612 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6613 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6614 | { |
| 6615 | int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
| 6616 | |
| 6617 | div = vlv_gpu_freq_div(czclk_freq); |
| 6618 | if (div < 0) |
| 6619 | return div; |
| 6620 | |
| 6621 | return DIV_ROUND_CLOSEST(czclk_freq * (val + 6 - 0xbd), div); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6622 | } |
| 6623 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6624 | 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] | 6625 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6626 | int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6627 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6628 | mul = vlv_gpu_freq_div(czclk_freq); |
| 6629 | if (mul < 0) |
| 6630 | return mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6631 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6632 | return DIV_ROUND_CLOSEST(mul * val, czclk_freq) + 0xbd - 6; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6633 | } |
| 6634 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6635 | 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] | 6636 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6637 | int div, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6638 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6639 | div = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6640 | if (div < 0) |
| 6641 | return div; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6642 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6643 | return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6644 | } |
| 6645 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6646 | 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] | 6647 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6648 | int mul, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6649 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6650 | mul = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6651 | if (mul < 0) |
| 6652 | return mul; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6653 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 6654 | /* CHV needs even values */ |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6655 | return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6656 | } |
| 6657 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6658 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6659 | { |
| 6660 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 6661 | return chv_gpu_freq(dev_priv, val); |
| 6662 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 6663 | return byt_gpu_freq(dev_priv, val); |
| 6664 | else |
| 6665 | return val * GT_FREQUENCY_MULTIPLIER; |
| 6666 | } |
| 6667 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6668 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 6669 | { |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6670 | if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6671 | return chv_freq_opcode(dev_priv, val); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6672 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6673 | return byt_freq_opcode(dev_priv, val); |
| 6674 | else |
| 6675 | return val / GT_FREQUENCY_MULTIPLIER; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6676 | } |
| 6677 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6678 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6679 | { |
| 6680 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6681 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6682 | mutex_init(&dev_priv->rps.hw_lock); |
| 6683 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6684 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 6685 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6686 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 6687 | dev_priv->pm.suspended = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6688 | } |