Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eugeni Dodonov <eugeni.dodonov@intel.com> |
| 25 | * |
| 26 | */ |
| 27 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 28 | #include <linux/cpufreq.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 29 | #include "i915_drv.h" |
| 30 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 31 | #include "../../../platform/x86/intel_ips.h" |
| 32 | #include <linux/module.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 33 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 34 | /** |
| 35 | * RC6 is a special power stage which allows the GPU to enter an very |
| 36 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 37 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 38 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 39 | * |
| 40 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 41 | * among each other with the latency required to enter and leave RC6 and |
| 42 | * voltage consumed by the GPU in different states. |
| 43 | * |
| 44 | * The combination of the following flags define which states GPU is allowed |
| 45 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 46 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 47 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 48 | * which brings the most power savings; deeper states save more power, but |
| 49 | * require higher latency to switch to and wake up. |
| 50 | */ |
| 51 | #define INTEL_RC6_ENABLE (1<<0) |
| 52 | #define INTEL_RC6p_ENABLE (1<<1) |
| 53 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 54 | |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 55 | static void gen9_init_clock_gating(struct drm_device *dev) |
| 56 | { |
Damien Lespiau | acd5c34 | 2014-03-26 16:55:46 +0000 | [diff] [blame] | 57 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 58 | |
Damien Lespiau | 77719d2 | 2015-02-09 19:33:13 +0000 | [diff] [blame] | 59 | /* WaEnableLbsSlaRetryTimerDecrement:skl */ |
| 60 | I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) | |
| 61 | GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE); |
| 62 | } |
Damien Lespiau | 91e41d1 | 2014-03-26 17:42:50 +0000 | [diff] [blame] | 63 | |
Damien Lespiau | 45db219 | 2015-02-09 19:33:09 +0000 | [diff] [blame] | 64 | static void skl_init_clock_gating(struct drm_device *dev) |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 65 | { |
Damien Lespiau | acd5c34 | 2014-03-26 16:55:46 +0000 | [diff] [blame] | 66 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 3ca5da4 | 2014-03-26 18:18:01 +0000 | [diff] [blame] | 67 | |
Damien Lespiau | 77719d2 | 2015-02-09 19:33:13 +0000 | [diff] [blame] | 68 | gen9_init_clock_gating(dev); |
| 69 | |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 70 | if (INTEL_REVID(dev) == SKL_REVID_A0) { |
| 71 | /* |
| 72 | * WaDisableSDEUnitClockGating:skl |
Damien Lespiau | 9253c2e | 2015-02-09 19:33:10 +0000 | [diff] [blame] | 73 | * WaSetGAPSunitClckGateDisable:skl |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 74 | */ |
| 75 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Damien Lespiau | 9253c2e | 2015-02-09 19:33:10 +0000 | [diff] [blame] | 76 | GEN8_GAPSUNIT_CLOCK_GATE_DISABLE | |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 77 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 78 | } |
Damien Lespiau | 8bc0ccf | 2015-02-09 19:33:18 +0000 | [diff] [blame] | 79 | |
Damien Lespiau | 2caa3b2 | 2015-02-09 19:33:20 +0000 | [diff] [blame] | 80 | if (INTEL_REVID(dev) <= SKL_REVID_D0) { |
Damien Lespiau | 81e231a | 2015-02-09 19:33:19 +0000 | [diff] [blame] | 81 | /* WaDisableHDCInvalidation:skl */ |
| 82 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | |
| 83 | BDW_DISABLE_HDC_INVALIDATION); |
| 84 | |
Damien Lespiau | 2caa3b2 | 2015-02-09 19:33:20 +0000 | [diff] [blame] | 85 | /* WaDisableChickenBitTSGBarrierAckForFFSliceCS:skl */ |
| 86 | I915_WRITE(FF_SLICE_CS_CHICKEN2, |
| 87 | I915_READ(FF_SLICE_CS_CHICKEN2) | |
| 88 | GEN9_TSG_BARRIER_ACK_DISABLE); |
| 89 | } |
Damien Lespiau | 81e231a | 2015-02-09 19:33:19 +0000 | [diff] [blame] | 90 | |
Damien Lespiau | 8bc0ccf | 2015-02-09 19:33:18 +0000 | [diff] [blame] | 91 | if (INTEL_REVID(dev) <= SKL_REVID_E0) |
| 92 | /* WaDisableLSQCROPERFforOCL:skl */ |
| 93 | I915_WRITE(GEN8_L3SQCREG4, I915_READ(GEN8_L3SQCREG4) | |
| 94 | GEN8_LQSC_RO_PERF_DIS); |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 95 | } |
| 96 | |
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 | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 556 | int pixel_size = crtc->primary->state->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 | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 632 | pixel_size = crtc->primary->state->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; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 647 | entries = line_count * crtc->cursor->state->crtc_w * 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 | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 719 | pixel_size = crtc->primary->state->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 */ |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 733 | entries = line_count * pixel_size * crtc->cursor->state->crtc_w; |
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 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 742 | static uint8_t vlv_compute_drain_latency(struct drm_crtc *crtc, |
| 743 | int pixel_size) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 744 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 745 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 746 | int entries, prec_mult, drain_latency; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 747 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 748 | const int high_precision = IS_CHERRYVIEW(dev) ? 16 : 64; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 749 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 750 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 751 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 752 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 753 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 754 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 755 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 756 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 757 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 758 | prec_mult = high_precision; |
| 759 | drain_latency = 64 * prec_mult * 4 / entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 760 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 761 | if (drain_latency > DRAIN_LATENCY_MASK) { |
| 762 | prec_mult /= 2; |
| 763 | drain_latency = 64 * prec_mult * 4 / entries; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 764 | } |
| 765 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [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 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 769 | return drain_latency | (prec_mult == high_precision ? |
| 770 | DDL_PRECISION_HIGH : DDL_PRECISION_LOW); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | /* |
| 774 | * Update drain latency registers of memory arbiter |
| 775 | * |
| 776 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 777 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 778 | * latency value. |
| 779 | */ |
| 780 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 781 | static void vlv_update_drain_latency(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 782 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 783 | struct drm_device *dev = crtc->dev; |
| 784 | struct drm_i915_private *dev_priv = dev->dev_private; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 785 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 786 | int pixel_size; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 787 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 788 | int plane_dl; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 789 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 790 | plane_dl = I915_READ(VLV_DDL(pipe)) & |
| 791 | ~(((DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK) << DDL_CURSOR_SHIFT) | |
| 792 | ((DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK) << DDL_PLANE_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 793 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 794 | if (!intel_crtc_active(crtc)) { |
| 795 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
| 796 | return; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 797 | } |
| 798 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 799 | /* Primary plane Drain Latency */ |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 800 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; /* BPP */ |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 801 | plane_dl = vlv_compute_drain_latency(crtc, pixel_size) << DDL_PLANE_SHIFT; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 802 | |
| 803 | /* Cursor Drain Latency |
| 804 | * BPP is always 4 for cursor |
| 805 | */ |
| 806 | pixel_size = 4; |
| 807 | |
| 808 | /* Program cursor DL only if it is enabled */ |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 809 | if (intel_crtc->cursor_base) |
| 810 | plane_dl |= vlv_compute_drain_latency(crtc, pixel_size) << DDL_CURSOR_SHIFT; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 811 | |
| 812 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 816 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 817 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 818 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 819 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 820 | static const int sr_latency_ns = 12000; |
| 821 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 822 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 823 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 824 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 825 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 826 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 827 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 828 | vlv_update_drain_latency(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 829 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 830 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 831 | &valleyview_wm_info, pessimal_latency_ns, |
| 832 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 833 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 834 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 835 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 836 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 837 | &valleyview_wm_info, pessimal_latency_ns, |
| 838 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 839 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 840 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 841 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 842 | if (single_plane_enabled(enabled) && |
| 843 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 844 | sr_latency_ns, |
| 845 | &valleyview_wm_info, |
| 846 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 847 | &plane_sr, &ignore_cursor_sr) && |
| 848 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 849 | 2*sr_latency_ns, |
| 850 | &valleyview_wm_info, |
| 851 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 852 | &ignore_plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 853 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 854 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 855 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 856 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 857 | plane_sr = cursor_sr = 0; |
| 858 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 859 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 860 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 861 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 862 | planea_wm, cursora_wm, |
| 863 | planeb_wm, cursorb_wm, |
| 864 | plane_sr, cursor_sr); |
| 865 | |
| 866 | I915_WRITE(DSPFW1, |
| 867 | (plane_sr << DSPFW_SR_SHIFT) | |
| 868 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 869 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 870 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 871 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 872 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 873 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 874 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 875 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 876 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 877 | |
| 878 | if (cxsr_enabled) |
| 879 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 880 | } |
| 881 | |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 882 | static void cherryview_update_wm(struct drm_crtc *crtc) |
| 883 | { |
| 884 | struct drm_device *dev = crtc->dev; |
| 885 | static const int sr_latency_ns = 12000; |
| 886 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 887 | int planea_wm, planeb_wm, planec_wm; |
| 888 | int cursora_wm, cursorb_wm, cursorc_wm; |
| 889 | int plane_sr, cursor_sr; |
| 890 | int ignore_plane_sr, ignore_cursor_sr; |
| 891 | unsigned int enabled = 0; |
| 892 | bool cxsr_enabled; |
| 893 | |
| 894 | vlv_update_drain_latency(crtc); |
| 895 | |
| 896 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 897 | &valleyview_wm_info, pessimal_latency_ns, |
| 898 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 899 | &planea_wm, &cursora_wm)) |
| 900 | enabled |= 1 << PIPE_A; |
| 901 | |
| 902 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 903 | &valleyview_wm_info, pessimal_latency_ns, |
| 904 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 905 | &planeb_wm, &cursorb_wm)) |
| 906 | enabled |= 1 << PIPE_B; |
| 907 | |
| 908 | if (g4x_compute_wm0(dev, PIPE_C, |
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 | &planec_wm, &cursorc_wm)) |
| 912 | enabled |= 1 << PIPE_C; |
| 913 | |
| 914 | if (single_plane_enabled(enabled) && |
| 915 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 916 | sr_latency_ns, |
| 917 | &valleyview_wm_info, |
| 918 | &valleyview_cursor_wm_info, |
| 919 | &plane_sr, &ignore_cursor_sr) && |
| 920 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 921 | 2*sr_latency_ns, |
| 922 | &valleyview_wm_info, |
| 923 | &valleyview_cursor_wm_info, |
| 924 | &ignore_plane_sr, &cursor_sr)) { |
| 925 | cxsr_enabled = true; |
| 926 | } else { |
| 927 | cxsr_enabled = false; |
| 928 | intel_set_memory_cxsr(dev_priv, false); |
| 929 | plane_sr = cursor_sr = 0; |
| 930 | } |
| 931 | |
| 932 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 933 | "B: plane=%d, cursor=%d, C: plane=%d, cursor=%d, " |
| 934 | "SR: plane=%d, cursor=%d\n", |
| 935 | planea_wm, cursora_wm, |
| 936 | planeb_wm, cursorb_wm, |
| 937 | planec_wm, cursorc_wm, |
| 938 | plane_sr, cursor_sr); |
| 939 | |
| 940 | I915_WRITE(DSPFW1, |
| 941 | (plane_sr << DSPFW_SR_SHIFT) | |
| 942 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 943 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 944 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
| 945 | I915_WRITE(DSPFW2, |
| 946 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
| 947 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 948 | I915_WRITE(DSPFW3, |
| 949 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 950 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 951 | I915_WRITE(DSPFW9_CHV, |
| 952 | (I915_READ(DSPFW9_CHV) & ~(DSPFW_PLANEC_MASK | |
| 953 | DSPFW_CURSORC_MASK)) | |
| 954 | (planec_wm << DSPFW_PLANEC_SHIFT) | |
| 955 | (cursorc_wm << DSPFW_CURSORC_SHIFT)); |
| 956 | |
| 957 | if (cxsr_enabled) |
| 958 | intel_set_memory_cxsr(dev_priv, true); |
| 959 | } |
| 960 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 961 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 962 | struct drm_crtc *crtc, |
| 963 | uint32_t sprite_width, |
| 964 | uint32_t sprite_height, |
| 965 | int pixel_size, |
| 966 | bool enabled, bool scaled) |
| 967 | { |
| 968 | struct drm_device *dev = crtc->dev; |
| 969 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 970 | int pipe = to_intel_plane(plane)->pipe; |
| 971 | int sprite = to_intel_plane(plane)->plane; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 972 | int sprite_dl; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 973 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 974 | sprite_dl = I915_READ(VLV_DDL(pipe)) & |
| 975 | ~((DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK) << DDL_SPRITE_SHIFT(sprite)); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 976 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame^] | 977 | if (enabled) |
| 978 | sprite_dl |= vlv_compute_drain_latency(crtc, pixel_size) << DDL_SPRITE_SHIFT(sprite); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 979 | |
| 980 | I915_WRITE(VLV_DDL(pipe), sprite_dl); |
| 981 | } |
| 982 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 983 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 984 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 985 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 986 | static const int sr_latency_ns = 12000; |
| 987 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 988 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 989 | int plane_sr, cursor_sr; |
| 990 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 991 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 992 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 993 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 994 | &g4x_wm_info, pessimal_latency_ns, |
| 995 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 996 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 997 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 998 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 999 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1000 | &g4x_wm_info, pessimal_latency_ns, |
| 1001 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1002 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1003 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1004 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1005 | if (single_plane_enabled(enabled) && |
| 1006 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1007 | sr_latency_ns, |
| 1008 | &g4x_wm_info, |
| 1009 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1010 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1011 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1012 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1013 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1014 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1015 | plane_sr = cursor_sr = 0; |
| 1016 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1017 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1018 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1019 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1020 | planea_wm, cursora_wm, |
| 1021 | planeb_wm, cursorb_wm, |
| 1022 | plane_sr, cursor_sr); |
| 1023 | |
| 1024 | I915_WRITE(DSPFW1, |
| 1025 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1026 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1027 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1028 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1029 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1030 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1031 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1032 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1033 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1034 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1035 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1036 | |
| 1037 | if (cxsr_enabled) |
| 1038 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1039 | } |
| 1040 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1041 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1042 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1043 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1044 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1045 | struct drm_crtc *crtc; |
| 1046 | int srwm = 1; |
| 1047 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1048 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1049 | |
| 1050 | /* Calc sr entries for one plane configs */ |
| 1051 | crtc = single_enabled_crtc(dev); |
| 1052 | if (crtc) { |
| 1053 | /* self-refresh has much higher latency */ |
| 1054 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1055 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1056 | &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1057 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1058 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1059 | int hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1060 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1061 | unsigned long line_time_us; |
| 1062 | int entries; |
| 1063 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1064 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1065 | |
| 1066 | /* Use ns/us then divide to preserve precision */ |
| 1067 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1068 | pixel_size * hdisplay; |
| 1069 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1070 | srwm = I965_FIFO_SIZE - entries; |
| 1071 | if (srwm < 0) |
| 1072 | srwm = 1; |
| 1073 | srwm &= 0x1ff; |
| 1074 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1075 | entries, srwm); |
| 1076 | |
| 1077 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 1078 | pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1079 | entries = DIV_ROUND_UP(entries, |
| 1080 | i965_cursor_wm_info.cacheline_size); |
| 1081 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1082 | (entries + i965_cursor_wm_info.guard_size); |
| 1083 | |
| 1084 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1085 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1086 | |
| 1087 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1088 | "cursor %d\n", srwm, cursor_sr); |
| 1089 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1090 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1091 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1092 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1093 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1094 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1098 | srwm); |
| 1099 | |
| 1100 | /* 965 has limitations... */ |
| 1101 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1102 | (8 << DSPFW_CURSORB_SHIFT) | |
| 1103 | (8 << DSPFW_PLANEB_SHIFT) | |
| 1104 | (8 << DSPFW_PLANEA_SHIFT)); |
| 1105 | I915_WRITE(DSPFW2, (8 << DSPFW_CURSORA_SHIFT) | |
| 1106 | (8 << DSPFW_PLANEC_SHIFT_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1107 | /* update cursor SR watermark */ |
| 1108 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1109 | |
| 1110 | if (cxsr_enabled) |
| 1111 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1112 | } |
| 1113 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1114 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1115 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1116 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1117 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1118 | const struct intel_watermark_params *wm_info; |
| 1119 | uint32_t fwater_lo; |
| 1120 | uint32_t fwater_hi; |
| 1121 | int cwm, srwm = 1; |
| 1122 | int fifo_size; |
| 1123 | int planea_wm, planeb_wm; |
| 1124 | struct drm_crtc *crtc, *enabled = NULL; |
| 1125 | |
| 1126 | if (IS_I945GM(dev)) |
| 1127 | wm_info = &i945_wm_info; |
| 1128 | else if (!IS_GEN2(dev)) |
| 1129 | wm_info = &i915_wm_info; |
| 1130 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1131 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1132 | |
| 1133 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1134 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1135 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1136 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1137 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1138 | if (IS_GEN2(dev)) |
| 1139 | cpp = 4; |
| 1140 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1141 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1142 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1143 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1144 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1145 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1146 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1147 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1148 | if (planea_wm > (long)wm_info->max_wm) |
| 1149 | planea_wm = wm_info->max_wm; |
| 1150 | } |
| 1151 | |
| 1152 | if (IS_GEN2(dev)) |
| 1153 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1154 | |
| 1155 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1156 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1157 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1158 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1159 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1160 | if (IS_GEN2(dev)) |
| 1161 | cpp = 4; |
| 1162 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1163 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1164 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1165 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1166 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1167 | if (enabled == NULL) |
| 1168 | enabled = crtc; |
| 1169 | else |
| 1170 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1171 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1172 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1173 | if (planeb_wm > (long)wm_info->max_wm) |
| 1174 | planeb_wm = wm_info->max_wm; |
| 1175 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1176 | |
| 1177 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1178 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1179 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1180 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1181 | |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1182 | obj = intel_fb_obj(enabled->primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1183 | |
| 1184 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1185 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1186 | enabled = NULL; |
| 1187 | } |
| 1188 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1189 | /* |
| 1190 | * Overlay gets an aggressive default since video jitter is bad. |
| 1191 | */ |
| 1192 | cwm = 2; |
| 1193 | |
| 1194 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1195 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1196 | |
| 1197 | /* Calc sr entries for one plane configs */ |
| 1198 | if (HAS_FW_BLC(dev) && enabled) { |
| 1199 | /* self-refresh has much higher latency */ |
| 1200 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1201 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1202 | &to_intel_crtc(enabled)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1203 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1204 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1205 | int hdisplay = to_intel_crtc(enabled)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1206 | int pixel_size = enabled->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1207 | unsigned long line_time_us; |
| 1208 | int entries; |
| 1209 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1210 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1211 | |
| 1212 | /* Use ns/us then divide to preserve precision */ |
| 1213 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1214 | pixel_size * hdisplay; |
| 1215 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1216 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1217 | srwm = wm_info->fifo_size - entries; |
| 1218 | if (srwm < 0) |
| 1219 | srwm = 1; |
| 1220 | |
| 1221 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1222 | I915_WRITE(FW_BLC_SELF, |
| 1223 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1224 | else if (IS_I915GM(dev)) |
| 1225 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1226 | } |
| 1227 | |
| 1228 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1229 | planea_wm, planeb_wm, cwm, srwm); |
| 1230 | |
| 1231 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1232 | fwater_hi = (cwm & 0x1f); |
| 1233 | |
| 1234 | /* Set request length to 8 cachelines per fetch */ |
| 1235 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1236 | fwater_hi = fwater_hi | (1 << 8); |
| 1237 | |
| 1238 | I915_WRITE(FW_BLC, fwater_lo); |
| 1239 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1240 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1241 | if (enabled) |
| 1242 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1243 | } |
| 1244 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1245 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1246 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1247 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1248 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1249 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1250 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1251 | uint32_t fwater_lo; |
| 1252 | int planea_wm; |
| 1253 | |
| 1254 | crtc = single_enabled_crtc(dev); |
| 1255 | if (crtc == NULL) |
| 1256 | return; |
| 1257 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1258 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1259 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1260 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1261 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1262 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1263 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1264 | fwater_lo |= (3<<8) | planea_wm; |
| 1265 | |
| 1266 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1267 | |
| 1268 | I915_WRITE(FW_BLC, fwater_lo); |
| 1269 | } |
| 1270 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1271 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1272 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1273 | { |
| 1274 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1275 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1276 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1277 | pixel_rate = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1278 | |
| 1279 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1280 | * adjust the pixel_rate here. */ |
| 1281 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1282 | if (intel_crtc->config->pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1283 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1284 | uint32_t pfit_size = intel_crtc->config->pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1285 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1286 | pipe_w = intel_crtc->config->pipe_src_w; |
| 1287 | pipe_h = intel_crtc->config->pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1288 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1289 | pfit_h = pfit_size & 0xFFFF; |
| 1290 | if (pipe_w < pfit_w) |
| 1291 | pipe_w = pfit_w; |
| 1292 | if (pipe_h < pfit_h) |
| 1293 | pipe_h = pfit_h; |
| 1294 | |
| 1295 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1296 | pfit_w * pfit_h); |
| 1297 | } |
| 1298 | |
| 1299 | return pixel_rate; |
| 1300 | } |
| 1301 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1302 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1303 | 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] | 1304 | uint32_t latency) |
| 1305 | { |
| 1306 | uint64_t ret; |
| 1307 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1308 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1309 | return UINT_MAX; |
| 1310 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1311 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1312 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1313 | |
| 1314 | return ret; |
| 1315 | } |
| 1316 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1317 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1318 | 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] | 1319 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1320 | uint32_t latency) |
| 1321 | { |
| 1322 | uint32_t ret; |
| 1323 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1324 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1325 | return UINT_MAX; |
| 1326 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1327 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1328 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1329 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1330 | return ret; |
| 1331 | } |
| 1332 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1333 | 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] | 1334 | uint8_t bytes_per_pixel) |
| 1335 | { |
| 1336 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1337 | } |
| 1338 | |
Pradeep Bhat | 2ac96d2 | 2014-11-04 17:06:40 +0000 | [diff] [blame] | 1339 | struct skl_pipe_wm_parameters { |
| 1340 | bool active; |
| 1341 | uint32_t pipe_htotal; |
| 1342 | uint32_t pixel_rate; /* in KHz */ |
| 1343 | struct intel_plane_wm_parameters plane[I915_MAX_PLANES]; |
| 1344 | struct intel_plane_wm_parameters cursor; |
| 1345 | }; |
| 1346 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1347 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1348 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1349 | uint32_t pipe_htotal; |
| 1350 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1351 | struct intel_plane_wm_parameters pri; |
| 1352 | struct intel_plane_wm_parameters spr; |
| 1353 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1354 | }; |
| 1355 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1356 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1357 | uint16_t pri; |
| 1358 | uint16_t spr; |
| 1359 | uint16_t cur; |
| 1360 | uint16_t fbc; |
| 1361 | }; |
| 1362 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1363 | /* used in computing the new watermarks state */ |
| 1364 | struct intel_wm_config { |
| 1365 | unsigned int num_pipes_active; |
| 1366 | bool sprites_enabled; |
| 1367 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1368 | }; |
| 1369 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1370 | /* |
| 1371 | * For both WM_PIPE and WM_LP. |
| 1372 | * mem_value must be in 0.1us units. |
| 1373 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1374 | 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] | 1375 | uint32_t mem_value, |
| 1376 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1377 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1378 | uint32_t method1, method2; |
| 1379 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1380 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1381 | return 0; |
| 1382 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1383 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1384 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1385 | mem_value); |
| 1386 | |
| 1387 | if (!is_lp) |
| 1388 | return method1; |
| 1389 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1390 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1391 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1392 | params->pri.horiz_pixels, |
| 1393 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1394 | mem_value); |
| 1395 | |
| 1396 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1397 | } |
| 1398 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1399 | /* |
| 1400 | * For both WM_PIPE and WM_LP. |
| 1401 | * mem_value must be in 0.1us units. |
| 1402 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1403 | 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] | 1404 | uint32_t mem_value) |
| 1405 | { |
| 1406 | uint32_t method1, method2; |
| 1407 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1408 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1409 | return 0; |
| 1410 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1411 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1412 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1413 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1414 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1415 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1416 | params->spr.horiz_pixels, |
| 1417 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1418 | mem_value); |
| 1419 | return min(method1, method2); |
| 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_cur_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 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1429 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1430 | return 0; |
| 1431 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1432 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1433 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1434 | params->cur.horiz_pixels, |
| 1435 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1436 | mem_value); |
| 1437 | } |
| 1438 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1439 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1440 | 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] | 1441 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1442 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1443 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1444 | return 0; |
| 1445 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1446 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1447 | params->pri.horiz_pixels, |
| 1448 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1449 | } |
| 1450 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1451 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1452 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1453 | if (INTEL_INFO(dev)->gen >= 8) |
| 1454 | return 3072; |
| 1455 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1456 | return 768; |
| 1457 | else |
| 1458 | return 512; |
| 1459 | } |
| 1460 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1461 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1462 | int level, bool is_sprite) |
| 1463 | { |
| 1464 | if (INTEL_INFO(dev)->gen >= 8) |
| 1465 | /* BDW primary/sprite plane watermarks */ |
| 1466 | return level == 0 ? 255 : 2047; |
| 1467 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1468 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1469 | return level == 0 ? 127 : 1023; |
| 1470 | else if (!is_sprite) |
| 1471 | /* ILK/SNB primary plane watermarks */ |
| 1472 | return level == 0 ? 127 : 511; |
| 1473 | else |
| 1474 | /* ILK/SNB sprite plane watermarks */ |
| 1475 | return level == 0 ? 63 : 255; |
| 1476 | } |
| 1477 | |
| 1478 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1479 | int level) |
| 1480 | { |
| 1481 | if (INTEL_INFO(dev)->gen >= 7) |
| 1482 | return level == 0 ? 63 : 255; |
| 1483 | else |
| 1484 | return level == 0 ? 31 : 63; |
| 1485 | } |
| 1486 | |
| 1487 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1488 | { |
| 1489 | if (INTEL_INFO(dev)->gen >= 8) |
| 1490 | return 31; |
| 1491 | else |
| 1492 | return 15; |
| 1493 | } |
| 1494 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1495 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1496 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1497 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1498 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1499 | enum intel_ddb_partitioning ddb_partitioning, |
| 1500 | bool is_sprite) |
| 1501 | { |
| 1502 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1503 | |
| 1504 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1505 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1506 | return 0; |
| 1507 | |
| 1508 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1509 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1510 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1511 | |
| 1512 | /* |
| 1513 | * For some reason the non self refresh |
| 1514 | * FIFO size is only half of the self |
| 1515 | * refresh FIFO size on ILK/SNB. |
| 1516 | */ |
| 1517 | if (INTEL_INFO(dev)->gen <= 6) |
| 1518 | fifo_size /= 2; |
| 1519 | } |
| 1520 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1521 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1522 | /* level 0 is always calculated with 1:1 split */ |
| 1523 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1524 | if (is_sprite) |
| 1525 | fifo_size *= 5; |
| 1526 | fifo_size /= 6; |
| 1527 | } else { |
| 1528 | fifo_size /= 2; |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1533 | 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] | 1534 | } |
| 1535 | |
| 1536 | /* Calculate the maximum cursor plane watermark */ |
| 1537 | 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] | 1538 | int level, |
| 1539 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1540 | { |
| 1541 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1542 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1543 | return 64; |
| 1544 | |
| 1545 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1546 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1547 | } |
| 1548 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1549 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1550 | int level, |
| 1551 | const struct intel_wm_config *config, |
| 1552 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1553 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1554 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1555 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1556 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1557 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1558 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1559 | } |
| 1560 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1561 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1562 | int level, |
| 1563 | struct ilk_wm_maximums *max) |
| 1564 | { |
| 1565 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1566 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1567 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1568 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1569 | } |
| 1570 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1571 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1572 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1573 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1574 | { |
| 1575 | bool ret; |
| 1576 | |
| 1577 | /* already determined to be invalid? */ |
| 1578 | if (!result->enable) |
| 1579 | return false; |
| 1580 | |
| 1581 | result->enable = result->pri_val <= max->pri && |
| 1582 | result->spr_val <= max->spr && |
| 1583 | result->cur_val <= max->cur; |
| 1584 | |
| 1585 | ret = result->enable; |
| 1586 | |
| 1587 | /* |
| 1588 | * HACK until we can pre-compute everything, |
| 1589 | * and thus fail gracefully if LP0 watermarks |
| 1590 | * are exceeded... |
| 1591 | */ |
| 1592 | if (level == 0 && !result->enable) { |
| 1593 | if (result->pri_val > max->pri) |
| 1594 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 1595 | level, result->pri_val, max->pri); |
| 1596 | if (result->spr_val > max->spr) |
| 1597 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 1598 | level, result->spr_val, max->spr); |
| 1599 | if (result->cur_val > max->cur) |
| 1600 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 1601 | level, result->cur_val, max->cur); |
| 1602 | |
| 1603 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 1604 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 1605 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 1606 | result->enable = true; |
| 1607 | } |
| 1608 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1609 | return ret; |
| 1610 | } |
| 1611 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1612 | 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] | 1613 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1614 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 1615 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1616 | { |
| 1617 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 1618 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 1619 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 1620 | |
| 1621 | /* WM1+ latency values stored in 0.5us units */ |
| 1622 | if (level > 0) { |
| 1623 | pri_latency *= 5; |
| 1624 | spr_latency *= 5; |
| 1625 | cur_latency *= 5; |
| 1626 | } |
| 1627 | |
| 1628 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 1629 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 1630 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 1631 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 1632 | result->enable = true; |
| 1633 | } |
| 1634 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1635 | static uint32_t |
| 1636 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1637 | { |
| 1638 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1639 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1640 | struct drm_display_mode *mode = &intel_crtc->config->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1641 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1642 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1643 | if (!intel_crtc_active(crtc)) |
| 1644 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1645 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1646 | /* The WM are computed with base on how long it takes to fill a single |
| 1647 | * row at the given clock rate, multiplied by 8. |
| 1648 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1649 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 1650 | mode->crtc_clock); |
| 1651 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1652 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1653 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1654 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 1655 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1656 | } |
| 1657 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1658 | 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] | 1659 | { |
| 1660 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1661 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1662 | if (IS_GEN9(dev)) { |
| 1663 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1664 | int ret, i; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1665 | int level, max_level = ilk_wm_max_level(dev); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1666 | |
| 1667 | /* read the first set of memory latencies[0:3] */ |
| 1668 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 1669 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1670 | ret = sandybridge_pcode_read(dev_priv, |
| 1671 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1672 | &val); |
| 1673 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1674 | |
| 1675 | if (ret) { |
| 1676 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1677 | return; |
| 1678 | } |
| 1679 | |
| 1680 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1681 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1682 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1683 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1684 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1685 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1686 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1687 | |
| 1688 | /* read the second set of memory latencies[4:7] */ |
| 1689 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 1690 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1691 | ret = sandybridge_pcode_read(dev_priv, |
| 1692 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1693 | &val); |
| 1694 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1695 | if (ret) { |
| 1696 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1697 | return; |
| 1698 | } |
| 1699 | |
| 1700 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1701 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1702 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1703 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1704 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1705 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1706 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1707 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1708 | /* |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 1709 | * WaWmMemoryReadLatency:skl |
| 1710 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1711 | * punit doesn't take into account the read latency so we need |
| 1712 | * to add 2us to the various latency levels we retrieve from |
| 1713 | * the punit. |
| 1714 | * - W0 is a bit special in that it's the only level that |
| 1715 | * can't be disabled if we want to have display working, so |
| 1716 | * we always add 2us there. |
| 1717 | * - For levels >=1, punit returns 0us latency when they are |
| 1718 | * disabled, so we respect that and don't add 2us then |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1719 | * |
| 1720 | * Additionally, if a level n (n > 1) has a 0us latency, all |
| 1721 | * levels m (m >= n) need to be disabled. We make sure to |
| 1722 | * sanitize the values out of the punit to satisfy this |
| 1723 | * requirement. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1724 | */ |
| 1725 | wm[0] += 2; |
| 1726 | for (level = 1; level <= max_level; level++) |
| 1727 | if (wm[level] != 0) |
| 1728 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1729 | else { |
| 1730 | for (i = level + 1; i <= max_level; i++) |
| 1731 | wm[i] = 0; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1732 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1733 | break; |
| 1734 | } |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1735 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1736 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 1737 | |
| 1738 | wm[0] = (sskpd >> 56) & 0xFF; |
| 1739 | if (wm[0] == 0) |
| 1740 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 1741 | wm[1] = (sskpd >> 4) & 0xFF; |
| 1742 | wm[2] = (sskpd >> 12) & 0xFF; |
| 1743 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 1744 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 1745 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 1746 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 1747 | |
| 1748 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 1749 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 1750 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 1751 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 1752 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1753 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 1754 | |
| 1755 | /* ILK primary LP0 latency is 700 ns */ |
| 1756 | wm[0] = 7; |
| 1757 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 1758 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1762 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1763 | { |
| 1764 | /* ILK sprite LP0 latency is 1300 ns */ |
| 1765 | if (INTEL_INFO(dev)->gen == 5) |
| 1766 | wm[0] = 13; |
| 1767 | } |
| 1768 | |
| 1769 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1770 | { |
| 1771 | /* ILK cursor LP0 latency is 1300 ns */ |
| 1772 | if (INTEL_INFO(dev)->gen == 5) |
| 1773 | wm[0] = 13; |
| 1774 | |
| 1775 | /* WaDoubleCursorLP3Latency:ivb */ |
| 1776 | if (IS_IVYBRIDGE(dev)) |
| 1777 | wm[3] *= 2; |
| 1778 | } |
| 1779 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 1780 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1781 | { |
| 1782 | /* how many WM levels are we expecting */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1783 | if (IS_GEN9(dev)) |
| 1784 | return 7; |
| 1785 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1786 | return 4; |
| 1787 | else if (INTEL_INFO(dev)->gen >= 6) |
| 1788 | return 3; |
| 1789 | else |
| 1790 | return 2; |
| 1791 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 1792 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1793 | static void intel_print_wm_latency(struct drm_device *dev, |
| 1794 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1795 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1796 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1797 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1798 | |
| 1799 | for (level = 0; level <= max_level; level++) { |
| 1800 | unsigned int latency = wm[level]; |
| 1801 | |
| 1802 | if (latency == 0) { |
| 1803 | DRM_ERROR("%s WM%d latency not provided\n", |
| 1804 | name, level); |
| 1805 | continue; |
| 1806 | } |
| 1807 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1808 | /* |
| 1809 | * - latencies are in us on gen9. |
| 1810 | * - before then, WM1+ latency values are in 0.5us units |
| 1811 | */ |
| 1812 | if (IS_GEN9(dev)) |
| 1813 | latency *= 10; |
| 1814 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1815 | latency *= 5; |
| 1816 | |
| 1817 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 1818 | name, level, wm[level], |
| 1819 | latency / 10, latency % 10); |
| 1820 | } |
| 1821 | } |
| 1822 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 1823 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 1824 | uint16_t wm[5], uint16_t min) |
| 1825 | { |
| 1826 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 1827 | |
| 1828 | if (wm[0] >= min) |
| 1829 | return false; |
| 1830 | |
| 1831 | wm[0] = max(wm[0], min); |
| 1832 | for (level = 1; level <= max_level; level++) |
| 1833 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 1834 | |
| 1835 | return true; |
| 1836 | } |
| 1837 | |
| 1838 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 1839 | { |
| 1840 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1841 | bool changed; |
| 1842 | |
| 1843 | /* |
| 1844 | * The BIOS provided WM memory latency values are often |
| 1845 | * inadequate for high resolution displays. Adjust them. |
| 1846 | */ |
| 1847 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 1848 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 1849 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 1850 | |
| 1851 | if (!changed) |
| 1852 | return; |
| 1853 | |
| 1854 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 1855 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 1856 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 1857 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 1858 | } |
| 1859 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 1860 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1861 | { |
| 1862 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1863 | |
| 1864 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 1865 | |
| 1866 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 1867 | sizeof(dev_priv->wm.pri_latency)); |
| 1868 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 1869 | sizeof(dev_priv->wm.pri_latency)); |
| 1870 | |
| 1871 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 1872 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1873 | |
| 1874 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 1875 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 1876 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 1877 | |
| 1878 | if (IS_GEN6(dev)) |
| 1879 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1880 | } |
| 1881 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1882 | static void skl_setup_wm_latency(struct drm_device *dev) |
| 1883 | { |
| 1884 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1885 | |
| 1886 | intel_read_wm_latency(dev, dev_priv->wm.skl_latency); |
| 1887 | intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency); |
| 1888 | } |
| 1889 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1890 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1891 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1892 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 1893 | struct drm_device *dev = crtc->dev; |
| 1894 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1895 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 1896 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1897 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1898 | if (!intel_crtc_active(crtc)) |
| 1899 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1900 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1901 | p->active = true; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1902 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1903 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1904 | p->pri.bytes_per_pixel = crtc->primary->state->fb->bits_per_pixel / 8; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1905 | p->cur.bytes_per_pixel = 4; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1906 | p->pri.horiz_pixels = intel_crtc->config->pipe_src_w; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 1907 | p->cur.horiz_pixels = intel_crtc->base.cursor->state->crtc_w; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1908 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 1909 | p->pri.enabled = true; |
| 1910 | p->cur.enabled = true; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 1911 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 1912 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1913 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1914 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1915 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 1916 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1917 | break; |
| 1918 | } |
| 1919 | } |
| 1920 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1921 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1922 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 1923 | struct intel_wm_config *config) |
| 1924 | { |
| 1925 | struct intel_crtc *intel_crtc; |
| 1926 | |
| 1927 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 1928 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1929 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 1930 | |
| 1931 | if (!wm->pipe_enabled) |
| 1932 | continue; |
| 1933 | |
| 1934 | config->sprites_enabled |= wm->sprites_enabled; |
| 1935 | config->sprites_scaled |= wm->sprites_scaled; |
| 1936 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1937 | } |
| 1938 | } |
| 1939 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1940 | /* Compute new watermarks for the pipe */ |
| 1941 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1942 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1943 | struct intel_pipe_wm *pipe_wm) |
| 1944 | { |
| 1945 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1946 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1947 | int level, max_level = ilk_wm_max_level(dev); |
| 1948 | /* LP0 watermark maximums depend on this pipe alone */ |
| 1949 | struct intel_wm_config config = { |
| 1950 | .num_pipes_active = 1, |
| 1951 | .sprites_enabled = params->spr.enabled, |
| 1952 | .sprites_scaled = params->spr.scaled, |
| 1953 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1954 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1955 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 1956 | pipe_wm->pipe_enabled = params->active; |
| 1957 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 1958 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 1959 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 1960 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 1961 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 1962 | max_level = 1; |
| 1963 | |
| 1964 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 1965 | if (params->spr.scaled) |
| 1966 | max_level = 0; |
| 1967 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1968 | 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] | 1969 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 1970 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 1971 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1972 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1973 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 1974 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 1975 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1976 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1977 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 1978 | return false; |
| 1979 | |
| 1980 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 1981 | |
| 1982 | for (level = 1; level <= max_level; level++) { |
| 1983 | struct intel_wm_level wm = {}; |
| 1984 | |
| 1985 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 1986 | |
| 1987 | /* |
| 1988 | * Disable any watermark level that exceeds the |
| 1989 | * register maximums since such watermarks are |
| 1990 | * always invalid. |
| 1991 | */ |
| 1992 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 1993 | break; |
| 1994 | |
| 1995 | pipe_wm->wm[level] = wm; |
| 1996 | } |
| 1997 | |
| 1998 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | /* |
| 2002 | * Merge the watermarks from all active pipes for a specific level. |
| 2003 | */ |
| 2004 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2005 | int level, |
| 2006 | struct intel_wm_level *ret_wm) |
| 2007 | { |
| 2008 | const struct intel_crtc *intel_crtc; |
| 2009 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2010 | ret_wm->enable = true; |
| 2011 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2012 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2013 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2014 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2015 | |
| 2016 | if (!active->pipe_enabled) |
| 2017 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2018 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2019 | /* |
| 2020 | * The watermark values may have been used in the past, |
| 2021 | * so we must maintain them in the registers for some |
| 2022 | * time even if the level is now disabled. |
| 2023 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2024 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2025 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2026 | |
| 2027 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2028 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2029 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2030 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2031 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | /* |
| 2035 | * Merge all low power watermarks for all active pipes. |
| 2036 | */ |
| 2037 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2038 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2039 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2040 | struct intel_pipe_wm *merged) |
| 2041 | { |
| 2042 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2043 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2044 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2045 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2046 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2047 | config->num_pipes_active > 1) |
| 2048 | return; |
| 2049 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2050 | /* ILK: FBC WM must be disabled always */ |
| 2051 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2052 | |
| 2053 | /* merge each WM1+ level */ |
| 2054 | for (level = 1; level <= max_level; level++) { |
| 2055 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2056 | |
| 2057 | ilk_merge_wm_level(dev, level, wm); |
| 2058 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2059 | if (level > last_enabled_level) |
| 2060 | wm->enable = false; |
| 2061 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2062 | /* make sure all following levels get disabled */ |
| 2063 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2064 | |
| 2065 | /* |
| 2066 | * The spec says it is preferred to disable |
| 2067 | * FBC WMs instead of disabling a WM level. |
| 2068 | */ |
| 2069 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2070 | if (wm->enable) |
| 2071 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2072 | wm->fbc_val = 0; |
| 2073 | } |
| 2074 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2075 | |
| 2076 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2077 | /* |
| 2078 | * FIXME this is racy. FBC might get enabled later. |
| 2079 | * What we should check here is whether FBC can be |
| 2080 | * enabled sometime later. |
| 2081 | */ |
| 2082 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2083 | for (level = 2; level <= max_level; level++) { |
| 2084 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2085 | |
| 2086 | wm->enable = false; |
| 2087 | } |
| 2088 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2089 | } |
| 2090 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2091 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2092 | { |
| 2093 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2094 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2095 | } |
| 2096 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2097 | /* The value we need to program into the WM_LPx latency field */ |
| 2098 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2099 | { |
| 2100 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2101 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2102 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2103 | return 2 * level; |
| 2104 | else |
| 2105 | return dev_priv->wm.pri_latency[level]; |
| 2106 | } |
| 2107 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2108 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2109 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2110 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2111 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2112 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2113 | struct intel_crtc *intel_crtc; |
| 2114 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2115 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2116 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2117 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2118 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2119 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2120 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2121 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2122 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2123 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2124 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2125 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2126 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2127 | /* |
| 2128 | * Maintain the watermark values even if the level is |
| 2129 | * disabled. Doing otherwise could cause underruns. |
| 2130 | */ |
| 2131 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2132 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2133 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2134 | r->cur_val; |
| 2135 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2136 | if (r->enable) |
| 2137 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2138 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2139 | if (INTEL_INFO(dev)->gen >= 8) |
| 2140 | results->wm_lp[wm_lp - 1] |= |
| 2141 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2142 | else |
| 2143 | results->wm_lp[wm_lp - 1] |= |
| 2144 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2145 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2146 | /* |
| 2147 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2148 | * level is disabled. Doing otherwise could cause underruns. |
| 2149 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2150 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2151 | WARN_ON(wm_lp != 1); |
| 2152 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2153 | } else |
| 2154 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2155 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2156 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2157 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2158 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2159 | enum pipe pipe = intel_crtc->pipe; |
| 2160 | const struct intel_wm_level *r = |
| 2161 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2162 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2163 | if (WARN_ON(!r->enable)) |
| 2164 | continue; |
| 2165 | |
| 2166 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2167 | |
| 2168 | results->wm_pipe[pipe] = |
| 2169 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2170 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2171 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2172 | } |
| 2173 | } |
| 2174 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2175 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2176 | * 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] | 2177 | 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] | 2178 | struct intel_pipe_wm *r1, |
| 2179 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2180 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2181 | int level, max_level = ilk_wm_max_level(dev); |
| 2182 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2183 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2184 | for (level = 1; level <= max_level; level++) { |
| 2185 | if (r1->wm[level].enable) |
| 2186 | level1 = level; |
| 2187 | if (r2->wm[level].enable) |
| 2188 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2189 | } |
| 2190 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2191 | if (level1 == level2) { |
| 2192 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2193 | return r2; |
| 2194 | else |
| 2195 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2196 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2197 | return r1; |
| 2198 | } else { |
| 2199 | return r2; |
| 2200 | } |
| 2201 | } |
| 2202 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2203 | /* dirty bits used to track which watermarks need changes */ |
| 2204 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2205 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2206 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2207 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2208 | #define WM_DIRTY_FBC (1 << 24) |
| 2209 | #define WM_DIRTY_DDB (1 << 25) |
| 2210 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2211 | 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] | 2212 | const struct ilk_wm_values *old, |
| 2213 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2214 | { |
| 2215 | unsigned int dirty = 0; |
| 2216 | enum pipe pipe; |
| 2217 | int wm_lp; |
| 2218 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2219 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2220 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2221 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2222 | /* Must disable LP1+ watermarks too */ |
| 2223 | dirty |= WM_DIRTY_LP_ALL; |
| 2224 | } |
| 2225 | |
| 2226 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2227 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2228 | /* Must disable LP1+ watermarks too */ |
| 2229 | dirty |= WM_DIRTY_LP_ALL; |
| 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2234 | dirty |= WM_DIRTY_FBC; |
| 2235 | /* Must disable LP1+ watermarks too */ |
| 2236 | dirty |= WM_DIRTY_LP_ALL; |
| 2237 | } |
| 2238 | |
| 2239 | if (old->partitioning != new->partitioning) { |
| 2240 | dirty |= WM_DIRTY_DDB; |
| 2241 | /* Must disable LP1+ watermarks too */ |
| 2242 | dirty |= WM_DIRTY_LP_ALL; |
| 2243 | } |
| 2244 | |
| 2245 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2246 | if (dirty & WM_DIRTY_LP_ALL) |
| 2247 | return dirty; |
| 2248 | |
| 2249 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2250 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2251 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2252 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2253 | break; |
| 2254 | } |
| 2255 | |
| 2256 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2257 | for (; wm_lp <= 3; wm_lp++) |
| 2258 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2259 | |
| 2260 | return dirty; |
| 2261 | } |
| 2262 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2263 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2264 | unsigned int dirty) |
| 2265 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2266 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2267 | bool changed = false; |
| 2268 | |
| 2269 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2270 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2271 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2272 | changed = true; |
| 2273 | } |
| 2274 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2275 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2276 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2277 | changed = true; |
| 2278 | } |
| 2279 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2280 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2281 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2282 | changed = true; |
| 2283 | } |
| 2284 | |
| 2285 | /* |
| 2286 | * Don't touch WM1S_LP_EN here. |
| 2287 | * Doing so could cause underruns. |
| 2288 | */ |
| 2289 | |
| 2290 | return changed; |
| 2291 | } |
| 2292 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2293 | /* |
| 2294 | * The spec says we shouldn't write when we don't need, because every write |
| 2295 | * causes WMs to be re-evaluated, expending some power. |
| 2296 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2297 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2298 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2299 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2300 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2301 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2302 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2303 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2304 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2305 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2306 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2307 | return; |
| 2308 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2309 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2310 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2311 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2312 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2313 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2314 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2315 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2316 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2317 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2318 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2319 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2320 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2321 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2322 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2323 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2324 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2325 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2326 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2327 | val = I915_READ(WM_MISC); |
| 2328 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2329 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2330 | else |
| 2331 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2332 | I915_WRITE(WM_MISC, val); |
| 2333 | } else { |
| 2334 | val = I915_READ(DISP_ARB_CTL2); |
| 2335 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2336 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2337 | else |
| 2338 | val |= DISP_DATA_PARTITION_5_6; |
| 2339 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2340 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2341 | } |
| 2342 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2343 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2344 | val = I915_READ(DISP_ARB_CTL); |
| 2345 | if (results->enable_fbc_wm) |
| 2346 | val &= ~DISP_FBC_WM_DIS; |
| 2347 | else |
| 2348 | val |= DISP_FBC_WM_DIS; |
| 2349 | I915_WRITE(DISP_ARB_CTL, val); |
| 2350 | } |
| 2351 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2352 | if (dirty & WM_DIRTY_LP(1) && |
| 2353 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2354 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2355 | |
| 2356 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2357 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2358 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2359 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2360 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2361 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2362 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2363 | 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] | 2364 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2365 | 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] | 2366 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2367 | 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] | 2368 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2369 | |
| 2370 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2371 | } |
| 2372 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2373 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2374 | { |
| 2375 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2376 | |
| 2377 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2378 | } |
| 2379 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2380 | /* |
| 2381 | * On gen9, we need to allocate Display Data Buffer (DDB) portions to the |
| 2382 | * different active planes. |
| 2383 | */ |
| 2384 | |
| 2385 | #define SKL_DDB_SIZE 896 /* in blocks */ |
| 2386 | |
| 2387 | static void |
| 2388 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
| 2389 | struct drm_crtc *for_crtc, |
| 2390 | const struct intel_wm_config *config, |
| 2391 | const struct skl_pipe_wm_parameters *params, |
| 2392 | struct skl_ddb_entry *alloc /* out */) |
| 2393 | { |
| 2394 | struct drm_crtc *crtc; |
| 2395 | unsigned int pipe_size, ddb_size; |
| 2396 | int nth_active_pipe; |
| 2397 | |
| 2398 | if (!params->active) { |
| 2399 | alloc->start = 0; |
| 2400 | alloc->end = 0; |
| 2401 | return; |
| 2402 | } |
| 2403 | |
| 2404 | ddb_size = SKL_DDB_SIZE; |
| 2405 | |
| 2406 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 2407 | |
| 2408 | nth_active_pipe = 0; |
| 2409 | for_each_crtc(dev, crtc) { |
| 2410 | if (!intel_crtc_active(crtc)) |
| 2411 | continue; |
| 2412 | |
| 2413 | if (crtc == for_crtc) |
| 2414 | break; |
| 2415 | |
| 2416 | nth_active_pipe++; |
| 2417 | } |
| 2418 | |
| 2419 | pipe_size = ddb_size / config->num_pipes_active; |
| 2420 | alloc->start = nth_active_pipe * ddb_size / config->num_pipes_active; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2421 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | static unsigned int skl_cursor_allocation(const struct intel_wm_config *config) |
| 2425 | { |
| 2426 | if (config->num_pipes_active == 1) |
| 2427 | return 32; |
| 2428 | |
| 2429 | return 8; |
| 2430 | } |
| 2431 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2432 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 2433 | { |
| 2434 | entry->start = reg & 0x3ff; |
| 2435 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2436 | if (entry->end) |
| 2437 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 2440 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 2441 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2442 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2443 | enum pipe pipe; |
| 2444 | int plane; |
| 2445 | u32 val; |
| 2446 | |
| 2447 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2448 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2449 | val = I915_READ(PLANE_BUF_CFG(pipe, plane)); |
| 2450 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane], |
| 2451 | val); |
| 2452 | } |
| 2453 | |
| 2454 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 2455 | skl_ddb_entry_init_from_hw(&ddb->cursor[pipe], val); |
| 2456 | } |
| 2457 | } |
| 2458 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2459 | static unsigned int |
| 2460 | skl_plane_relative_data_rate(const struct intel_plane_wm_parameters *p) |
| 2461 | { |
| 2462 | return p->horiz_pixels * p->vert_pixels * p->bytes_per_pixel; |
| 2463 | } |
| 2464 | |
| 2465 | /* |
| 2466 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 2467 | * a 8192x4096@32bpp framebuffer: |
| 2468 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 2469 | */ |
| 2470 | static unsigned int |
| 2471 | skl_get_total_relative_data_rate(struct intel_crtc *intel_crtc, |
| 2472 | const struct skl_pipe_wm_parameters *params) |
| 2473 | { |
| 2474 | unsigned int total_data_rate = 0; |
| 2475 | int plane; |
| 2476 | |
| 2477 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2478 | const struct intel_plane_wm_parameters *p; |
| 2479 | |
| 2480 | p = ¶ms->plane[plane]; |
| 2481 | if (!p->enabled) |
| 2482 | continue; |
| 2483 | |
| 2484 | total_data_rate += skl_plane_relative_data_rate(p); |
| 2485 | } |
| 2486 | |
| 2487 | return total_data_rate; |
| 2488 | } |
| 2489 | |
| 2490 | static void |
| 2491 | skl_allocate_pipe_ddb(struct drm_crtc *crtc, |
| 2492 | const struct intel_wm_config *config, |
| 2493 | const struct skl_pipe_wm_parameters *params, |
| 2494 | struct skl_ddb_allocation *ddb /* out */) |
| 2495 | { |
| 2496 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2497 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2498 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2499 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2500 | struct skl_ddb_entry *alloc = &ddb->pipe[pipe]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2501 | uint16_t alloc_size, start, cursor_blocks; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2502 | uint16_t minimum[I915_MAX_PLANES]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2503 | unsigned int total_data_rate; |
| 2504 | int plane; |
| 2505 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2506 | skl_ddb_get_pipe_allocation_limits(dev, crtc, config, params, alloc); |
| 2507 | alloc_size = skl_ddb_entry_size(alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2508 | if (alloc_size == 0) { |
| 2509 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 2510 | memset(&ddb->cursor[pipe], 0, sizeof(ddb->cursor[pipe])); |
| 2511 | return; |
| 2512 | } |
| 2513 | |
| 2514 | cursor_blocks = skl_cursor_allocation(config); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2515 | ddb->cursor[pipe].start = alloc->end - cursor_blocks; |
| 2516 | ddb->cursor[pipe].end = alloc->end; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2517 | |
| 2518 | alloc_size -= cursor_blocks; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2519 | alloc->end -= cursor_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2520 | |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2521 | /* 1. Allocate the mininum required blocks for each active plane */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2522 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2523 | const struct intel_plane_wm_parameters *p; |
| 2524 | |
| 2525 | p = ¶ms->plane[plane]; |
| 2526 | if (!p->enabled) |
| 2527 | continue; |
| 2528 | |
| 2529 | minimum[plane] = 8; |
| 2530 | alloc_size -= minimum[plane]; |
| 2531 | } |
| 2532 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2533 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2534 | * 2. Distribute the remaining space in proportion to the amount of |
| 2535 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2536 | * |
| 2537 | * FIXME: we may not allocate every single block here. |
| 2538 | */ |
| 2539 | total_data_rate = skl_get_total_relative_data_rate(intel_crtc, params); |
| 2540 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2541 | start = alloc->start; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2542 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2543 | const struct intel_plane_wm_parameters *p; |
| 2544 | unsigned int data_rate; |
| 2545 | uint16_t plane_blocks; |
| 2546 | |
| 2547 | p = ¶ms->plane[plane]; |
| 2548 | if (!p->enabled) |
| 2549 | continue; |
| 2550 | |
| 2551 | data_rate = skl_plane_relative_data_rate(p); |
| 2552 | |
| 2553 | /* |
| 2554 | * promote the expression to 64 bits to avoid overflowing, the |
| 2555 | * result is < available as data_rate / total_data_rate < 1 |
| 2556 | */ |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2557 | plane_blocks = minimum[plane]; |
| 2558 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 2559 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2560 | |
| 2561 | ddb->plane[pipe][plane].start = start; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2562 | ddb->plane[pipe][plane].end = start + plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2563 | |
| 2564 | start += plane_blocks; |
| 2565 | } |
| 2566 | |
| 2567 | } |
| 2568 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2569 | 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] | 2570 | { |
| 2571 | /* TODO: Take into account the scalers once we support them */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2572 | return config->base.adjusted_mode.crtc_clock; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | /* |
| 2576 | * The max latency should be 257 (max the punit can code is 255 and we add 2us |
| 2577 | * for the read latency) and bytes_per_pixel should always be <= 8, so that |
| 2578 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 2579 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 2580 | */ |
| 2581 | static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel, |
| 2582 | uint32_t latency) |
| 2583 | { |
| 2584 | uint32_t wm_intermediate_val, ret; |
| 2585 | |
| 2586 | if (latency == 0) |
| 2587 | return UINT_MAX; |
| 2588 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2589 | wm_intermediate_val = latency * pixel_rate * bytes_per_pixel / 512; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2590 | ret = DIV_ROUND_UP(wm_intermediate_val, 1000); |
| 2591 | |
| 2592 | return ret; |
| 2593 | } |
| 2594 | |
| 2595 | static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
| 2596 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2597 | uint64_t tiling, uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2598 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2599 | uint32_t ret; |
| 2600 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2601 | uint32_t wm_intermediate_val; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2602 | |
| 2603 | if (latency == 0) |
| 2604 | return UINT_MAX; |
| 2605 | |
| 2606 | plane_bytes_per_line = horiz_pixels * bytes_per_pixel; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2607 | |
| 2608 | if (tiling == I915_FORMAT_MOD_Y_TILED || |
| 2609 | tiling == I915_FORMAT_MOD_Yf_TILED) { |
| 2610 | plane_bytes_per_line *= 4; |
| 2611 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2612 | plane_blocks_per_line /= 4; |
| 2613 | } else { |
| 2614 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2615 | } |
| 2616 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2617 | wm_intermediate_val = latency * pixel_rate; |
| 2618 | ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) * |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2619 | plane_blocks_per_line; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2620 | |
| 2621 | return ret; |
| 2622 | } |
| 2623 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2624 | static bool skl_ddb_allocation_changed(const struct skl_ddb_allocation *new_ddb, |
| 2625 | const struct intel_crtc *intel_crtc) |
| 2626 | { |
| 2627 | struct drm_device *dev = intel_crtc->base.dev; |
| 2628 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2629 | const struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 2630 | enum pipe pipe = intel_crtc->pipe; |
| 2631 | |
| 2632 | if (memcmp(new_ddb->plane[pipe], cur_ddb->plane[pipe], |
| 2633 | sizeof(new_ddb->plane[pipe]))) |
| 2634 | return true; |
| 2635 | |
| 2636 | if (memcmp(&new_ddb->cursor[pipe], &cur_ddb->cursor[pipe], |
| 2637 | sizeof(new_ddb->cursor[pipe]))) |
| 2638 | return true; |
| 2639 | |
| 2640 | return false; |
| 2641 | } |
| 2642 | |
| 2643 | static void skl_compute_wm_global_parameters(struct drm_device *dev, |
| 2644 | struct intel_wm_config *config) |
| 2645 | { |
| 2646 | struct drm_crtc *crtc; |
| 2647 | struct drm_plane *plane; |
| 2648 | |
| 2649 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 2650 | config->num_pipes_active += intel_crtc_active(crtc); |
| 2651 | |
| 2652 | /* FIXME: I don't think we need those two global parameters on SKL */ |
| 2653 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2654 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2655 | |
| 2656 | config->sprites_enabled |= intel_plane->wm.enabled; |
| 2657 | config->sprites_scaled |= intel_plane->wm.scaled; |
| 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | static void skl_compute_wm_pipe_parameters(struct drm_crtc *crtc, |
| 2662 | struct skl_pipe_wm_parameters *p) |
| 2663 | { |
| 2664 | struct drm_device *dev = crtc->dev; |
| 2665 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2666 | enum pipe pipe = intel_crtc->pipe; |
| 2667 | struct drm_plane *plane; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2668 | struct drm_framebuffer *fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2669 | int i = 1; /* Index for sprite planes start */ |
| 2670 | |
| 2671 | p->active = intel_crtc_active(crtc); |
| 2672 | if (p->active) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2673 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
| 2674 | p->pixel_rate = skl_pipe_pixel_rate(intel_crtc->config); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2675 | |
| 2676 | /* |
| 2677 | * For now, assume primary and cursor planes are always enabled. |
| 2678 | */ |
| 2679 | p->plane[0].enabled = true; |
| 2680 | p->plane[0].bytes_per_pixel = |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 2681 | crtc->primary->state->fb->bits_per_pixel / 8; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2682 | p->plane[0].horiz_pixels = intel_crtc->config->pipe_src_w; |
| 2683 | p->plane[0].vert_pixels = intel_crtc->config->pipe_src_h; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2684 | p->plane[0].tiling = DRM_FORMAT_MOD_NONE; |
| 2685 | fb = crtc->primary->state->fb; |
| 2686 | /* |
| 2687 | * Framebuffer can be NULL on plane disable, but it does not |
| 2688 | * matter for watermarks if we assume no tiling in that case. |
| 2689 | */ |
| 2690 | if (fb) |
| 2691 | p->plane[0].tiling = fb->modifier[0]; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2692 | |
| 2693 | p->cursor.enabled = true; |
| 2694 | p->cursor.bytes_per_pixel = 4; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 2695 | p->cursor.horiz_pixels = intel_crtc->base.cursor->state->crtc_w ? |
| 2696 | intel_crtc->base.cursor->state->crtc_w : 64; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2700 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2701 | |
Sonika Jindal | a712f8e | 2014-12-09 10:59:15 +0530 | [diff] [blame] | 2702 | if (intel_plane->pipe == pipe && |
| 2703 | plane->type == DRM_PLANE_TYPE_OVERLAY) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2704 | p->plane[i++] = intel_plane->wm; |
| 2705 | } |
| 2706 | } |
| 2707 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2708 | static bool skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 2709 | struct skl_pipe_wm_parameters *p, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2710 | struct intel_plane_wm_parameters *p_params, |
| 2711 | uint16_t ddb_allocation, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2712 | int level, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2713 | uint16_t *out_blocks, /* out */ |
| 2714 | uint8_t *out_lines /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2715 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2716 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
| 2717 | uint32_t method1, method2; |
| 2718 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2719 | uint32_t res_blocks, res_lines; |
| 2720 | uint32_t selected_result; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2721 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2722 | if (latency == 0 || !p->active || !p_params->enabled) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2723 | return false; |
| 2724 | |
| 2725 | method1 = skl_wm_method1(p->pixel_rate, |
| 2726 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2727 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2728 | method2 = skl_wm_method2(p->pixel_rate, |
| 2729 | p->pipe_htotal, |
| 2730 | p_params->horiz_pixels, |
| 2731 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2732 | p_params->tiling, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2733 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2734 | |
| 2735 | plane_bytes_per_line = p_params->horiz_pixels * |
| 2736 | p_params->bytes_per_pixel; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2737 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2738 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2739 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2740 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) { |
| 2741 | uint32_t y_tile_minimum = plane_blocks_per_line * 4; |
| 2742 | selected_result = max(method2, y_tile_minimum); |
| 2743 | } else { |
| 2744 | if ((ddb_allocation / plane_blocks_per_line) >= 1) |
| 2745 | selected_result = min(method1, method2); |
| 2746 | else |
| 2747 | selected_result = method1; |
| 2748 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2749 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2750 | res_blocks = selected_result + 1; |
| 2751 | res_lines = DIV_ROUND_UP(selected_result, plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2752 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2753 | if (level >= 1 && level <= 7) { |
| 2754 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2755 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) |
| 2756 | res_lines += 4; |
| 2757 | else |
| 2758 | res_blocks++; |
| 2759 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2760 | |
| 2761 | if (res_blocks >= ddb_allocation || res_lines > 31) |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2762 | return false; |
| 2763 | |
| 2764 | *out_blocks = res_blocks; |
| 2765 | *out_lines = res_lines; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2766 | |
| 2767 | return true; |
| 2768 | } |
| 2769 | |
| 2770 | static void skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 2771 | struct skl_ddb_allocation *ddb, |
| 2772 | struct skl_pipe_wm_parameters *p, |
| 2773 | enum pipe pipe, |
| 2774 | int level, |
| 2775 | int num_planes, |
| 2776 | struct skl_wm_level *result) |
| 2777 | { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2778 | uint16_t ddb_blocks; |
| 2779 | int i; |
| 2780 | |
| 2781 | for (i = 0; i < num_planes; i++) { |
| 2782 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]); |
| 2783 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2784 | result->plane_en[i] = skl_compute_plane_wm(dev_priv, |
| 2785 | p, &p->plane[i], |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2786 | ddb_blocks, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2787 | level, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2788 | &result->plane_res_b[i], |
| 2789 | &result->plane_res_l[i]); |
| 2790 | } |
| 2791 | |
| 2792 | ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]); |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2793 | result->cursor_en = skl_compute_plane_wm(dev_priv, p, &p->cursor, |
| 2794 | ddb_blocks, level, |
| 2795 | &result->cursor_res_b, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2796 | &result->cursor_res_l); |
| 2797 | } |
| 2798 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2799 | static uint32_t |
| 2800 | skl_compute_linetime_wm(struct drm_crtc *crtc, struct skl_pipe_wm_parameters *p) |
| 2801 | { |
| 2802 | if (!intel_crtc_active(crtc)) |
| 2803 | return 0; |
| 2804 | |
| 2805 | return DIV_ROUND_UP(8 * p->pipe_htotal * 1000, p->pixel_rate); |
| 2806 | |
| 2807 | } |
| 2808 | |
| 2809 | static void skl_compute_transition_wm(struct drm_crtc *crtc, |
| 2810 | struct skl_pipe_wm_parameters *params, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2811 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2812 | { |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2813 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2814 | int i; |
| 2815 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2816 | if (!params->active) |
| 2817 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2818 | |
| 2819 | /* Until we know more, just disable transition WMs */ |
| 2820 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 2821 | trans_wm->plane_en[i] = false; |
| 2822 | trans_wm->cursor_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2823 | } |
| 2824 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2825 | static void skl_compute_pipe_wm(struct drm_crtc *crtc, |
| 2826 | struct skl_ddb_allocation *ddb, |
| 2827 | struct skl_pipe_wm_parameters *params, |
| 2828 | struct skl_pipe_wm *pipe_wm) |
| 2829 | { |
| 2830 | struct drm_device *dev = crtc->dev; |
| 2831 | const struct drm_i915_private *dev_priv = dev->dev_private; |
| 2832 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2833 | int level, max_level = ilk_wm_max_level(dev); |
| 2834 | |
| 2835 | for (level = 0; level <= max_level; level++) { |
| 2836 | skl_compute_wm_level(dev_priv, ddb, params, intel_crtc->pipe, |
| 2837 | level, intel_num_planes(intel_crtc), |
| 2838 | &pipe_wm->wm[level]); |
| 2839 | } |
| 2840 | pipe_wm->linetime = skl_compute_linetime_wm(crtc, params); |
| 2841 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2842 | skl_compute_transition_wm(crtc, params, &pipe_wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | static void skl_compute_wm_results(struct drm_device *dev, |
| 2846 | struct skl_pipe_wm_parameters *p, |
| 2847 | struct skl_pipe_wm *p_wm, |
| 2848 | struct skl_wm_values *r, |
| 2849 | struct intel_crtc *intel_crtc) |
| 2850 | { |
| 2851 | int level, max_level = ilk_wm_max_level(dev); |
| 2852 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2853 | uint32_t temp; |
| 2854 | int i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2855 | |
| 2856 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2857 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 2858 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2859 | |
| 2860 | temp |= p_wm->wm[level].plane_res_l[i] << |
| 2861 | PLANE_WM_LINES_SHIFT; |
| 2862 | temp |= p_wm->wm[level].plane_res_b[i]; |
| 2863 | if (p_wm->wm[level].plane_en[i]) |
| 2864 | temp |= PLANE_WM_EN; |
| 2865 | |
| 2866 | r->plane[pipe][i][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2870 | |
| 2871 | temp |= p_wm->wm[level].cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 2872 | temp |= p_wm->wm[level].cursor_res_b; |
| 2873 | |
| 2874 | if (p_wm->wm[level].cursor_en) |
| 2875 | temp |= PLANE_WM_EN; |
| 2876 | |
| 2877 | r->cursor[pipe][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2878 | |
| 2879 | } |
| 2880 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2881 | /* transition WMs */ |
| 2882 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 2883 | temp = 0; |
| 2884 | temp |= p_wm->trans_wm.plane_res_l[i] << PLANE_WM_LINES_SHIFT; |
| 2885 | temp |= p_wm->trans_wm.plane_res_b[i]; |
| 2886 | if (p_wm->trans_wm.plane_en[i]) |
| 2887 | temp |= PLANE_WM_EN; |
| 2888 | |
| 2889 | r->plane_trans[pipe][i] = temp; |
| 2890 | } |
| 2891 | |
| 2892 | temp = 0; |
| 2893 | temp |= p_wm->trans_wm.cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 2894 | temp |= p_wm->trans_wm.cursor_res_b; |
| 2895 | if (p_wm->trans_wm.cursor_en) |
| 2896 | temp |= PLANE_WM_EN; |
| 2897 | |
| 2898 | r->cursor_trans[pipe] = temp; |
| 2899 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2900 | r->wm_linetime[pipe] = p_wm->linetime; |
| 2901 | } |
| 2902 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2903 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, uint32_t reg, |
| 2904 | const struct skl_ddb_entry *entry) |
| 2905 | { |
| 2906 | if (entry->end) |
| 2907 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 2908 | else |
| 2909 | I915_WRITE(reg, 0); |
| 2910 | } |
| 2911 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2912 | static void skl_write_wm_values(struct drm_i915_private *dev_priv, |
| 2913 | const struct skl_wm_values *new) |
| 2914 | { |
| 2915 | struct drm_device *dev = dev_priv->dev; |
| 2916 | struct intel_crtc *crtc; |
| 2917 | |
| 2918 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
| 2919 | int i, level, max_level = ilk_wm_max_level(dev); |
| 2920 | enum pipe pipe = crtc->pipe; |
| 2921 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 2922 | if (!new->dirty[pipe]) |
| 2923 | continue; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2924 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 2925 | I915_WRITE(PIPE_WM_LINETIME(pipe), new->wm_linetime[pipe]); |
| 2926 | |
| 2927 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2928 | for (i = 0; i < intel_num_planes(crtc); i++) |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 2929 | I915_WRITE(PLANE_WM(pipe, i, level), |
| 2930 | new->plane[pipe][i][level]); |
| 2931 | I915_WRITE(CUR_WM(pipe, level), |
| 2932 | new->cursor[pipe][level]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2933 | } |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 2934 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 2935 | I915_WRITE(PLANE_WM_TRANS(pipe, i), |
| 2936 | new->plane_trans[pipe][i]); |
| 2937 | I915_WRITE(CUR_WM_TRANS(pipe), new->cursor_trans[pipe]); |
| 2938 | |
| 2939 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 2940 | skl_ddb_entry_write(dev_priv, |
| 2941 | PLANE_BUF_CFG(pipe, i), |
| 2942 | &new->ddb.plane[pipe][i]); |
| 2943 | |
| 2944 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
| 2945 | &new->ddb.cursor[pipe]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2946 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 2949 | /* |
| 2950 | * When setting up a new DDB allocation arrangement, we need to correctly |
| 2951 | * sequence the times at which the new allocations for the pipes are taken into |
| 2952 | * account or we'll have pipes fetching from space previously allocated to |
| 2953 | * another pipe. |
| 2954 | * |
| 2955 | * Roughly the sequence looks like: |
| 2956 | * 1. re-allocate the pipe(s) with the allocation being reduced and not |
| 2957 | * overlapping with a previous light-up pipe (another way to put it is: |
| 2958 | * pipes with their new allocation strickly included into their old ones). |
| 2959 | * 2. re-allocate the other pipes that get their allocation reduced |
| 2960 | * 3. allocate the pipes having their allocation increased |
| 2961 | * |
| 2962 | * Steps 1. and 2. are here to take care of the following case: |
| 2963 | * - Initially DDB looks like this: |
| 2964 | * | B | C | |
| 2965 | * - enable pipe A. |
| 2966 | * - pipe B has a reduced DDB allocation that overlaps with the old pipe C |
| 2967 | * allocation |
| 2968 | * | A | B | C | |
| 2969 | * |
| 2970 | * We need to sequence the re-allocation: C, B, A (and not B, C, A). |
| 2971 | */ |
| 2972 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 2973 | static void |
| 2974 | 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] | 2975 | { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 2976 | int plane; |
| 2977 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 2978 | DRM_DEBUG_KMS("flush pipe %c (pass %d)\n", pipe_name(pipe), pass); |
| 2979 | |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2980 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 2981 | I915_WRITE(PLANE_SURF(pipe, plane), |
| 2982 | I915_READ(PLANE_SURF(pipe, plane))); |
| 2983 | } |
| 2984 | I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe))); |
| 2985 | } |
| 2986 | |
| 2987 | static bool |
| 2988 | skl_ddb_allocation_included(const struct skl_ddb_allocation *old, |
| 2989 | const struct skl_ddb_allocation *new, |
| 2990 | enum pipe pipe) |
| 2991 | { |
| 2992 | uint16_t old_size, new_size; |
| 2993 | |
| 2994 | old_size = skl_ddb_entry_size(&old->pipe[pipe]); |
| 2995 | new_size = skl_ddb_entry_size(&new->pipe[pipe]); |
| 2996 | |
| 2997 | return old_size != new_size && |
| 2998 | new->pipe[pipe].start >= old->pipe[pipe].start && |
| 2999 | new->pipe[pipe].end <= old->pipe[pipe].end; |
| 3000 | } |
| 3001 | |
| 3002 | static void skl_flush_wm_values(struct drm_i915_private *dev_priv, |
| 3003 | struct skl_wm_values *new_values) |
| 3004 | { |
| 3005 | struct drm_device *dev = dev_priv->dev; |
| 3006 | struct skl_ddb_allocation *cur_ddb, *new_ddb; |
| 3007 | bool reallocated[I915_MAX_PIPES] = {false, false, false}; |
| 3008 | struct intel_crtc *crtc; |
| 3009 | enum pipe pipe; |
| 3010 | |
| 3011 | new_ddb = &new_values->ddb; |
| 3012 | cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 3013 | |
| 3014 | /* |
| 3015 | * First pass: flush the pipes with the new allocation contained into |
| 3016 | * the old space. |
| 3017 | * |
| 3018 | * We'll wait for the vblank on those pipes to ensure we can safely |
| 3019 | * re-allocate the freed space without this pipe fetching from it. |
| 3020 | */ |
| 3021 | for_each_intel_crtc(dev, crtc) { |
| 3022 | if (!crtc->active) |
| 3023 | continue; |
| 3024 | |
| 3025 | pipe = crtc->pipe; |
| 3026 | |
| 3027 | if (!skl_ddb_allocation_included(cur_ddb, new_ddb, pipe)) |
| 3028 | continue; |
| 3029 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3030 | skl_wm_flush_pipe(dev_priv, pipe, 1); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3031 | intel_wait_for_vblank(dev, pipe); |
| 3032 | |
| 3033 | reallocated[pipe] = true; |
| 3034 | } |
| 3035 | |
| 3036 | |
| 3037 | /* |
| 3038 | * Second pass: flush the pipes that are having their allocation |
| 3039 | * reduced, but overlapping with a previous allocation. |
| 3040 | * |
| 3041 | * Here as well we need to wait for the vblank to make sure the freed |
| 3042 | * space is not used anymore. |
| 3043 | */ |
| 3044 | for_each_intel_crtc(dev, crtc) { |
| 3045 | if (!crtc->active) |
| 3046 | continue; |
| 3047 | |
| 3048 | pipe = crtc->pipe; |
| 3049 | |
| 3050 | if (reallocated[pipe]) |
| 3051 | continue; |
| 3052 | |
| 3053 | if (skl_ddb_entry_size(&new_ddb->pipe[pipe]) < |
| 3054 | skl_ddb_entry_size(&cur_ddb->pipe[pipe])) { |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3055 | skl_wm_flush_pipe(dev_priv, pipe, 2); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3056 | intel_wait_for_vblank(dev, pipe); |
Sonika Jindal | d9d8e6b | 2014-12-11 17:58:15 +0530 | [diff] [blame] | 3057 | reallocated[pipe] = true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3058 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | /* |
| 3062 | * Third pass: flush the pipes that got more space allocated. |
| 3063 | * |
| 3064 | * We don't need to actively wait for the update here, next vblank |
| 3065 | * will just get more DDB space with the correct WM values. |
| 3066 | */ |
| 3067 | for_each_intel_crtc(dev, crtc) { |
| 3068 | if (!crtc->active) |
| 3069 | continue; |
| 3070 | |
| 3071 | pipe = crtc->pipe; |
| 3072 | |
| 3073 | /* |
| 3074 | * At this point, only the pipes more space than before are |
| 3075 | * left to re-allocate. |
| 3076 | */ |
| 3077 | if (reallocated[pipe]) |
| 3078 | continue; |
| 3079 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3080 | skl_wm_flush_pipe(dev_priv, pipe, 3); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3084 | static bool skl_update_pipe_wm(struct drm_crtc *crtc, |
| 3085 | struct skl_pipe_wm_parameters *params, |
| 3086 | struct intel_wm_config *config, |
| 3087 | struct skl_ddb_allocation *ddb, /* out */ |
| 3088 | struct skl_pipe_wm *pipe_wm /* out */) |
| 3089 | { |
| 3090 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3091 | |
| 3092 | skl_compute_wm_pipe_parameters(crtc, params); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3093 | skl_allocate_pipe_ddb(crtc, config, params, ddb); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3094 | skl_compute_pipe_wm(crtc, ddb, params, pipe_wm); |
| 3095 | |
| 3096 | if (!memcmp(&intel_crtc->wm.skl_active, pipe_wm, sizeof(*pipe_wm))) |
| 3097 | return false; |
| 3098 | |
| 3099 | intel_crtc->wm.skl_active = *pipe_wm; |
| 3100 | return true; |
| 3101 | } |
| 3102 | |
| 3103 | static void skl_update_other_pipe_wm(struct drm_device *dev, |
| 3104 | struct drm_crtc *crtc, |
| 3105 | struct intel_wm_config *config, |
| 3106 | struct skl_wm_values *r) |
| 3107 | { |
| 3108 | struct intel_crtc *intel_crtc; |
| 3109 | struct intel_crtc *this_crtc = to_intel_crtc(crtc); |
| 3110 | |
| 3111 | /* |
| 3112 | * If the WM update hasn't changed the allocation for this_crtc (the |
| 3113 | * crtc we are currently computing the new WM values for), other |
| 3114 | * enabled crtcs will keep the same allocation and we don't need to |
| 3115 | * recompute anything for them. |
| 3116 | */ |
| 3117 | if (!skl_ddb_allocation_changed(&r->ddb, this_crtc)) |
| 3118 | return; |
| 3119 | |
| 3120 | /* |
| 3121 | * Otherwise, because of this_crtc being freshly enabled/disabled, the |
| 3122 | * other active pipes need new DDB allocation and WM values. |
| 3123 | */ |
| 3124 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 3125 | base.head) { |
| 3126 | struct skl_pipe_wm_parameters params = {}; |
| 3127 | struct skl_pipe_wm pipe_wm = {}; |
| 3128 | bool wm_changed; |
| 3129 | |
| 3130 | if (this_crtc->pipe == intel_crtc->pipe) |
| 3131 | continue; |
| 3132 | |
| 3133 | if (!intel_crtc->active) |
| 3134 | continue; |
| 3135 | |
| 3136 | wm_changed = skl_update_pipe_wm(&intel_crtc->base, |
| 3137 | ¶ms, config, |
| 3138 | &r->ddb, &pipe_wm); |
| 3139 | |
| 3140 | /* |
| 3141 | * If we end up re-computing the other pipe WM values, it's |
| 3142 | * because it was really needed, so we expect the WM values to |
| 3143 | * be different. |
| 3144 | */ |
| 3145 | WARN_ON(!wm_changed); |
| 3146 | |
| 3147 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, r, intel_crtc); |
| 3148 | r->dirty[intel_crtc->pipe] = true; |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | static void skl_update_wm(struct drm_crtc *crtc) |
| 3153 | { |
| 3154 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3155 | struct drm_device *dev = crtc->dev; |
| 3156 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3157 | struct skl_pipe_wm_parameters params = {}; |
| 3158 | struct skl_wm_values *results = &dev_priv->wm.skl_results; |
| 3159 | struct skl_pipe_wm pipe_wm = {}; |
| 3160 | struct intel_wm_config config = {}; |
| 3161 | |
| 3162 | memset(results, 0, sizeof(*results)); |
| 3163 | |
| 3164 | skl_compute_wm_global_parameters(dev, &config); |
| 3165 | |
| 3166 | if (!skl_update_pipe_wm(crtc, ¶ms, &config, |
| 3167 | &results->ddb, &pipe_wm)) |
| 3168 | return; |
| 3169 | |
| 3170 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, results, intel_crtc); |
| 3171 | results->dirty[intel_crtc->pipe] = true; |
| 3172 | |
| 3173 | skl_update_other_pipe_wm(dev, crtc, &config, results); |
| 3174 | skl_write_wm_values(dev_priv, results); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3175 | skl_flush_wm_values(dev_priv, results); |
Damien Lespiau | 53b0deb | 2014-11-04 17:06:48 +0000 | [diff] [blame] | 3176 | |
| 3177 | /* store the new configuration */ |
| 3178 | dev_priv->wm.skl_hw = *results; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | static void |
| 3182 | skl_update_sprite_wm(struct drm_plane *plane, struct drm_crtc *crtc, |
| 3183 | uint32_t sprite_width, uint32_t sprite_height, |
| 3184 | int pixel_size, bool enabled, bool scaled) |
| 3185 | { |
| 3186 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3187 | struct drm_framebuffer *fb = plane->state->fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3188 | |
| 3189 | intel_plane->wm.enabled = enabled; |
| 3190 | intel_plane->wm.scaled = scaled; |
| 3191 | intel_plane->wm.horiz_pixels = sprite_width; |
| 3192 | intel_plane->wm.vert_pixels = sprite_height; |
| 3193 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3194 | intel_plane->wm.tiling = DRM_FORMAT_MOD_NONE; |
| 3195 | /* |
| 3196 | * Framebuffer can be NULL on plane disable, but it does not |
| 3197 | * matter for watermarks if we assume no tiling in that case. |
| 3198 | */ |
| 3199 | if (fb) |
| 3200 | intel_plane->wm.tiling = fb->modifier[0]; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3201 | |
| 3202 | skl_update_wm(crtc); |
| 3203 | } |
| 3204 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3205 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3206 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3207 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3208 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3209 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3210 | struct ilk_wm_maximums max; |
| 3211 | struct ilk_pipe_wm_parameters params = {}; |
| 3212 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3213 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3214 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3215 | 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] | 3216 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3217 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3218 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3219 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3220 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 3221 | |
| 3222 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 3223 | return; |
| 3224 | |
| 3225 | intel_crtc->wm.active = pipe_wm; |
| 3226 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3227 | ilk_compute_wm_config(dev, &config); |
| 3228 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3229 | 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] | 3230 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3231 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3232 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 3233 | if (INTEL_INFO(dev)->gen >= 7 && |
| 3234 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3235 | 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] | 3236 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3237 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3238 | 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] | 3239 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3240 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3241 | } |
| 3242 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3243 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3244 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3245 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3246 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3247 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3248 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3249 | } |
| 3250 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3251 | static void |
| 3252 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 3253 | struct drm_crtc *crtc, |
| 3254 | uint32_t sprite_width, uint32_t sprite_height, |
| 3255 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3256 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3257 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3258 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3259 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3260 | intel_plane->wm.enabled = enabled; |
| 3261 | intel_plane->wm.scaled = scaled; |
| 3262 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3263 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3264 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3265 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3266 | /* |
| 3267 | * IVB workaround: must disable low power watermarks for at least |
| 3268 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 3269 | * when scaling is disabled. |
| 3270 | * |
| 3271 | * WaCxSRDisabledForSpriteScaling:ivb |
| 3272 | */ |
| 3273 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 3274 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 3275 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3276 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3277 | } |
| 3278 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3279 | static void skl_pipe_wm_active_state(uint32_t val, |
| 3280 | struct skl_pipe_wm *active, |
| 3281 | bool is_transwm, |
| 3282 | bool is_cursor, |
| 3283 | int i, |
| 3284 | int level) |
| 3285 | { |
| 3286 | bool is_enabled = (val & PLANE_WM_EN) != 0; |
| 3287 | |
| 3288 | if (!is_transwm) { |
| 3289 | if (!is_cursor) { |
| 3290 | active->wm[level].plane_en[i] = is_enabled; |
| 3291 | active->wm[level].plane_res_b[i] = |
| 3292 | val & PLANE_WM_BLOCKS_MASK; |
| 3293 | active->wm[level].plane_res_l[i] = |
| 3294 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3295 | PLANE_WM_LINES_MASK; |
| 3296 | } else { |
| 3297 | active->wm[level].cursor_en = is_enabled; |
| 3298 | active->wm[level].cursor_res_b = |
| 3299 | val & PLANE_WM_BLOCKS_MASK; |
| 3300 | active->wm[level].cursor_res_l = |
| 3301 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3302 | PLANE_WM_LINES_MASK; |
| 3303 | } |
| 3304 | } else { |
| 3305 | if (!is_cursor) { |
| 3306 | active->trans_wm.plane_en[i] = is_enabled; |
| 3307 | active->trans_wm.plane_res_b[i] = |
| 3308 | val & PLANE_WM_BLOCKS_MASK; |
| 3309 | active->trans_wm.plane_res_l[i] = |
| 3310 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3311 | PLANE_WM_LINES_MASK; |
| 3312 | } else { |
| 3313 | active->trans_wm.cursor_en = is_enabled; |
| 3314 | active->trans_wm.cursor_res_b = |
| 3315 | val & PLANE_WM_BLOCKS_MASK; |
| 3316 | active->trans_wm.cursor_res_l = |
| 3317 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3318 | PLANE_WM_LINES_MASK; |
| 3319 | } |
| 3320 | } |
| 3321 | } |
| 3322 | |
| 3323 | static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3324 | { |
| 3325 | struct drm_device *dev = crtc->dev; |
| 3326 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3327 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
| 3328 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3329 | struct skl_pipe_wm *active = &intel_crtc->wm.skl_active; |
| 3330 | enum pipe pipe = intel_crtc->pipe; |
| 3331 | int level, i, max_level; |
| 3332 | uint32_t temp; |
| 3333 | |
| 3334 | max_level = ilk_wm_max_level(dev); |
| 3335 | |
| 3336 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
| 3337 | |
| 3338 | for (level = 0; level <= max_level; level++) { |
| 3339 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3340 | hw->plane[pipe][i][level] = |
| 3341 | I915_READ(PLANE_WM(pipe, i, level)); |
| 3342 | hw->cursor[pipe][level] = I915_READ(CUR_WM(pipe, level)); |
| 3343 | } |
| 3344 | |
| 3345 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3346 | hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i)); |
| 3347 | hw->cursor_trans[pipe] = I915_READ(CUR_WM_TRANS(pipe)); |
| 3348 | |
| 3349 | if (!intel_crtc_active(crtc)) |
| 3350 | return; |
| 3351 | |
| 3352 | hw->dirty[pipe] = true; |
| 3353 | |
| 3354 | active->linetime = hw->wm_linetime[pipe]; |
| 3355 | |
| 3356 | for (level = 0; level <= max_level; level++) { |
| 3357 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3358 | temp = hw->plane[pipe][i][level]; |
| 3359 | skl_pipe_wm_active_state(temp, active, false, |
| 3360 | false, i, level); |
| 3361 | } |
| 3362 | temp = hw->cursor[pipe][level]; |
| 3363 | skl_pipe_wm_active_state(temp, active, false, true, i, level); |
| 3364 | } |
| 3365 | |
| 3366 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3367 | temp = hw->plane_trans[pipe][i]; |
| 3368 | skl_pipe_wm_active_state(temp, active, true, false, i, 0); |
| 3369 | } |
| 3370 | |
| 3371 | temp = hw->cursor_trans[pipe]; |
| 3372 | skl_pipe_wm_active_state(temp, active, true, true, i, 0); |
| 3373 | } |
| 3374 | |
| 3375 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 3376 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3377 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3378 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3379 | struct drm_crtc *crtc; |
| 3380 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3381 | skl_ddb_get_hw_state(dev_priv, ddb); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3382 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3383 | skl_pipe_wm_get_hw_state(crtc); |
| 3384 | } |
| 3385 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3386 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3387 | { |
| 3388 | struct drm_device *dev = crtc->dev; |
| 3389 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3390 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3391 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3392 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 3393 | enum pipe pipe = intel_crtc->pipe; |
| 3394 | static const unsigned int wm0_pipe_reg[] = { |
| 3395 | [PIPE_A] = WM0_PIPEA_ILK, |
| 3396 | [PIPE_B] = WM0_PIPEB_ILK, |
| 3397 | [PIPE_C] = WM0_PIPEC_IVB, |
| 3398 | }; |
| 3399 | |
| 3400 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3401 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 3402 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3403 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3404 | active->pipe_enabled = intel_crtc_active(crtc); |
| 3405 | |
| 3406 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3407 | u32 tmp = hw->wm_pipe[pipe]; |
| 3408 | |
| 3409 | /* |
| 3410 | * For active pipes LP0 watermark is marked as |
| 3411 | * enabled, and LP1+ watermaks as disabled since |
| 3412 | * we can't really reverse compute them in case |
| 3413 | * multiple pipes are active. |
| 3414 | */ |
| 3415 | active->wm[0].enable = true; |
| 3416 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 3417 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 3418 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 3419 | active->linetime = hw->wm_linetime[pipe]; |
| 3420 | } else { |
| 3421 | int level, max_level = ilk_wm_max_level(dev); |
| 3422 | |
| 3423 | /* |
| 3424 | * For inactive pipes, all watermark levels |
| 3425 | * should be marked as enabled but zeroed, |
| 3426 | * which is what we'd compute them to. |
| 3427 | */ |
| 3428 | for (level = 0; level <= max_level; level++) |
| 3429 | active->wm[level].enable = true; |
| 3430 | } |
| 3431 | } |
| 3432 | |
| 3433 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 3434 | { |
| 3435 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3436 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3437 | struct drm_crtc *crtc; |
| 3438 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3439 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3440 | ilk_pipe_wm_get_hw_state(crtc); |
| 3441 | |
| 3442 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 3443 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 3444 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 3445 | |
| 3446 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 3447 | if (INTEL_INFO(dev)->gen >= 7) { |
| 3448 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 3449 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 3450 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3451 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3452 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3453 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 3454 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 3455 | else if (IS_IVYBRIDGE(dev)) |
| 3456 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 3457 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3458 | |
| 3459 | hw->enable_fbc_wm = |
| 3460 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3461 | } |
| 3462 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3463 | /** |
| 3464 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3465 | * |
| 3466 | * Calculate watermark values for the various WM regs based on current mode |
| 3467 | * and plane configuration. |
| 3468 | * |
| 3469 | * There are several cases to deal with here: |
| 3470 | * - normal (i.e. non-self-refresh) |
| 3471 | * - self-refresh (SR) mode |
| 3472 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3473 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3474 | * lines), so need to account for TLB latency |
| 3475 | * |
| 3476 | * The normal calculation is: |
| 3477 | * watermark = dotclock * bytes per pixel * latency |
| 3478 | * where latency is platform & configuration dependent (we assume pessimal |
| 3479 | * values here). |
| 3480 | * |
| 3481 | * The SR calculation is: |
| 3482 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3483 | * bytes per pixel |
| 3484 | * where |
| 3485 | * line time = htotal / dotclock |
| 3486 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3487 | * and latency is assumed to be high, as above. |
| 3488 | * |
| 3489 | * The final value programmed to the register should always be rounded up, |
| 3490 | * and include an extra 2 entries to account for clock crossings. |
| 3491 | * |
| 3492 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3493 | * to set the non-SR watermarks to 8. |
| 3494 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3495 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3496 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3497 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3498 | |
| 3499 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3500 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3501 | } |
| 3502 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3503 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3504 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3505 | uint32_t sprite_width, |
| 3506 | uint32_t sprite_height, |
| 3507 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3508 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3509 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3510 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3511 | |
| 3512 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3513 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3514 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3515 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3516 | } |
| 3517 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3518 | /** |
| 3519 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3520 | */ |
| 3521 | DEFINE_SPINLOCK(mchdev_lock); |
| 3522 | |
| 3523 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3524 | * mchdev_lock. */ |
| 3525 | static struct drm_i915_private *i915_mch_dev; |
| 3526 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3527 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3528 | { |
| 3529 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3530 | u16 rgvswctl; |
| 3531 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3532 | assert_spin_locked(&mchdev_lock); |
| 3533 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3534 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3535 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3536 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3537 | return false; /* still busy with another command */ |
| 3538 | } |
| 3539 | |
| 3540 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3541 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3542 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3543 | POSTING_READ16(MEMSWCTL); |
| 3544 | |
| 3545 | rgvswctl |= MEMCTL_CMD_STS; |
| 3546 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3547 | |
| 3548 | return true; |
| 3549 | } |
| 3550 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3551 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3552 | { |
| 3553 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3554 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 3555 | u8 fmax, fmin, fstart, vstart; |
| 3556 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3557 | spin_lock_irq(&mchdev_lock); |
| 3558 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3559 | /* Enable temp reporting */ |
| 3560 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 3561 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 3562 | |
| 3563 | /* 100ms RC evaluation intervals */ |
| 3564 | I915_WRITE(RCUPEI, 100000); |
| 3565 | I915_WRITE(RCDNEI, 100000); |
| 3566 | |
| 3567 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 3568 | I915_WRITE(RCBMAXAVG, 90000); |
| 3569 | I915_WRITE(RCBMINAVG, 80000); |
| 3570 | |
| 3571 | I915_WRITE(MEMIHYST, 1); |
| 3572 | |
| 3573 | /* Set up min, max, and cur for interrupt handling */ |
| 3574 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 3575 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3576 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3577 | MEMMODE_FSTART_SHIFT; |
| 3578 | |
| 3579 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3580 | PXVFREQ_PX_SHIFT; |
| 3581 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3582 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3583 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3584 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3585 | dev_priv->ips.max_delay = fstart; |
| 3586 | dev_priv->ips.min_delay = fmin; |
| 3587 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3588 | |
| 3589 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3590 | fmax, fmin, fstart); |
| 3591 | |
| 3592 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3593 | |
| 3594 | /* |
| 3595 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3596 | */ |
| 3597 | |
| 3598 | I915_WRITE(VIDSTART, vstart); |
| 3599 | POSTING_READ(VIDSTART); |
| 3600 | |
| 3601 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3602 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3603 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3604 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3605 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3606 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3607 | |
| 3608 | ironlake_set_drps(dev, fstart); |
| 3609 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3610 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3611 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3612 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3613 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 3614 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3615 | |
| 3616 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3617 | } |
| 3618 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3619 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3620 | { |
| 3621 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3622 | u16 rgvswctl; |
| 3623 | |
| 3624 | spin_lock_irq(&mchdev_lock); |
| 3625 | |
| 3626 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3627 | |
| 3628 | /* Ack interrupts, disable EFC interrupt */ |
| 3629 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3630 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3631 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3632 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3633 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3634 | |
| 3635 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3636 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3637 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3638 | rgvswctl |= MEMCTL_CMD_STS; |
| 3639 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3640 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3641 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3642 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3643 | } |
| 3644 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3645 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3646 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3647 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3648 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3649 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 3650 | 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] | 3651 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3652 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3653 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3654 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3655 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3656 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3657 | * the hw runs at the minimal clock before selecting the desired |
| 3658 | * frequency, if the down threshold expires in that window we will not |
| 3659 | * receive a down interrupt. */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3660 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3661 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3662 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3663 | |
| 3664 | return limits; |
| 3665 | } |
| 3666 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3667 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3668 | { |
| 3669 | int new_power; |
| 3670 | |
| 3671 | new_power = dev_priv->rps.power; |
| 3672 | switch (dev_priv->rps.power) { |
| 3673 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3674 | 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] | 3675 | new_power = BETWEEN; |
| 3676 | break; |
| 3677 | |
| 3678 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3679 | 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] | 3680 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3681 | 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] | 3682 | new_power = HIGH_POWER; |
| 3683 | break; |
| 3684 | |
| 3685 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3686 | 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] | 3687 | new_power = BETWEEN; |
| 3688 | break; |
| 3689 | } |
| 3690 | /* Max/min bins are special */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3691 | if (val == dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3692 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3693 | if (val == dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3694 | new_power = HIGH_POWER; |
| 3695 | if (new_power == dev_priv->rps.power) |
| 3696 | return; |
| 3697 | |
| 3698 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3699 | switch (new_power) { |
| 3700 | case LOW_POWER: |
| 3701 | /* Upclock if more than 95% busy over 16ms */ |
| 3702 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 3703 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 3704 | |
| 3705 | /* Downclock if less than 85% busy over 32ms */ |
| 3706 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3707 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 3708 | |
| 3709 | I915_WRITE(GEN6_RP_CONTROL, |
| 3710 | GEN6_RP_MEDIA_TURBO | |
| 3711 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3712 | GEN6_RP_MEDIA_IS_GFX | |
| 3713 | GEN6_RP_ENABLE | |
| 3714 | GEN6_RP_UP_BUSY_AVG | |
| 3715 | GEN6_RP_DOWN_IDLE_AVG); |
| 3716 | break; |
| 3717 | |
| 3718 | case BETWEEN: |
| 3719 | /* Upclock if more than 90% busy over 13ms */ |
| 3720 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 3721 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 3722 | |
| 3723 | /* Downclock if less than 75% busy over 32ms */ |
| 3724 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3725 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 3726 | |
| 3727 | I915_WRITE(GEN6_RP_CONTROL, |
| 3728 | GEN6_RP_MEDIA_TURBO | |
| 3729 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3730 | GEN6_RP_MEDIA_IS_GFX | |
| 3731 | GEN6_RP_ENABLE | |
| 3732 | GEN6_RP_UP_BUSY_AVG | |
| 3733 | GEN6_RP_DOWN_IDLE_AVG); |
| 3734 | break; |
| 3735 | |
| 3736 | case HIGH_POWER: |
| 3737 | /* Upclock if more than 85% busy over 10ms */ |
| 3738 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 3739 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 3740 | |
| 3741 | /* Downclock if less than 60% busy over 32ms */ |
| 3742 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3743 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 3744 | |
| 3745 | I915_WRITE(GEN6_RP_CONTROL, |
| 3746 | GEN6_RP_MEDIA_TURBO | |
| 3747 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3748 | GEN6_RP_MEDIA_IS_GFX | |
| 3749 | GEN6_RP_ENABLE | |
| 3750 | GEN6_RP_UP_BUSY_AVG | |
| 3751 | GEN6_RP_DOWN_IDLE_AVG); |
| 3752 | break; |
| 3753 | } |
| 3754 | |
| 3755 | dev_priv->rps.power = new_power; |
| 3756 | dev_priv->rps.last_adj = 0; |
| 3757 | } |
| 3758 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3759 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3760 | { |
| 3761 | u32 mask = 0; |
| 3762 | |
| 3763 | if (val > dev_priv->rps.min_freq_softlimit) |
| 3764 | mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
| 3765 | if (val < dev_priv->rps.max_freq_softlimit) |
| 3766 | mask |= GEN6_PM_RP_UP_THRESHOLD; |
| 3767 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3768 | mask |= dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED); |
| 3769 | mask &= dev_priv->pm_rps_events; |
| 3770 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 3771 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3774 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3775 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3776 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3777 | static void gen6_set_rps(struct drm_device *dev, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3778 | { |
| 3779 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3780 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3781 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3782 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3783 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3784 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3785 | /* min/max delay may still have been modified so be sure to |
| 3786 | * write the limits value. |
| 3787 | */ |
| 3788 | if (val != dev_priv->rps.cur_freq) { |
| 3789 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3790 | |
Ben Widawsky | 50e6a2a | 2014-03-31 17:16:43 -0700 | [diff] [blame] | 3791 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3792 | I915_WRITE(GEN6_RPNSWREQ, |
| 3793 | HSW_FREQUENCY(val)); |
| 3794 | else |
| 3795 | I915_WRITE(GEN6_RPNSWREQ, |
| 3796 | GEN6_FREQUENCY(val) | |
| 3797 | GEN6_OFFSET(0) | |
| 3798 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3799 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3800 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3801 | /* Make sure we continue to get interrupts |
| 3802 | * until we hit the minimum or maximum frequencies. |
| 3803 | */ |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3804 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3805 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3806 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3807 | POSTING_READ(GEN6_RPNSWREQ); |
| 3808 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3809 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3810 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3811 | } |
| 3812 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3813 | static void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 3814 | { |
| 3815 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3816 | |
| 3817 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 3818 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3819 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
| 3820 | |
| 3821 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 3822 | "Odd GPU freq value\n")) |
| 3823 | val &= ~1; |
| 3824 | |
| 3825 | if (val != dev_priv->rps.cur_freq) |
| 3826 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 3827 | |
| 3828 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 3829 | |
| 3830 | dev_priv->rps.cur_freq = val; |
| 3831 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
| 3832 | } |
| 3833 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3834 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 3835 | * |
| 3836 | * * If Gfx is Idle, then |
| 3837 | * 1. Mask Turbo interrupts |
| 3838 | * 2. Bring up Gfx clock |
| 3839 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 3840 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 3841 | * 5. Unmask Turbo interrupts |
| 3842 | */ |
| 3843 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 3844 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 3845 | struct drm_device *dev = dev_priv->dev; |
| 3846 | |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 3847 | /* CHV and latest VLV don't need to force the gfx clock */ |
| 3848 | if (IS_CHERRYVIEW(dev) || dev->pdev->revision >= 0xd) { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 3849 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3850 | return; |
| 3851 | } |
| 3852 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3853 | /* |
| 3854 | * When we are idle. Drop to min voltage state. |
| 3855 | */ |
| 3856 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3857 | if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3858 | return; |
| 3859 | |
| 3860 | /* Mask turbo interrupt so that they will not come in between */ |
Imre Deak | f24eeb1 | 2014-12-19 19:33:27 +0200 | [diff] [blame] | 3861 | I915_WRITE(GEN6_PMINTRMSK, |
| 3862 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3863 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3864 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3865 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3866 | dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3867 | |
| 3868 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3869 | dev_priv->rps.min_freq_softlimit); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3870 | |
| 3871 | 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] | 3872 | & GENFREQSTATUS) == 0, 100)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3873 | DRM_ERROR("timed out waiting for Punit\n"); |
| 3874 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3875 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3876 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3877 | I915_WRITE(GEN6_PMINTRMSK, |
| 3878 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3879 | } |
| 3880 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3881 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 3882 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3883 | struct drm_device *dev = dev_priv->dev; |
| 3884 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3885 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3886 | if (dev_priv->rps.enabled) { |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 3887 | if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3888 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 3889 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3890 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3891 | dev_priv->rps.last_adj = 0; |
| 3892 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3893 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3894 | } |
| 3895 | |
| 3896 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 3897 | { |
| 3898 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3899 | if (dev_priv->rps.enabled) { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3900 | intel_set_rps(dev_priv->dev, dev_priv->rps.max_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 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3906 | void intel_set_rps(struct drm_device *dev, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3907 | { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3908 | if (IS_VALLEYVIEW(dev)) |
| 3909 | valleyview_set_rps(dev, val); |
| 3910 | else |
| 3911 | gen6_set_rps(dev, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 3914 | static void gen9_disable_rps(struct drm_device *dev) |
| 3915 | { |
| 3916 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3917 | |
| 3918 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 3919 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3922 | static void gen6_disable_rps(struct drm_device *dev) |
| 3923 | { |
| 3924 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3925 | |
| 3926 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3927 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3928 | } |
| 3929 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3930 | static void cherryview_disable_rps(struct drm_device *dev) |
| 3931 | { |
| 3932 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3933 | |
| 3934 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3935 | } |
| 3936 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3937 | static void valleyview_disable_rps(struct drm_device *dev) |
| 3938 | { |
| 3939 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3940 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 3941 | /* we're doing forcewake before Disabling RC6, |
| 3942 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 3943 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 3944 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3945 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3946 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 3947 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3950 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 3951 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 3952 | if (IS_VALLEYVIEW(dev)) { |
| 3953 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 3954 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 3955 | else |
| 3956 | mode = 0; |
| 3957 | } |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 3958 | if (HAS_RC6p(dev)) |
| 3959 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s RC6p %s RC6pp %s\n", |
| 3960 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 3961 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 3962 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
| 3963 | |
| 3964 | else |
| 3965 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s\n", |
| 3966 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3967 | } |
| 3968 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3969 | 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] | 3970 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 3971 | /* No RC6 before Ironlake */ |
| 3972 | if (INTEL_INFO(dev)->gen < 5) |
| 3973 | return 0; |
| 3974 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3975 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 3976 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 3977 | return 0; |
| 3978 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3979 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3980 | if (enable_rc6 >= 0) { |
| 3981 | int mask; |
| 3982 | |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 3983 | if (HAS_RC6p(dev)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3984 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 3985 | INTEL_RC6pp_ENABLE; |
| 3986 | else |
| 3987 | mask = INTEL_RC6_ENABLE; |
| 3988 | |
| 3989 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 3990 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 3991 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3992 | |
| 3993 | return enable_rc6 & mask; |
| 3994 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3995 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 3996 | /* Disable RC6 on Ironlake */ |
| 3997 | if (INTEL_INFO(dev)->gen == 5) |
| 3998 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3999 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4000 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 4001 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4002 | |
| 4003 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4004 | } |
| 4005 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4006 | int intel_enable_rc6(const struct drm_device *dev) |
| 4007 | { |
| 4008 | return i915.enable_rc6; |
| 4009 | } |
| 4010 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4011 | static void gen6_init_rps_frequencies(struct drm_device *dev) |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4012 | { |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4013 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4014 | uint32_t rp_state_cap; |
| 4015 | u32 ddcc_status = 0; |
| 4016 | int ret; |
| 4017 | |
| 4018 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4019 | /* All of these values are in units of 50MHz */ |
| 4020 | dev_priv->rps.cur_freq = 0; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4021 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4022 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4023 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4024 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4025 | /* hw_max = RP0 until we check for overclocking */ |
| 4026 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 4027 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4028 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 4029 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
| 4030 | ret = sandybridge_pcode_read(dev_priv, |
| 4031 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 4032 | &ddcc_status); |
| 4033 | if (0 == ret) |
| 4034 | dev_priv->rps.efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 4035 | clamp_t(u8, |
| 4036 | ((ddcc_status >> 8) & 0xff), |
| 4037 | dev_priv->rps.min_freq, |
| 4038 | dev_priv->rps.max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4039 | } |
| 4040 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4041 | /* Preserve min/max settings in case of re-init */ |
| 4042 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4043 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4044 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4045 | if (dev_priv->rps.min_freq_softlimit == 0) { |
| 4046 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 4047 | dev_priv->rps.min_freq_softlimit = |
Tom O'Rourke | f4ab408 | 2014-11-19 14:21:53 -0800 | [diff] [blame] | 4048 | /* max(RPe, 450 MHz) */ |
| 4049 | max(dev_priv->rps.efficient_freq, (u8) 9); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4050 | else |
| 4051 | dev_priv->rps.min_freq_softlimit = |
| 4052 | dev_priv->rps.min_freq; |
| 4053 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4056 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4057 | static void gen9_enable_rps(struct drm_device *dev) |
| 4058 | { |
| 4059 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4060 | |
| 4061 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 4062 | |
Damien Lespiau | ba1c554 | 2015-01-16 18:07:26 +0000 | [diff] [blame] | 4063 | gen6_init_rps_frequencies(dev); |
| 4064 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4065 | I915_WRITE(GEN6_RPNSWREQ, 0xc800000); |
| 4066 | I915_WRITE(GEN6_RC_VIDEO_FREQ, 0xc800000); |
| 4067 | |
| 4068 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 0xf4240); |
| 4069 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, 0x12060000); |
| 4070 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 0xe808); |
| 4071 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 0x3bd08); |
| 4072 | I915_WRITE(GEN6_RP_UP_EI, 0x101d0); |
| 4073 | I915_WRITE(GEN6_RP_DOWN_EI, 0x55730); |
| 4074 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
| 4075 | I915_WRITE(GEN6_PMINTRMSK, 0x6); |
| 4076 | I915_WRITE(GEN6_RP_CONTROL, GEN6_RP_MEDIA_TURBO | |
| 4077 | GEN6_RP_MEDIA_HW_MODE | GEN6_RP_MEDIA_IS_GFX | |
| 4078 | GEN6_RP_ENABLE | GEN6_RP_UP_BUSY_AVG | |
| 4079 | GEN6_RP_DOWN_IDLE_AVG); |
| 4080 | |
| 4081 | gen6_enable_rps_interrupts(dev); |
| 4082 | |
| 4083 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 4084 | } |
| 4085 | |
| 4086 | static void gen9_enable_rc6(struct drm_device *dev) |
| 4087 | { |
| 4088 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4089 | struct intel_engine_cs *ring; |
| 4090 | uint32_t rc6_mask = 0; |
| 4091 | int unused; |
| 4092 | |
| 4093 | /* 1a: Software RC state - RC0 */ |
| 4094 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4095 | |
| 4096 | /* 1b: Get forcewake during program sequence. Although the driver |
| 4097 | * 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] | 4098 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4099 | |
| 4100 | /* 2a: Disable RC states. */ |
| 4101 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4102 | |
| 4103 | /* 2b: Program RC6 thresholds.*/ |
| 4104 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
| 4105 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4106 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4107 | for_each_ring(ring, dev_priv, unused) |
| 4108 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4109 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4110 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
| 4111 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4112 | /* 2c: Program Coarse Power Gating Policies. */ |
| 4113 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 4114 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 4115 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4116 | /* 3a: Enable RC6 */ |
| 4117 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4118 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 4119 | DRM_INFO("RC6 %s\n", (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 4120 | "on" : "off"); |
| 4121 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4122 | GEN6_RC_CTL_EI_MODE(1) | |
| 4123 | rc6_mask); |
| 4124 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4125 | /* 3b: Enable Coarse Power Gating only when RC6 is enabled */ |
| 4126 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? 3 : 0); |
| 4127 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4128 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4129 | |
| 4130 | } |
| 4131 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4132 | static void gen8_enable_rps(struct drm_device *dev) |
| 4133 | { |
| 4134 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4135 | struct intel_engine_cs *ring; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4136 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4137 | int unused; |
| 4138 | |
| 4139 | /* 1a: Software RC state - RC0 */ |
| 4140 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4141 | |
| 4142 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 4143 | * 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] | 4144 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4145 | |
| 4146 | /* 2a: Disable RC states. */ |
| 4147 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4148 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4149 | /* Initialize rps frequencies */ |
| 4150 | gen6_init_rps_frequencies(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4151 | |
| 4152 | /* 2b: Program RC6 thresholds.*/ |
| 4153 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4154 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4155 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4156 | for_each_ring(ring, dev_priv, unused) |
| 4157 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4158 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4159 | if (IS_BROADWELL(dev)) |
| 4160 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 4161 | else |
| 4162 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4163 | |
| 4164 | /* 3: Enable RC6 */ |
| 4165 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4166 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 4167 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4168 | if (IS_BROADWELL(dev)) |
| 4169 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4170 | GEN7_RC_CTL_TO_MODE | |
| 4171 | rc6_mask); |
| 4172 | else |
| 4173 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4174 | GEN6_RC_CTL_EI_MODE(1) | |
| 4175 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4176 | |
| 4177 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 4178 | I915_WRITE(GEN6_RPNSWREQ, |
| 4179 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 4180 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4181 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4182 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 4183 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4184 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4185 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 4186 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 4187 | dev_priv->rps.max_freq_softlimit << 24 | |
| 4188 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4189 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4190 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 4191 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 4192 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 4193 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4194 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4195 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4196 | |
| 4197 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4198 | I915_WRITE(GEN6_RP_CONTROL, |
| 4199 | GEN6_RP_MEDIA_TURBO | |
| 4200 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4201 | GEN6_RP_MEDIA_IS_GFX | |
| 4202 | GEN6_RP_ENABLE | |
| 4203 | GEN6_RP_UP_BUSY_AVG | |
| 4204 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4205 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4206 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4207 | |
Tom O'Rourke | c7f3153 | 2014-11-19 14:21:54 -0800 | [diff] [blame] | 4208 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
| 4209 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4210 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4211 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4212 | } |
| 4213 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4214 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4215 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4216 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4217 | struct intel_engine_cs *ring; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4218 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4219 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4220 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4221 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4222 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4223 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4224 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4225 | /* Here begins a magic sequence of register writes to enable |
| 4226 | * auto-downclocking. |
| 4227 | * |
| 4228 | * Perhaps there might be some value in exposing these to |
| 4229 | * userspace... |
| 4230 | */ |
| 4231 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4232 | |
| 4233 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 4234 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 4235 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 4236 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4237 | } |
| 4238 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4239 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4240 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4241 | /* Initialize rps frequencies */ |
| 4242 | gen6_init_rps_frequencies(dev); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 4243 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4244 | /* disable the counters and set deterministic thresholds */ |
| 4245 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4246 | |
| 4247 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 4248 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 4249 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 4250 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4251 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4252 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 4253 | for_each_ring(ring, dev_priv, i) |
| 4254 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4255 | |
| 4256 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4257 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 4258 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 4259 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 4260 | else |
| 4261 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 4262 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4263 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 4264 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4265 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4266 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 4267 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 4268 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 4269 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4270 | /* We don't use those on Haswell */ |
| 4271 | if (!IS_HASWELL(dev)) { |
| 4272 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 4273 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4274 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4275 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 4276 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 4277 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4278 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4279 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4280 | |
| 4281 | I915_WRITE(GEN6_RC_CONTROL, |
| 4282 | rc6_mask | |
| 4283 | GEN6_RC_CTL_EI_MODE(1) | |
| 4284 | GEN6_RC_CTL_HW_ENABLE); |
| 4285 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4286 | /* Power down if completely idle for over 50ms */ |
| 4287 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4288 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4289 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4290 | 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] | 4291 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4292 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4293 | |
| 4294 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 4295 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 4296 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4297 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4298 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4299 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4300 | } |
| 4301 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4302 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4303 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4304 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4305 | rc6vids = 0; |
| 4306 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4307 | if (IS_GEN6(dev) && ret) { |
| 4308 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4309 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4310 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4311 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4312 | rc6vids &= 0xffff00; |
| 4313 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4314 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4315 | if (ret) |
| 4316 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4317 | } |
| 4318 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4319 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4320 | } |
| 4321 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4322 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4323 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4324 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4325 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4326 | unsigned int gpu_freq; |
| 4327 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4328 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4329 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4330 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4331 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4332 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4333 | policy = cpufreq_cpu_get(0); |
| 4334 | if (policy) { |
| 4335 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4336 | cpufreq_cpu_put(policy); |
| 4337 | } else { |
| 4338 | /* |
| 4339 | * Default to measured freq if none found, PCU will ensure we |
| 4340 | * don't go over |
| 4341 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4342 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4343 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4344 | |
| 4345 | /* Convert from kHz to MHz */ |
| 4346 | max_ia_freq /= 1000; |
| 4347 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4348 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4349 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4350 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4351 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4352 | /* |
| 4353 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4354 | * to use for memory access. We do this by specifying the IA frequency |
| 4355 | * the PCU should use as a reference to determine the ring frequency. |
| 4356 | */ |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4357 | 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] | 4358 | gpu_freq--) { |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4359 | int diff = dev_priv->rps.max_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4360 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4361 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4362 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4363 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4364 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4365 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4366 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4367 | ring_freq = max(min_ring_freq, ring_freq); |
| 4368 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4369 | } else { |
| 4370 | /* On older processors, there is no separate ring |
| 4371 | * clock domain, so in order to boost the bandwidth |
| 4372 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4373 | * |
| 4374 | * For GPU frequencies less than 750MHz, |
| 4375 | * just use the lowest ring freq. |
| 4376 | */ |
| 4377 | if (gpu_freq < min_freq) |
| 4378 | ia_freq = 800; |
| 4379 | else |
| 4380 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4381 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4382 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4383 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4384 | sandybridge_pcode_write(dev_priv, |
| 4385 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4386 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4387 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4388 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4389 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4390 | } |
| 4391 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4392 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4393 | { |
| 4394 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4395 | |
| 4396 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4397 | return; |
| 4398 | |
| 4399 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4400 | __gen6_update_ring_freq(dev); |
| 4401 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4402 | } |
| 4403 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4404 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4405 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4406 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4407 | u32 val, rp0; |
| 4408 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4409 | if (dev->pdev->revision >= 0x20) { |
| 4410 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4411 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4412 | switch (INTEL_INFO(dev)->eu_total) { |
| 4413 | case 8: |
| 4414 | /* (2 * 4) config */ |
| 4415 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 4416 | break; |
| 4417 | case 12: |
| 4418 | /* (2 * 6) config */ |
| 4419 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 4420 | break; |
| 4421 | case 16: |
| 4422 | /* (2 * 8) config */ |
| 4423 | default: |
| 4424 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 4425 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 4426 | break; |
| 4427 | } |
| 4428 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 4429 | } else { |
| 4430 | /* For pre-production hardware */ |
| 4431 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4432 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4433 | PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4434 | } |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4435 | return rp0; |
| 4436 | } |
| 4437 | |
| 4438 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4439 | { |
| 4440 | u32 val, rpe; |
| 4441 | |
| 4442 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4443 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4444 | |
| 4445 | return rpe; |
| 4446 | } |
| 4447 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4448 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4449 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4450 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4451 | u32 val, rp1; |
| 4452 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4453 | if (dev->pdev->revision >= 0x20) { |
| 4454 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 4455 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 4456 | } else { |
| 4457 | /* For pre-production hardware */ |
| 4458 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4459 | rp1 = ((val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4460 | PUNIT_GPU_STATUS_MAX_FREQ_MASK); |
| 4461 | } |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4462 | return rp1; |
| 4463 | } |
| 4464 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4465 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4466 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4467 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4468 | u32 val, rpn; |
| 4469 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4470 | if (dev->pdev->revision >= 0x20) { |
| 4471 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 4472 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 4473 | FB_GFX_FREQ_FUSE_MASK); |
| 4474 | } else { /* For pre-production hardware */ |
| 4475 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4476 | rpn = ((val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & |
| 4477 | PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK); |
| 4478 | } |
| 4479 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4480 | return rpn; |
| 4481 | } |
| 4482 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4483 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4484 | { |
| 4485 | u32 val, rp1; |
| 4486 | |
| 4487 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4488 | |
| 4489 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4490 | |
| 4491 | return rp1; |
| 4492 | } |
| 4493 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4494 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4495 | { |
| 4496 | u32 val, rp0; |
| 4497 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4498 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4499 | |
| 4500 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4501 | /* Clamp to max */ |
| 4502 | rp0 = min_t(u32, rp0, 0xea); |
| 4503 | |
| 4504 | return rp0; |
| 4505 | } |
| 4506 | |
| 4507 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4508 | { |
| 4509 | u32 val, rpe; |
| 4510 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4511 | 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] | 4512 | 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] | 4513 | 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] | 4514 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4515 | |
| 4516 | return rpe; |
| 4517 | } |
| 4518 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4519 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4520 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4521 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4522 | } |
| 4523 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4524 | /* Check that the pctx buffer wasn't move under us. */ |
| 4525 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4526 | { |
| 4527 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4528 | |
| 4529 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4530 | dev_priv->vlv_pctx->stolen->start); |
| 4531 | } |
| 4532 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4533 | |
| 4534 | /* Check that the pcbr address is not empty. */ |
| 4535 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4536 | { |
| 4537 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4538 | |
| 4539 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4540 | } |
| 4541 | |
| 4542 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4543 | { |
| 4544 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4545 | unsigned long pctx_paddr, paddr; |
| 4546 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4547 | u32 pcbr; |
| 4548 | int pctx_size = 32*1024; |
| 4549 | |
| 4550 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4551 | |
| 4552 | pcbr = I915_READ(VLV_PCBR); |
| 4553 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4554 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4555 | paddr = (dev_priv->mm.stolen_base + |
| 4556 | (gtt->stolen_size - pctx_size)); |
| 4557 | |
| 4558 | pctx_paddr = (paddr & (~4095)); |
| 4559 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4560 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4561 | |
| 4562 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4563 | } |
| 4564 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4565 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4566 | { |
| 4567 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4568 | struct drm_i915_gem_object *pctx; |
| 4569 | unsigned long pctx_paddr; |
| 4570 | u32 pcbr; |
| 4571 | int pctx_size = 24*1024; |
| 4572 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4573 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4574 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4575 | pcbr = I915_READ(VLV_PCBR); |
| 4576 | if (pcbr) { |
| 4577 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4578 | int pcbr_offset; |
| 4579 | |
| 4580 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4581 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4582 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4583 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4584 | pctx_size); |
| 4585 | goto out; |
| 4586 | } |
| 4587 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4588 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 4589 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4590 | /* |
| 4591 | * From the Gunit register HAS: |
| 4592 | * The Gfx driver is expected to program this register and ensure |
| 4593 | * proper allocation within Gfx stolen memory. For example, this |
| 4594 | * register should be programmed such than the PCBR range does not |
| 4595 | * overlap with other ranges, such as the frame buffer, protected |
| 4596 | * memory, or any other relevant ranges. |
| 4597 | */ |
| 4598 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4599 | if (!pctx) { |
| 4600 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4601 | return; |
| 4602 | } |
| 4603 | |
| 4604 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4605 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4606 | |
| 4607 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4608 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4609 | dev_priv->vlv_pctx = pctx; |
| 4610 | } |
| 4611 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4612 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4613 | { |
| 4614 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4615 | |
| 4616 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4617 | return; |
| 4618 | |
| 4619 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 4620 | dev_priv->vlv_pctx = NULL; |
| 4621 | } |
| 4622 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4623 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 4624 | { |
| 4625 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4626 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4627 | |
| 4628 | valleyview_setup_pctx(dev); |
| 4629 | |
| 4630 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4631 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4632 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4633 | switch ((val >> 6) & 3) { |
| 4634 | case 0: |
| 4635 | case 1: |
| 4636 | dev_priv->mem_freq = 800; |
| 4637 | break; |
| 4638 | case 2: |
| 4639 | dev_priv->mem_freq = 1066; |
| 4640 | break; |
| 4641 | case 3: |
| 4642 | dev_priv->mem_freq = 1333; |
| 4643 | break; |
| 4644 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4645 | 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] | 4646 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4647 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 4648 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4649 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4650 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4651 | dev_priv->rps.max_freq); |
| 4652 | |
| 4653 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 4654 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4655 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4656 | dev_priv->rps.efficient_freq); |
| 4657 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4658 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 4659 | 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] | 4660 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4661 | dev_priv->rps.rp1_freq); |
| 4662 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4663 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 4664 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4665 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4666 | dev_priv->rps.min_freq); |
| 4667 | |
| 4668 | /* Preserve min/max settings in case of re-init */ |
| 4669 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4670 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4671 | |
| 4672 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4673 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4674 | |
| 4675 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4676 | } |
| 4677 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4678 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4679 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4680 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4681 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4682 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4683 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4684 | |
| 4685 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4686 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 4687 | mutex_lock(&dev_priv->dpio_lock); |
| 4688 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
| 4689 | mutex_unlock(&dev_priv->dpio_lock); |
| 4690 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4691 | switch ((val >> 2) & 0x7) { |
| 4692 | case 0: |
| 4693 | case 1: |
| 4694 | dev_priv->rps.cz_freq = 200; |
| 4695 | dev_priv->mem_freq = 1600; |
| 4696 | break; |
| 4697 | case 2: |
| 4698 | dev_priv->rps.cz_freq = 267; |
| 4699 | dev_priv->mem_freq = 1600; |
| 4700 | break; |
| 4701 | case 3: |
| 4702 | dev_priv->rps.cz_freq = 333; |
| 4703 | dev_priv->mem_freq = 2000; |
| 4704 | break; |
| 4705 | case 4: |
| 4706 | dev_priv->rps.cz_freq = 320; |
| 4707 | dev_priv->mem_freq = 1600; |
| 4708 | break; |
| 4709 | case 5: |
| 4710 | dev_priv->rps.cz_freq = 400; |
| 4711 | dev_priv->mem_freq = 1600; |
| 4712 | break; |
| 4713 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4714 | 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] | 4715 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4716 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4717 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4718 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4719 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4720 | dev_priv->rps.max_freq); |
| 4721 | |
| 4722 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4723 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4724 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4725 | dev_priv->rps.efficient_freq); |
| 4726 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4727 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4728 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4729 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4730 | dev_priv->rps.rp1_freq); |
| 4731 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4732 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4733 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4734 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4735 | dev_priv->rps.min_freq); |
| 4736 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4737 | WARN_ONCE((dev_priv->rps.max_freq | |
| 4738 | dev_priv->rps.efficient_freq | |
| 4739 | dev_priv->rps.rp1_freq | |
| 4740 | dev_priv->rps.min_freq) & 1, |
| 4741 | "Odd GPU freq values\n"); |
| 4742 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4743 | /* Preserve min/max settings in case of re-init */ |
| 4744 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4745 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4746 | |
| 4747 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4748 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4749 | |
| 4750 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4751 | } |
| 4752 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4753 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4754 | { |
| 4755 | valleyview_cleanup_pctx(dev); |
| 4756 | } |
| 4757 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4758 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4759 | { |
| 4760 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4761 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4762 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4763 | int i; |
| 4764 | |
| 4765 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4766 | |
| 4767 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4768 | if (gtfifodbg) { |
| 4769 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4770 | gtfifodbg); |
| 4771 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4772 | } |
| 4773 | |
| 4774 | cherryview_check_pctx(dev_priv); |
| 4775 | |
| 4776 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 4777 | * 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] | 4778 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4779 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 4780 | /* Disable RC states. */ |
| 4781 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4782 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4783 | /* 2a: Program RC6 thresholds.*/ |
| 4784 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4785 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4786 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4787 | |
| 4788 | for_each_ring(ring, dev_priv, i) |
| 4789 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4790 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4791 | |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 4792 | /* TO threshold set to 1750 us ( 0x557 * 1.28 us) */ |
| 4793 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4794 | |
| 4795 | /* allows RC6 residency counter to work */ |
| 4796 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 4797 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 4798 | VLV_MEDIA_RC6_COUNT_EN | |
| 4799 | VLV_RENDER_RC6_COUNT_EN)); |
| 4800 | |
| 4801 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 4802 | pcbr = I915_READ(VLV_PCBR); |
| 4803 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4804 | /* 3: Enable RC6 */ |
| 4805 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 4806 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 4807 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4808 | |
| 4809 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 4810 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4811 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 4812 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4813 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4814 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4815 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4816 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4817 | |
| 4818 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4819 | |
| 4820 | /* 5: Enable RPS */ |
| 4821 | I915_WRITE(GEN6_RP_CONTROL, |
| 4822 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 4823 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4824 | GEN6_RP_ENABLE | |
| 4825 | GEN6_RP_UP_BUSY_AVG | |
| 4826 | GEN6_RP_DOWN_IDLE_AVG); |
| 4827 | |
| 4828 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4829 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 4830 | /* RPS code assumes GPLL is used */ |
| 4831 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 4832 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 4833 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4834 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4835 | |
| 4836 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 4837 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4838 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4839 | dev_priv->rps.cur_freq); |
| 4840 | |
| 4841 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4842 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4843 | dev_priv->rps.efficient_freq); |
| 4844 | |
| 4845 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 4846 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4847 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4848 | } |
| 4849 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4850 | static void valleyview_enable_rps(struct drm_device *dev) |
| 4851 | { |
| 4852 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4853 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 4854 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4855 | int i; |
| 4856 | |
| 4857 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4858 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4859 | valleyview_check_pctx(dev_priv); |
| 4860 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4861 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 4862 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4863 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4864 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4865 | } |
| 4866 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4867 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4868 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4869 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 4870 | /* Disable RC states. */ |
| 4871 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4872 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 4873 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4874 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4875 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4876 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4877 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4878 | |
| 4879 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4880 | |
| 4881 | I915_WRITE(GEN6_RP_CONTROL, |
| 4882 | GEN6_RP_MEDIA_TURBO | |
| 4883 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4884 | GEN6_RP_MEDIA_IS_GFX | |
| 4885 | GEN6_RP_ENABLE | |
| 4886 | GEN6_RP_UP_BUSY_AVG | |
| 4887 | GEN6_RP_DOWN_IDLE_CONT); |
| 4888 | |
| 4889 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 4890 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4891 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4892 | |
| 4893 | for_each_ring(ring, dev_priv, i) |
| 4894 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4895 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 4896 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4897 | |
| 4898 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4899 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4900 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 4901 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4902 | VLV_MEDIA_RC6_COUNT_EN | |
| 4903 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4904 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4905 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 4906 | 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] | 4907 | |
| 4908 | intel_print_rc6_info(dev, rc6_mode); |
| 4909 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4910 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4911 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4912 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4913 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 4914 | /* RPS code assumes GPLL is used */ |
| 4915 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 4916 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 4917 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4918 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4919 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4920 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4921 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4922 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4923 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4924 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4925 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4926 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4927 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4928 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4929 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4930 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4931 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4934 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 4935 | { |
| 4936 | unsigned long freq; |
| 4937 | int div = (vidfreq & 0x3f0000) >> 16; |
| 4938 | int post = (vidfreq & 0x3000) >> 12; |
| 4939 | int pre = (vidfreq & 0x7); |
| 4940 | |
| 4941 | if (!pre) |
| 4942 | return 0; |
| 4943 | |
| 4944 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 4945 | |
| 4946 | return freq; |
| 4947 | } |
| 4948 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4949 | static const struct cparams { |
| 4950 | u16 i; |
| 4951 | u16 t; |
| 4952 | u16 m; |
| 4953 | u16 c; |
| 4954 | } cparams[] = { |
| 4955 | { 1, 1333, 301, 28664 }, |
| 4956 | { 1, 1066, 294, 24460 }, |
| 4957 | { 1, 800, 294, 25192 }, |
| 4958 | { 0, 1333, 276, 27605 }, |
| 4959 | { 0, 1066, 276, 27605 }, |
| 4960 | { 0, 800, 231, 23784 }, |
| 4961 | }; |
| 4962 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4963 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4964 | { |
| 4965 | u64 total_count, diff, ret; |
| 4966 | u32 count1, count2, count3, m = 0, c = 0; |
| 4967 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 4968 | int i; |
| 4969 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4970 | assert_spin_locked(&mchdev_lock); |
| 4971 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4972 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4973 | |
| 4974 | /* Prevent division-by-zero if we are asking too fast. |
| 4975 | * Also, we don't get interesting results if we are polling |
| 4976 | * faster than once in 10ms, so just return the saved value |
| 4977 | * in such cases. |
| 4978 | */ |
| 4979 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4980 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4981 | |
| 4982 | count1 = I915_READ(DMIEC); |
| 4983 | count2 = I915_READ(DDREC); |
| 4984 | count3 = I915_READ(CSIEC); |
| 4985 | |
| 4986 | total_count = count1 + count2 + count3; |
| 4987 | |
| 4988 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4989 | if (total_count < dev_priv->ips.last_count1) { |
| 4990 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4991 | diff += total_count; |
| 4992 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4993 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4997 | if (cparams[i].i == dev_priv->ips.c_m && |
| 4998 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4999 | m = cparams[i].m; |
| 5000 | c = cparams[i].c; |
| 5001 | break; |
| 5002 | } |
| 5003 | } |
| 5004 | |
| 5005 | diff = div_u64(diff, diff1); |
| 5006 | ret = ((m * diff) + c); |
| 5007 | ret = div_u64(ret, 10); |
| 5008 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5009 | dev_priv->ips.last_count1 = total_count; |
| 5010 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5011 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5012 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5013 | |
| 5014 | return ret; |
| 5015 | } |
| 5016 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5017 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 5018 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5019 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5020 | unsigned long val; |
| 5021 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5022 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5023 | return 0; |
| 5024 | |
| 5025 | spin_lock_irq(&mchdev_lock); |
| 5026 | |
| 5027 | val = __i915_chipset_val(dev_priv); |
| 5028 | |
| 5029 | spin_unlock_irq(&mchdev_lock); |
| 5030 | |
| 5031 | return val; |
| 5032 | } |
| 5033 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5034 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 5035 | { |
| 5036 | unsigned long m, x, b; |
| 5037 | u32 tsfs; |
| 5038 | |
| 5039 | tsfs = I915_READ(TSFS); |
| 5040 | |
| 5041 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 5042 | x = I915_READ8(TR1); |
| 5043 | |
| 5044 | b = tsfs & TSFS_INTR_MASK; |
| 5045 | |
| 5046 | return ((m * x) / 127) - b; |
| 5047 | } |
| 5048 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5049 | static int _pxvid_to_vd(u8 pxvid) |
| 5050 | { |
| 5051 | if (pxvid == 0) |
| 5052 | return 0; |
| 5053 | |
| 5054 | if (pxvid >= 8 && pxvid < 31) |
| 5055 | pxvid = 31; |
| 5056 | |
| 5057 | return (pxvid + 2) * 125; |
| 5058 | } |
| 5059 | |
| 5060 | 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] | 5061 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5062 | struct drm_device *dev = dev_priv->dev; |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5063 | const int vd = _pxvid_to_vd(pxvid); |
| 5064 | const int vm = vd - 1125; |
| 5065 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5066 | if (INTEL_INFO(dev)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5067 | return vm > 0 ? vm : 0; |
| 5068 | |
| 5069 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5070 | } |
| 5071 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5072 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5073 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5074 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5075 | u32 count; |
| 5076 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5077 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5078 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5079 | now = ktime_get_raw_ns(); |
| 5080 | diffms = now - dev_priv->ips.last_time2; |
| 5081 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5082 | |
| 5083 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5084 | if (!diffms) |
| 5085 | return; |
| 5086 | |
| 5087 | count = I915_READ(GFXEC); |
| 5088 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5089 | if (count < dev_priv->ips.last_count2) { |
| 5090 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5091 | diff += count; |
| 5092 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5093 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5094 | } |
| 5095 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5096 | dev_priv->ips.last_count2 = count; |
| 5097 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5098 | |
| 5099 | /* More magic constants... */ |
| 5100 | diff = diff * 1181; |
| 5101 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5102 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5103 | } |
| 5104 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5105 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 5106 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5107 | struct drm_device *dev = dev_priv->dev; |
| 5108 | |
| 5109 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5110 | return; |
| 5111 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5112 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5113 | |
| 5114 | __i915_update_gfx_val(dev_priv); |
| 5115 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5116 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5117 | } |
| 5118 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5119 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5120 | { |
| 5121 | unsigned long t, corr, state1, corr2, state2; |
| 5122 | u32 pxvid, ext_v; |
| 5123 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5124 | assert_spin_locked(&mchdev_lock); |
| 5125 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5126 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5127 | pxvid = (pxvid >> 24) & 0x7f; |
| 5128 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5129 | |
| 5130 | state1 = ext_v; |
| 5131 | |
| 5132 | t = i915_mch_val(dev_priv); |
| 5133 | |
| 5134 | /* Revel in the empirically derived constants */ |
| 5135 | |
| 5136 | /* Correction factor in 1/100000 units */ |
| 5137 | if (t > 80) |
| 5138 | corr = ((t * 2349) + 135940); |
| 5139 | else if (t >= 50) |
| 5140 | corr = ((t * 964) + 29317); |
| 5141 | else /* < 50 */ |
| 5142 | corr = ((t * 301) + 1004); |
| 5143 | |
| 5144 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5145 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5146 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5147 | |
| 5148 | state2 = (corr2 * state1) / 10000; |
| 5149 | state2 /= 100; /* convert to mW */ |
| 5150 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5151 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5152 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5153 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5154 | } |
| 5155 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5156 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5157 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5158 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5159 | unsigned long val; |
| 5160 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5161 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5162 | return 0; |
| 5163 | |
| 5164 | spin_lock_irq(&mchdev_lock); |
| 5165 | |
| 5166 | val = __i915_gfx_val(dev_priv); |
| 5167 | |
| 5168 | spin_unlock_irq(&mchdev_lock); |
| 5169 | |
| 5170 | return val; |
| 5171 | } |
| 5172 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5173 | /** |
| 5174 | * i915_read_mch_val - return value for IPS use |
| 5175 | * |
| 5176 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5177 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5178 | */ |
| 5179 | unsigned long i915_read_mch_val(void) |
| 5180 | { |
| 5181 | struct drm_i915_private *dev_priv; |
| 5182 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5183 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5184 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5185 | if (!i915_mch_dev) |
| 5186 | goto out_unlock; |
| 5187 | dev_priv = i915_mch_dev; |
| 5188 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5189 | chipset_val = __i915_chipset_val(dev_priv); |
| 5190 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5191 | |
| 5192 | ret = chipset_val + graphics_val; |
| 5193 | |
| 5194 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5195 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5196 | |
| 5197 | return ret; |
| 5198 | } |
| 5199 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5200 | |
| 5201 | /** |
| 5202 | * i915_gpu_raise - raise GPU frequency limit |
| 5203 | * |
| 5204 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5205 | */ |
| 5206 | bool i915_gpu_raise(void) |
| 5207 | { |
| 5208 | struct drm_i915_private *dev_priv; |
| 5209 | bool ret = true; |
| 5210 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5211 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5212 | if (!i915_mch_dev) { |
| 5213 | ret = false; |
| 5214 | goto out_unlock; |
| 5215 | } |
| 5216 | dev_priv = i915_mch_dev; |
| 5217 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5218 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5219 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5220 | |
| 5221 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5222 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5223 | |
| 5224 | return ret; |
| 5225 | } |
| 5226 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5227 | |
| 5228 | /** |
| 5229 | * i915_gpu_lower - lower GPU frequency limit |
| 5230 | * |
| 5231 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5232 | * frequency maximum. |
| 5233 | */ |
| 5234 | bool i915_gpu_lower(void) |
| 5235 | { |
| 5236 | struct drm_i915_private *dev_priv; |
| 5237 | bool ret = true; |
| 5238 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5239 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5240 | if (!i915_mch_dev) { |
| 5241 | ret = false; |
| 5242 | goto out_unlock; |
| 5243 | } |
| 5244 | dev_priv = i915_mch_dev; |
| 5245 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5246 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 5247 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5248 | |
| 5249 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5250 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5251 | |
| 5252 | return ret; |
| 5253 | } |
| 5254 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 5255 | |
| 5256 | /** |
| 5257 | * i915_gpu_busy - indicate GPU business to IPS |
| 5258 | * |
| 5259 | * Tell the IPS driver whether or not the GPU is busy. |
| 5260 | */ |
| 5261 | bool i915_gpu_busy(void) |
| 5262 | { |
| 5263 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5264 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5265 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5266 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5267 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5268 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5269 | if (!i915_mch_dev) |
| 5270 | goto out_unlock; |
| 5271 | dev_priv = i915_mch_dev; |
| 5272 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5273 | for_each_ring(ring, dev_priv, i) |
| 5274 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5275 | |
| 5276 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5277 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5278 | |
| 5279 | return ret; |
| 5280 | } |
| 5281 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 5282 | |
| 5283 | /** |
| 5284 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5285 | * |
| 5286 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5287 | * current frequency to the default. |
| 5288 | */ |
| 5289 | bool i915_gpu_turbo_disable(void) |
| 5290 | { |
| 5291 | struct drm_i915_private *dev_priv; |
| 5292 | bool ret = true; |
| 5293 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5294 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5295 | if (!i915_mch_dev) { |
| 5296 | ret = false; |
| 5297 | goto out_unlock; |
| 5298 | } |
| 5299 | dev_priv = i915_mch_dev; |
| 5300 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5301 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5302 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5303 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5304 | ret = false; |
| 5305 | |
| 5306 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5307 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5308 | |
| 5309 | return ret; |
| 5310 | } |
| 5311 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5312 | |
| 5313 | /** |
| 5314 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5315 | * IPS got loaded first. |
| 5316 | * |
| 5317 | * This awkward dance is so that neither module has to depend on the |
| 5318 | * other in order for IPS to do the appropriate communication of |
| 5319 | * GPU turbo limits to i915. |
| 5320 | */ |
| 5321 | static void |
| 5322 | ips_ping_for_i915_load(void) |
| 5323 | { |
| 5324 | void (*link)(void); |
| 5325 | |
| 5326 | link = symbol_get(ips_link_to_i915_driver); |
| 5327 | if (link) { |
| 5328 | link(); |
| 5329 | symbol_put(ips_link_to_i915_driver); |
| 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5334 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5335 | /* We only register the i915 ips part with intel-ips once everything is |
| 5336 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5337 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5338 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5339 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5340 | |
| 5341 | ips_ping_for_i915_load(); |
| 5342 | } |
| 5343 | |
| 5344 | void intel_gpu_ips_teardown(void) |
| 5345 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5346 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5347 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5348 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5349 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5350 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5351 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5352 | { |
| 5353 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5354 | u32 lcfuse; |
| 5355 | u8 pxw[16]; |
| 5356 | int i; |
| 5357 | |
| 5358 | /* Disable to program */ |
| 5359 | I915_WRITE(ECR, 0); |
| 5360 | POSTING_READ(ECR); |
| 5361 | |
| 5362 | /* Program energy weights for various events */ |
| 5363 | I915_WRITE(SDEW, 0x15040d00); |
| 5364 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5365 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5366 | I915_WRITE(CSIEW2, 0x04000004); |
| 5367 | |
| 5368 | for (i = 0; i < 5; i++) |
| 5369 | I915_WRITE(PEW + (i * 4), 0); |
| 5370 | for (i = 0; i < 3; i++) |
| 5371 | I915_WRITE(DEW + (i * 4), 0); |
| 5372 | |
| 5373 | /* Program P-state weights to account for frequency power adjustment */ |
| 5374 | for (i = 0; i < 16; i++) { |
| 5375 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5376 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5377 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5378 | PXVFREQ_PX_SHIFT; |
| 5379 | unsigned long val; |
| 5380 | |
| 5381 | val = vid * vid; |
| 5382 | val *= (freq / 1000); |
| 5383 | val *= 255; |
| 5384 | val /= (127*127*900); |
| 5385 | if (val > 0xff) |
| 5386 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5387 | pxw[i] = val; |
| 5388 | } |
| 5389 | /* Render standby states get 0 weight */ |
| 5390 | pxw[14] = 0; |
| 5391 | pxw[15] = 0; |
| 5392 | |
| 5393 | for (i = 0; i < 4; i++) { |
| 5394 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 5395 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 5396 | I915_WRITE(PXW + (i * 4), val); |
| 5397 | } |
| 5398 | |
| 5399 | /* Adjust magic regs to magic values (more experimental results) */ |
| 5400 | I915_WRITE(OGW0, 0); |
| 5401 | I915_WRITE(OGW1, 0); |
| 5402 | I915_WRITE(EG0, 0x00007f00); |
| 5403 | I915_WRITE(EG1, 0x0000000e); |
| 5404 | I915_WRITE(EG2, 0x000e0000); |
| 5405 | I915_WRITE(EG3, 0x68000300); |
| 5406 | I915_WRITE(EG4, 0x42000000); |
| 5407 | I915_WRITE(EG5, 0x00140031); |
| 5408 | I915_WRITE(EG6, 0); |
| 5409 | I915_WRITE(EG7, 0); |
| 5410 | |
| 5411 | for (i = 0; i < 8; i++) |
| 5412 | I915_WRITE(PXWL + (i * 4), 0); |
| 5413 | |
| 5414 | /* Enable PMON + select events */ |
| 5415 | I915_WRITE(ECR, 0x80000019); |
| 5416 | |
| 5417 | lcfuse = I915_READ(LCFUSE02); |
| 5418 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5419 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5420 | } |
| 5421 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5422 | void intel_init_gt_powersave(struct drm_device *dev) |
| 5423 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5424 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 5425 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5426 | if (IS_CHERRYVIEW(dev)) |
| 5427 | cherryview_init_gt_powersave(dev); |
| 5428 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5429 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 5433 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5434 | if (IS_CHERRYVIEW(dev)) |
| 5435 | return; |
| 5436 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5437 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5438 | } |
| 5439 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5440 | static void gen6_suspend_rps(struct drm_device *dev) |
| 5441 | { |
| 5442 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5443 | |
| 5444 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 5445 | |
| 5446 | /* |
| 5447 | * TODO: disable RPS interrupts on GEN9+ too once RPS support |
| 5448 | * is added for it. |
| 5449 | */ |
| 5450 | if (INTEL_INFO(dev)->gen < 9) |
| 5451 | gen6_disable_rps_interrupts(dev); |
| 5452 | } |
| 5453 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5454 | /** |
| 5455 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 5456 | * @dev: drm device |
| 5457 | * |
| 5458 | * We don't want to disable RC6 or other features here, we just want |
| 5459 | * to make sure any work we've queued has finished and won't bother |
| 5460 | * us while we're suspended. |
| 5461 | */ |
| 5462 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 5463 | { |
| 5464 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5465 | |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 5466 | if (INTEL_INFO(dev)->gen < 6) |
| 5467 | return; |
| 5468 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5469 | gen6_suspend_rps(dev); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 5470 | |
| 5471 | /* Force GPU to min freq during suspend */ |
| 5472 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5473 | } |
| 5474 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5475 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 5476 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5477 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5478 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5479 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5480 | ironlake_disable_drps(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5481 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5482 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5483 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5484 | mutex_lock(&dev_priv->rps.hw_lock); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5485 | if (INTEL_INFO(dev)->gen >= 9) |
| 5486 | gen9_disable_rps(dev); |
| 5487 | else if (IS_CHERRYVIEW(dev)) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5488 | cherryview_disable_rps(dev); |
| 5489 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5490 | valleyview_disable_rps(dev); |
| 5491 | else |
| 5492 | gen6_disable_rps(dev); |
Imre Deak | e534770 | 2014-11-19 15:30:02 +0200 | [diff] [blame] | 5493 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5494 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5495 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5496 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5497 | } |
| 5498 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5499 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5500 | { |
| 5501 | struct drm_i915_private *dev_priv = |
| 5502 | container_of(work, struct drm_i915_private, |
| 5503 | rps.delayed_resume_work.work); |
| 5504 | struct drm_device *dev = dev_priv->dev; |
| 5505 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5506 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5507 | |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5508 | /* |
| 5509 | * TODO: reset/enable RPS interrupts on GEN9+ too, once RPS support is |
| 5510 | * added for it. |
| 5511 | */ |
| 5512 | if (INTEL_INFO(dev)->gen < 9) |
| 5513 | gen6_reset_rps_interrupts(dev); |
| 5514 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5515 | if (IS_CHERRYVIEW(dev)) { |
| 5516 | cherryview_enable_rps(dev); |
| 5517 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5518 | valleyview_enable_rps(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5519 | } else if (INTEL_INFO(dev)->gen >= 9) { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5520 | gen9_enable_rc6(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5521 | gen9_enable_rps(dev); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5522 | __gen6_update_ring_freq(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5523 | } else if (IS_BROADWELL(dev)) { |
| 5524 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5525 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5526 | } else { |
| 5527 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5528 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5529 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5530 | dev_priv->rps.enabled = true; |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5531 | |
| 5532 | if (INTEL_INFO(dev)->gen < 9) |
| 5533 | gen6_enable_rps_interrupts(dev); |
| 5534 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5535 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5536 | |
| 5537 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5538 | } |
| 5539 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5540 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5541 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5542 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5543 | |
Yu Zhang | f61018b | 2015-02-10 19:05:52 +0800 | [diff] [blame] | 5544 | /* Powersaving is controlled by the host when inside a VM */ |
| 5545 | if (intel_vgpu_active(dev)) |
| 5546 | return; |
| 5547 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5548 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5549 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5550 | ironlake_enable_drps(dev); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5551 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5552 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5553 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5554 | /* |
| 5555 | * PCU communication is slow and this doesn't need to be |
| 5556 | * done at any specific time, so do this out of our fast path |
| 5557 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5558 | * |
| 5559 | * We depend on the HW RC6 power context save/restore |
| 5560 | * mechanism when entering D3 through runtime PM suspend. So |
| 5561 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5562 | * get here via the driver load/system resume/runtime resume |
| 5563 | * paths, so the _noresume version is enough (and in case of |
| 5564 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5565 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5566 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5567 | round_jiffies_up_relative(HZ))) |
| 5568 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5569 | } |
| 5570 | } |
| 5571 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5572 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5573 | { |
| 5574 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5575 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5576 | if (INTEL_INFO(dev)->gen < 6) |
| 5577 | return; |
| 5578 | |
| 5579 | gen6_suspend_rps(dev); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5580 | dev_priv->rps.enabled = false; |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5581 | } |
| 5582 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5583 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5584 | { |
| 5585 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5586 | |
| 5587 | /* |
| 5588 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5589 | * gating for the panel power sequencer or it will fail to |
| 5590 | * start up when no ports are active. |
| 5591 | */ |
| 5592 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5593 | } |
| 5594 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5595 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5596 | { |
| 5597 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5598 | int pipe; |
| 5599 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5600 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5601 | I915_WRITE(DSPCNTR(pipe), |
| 5602 | I915_READ(DSPCNTR(pipe)) | |
| 5603 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5604 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5605 | } |
| 5606 | } |
| 5607 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5608 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5609 | { |
| 5610 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5611 | |
| 5612 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5613 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5614 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5615 | |
| 5616 | /* |
| 5617 | * Don't touch WM1S_LP_EN here. |
| 5618 | * Doing so could cause underruns. |
| 5619 | */ |
| 5620 | } |
| 5621 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5622 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5623 | { |
| 5624 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5625 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5626 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5627 | /* |
| 5628 | * Required for FBC |
| 5629 | * WaFbcDisableDpfcClockGating:ilk |
| 5630 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5631 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5632 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5633 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5634 | |
| 5635 | I915_WRITE(PCH_3DCGDIS0, |
| 5636 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5637 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5638 | I915_WRITE(PCH_3DCGDIS1, |
| 5639 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5640 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5641 | /* |
| 5642 | * According to the spec the following bits should be set in |
| 5643 | * order to enable memory self-refresh |
| 5644 | * The bit 22/21 of 0x42004 |
| 5645 | * The bit 5 of 0x42020 |
| 5646 | * The bit 15 of 0x45000 |
| 5647 | */ |
| 5648 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5649 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5650 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5651 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5652 | I915_WRITE(DISP_ARB_CTL, |
| 5653 | (I915_READ(DISP_ARB_CTL) | |
| 5654 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5655 | |
| 5656 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5657 | |
| 5658 | /* |
| 5659 | * Based on the document from hardware guys the following bits |
| 5660 | * should be set unconditionally in order to enable FBC. |
| 5661 | * The bit 22 of 0x42000 |
| 5662 | * The bit 22 of 0x42004 |
| 5663 | * The bit 7,8,9 of 0x42020. |
| 5664 | */ |
| 5665 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5666 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5667 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5668 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5669 | ILK_FBCQ_DIS); |
| 5670 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5671 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5672 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5673 | } |
| 5674 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5675 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5676 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5677 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5678 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5679 | ILK_ELPIN_409_SELECT); |
| 5680 | I915_WRITE(_3D_CHICKEN2, |
| 5681 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5682 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5683 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5684 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5685 | I915_WRITE(CACHE_MODE_0, |
| 5686 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5687 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5688 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5689 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5690 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5691 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5692 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5693 | ibx_init_clock_gating(dev); |
| 5694 | } |
| 5695 | |
| 5696 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5697 | { |
| 5698 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5699 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5700 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5701 | |
| 5702 | /* |
| 5703 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5704 | * gating for the panel power sequencer or it will fail to |
| 5705 | * start up when no ports are active. |
| 5706 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5707 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5708 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5709 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5710 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5711 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5712 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5713 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5714 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5715 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5716 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5717 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5718 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5719 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5720 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5721 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5722 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5723 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5724 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5725 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5726 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5727 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5728 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5729 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5730 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5731 | } |
| 5732 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5733 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5734 | { |
| 5735 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5736 | uint32_t tmp; |
| 5737 | |
| 5738 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 5739 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5740 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5741 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5742 | } |
| 5743 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5744 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5745 | { |
| 5746 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5747 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5748 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5749 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5750 | |
| 5751 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5752 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5753 | ILK_ELPIN_409_SELECT); |
| 5754 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5755 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5756 | I915_WRITE(_3D_CHICKEN, |
| 5757 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5758 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5759 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5760 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5761 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5762 | /* |
| 5763 | * BSpec recoomends 8x4 when MSAA is used, |
| 5764 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5765 | * |
| 5766 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5767 | * disable bit, which we don't touch here, but it's good |
| 5768 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5769 | */ |
| 5770 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 5771 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5772 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5773 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5774 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5775 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 5776 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5777 | |
| 5778 | I915_WRITE(GEN6_UCGCTL1, |
| 5779 | I915_READ(GEN6_UCGCTL1) | |
| 5780 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 5781 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 5782 | |
| 5783 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 5784 | * gating disable must be set. Failure to set it results in |
| 5785 | * flickering pixels due to Z write ordering failures after |
| 5786 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 5787 | * Sanctuary and Tropics, and apparently anything else with |
| 5788 | * alpha test or pixel discard. |
| 5789 | * |
| 5790 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 5791 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5792 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 5793 | * WaDisableRCCUnitClockGating:snb |
| 5794 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5795 | */ |
| 5796 | I915_WRITE(GEN6_UCGCTL2, |
| 5797 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 5798 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 5799 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 5800 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 5801 | I915_WRITE(_3D_CHICKEN3, |
| 5802 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5803 | |
| 5804 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 5805 | * Bspec says: |
| 5806 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 5807 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 5808 | */ |
| 5809 | I915_WRITE(_3D_CHICKEN3, |
| 5810 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 5811 | |
| 5812 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5813 | * According to the spec the following bits should be |
| 5814 | * set in order to enable memory self-refresh and fbc: |
| 5815 | * The bit21 and bit22 of 0x42000 |
| 5816 | * The bit21 and bit22 of 0x42004 |
| 5817 | * The bit5 and bit7 of 0x42020 |
| 5818 | * The bit14 of 0x70180 |
| 5819 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5820 | * |
| 5821 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5822 | */ |
| 5823 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5824 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5825 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 5826 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5827 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5828 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5829 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 5830 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 5831 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 5832 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5833 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5834 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 5835 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5836 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5837 | |
| 5838 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 5842 | { |
| 5843 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 5844 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5845 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5846 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5847 | * |
| 5848 | * This actually overrides the dispatch |
| 5849 | * mode for all thread types. |
| 5850 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5851 | reg &= ~GEN7_FF_SCHED_MASK; |
| 5852 | reg |= GEN7_FF_TS_SCHED_HW; |
| 5853 | reg |= GEN7_FF_VS_SCHED_HW; |
| 5854 | reg |= GEN7_FF_DS_SCHED_HW; |
| 5855 | |
| 5856 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 5857 | } |
| 5858 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5859 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 5860 | { |
| 5861 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5862 | |
| 5863 | /* |
| 5864 | * TODO: this bit should only be enabled when really needed, then |
| 5865 | * disabled when not needed anymore in order to save power. |
| 5866 | */ |
| 5867 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 5868 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 5869 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 5870 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 5871 | |
| 5872 | /* WADPOClockGatingDisable:hsw */ |
| 5873 | I915_WRITE(_TRANSA_CHICKEN1, |
| 5874 | I915_READ(_TRANSA_CHICKEN1) | |
| 5875 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5876 | } |
| 5877 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5878 | static void lpt_suspend_hw(struct drm_device *dev) |
| 5879 | { |
| 5880 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5881 | |
| 5882 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 5883 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 5884 | |
| 5885 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 5886 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 5887 | } |
| 5888 | } |
| 5889 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 5890 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5891 | { |
| 5892 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5893 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5894 | |
| 5895 | I915_WRITE(WM3_LP_ILK, 0); |
| 5896 | I915_WRITE(WM2_LP_ILK, 0); |
| 5897 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5898 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5899 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5900 | 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] | 5901 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5902 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5903 | I915_WRITE(CHICKEN_PAR1_1, |
| 5904 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 5905 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5906 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5907 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5908 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 5909 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 5910 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5911 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 5912 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5913 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 5914 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 5915 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5916 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 5917 | ~(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] | 5918 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 5919 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5920 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 5921 | |
| 5922 | /* WaDisableSDEUnitClockGating:bdw */ |
| 5923 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 5924 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 5925 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 5926 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5927 | } |
| 5928 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5929 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 5930 | { |
| 5931 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5932 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5933 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5934 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 5935 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 5936 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 5937 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 5938 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 5939 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5940 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5941 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5942 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5943 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5944 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 5945 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 5946 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5947 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5948 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5949 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 5950 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5951 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 5952 | /* enable HiZ Raw Stall Optimization */ |
| 5953 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5954 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5955 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5956 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5957 | I915_WRITE(CACHE_MODE_1, |
| 5958 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5959 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5960 | /* |
| 5961 | * BSpec recommends 8x4 when MSAA is used, |
| 5962 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5963 | * |
| 5964 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5965 | * disable bit, which we don't touch here, but it's good |
| 5966 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5967 | */ |
| 5968 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 5969 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5970 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 5971 | /* WaSampleCChickenBitEnable:hsw */ |
| 5972 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 5973 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 5974 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5975 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 5976 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 5977 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 5978 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 5979 | I915_WRITE(CHICKEN_PAR1_1, |
| 5980 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5981 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5982 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5983 | } |
| 5984 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5985 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5986 | { |
| 5987 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5988 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5989 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5990 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5991 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5992 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5993 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5994 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5995 | I915_WRITE(_3D_CHICKEN3, |
| 5996 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5997 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5998 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5999 | I915_WRITE(IVB_CHICKEN3, |
| 6000 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6001 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6002 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6003 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6004 | if (IS_IVB_GT1(dev)) |
| 6005 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 6006 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6007 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6008 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 6009 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6010 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6011 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6012 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 6013 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 6014 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6015 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6016 | I915_WRITE(GEN7_L3CNTLREG1, |
| 6017 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 6018 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6019 | GEN7_WA_L3_CHICKEN_MODE); |
| 6020 | if (IS_IVB_GT1(dev)) |
| 6021 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6022 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6023 | else { |
| 6024 | /* must write both registers */ |
| 6025 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6026 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6027 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 6028 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6029 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6030 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6031 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6032 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6033 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6034 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 6035 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6036 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6037 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6038 | */ |
| 6039 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 6040 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6041 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6042 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6043 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6044 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6045 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6046 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6047 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6048 | |
| 6049 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6050 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 6051 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 6052 | /* enable HiZ Raw Stall Optimization */ |
| 6053 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6054 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6055 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 6056 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6057 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6058 | I915_WRITE(CACHE_MODE_1, |
| 6059 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6060 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6061 | /* |
| 6062 | * BSpec recommends 8x4 when MSAA is used, |
| 6063 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6064 | * |
| 6065 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6066 | * disable bit, which we don't touch here, but it's good |
| 6067 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6068 | */ |
| 6069 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6070 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6071 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6072 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 6073 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 6074 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 6075 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6076 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 6077 | if (!HAS_PCH_NOP(dev)) |
| 6078 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6079 | |
| 6080 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6081 | } |
| 6082 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6083 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6084 | { |
| 6085 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6086 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 6087 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6088 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6089 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6090 | I915_WRITE(_3D_CHICKEN3, |
| 6091 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6092 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6093 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6094 | I915_WRITE(IVB_CHICKEN3, |
| 6095 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6096 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6097 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 6098 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6099 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6100 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 6101 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 6102 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6103 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6104 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 6105 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6106 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6107 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6108 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6109 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6110 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6111 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6112 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6113 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 6114 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6115 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6116 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6117 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6118 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6119 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6120 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 6121 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6122 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6123 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6124 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6125 | */ |
| 6126 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6127 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6128 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6129 | /* WaDisableL3Bank2xClockGate:vlv |
| 6130 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6131 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6132 | I915_WRITE(GEN7_UCGCTL4, |
| 6133 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6134 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 6135 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6136 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6137 | /* |
| 6138 | * BSpec says this must be set, even though |
| 6139 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6140 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6141 | I915_WRITE(CACHE_MODE_1, |
| 6142 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6143 | |
| 6144 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 6145 | * BSpec recommends 8x4 when MSAA is used, |
| 6146 | * however in practice 16x4 seems fastest. |
| 6147 | * |
| 6148 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6149 | * disable bit, which we don't touch here, but it's good |
| 6150 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 6151 | */ |
| 6152 | I915_WRITE(GEN7_GT_MODE, |
| 6153 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 6154 | |
| 6155 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6156 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6157 | * This is the hardware default actually. |
| 6158 | */ |
| 6159 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6160 | |
| 6161 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6162 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6163 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6164 | * in the reporting of vblank events. |
| 6165 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6166 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6167 | } |
| 6168 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6169 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6170 | { |
| 6171 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6172 | |
| 6173 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6174 | |
| 6175 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6176 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6177 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6178 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6179 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6180 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6181 | ~(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] | 6182 | |
| 6183 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6184 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6185 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6186 | |
| 6187 | /* WaDisableCSUnitClockGating:chv */ |
| 6188 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6189 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6190 | |
| 6191 | /* WaDisableSDEUnitClockGating:chv */ |
| 6192 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6193 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6194 | } |
| 6195 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6196 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6197 | { |
| 6198 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6199 | uint32_t dspclk_gate; |
| 6200 | |
| 6201 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6202 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6203 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6204 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6205 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6206 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6207 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6208 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6209 | if (IS_GM45(dev)) |
| 6210 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6211 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6212 | |
| 6213 | /* WaDisableRenderCachePipelinedFlush */ |
| 6214 | I915_WRITE(CACHE_MODE_0, |
| 6215 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6216 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6217 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6218 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6219 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6220 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6221 | } |
| 6222 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6223 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6224 | { |
| 6225 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6226 | |
| 6227 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6228 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6229 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6230 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6231 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6232 | I915_WRITE(MI_ARB_STATE, |
| 6233 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6234 | |
| 6235 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6236 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6237 | } |
| 6238 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6239 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6240 | { |
| 6241 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6242 | |
| 6243 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6244 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6245 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6246 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6247 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6248 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6249 | I915_WRITE(MI_ARB_STATE, |
| 6250 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6251 | |
| 6252 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6253 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6254 | } |
| 6255 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6256 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6257 | { |
| 6258 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6259 | u32 dstate = I915_READ(D_STATE); |
| 6260 | |
| 6261 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6262 | DSTATE_DOT_CLOCK_GATING; |
| 6263 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6264 | |
| 6265 | if (IS_PINEVIEW(dev)) |
| 6266 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6267 | |
| 6268 | /* IIR "flip pending" means done if this bit is set */ |
| 6269 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6270 | |
| 6271 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6272 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6273 | |
| 6274 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6275 | 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] | 6276 | |
| 6277 | I915_WRITE(MI_ARB_STATE, |
| 6278 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6279 | } |
| 6280 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6281 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6282 | { |
| 6283 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6284 | |
| 6285 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6286 | |
| 6287 | /* interrupts should cause a wake up from C3 */ |
| 6288 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6289 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6290 | |
| 6291 | I915_WRITE(MEM_MODE, |
| 6292 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6293 | } |
| 6294 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6295 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6296 | { |
| 6297 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6298 | |
| 6299 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6300 | |
| 6301 | I915_WRITE(MEM_MODE, |
| 6302 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6303 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6304 | } |
| 6305 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6306 | void intel_init_clock_gating(struct drm_device *dev) |
| 6307 | { |
| 6308 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6309 | |
Damien Lespiau | c57e355 | 2015-02-09 19:33:05 +0000 | [diff] [blame] | 6310 | if (dev_priv->display.init_clock_gating) |
| 6311 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6312 | } |
| 6313 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6314 | void intel_suspend_hw(struct drm_device *dev) |
| 6315 | { |
| 6316 | if (HAS_PCH_LPT(dev)) |
| 6317 | lpt_suspend_hw(dev); |
| 6318 | } |
| 6319 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6320 | /* Set up chip specific power management-related functions */ |
| 6321 | void intel_init_pm(struct drm_device *dev) |
| 6322 | { |
| 6323 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6324 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 6325 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6326 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6327 | /* For cxsr */ |
| 6328 | if (IS_PINEVIEW(dev)) |
| 6329 | i915_pineview_get_mem_freq(dev); |
| 6330 | else if (IS_GEN5(dev)) |
| 6331 | i915_ironlake_get_mem_freq(dev); |
| 6332 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6333 | /* For FIFO watermark updates */ |
Damien Lespiau | f5ed50c | 2014-11-13 17:51:52 +0000 | [diff] [blame] | 6334 | if (INTEL_INFO(dev)->gen >= 9) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 6335 | skl_setup_wm_latency(dev); |
| 6336 | |
Damien Lespiau | 45db219 | 2015-02-09 19:33:09 +0000 | [diff] [blame] | 6337 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 6338 | dev_priv->display.update_wm = skl_update_wm; |
| 6339 | dev_priv->display.update_sprite_wm = skl_update_sprite_wm; |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6340 | } else if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6341 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6342 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6343 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6344 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6345 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6346 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6347 | dev_priv->display.update_wm = ilk_update_wm; |
| 6348 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6349 | } else { |
| 6350 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6351 | "Disable CxSR\n"); |
| 6352 | } |
| 6353 | |
| 6354 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6355 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6356 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6357 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6358 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6359 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6360 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6361 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6362 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6363 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6364 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 6365 | dev_priv->display.update_wm = cherryview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6366 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6367 | dev_priv->display.init_clock_gating = |
| 6368 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6369 | } else if (IS_VALLEYVIEW(dev)) { |
| 6370 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6371 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6372 | dev_priv->display.init_clock_gating = |
| 6373 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6374 | } else if (IS_PINEVIEW(dev)) { |
| 6375 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6376 | dev_priv->is_ddr3, |
| 6377 | dev_priv->fsb_freq, |
| 6378 | dev_priv->mem_freq)) { |
| 6379 | DRM_INFO("failed to find known CxSR latency " |
| 6380 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6381 | "disabling CxSR\n", |
| 6382 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6383 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6384 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6385 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6386 | dev_priv->display.update_wm = NULL; |
| 6387 | } else |
| 6388 | dev_priv->display.update_wm = pineview_update_wm; |
| 6389 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6390 | } else if (IS_G4X(dev)) { |
| 6391 | dev_priv->display.update_wm = g4x_update_wm; |
| 6392 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6393 | } else if (IS_GEN4(dev)) { |
| 6394 | dev_priv->display.update_wm = i965_update_wm; |
| 6395 | if (IS_CRESTLINE(dev)) |
| 6396 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6397 | else if (IS_BROADWATER(dev)) |
| 6398 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6399 | } else if (IS_GEN3(dev)) { |
| 6400 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6401 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6402 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6403 | } else if (IS_GEN2(dev)) { |
| 6404 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6405 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6406 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6407 | } else { |
| 6408 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6409 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6413 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6414 | else |
| 6415 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6416 | } else { |
| 6417 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6418 | } |
| 6419 | } |
| 6420 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6421 | 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] | 6422 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6423 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6424 | |
| 6425 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6426 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6427 | return -EAGAIN; |
| 6428 | } |
| 6429 | |
| 6430 | I915_WRITE(GEN6_PCODE_DATA, *val); |
Damien Lespiau | dddab34 | 2014-11-13 17:51:50 +0000 | [diff] [blame] | 6431 | I915_WRITE(GEN6_PCODE_DATA1, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6432 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6433 | |
| 6434 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6435 | 500)) { |
| 6436 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6437 | return -ETIMEDOUT; |
| 6438 | } |
| 6439 | |
| 6440 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6441 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6442 | |
| 6443 | return 0; |
| 6444 | } |
| 6445 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6446 | 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] | 6447 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6448 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6449 | |
| 6450 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6451 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6452 | return -EAGAIN; |
| 6453 | } |
| 6454 | |
| 6455 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6456 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6457 | |
| 6458 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6459 | 500)) { |
| 6460 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6461 | return -ETIMEDOUT; |
| 6462 | } |
| 6463 | |
| 6464 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6465 | |
| 6466 | return 0; |
| 6467 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6468 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6469 | static int vlv_gpu_freq_div(unsigned int czclk_freq) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6470 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6471 | switch (czclk_freq) { |
| 6472 | case 200: |
| 6473 | return 10; |
| 6474 | case 267: |
| 6475 | return 12; |
| 6476 | case 320: |
| 6477 | case 333: |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6478 | return 16; |
Ville Syrjälä | ab3fb15 | 2014-11-10 22:55:15 +0200 | [diff] [blame] | 6479 | case 400: |
| 6480 | return 20; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6481 | default: |
| 6482 | return -1; |
| 6483 | } |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6484 | } |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6485 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6486 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6487 | { |
| 6488 | int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
| 6489 | |
| 6490 | div = vlv_gpu_freq_div(czclk_freq); |
| 6491 | if (div < 0) |
| 6492 | return div; |
| 6493 | |
| 6494 | return DIV_ROUND_CLOSEST(czclk_freq * (val + 6 - 0xbd), div); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6495 | } |
| 6496 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6497 | 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] | 6498 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6499 | int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6500 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6501 | mul = vlv_gpu_freq_div(czclk_freq); |
| 6502 | if (mul < 0) |
| 6503 | return mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6504 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6505 | return DIV_ROUND_CLOSEST(mul * val, czclk_freq) + 0xbd - 6; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6506 | } |
| 6507 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6508 | 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] | 6509 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6510 | int div, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6511 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6512 | div = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6513 | if (div < 0) |
| 6514 | return div; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6515 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6516 | return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6517 | } |
| 6518 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6519 | 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] | 6520 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6521 | int mul, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6522 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6523 | mul = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6524 | if (mul < 0) |
| 6525 | return mul; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6526 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 6527 | /* CHV needs even values */ |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6528 | return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6529 | } |
| 6530 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6531 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6532 | { |
| 6533 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 6534 | return chv_gpu_freq(dev_priv, val); |
| 6535 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 6536 | return byt_gpu_freq(dev_priv, val); |
| 6537 | else |
| 6538 | return val * GT_FREQUENCY_MULTIPLIER; |
| 6539 | } |
| 6540 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6541 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 6542 | { |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6543 | if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6544 | return chv_freq_opcode(dev_priv, val); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6545 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6546 | return byt_freq_opcode(dev_priv, val); |
| 6547 | else |
| 6548 | return val / GT_FREQUENCY_MULTIPLIER; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6549 | } |
| 6550 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6551 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6552 | { |
| 6553 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6554 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6555 | mutex_init(&dev_priv->rps.hw_lock); |
| 6556 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6557 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 6558 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6559 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 6560 | dev_priv->pm.suspended = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6561 | } |