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> |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 29 | #include <drm/drm_plane_helper.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 30 | #include "i915_drv.h" |
| 31 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 32 | #include "../../../platform/x86/intel_ips.h" |
| 33 | #include <linux/module.h> |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 34 | #include <drm/drm_atomic_helper.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 35 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 36 | /** |
Jani Nikula | 18afd44 | 2016-01-18 09:19:48 +0200 | [diff] [blame] | 37 | * DOC: RC6 |
| 38 | * |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 39 | * RC6 is a special power stage which allows the GPU to enter an very |
| 40 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 41 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 42 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 43 | * |
| 44 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 45 | * among each other with the latency required to enter and leave RC6 and |
| 46 | * voltage consumed by the GPU in different states. |
| 47 | * |
| 48 | * The combination of the following flags define which states GPU is allowed |
| 49 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 50 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 51 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 52 | * which brings the most power savings; deeper states save more power, but |
| 53 | * require higher latency to switch to and wake up. |
| 54 | */ |
| 55 | #define INTEL_RC6_ENABLE (1<<0) |
| 56 | #define INTEL_RC6p_ENABLE (1<<1) |
| 57 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 58 | |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 59 | static void gen9_init_clock_gating(struct drm_device *dev) |
| 60 | { |
Mika Kuoppala | 11b2834 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 61 | struct drm_i915_private *dev_priv = dev->dev_private; |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 62 | |
| 63 | /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl */ |
| 64 | I915_WRITE(CHICKEN_PAR1_1, |
| 65 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 66 | |
| 67 | I915_WRITE(GEN8_CONFIG0, |
| 68 | I915_READ(GEN8_CONFIG0) | GEN9_DEFAULT_FIXES); |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 69 | |
| 70 | /* WaEnableChickenDCPR:skl,bxt,kbl */ |
| 71 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 72 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 73 | |
| 74 | /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl */ |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 75 | /* WaFbcWakeMemOn:skl,bxt,kbl */ |
| 76 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 77 | DISP_FBC_WM_DIS | |
| 78 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 79 | |
| 80 | /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl */ |
| 81 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 82 | ILK_DPFC_DISABLE_DUMMY0); |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 83 | } |
| 84 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 85 | static void bxt_init_clock_gating(struct drm_device *dev) |
| 86 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 87 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 88 | |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 89 | gen9_init_clock_gating(dev); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 90 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 91 | /* WaDisableSDEUnitClockGating:bxt */ |
| 92 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 93 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 94 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 95 | /* |
| 96 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 97 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 98 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 99 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 100 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7a | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 104 | * to stay fully on. |
| 105 | */ |
| 106 | if (IS_BXT_REVID(dev_priv, BXT_REVID_B0, REVID_FOREVER)) |
| 107 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 108 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 111 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 112 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 113 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 114 | u32 tmp; |
| 115 | |
| 116 | tmp = I915_READ(CLKCFG); |
| 117 | |
| 118 | switch (tmp & CLKCFG_FSB_MASK) { |
| 119 | case CLKCFG_FSB_533: |
| 120 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 121 | break; |
| 122 | case CLKCFG_FSB_800: |
| 123 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 124 | break; |
| 125 | case CLKCFG_FSB_667: |
| 126 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 127 | break; |
| 128 | case CLKCFG_FSB_400: |
| 129 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 130 | break; |
| 131 | } |
| 132 | |
| 133 | switch (tmp & CLKCFG_MEM_MASK) { |
| 134 | case CLKCFG_MEM_533: |
| 135 | dev_priv->mem_freq = 533; |
| 136 | break; |
| 137 | case CLKCFG_MEM_667: |
| 138 | dev_priv->mem_freq = 667; |
| 139 | break; |
| 140 | case CLKCFG_MEM_800: |
| 141 | dev_priv->mem_freq = 800; |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | /* detect pineview DDR3 setting */ |
| 146 | tmp = I915_READ(CSHRDDR3CTL); |
| 147 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 148 | } |
| 149 | |
| 150 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 151 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 152 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 153 | u16 ddrpll, csipll; |
| 154 | |
| 155 | ddrpll = I915_READ16(DDRMPLL1); |
| 156 | csipll = I915_READ16(CSIPLL0); |
| 157 | |
| 158 | switch (ddrpll & 0xff) { |
| 159 | case 0xc: |
| 160 | dev_priv->mem_freq = 800; |
| 161 | break; |
| 162 | case 0x10: |
| 163 | dev_priv->mem_freq = 1066; |
| 164 | break; |
| 165 | case 0x14: |
| 166 | dev_priv->mem_freq = 1333; |
| 167 | break; |
| 168 | case 0x18: |
| 169 | dev_priv->mem_freq = 1600; |
| 170 | break; |
| 171 | default: |
| 172 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 173 | ddrpll & 0xff); |
| 174 | dev_priv->mem_freq = 0; |
| 175 | break; |
| 176 | } |
| 177 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 178 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 179 | |
| 180 | switch (csipll & 0x3ff) { |
| 181 | case 0x00c: |
| 182 | dev_priv->fsb_freq = 3200; |
| 183 | break; |
| 184 | case 0x00e: |
| 185 | dev_priv->fsb_freq = 3733; |
| 186 | break; |
| 187 | case 0x010: |
| 188 | dev_priv->fsb_freq = 4266; |
| 189 | break; |
| 190 | case 0x012: |
| 191 | dev_priv->fsb_freq = 4800; |
| 192 | break; |
| 193 | case 0x014: |
| 194 | dev_priv->fsb_freq = 5333; |
| 195 | break; |
| 196 | case 0x016: |
| 197 | dev_priv->fsb_freq = 5866; |
| 198 | break; |
| 199 | case 0x018: |
| 200 | dev_priv->fsb_freq = 6400; |
| 201 | break; |
| 202 | default: |
| 203 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 204 | csipll & 0x3ff); |
| 205 | dev_priv->fsb_freq = 0; |
| 206 | break; |
| 207 | } |
| 208 | |
| 209 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 210 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 211 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 212 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 213 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 214 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 218 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 219 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 220 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 221 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 222 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 223 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 224 | |
| 225 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 226 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 227 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 228 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 229 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 230 | |
| 231 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 232 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 233 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 234 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 235 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 236 | |
| 237 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 238 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 239 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 240 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 241 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 242 | |
| 243 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 244 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 245 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 246 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 247 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 248 | |
| 249 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 250 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 251 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 252 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 253 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 254 | }; |
| 255 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 256 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 257 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 258 | int fsb, |
| 259 | int mem) |
| 260 | { |
| 261 | const struct cxsr_latency *latency; |
| 262 | int i; |
| 263 | |
| 264 | if (fsb == 0 || mem == 0) |
| 265 | return NULL; |
| 266 | |
| 267 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 268 | latency = &cxsr_latency_table[i]; |
| 269 | if (is_desktop == latency->is_desktop && |
| 270 | is_ddr3 == latency->is_ddr3 && |
| 271 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 272 | return latency; |
| 273 | } |
| 274 | |
| 275 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 276 | |
| 277 | return NULL; |
| 278 | } |
| 279 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 280 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 281 | { |
| 282 | u32 val; |
| 283 | |
| 284 | mutex_lock(&dev_priv->rps.hw_lock); |
| 285 | |
| 286 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 287 | if (enable) |
| 288 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 289 | else |
| 290 | val |= FORCE_DDR_HIGH_FREQ; |
| 291 | val &= ~FORCE_DDR_LOW_FREQ; |
| 292 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 293 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 294 | |
| 295 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 296 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 297 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 298 | |
| 299 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 300 | } |
| 301 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 302 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 303 | { |
| 304 | u32 val; |
| 305 | |
| 306 | mutex_lock(&dev_priv->rps.hw_lock); |
| 307 | |
| 308 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 309 | if (enable) |
| 310 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 311 | else |
| 312 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
| 313 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 314 | |
| 315 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 316 | } |
| 317 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 318 | #define FW_WM(value, plane) \ |
| 319 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 320 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 321 | 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] | 322 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 323 | struct drm_device *dev = &dev_priv->drm; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 324 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 325 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 326 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 327 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 328 | POSTING_READ(FW_BLC_SELF_VLV); |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 329 | dev_priv->wm.vlv.cxsr = enable; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 330 | } else if (IS_G4X(dev_priv) || IS_CRESTLINE(dev_priv)) { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 331 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 332 | POSTING_READ(FW_BLC_SELF); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 333 | } else if (IS_PINEVIEW(dev)) { |
| 334 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 335 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 336 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 337 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 338 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 339 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 340 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 341 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 342 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 343 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 344 | /* |
| 345 | * FIXME can't find a bit like this for 915G, and |
| 346 | * and yet it does have the related watermark in |
| 347 | * FW_BLC_SELF. What's going on? |
| 348 | */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 349 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 350 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 351 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 352 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 353 | } else { |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 358 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 359 | } |
| 360 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 361 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 362 | /* |
| 363 | * Latency for FIFO fetches is dependent on several factors: |
| 364 | * - memory configuration (speed, channels) |
| 365 | * - chipset |
| 366 | * - current MCH state |
| 367 | * It can be fairly high in some situations, so here we assume a fairly |
| 368 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 369 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 370 | * and power consumption (set it too low to save power and we might see |
| 371 | * FIFO underruns and display "flicker"). |
| 372 | * |
| 373 | * A value of 5us seems to be a good balance; safe for very low end |
| 374 | * platforms but not overly aggressive on lower latency configs. |
| 375 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 376 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 377 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 378 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 379 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 380 | |
| 381 | static int vlv_get_fifo_size(struct drm_device *dev, |
| 382 | enum pipe pipe, int plane) |
| 383 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 384 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 385 | int sprite0_start, sprite1_start, size; |
| 386 | |
| 387 | switch (pipe) { |
| 388 | uint32_t dsparb, dsparb2, dsparb3; |
| 389 | case PIPE_A: |
| 390 | dsparb = I915_READ(DSPARB); |
| 391 | dsparb2 = I915_READ(DSPARB2); |
| 392 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 393 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 394 | break; |
| 395 | case PIPE_B: |
| 396 | dsparb = I915_READ(DSPARB); |
| 397 | dsparb2 = I915_READ(DSPARB2); |
| 398 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 399 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 400 | break; |
| 401 | case PIPE_C: |
| 402 | dsparb2 = I915_READ(DSPARB2); |
| 403 | dsparb3 = I915_READ(DSPARB3); |
| 404 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 405 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 406 | break; |
| 407 | default: |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | switch (plane) { |
| 412 | case 0: |
| 413 | size = sprite0_start; |
| 414 | break; |
| 415 | case 1: |
| 416 | size = sprite1_start - sprite0_start; |
| 417 | break; |
| 418 | case 2: |
| 419 | size = 512 - 1 - sprite1_start; |
| 420 | break; |
| 421 | default: |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | DRM_DEBUG_KMS("Pipe %c %s %c FIFO size: %d\n", |
| 426 | pipe_name(pipe), plane == 0 ? "primary" : "sprite", |
| 427 | plane == 0 ? plane_name(pipe) : sprite_name(pipe, plane - 1), |
| 428 | size); |
| 429 | |
| 430 | return size; |
| 431 | } |
| 432 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 433 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 434 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 435 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 436 | uint32_t dsparb = I915_READ(DSPARB); |
| 437 | int size; |
| 438 | |
| 439 | size = dsparb & 0x7f; |
| 440 | if (plane) |
| 441 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 442 | |
| 443 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 444 | plane ? "B" : "A", size); |
| 445 | |
| 446 | return size; |
| 447 | } |
| 448 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 449 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 450 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 451 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 452 | uint32_t dsparb = I915_READ(DSPARB); |
| 453 | int size; |
| 454 | |
| 455 | size = dsparb & 0x1ff; |
| 456 | if (plane) |
| 457 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 458 | size >>= 1; /* Convert to cachelines */ |
| 459 | |
| 460 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 461 | plane ? "B" : "A", size); |
| 462 | |
| 463 | return size; |
| 464 | } |
| 465 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 466 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 467 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 468 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 469 | uint32_t dsparb = I915_READ(DSPARB); |
| 470 | int size; |
| 471 | |
| 472 | size = dsparb & 0x7f; |
| 473 | size >>= 2; /* Convert to cachelines */ |
| 474 | |
| 475 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 476 | plane ? "B" : "A", |
| 477 | size); |
| 478 | |
| 479 | return size; |
| 480 | } |
| 481 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 482 | /* Pineview has different values for various configs */ |
| 483 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 484 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 485 | .max_wm = PINEVIEW_MAX_WM, |
| 486 | .default_wm = PINEVIEW_DFT_WM, |
| 487 | .guard_size = PINEVIEW_GUARD_WM, |
| 488 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 489 | }; |
| 490 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 491 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 492 | .max_wm = PINEVIEW_MAX_WM, |
| 493 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 494 | .guard_size = PINEVIEW_GUARD_WM, |
| 495 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 496 | }; |
| 497 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 498 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 499 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 500 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 501 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 502 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 503 | }; |
| 504 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 505 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 506 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 507 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 508 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 509 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 510 | }; |
| 511 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 512 | .fifo_size = G4X_FIFO_SIZE, |
| 513 | .max_wm = G4X_MAX_WM, |
| 514 | .default_wm = G4X_MAX_WM, |
| 515 | .guard_size = 2, |
| 516 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 517 | }; |
| 518 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 519 | .fifo_size = I965_CURSOR_FIFO, |
| 520 | .max_wm = I965_CURSOR_MAX_WM, |
| 521 | .default_wm = I965_CURSOR_DFT_WM, |
| 522 | .guard_size = 2, |
| 523 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 524 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 525 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 526 | .fifo_size = I965_CURSOR_FIFO, |
| 527 | .max_wm = I965_CURSOR_MAX_WM, |
| 528 | .default_wm = I965_CURSOR_DFT_WM, |
| 529 | .guard_size = 2, |
| 530 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 531 | }; |
| 532 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 533 | .fifo_size = I945_FIFO_SIZE, |
| 534 | .max_wm = I915_MAX_WM, |
| 535 | .default_wm = 1, |
| 536 | .guard_size = 2, |
| 537 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 538 | }; |
| 539 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 540 | .fifo_size = I915_FIFO_SIZE, |
| 541 | .max_wm = I915_MAX_WM, |
| 542 | .default_wm = 1, |
| 543 | .guard_size = 2, |
| 544 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 545 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 546 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 547 | .fifo_size = I855GM_FIFO_SIZE, |
| 548 | .max_wm = I915_MAX_WM, |
| 549 | .default_wm = 1, |
| 550 | .guard_size = 2, |
| 551 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 552 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 553 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 554 | .fifo_size = I855GM_FIFO_SIZE, |
| 555 | .max_wm = I915_MAX_WM/2, |
| 556 | .default_wm = 1, |
| 557 | .guard_size = 2, |
| 558 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 559 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 560 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 561 | .fifo_size = I830_FIFO_SIZE, |
| 562 | .max_wm = I915_MAX_WM, |
| 563 | .default_wm = 1, |
| 564 | .guard_size = 2, |
| 565 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 566 | }; |
| 567 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 568 | /** |
| 569 | * intel_calculate_wm - calculate watermark level |
| 570 | * @clock_in_khz: pixel clock |
| 571 | * @wm: chip FIFO params |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 572 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 573 | * @latency_ns: memory latency for the platform |
| 574 | * |
| 575 | * Calculate the watermark level (the level at which the display plane will |
| 576 | * start fetching from memory again). Each chip has a different display |
| 577 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 578 | * in the correct intel_watermark_params structure. |
| 579 | * |
| 580 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 581 | * on the pixel size. When it reaches the watermark level, it'll start |
| 582 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 583 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 584 | * will occur, and a display engine hang could result. |
| 585 | */ |
| 586 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 587 | const struct intel_watermark_params *wm, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 588 | int fifo_size, int cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 589 | unsigned long latency_ns) |
| 590 | { |
| 591 | long entries_required, wm_size; |
| 592 | |
| 593 | /* |
| 594 | * Note: we need to make sure we don't overflow for various clock & |
| 595 | * latency values. |
| 596 | * clocks go from a few thousand to several hundred thousand. |
| 597 | * latency is usually a few thousand |
| 598 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 599 | entries_required = ((clock_in_khz / 1000) * cpp * latency_ns) / |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 600 | 1000; |
| 601 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 602 | |
| 603 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 604 | |
| 605 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 606 | |
| 607 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 608 | |
| 609 | /* Don't promote wm_size to unsigned... */ |
| 610 | if (wm_size > (long)wm->max_wm) |
| 611 | wm_size = wm->max_wm; |
| 612 | if (wm_size <= 0) |
| 613 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 614 | |
| 615 | /* |
| 616 | * Bspec seems to indicate that the value shouldn't be lower than |
| 617 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 618 | * Lets go for 8 which is the burst size since certain platforms |
| 619 | * already use a hardcoded 8 (which is what the spec says should be |
| 620 | * done). |
| 621 | */ |
| 622 | if (wm_size <= 8) |
| 623 | wm_size = 8; |
| 624 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 625 | return wm_size; |
| 626 | } |
| 627 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 628 | static struct intel_crtc *single_enabled_crtc(struct drm_device *dev) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 629 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 630 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 631 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 632 | for_each_intel_crtc(dev, crtc) { |
| 633 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 634 | if (enabled) |
| 635 | return NULL; |
| 636 | enabled = crtc; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | return enabled; |
| 641 | } |
| 642 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 643 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 644 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 645 | struct drm_device *dev = unused_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 646 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 647 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 648 | const struct cxsr_latency *latency; |
| 649 | u32 reg; |
| 650 | unsigned long wm; |
| 651 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 652 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
| 653 | dev_priv->is_ddr3, |
| 654 | dev_priv->fsb_freq, |
| 655 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 656 | if (!latency) { |
| 657 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 658 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 659 | return; |
| 660 | } |
| 661 | |
| 662 | crtc = single_enabled_crtc(dev); |
| 663 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 664 | const struct drm_display_mode *adjusted_mode = |
| 665 | &crtc->config->base.adjusted_mode; |
| 666 | const struct drm_framebuffer *fb = |
| 667 | crtc->base.primary->state->fb; |
| 668 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 669 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 670 | |
| 671 | /* Display SR */ |
| 672 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 673 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 674 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 675 | reg = I915_READ(DSPFW1); |
| 676 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 677 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 678 | I915_WRITE(DSPFW1, reg); |
| 679 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 680 | |
| 681 | /* cursor SR */ |
| 682 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 683 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 684 | cpp, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 685 | reg = I915_READ(DSPFW3); |
| 686 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 687 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 688 | I915_WRITE(DSPFW3, reg); |
| 689 | |
| 690 | /* Display HPLL off SR */ |
| 691 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 692 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 693 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 694 | reg = I915_READ(DSPFW3); |
| 695 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 696 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 697 | I915_WRITE(DSPFW3, reg); |
| 698 | |
| 699 | /* cursor HPLL off SR */ |
| 700 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 701 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 702 | cpp, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 703 | reg = I915_READ(DSPFW3); |
| 704 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 705 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 706 | I915_WRITE(DSPFW3, reg); |
| 707 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 708 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 709 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 710 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 711 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Ville Syrjälä | f0ce231 | 2016-10-31 22:37:08 +0200 | [diff] [blame] | 715 | static bool g4x_compute_wm0(struct drm_i915_private *dev_priv, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 716 | int plane, |
| 717 | const struct intel_watermark_params *display, |
| 718 | int display_latency_ns, |
| 719 | const struct intel_watermark_params *cursor, |
| 720 | int cursor_latency_ns, |
| 721 | int *plane_wm, |
| 722 | int *cursor_wm) |
| 723 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 724 | struct intel_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 725 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 726 | const struct drm_framebuffer *fb; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 727 | int htotal, hdisplay, clock, cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 728 | int line_time_us, line_count; |
| 729 | int entries, tlb_miss; |
| 730 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 731 | crtc = intel_get_crtc_for_plane(dev_priv, plane); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 732 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 733 | *cursor_wm = cursor->guard_size; |
| 734 | *plane_wm = display->guard_size; |
| 735 | return false; |
| 736 | } |
| 737 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 738 | adjusted_mode = &crtc->config->base.adjusted_mode; |
| 739 | fb = crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 740 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 741 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 742 | hdisplay = crtc->config->pipe_src_w; |
| 743 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 744 | |
| 745 | /* Use the small buffer method to calculate plane watermark */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 746 | entries = ((clock * cpp / 1000) * display_latency_ns) / 1000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 747 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 748 | if (tlb_miss > 0) |
| 749 | entries += tlb_miss; |
| 750 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 751 | *plane_wm = entries + display->guard_size; |
| 752 | if (*plane_wm > (int)display->max_wm) |
| 753 | *plane_wm = display->max_wm; |
| 754 | |
| 755 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 756 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 757 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 758 | entries = line_count * crtc->base.cursor->state->crtc_w * cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 759 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 760 | if (tlb_miss > 0) |
| 761 | entries += tlb_miss; |
| 762 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 763 | *cursor_wm = entries + cursor->guard_size; |
| 764 | if (*cursor_wm > (int)cursor->max_wm) |
| 765 | *cursor_wm = (int)cursor->max_wm; |
| 766 | |
| 767 | return true; |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * Check the wm result. |
| 772 | * |
| 773 | * If any calculated watermark values is larger than the maximum value that |
| 774 | * can be programmed into the associated watermark register, that watermark |
| 775 | * must be disabled. |
| 776 | */ |
Ville Syrjälä | f0ce231 | 2016-10-31 22:37:08 +0200 | [diff] [blame] | 777 | static bool g4x_check_srwm(struct drm_i915_private *dev_priv, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 778 | int display_wm, int cursor_wm, |
| 779 | const struct intel_watermark_params *display, |
| 780 | const struct intel_watermark_params *cursor) |
| 781 | { |
| 782 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 783 | display_wm, cursor_wm); |
| 784 | |
| 785 | if (display_wm > display->max_wm) { |
Tvrtko Ursulin | ae9400c | 2016-10-13 11:09:25 +0100 | [diff] [blame] | 786 | DRM_DEBUG_KMS("display watermark is too large(%d/%u), disabling\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 787 | display_wm, display->max_wm); |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | if (cursor_wm > cursor->max_wm) { |
Tvrtko Ursulin | ae9400c | 2016-10-13 11:09:25 +0100 | [diff] [blame] | 792 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%u), disabling\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 793 | cursor_wm, cursor->max_wm); |
| 794 | return false; |
| 795 | } |
| 796 | |
| 797 | if (!(display_wm || cursor_wm)) { |
| 798 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 799 | return false; |
| 800 | } |
| 801 | |
| 802 | return true; |
| 803 | } |
| 804 | |
Ville Syrjälä | f0ce231 | 2016-10-31 22:37:08 +0200 | [diff] [blame] | 805 | static bool g4x_compute_srwm(struct drm_i915_private *dev_priv, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 806 | int plane, |
| 807 | int latency_ns, |
| 808 | const struct intel_watermark_params *display, |
| 809 | const struct intel_watermark_params *cursor, |
| 810 | int *display_wm, int *cursor_wm) |
| 811 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 812 | struct intel_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 813 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 814 | const struct drm_framebuffer *fb; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 815 | int hdisplay, htotal, cpp, clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 816 | unsigned long line_time_us; |
| 817 | int line_count, line_size; |
| 818 | int small, large; |
| 819 | int entries; |
| 820 | |
| 821 | if (!latency_ns) { |
| 822 | *display_wm = *cursor_wm = 0; |
| 823 | return false; |
| 824 | } |
| 825 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 826 | crtc = intel_get_crtc_for_plane(dev_priv, plane); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 827 | adjusted_mode = &crtc->config->base.adjusted_mode; |
| 828 | fb = crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 829 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 830 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 831 | hdisplay = crtc->config->pipe_src_w; |
| 832 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 833 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 834 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 835 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 836 | line_size = hdisplay * cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 837 | |
| 838 | /* Use the minimum of the small and large buffer method for primary */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 839 | small = ((clock * cpp / 1000) * latency_ns) / 1000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 840 | large = line_count * line_size; |
| 841 | |
| 842 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 843 | *display_wm = entries + display->guard_size; |
| 844 | |
| 845 | /* calculate the self-refresh watermark for display cursor */ |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 846 | entries = line_count * cpp * crtc->base.cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 847 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 848 | *cursor_wm = entries + cursor->guard_size; |
| 849 | |
Ville Syrjälä | f0ce231 | 2016-10-31 22:37:08 +0200 | [diff] [blame] | 850 | return g4x_check_srwm(dev_priv, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 851 | *display_wm, *cursor_wm, |
| 852 | display, cursor); |
| 853 | } |
| 854 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 855 | #define FW_WM_VLV(value, plane) \ |
| 856 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 857 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 858 | static void vlv_write_wm_values(struct intel_crtc *crtc, |
| 859 | const struct vlv_wm_values *wm) |
| 860 | { |
| 861 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 862 | enum pipe pipe = crtc->pipe; |
| 863 | |
| 864 | I915_WRITE(VLV_DDL(pipe), |
| 865 | (wm->ddl[pipe].cursor << DDL_CURSOR_SHIFT) | |
| 866 | (wm->ddl[pipe].sprite[1] << DDL_SPRITE_SHIFT(1)) | |
| 867 | (wm->ddl[pipe].sprite[0] << DDL_SPRITE_SHIFT(0)) | |
| 868 | (wm->ddl[pipe].primary << DDL_PLANE_SHIFT)); |
| 869 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 870 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 871 | FW_WM(wm->sr.plane, SR) | |
| 872 | FW_WM(wm->pipe[PIPE_B].cursor, CURSORB) | |
| 873 | FW_WM_VLV(wm->pipe[PIPE_B].primary, PLANEB) | |
| 874 | FW_WM_VLV(wm->pipe[PIPE_A].primary, PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 875 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 876 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[1], SPRITEB) | |
| 877 | FW_WM(wm->pipe[PIPE_A].cursor, CURSORA) | |
| 878 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 879 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 880 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 881 | |
| 882 | if (IS_CHERRYVIEW(dev_priv)) { |
| 883 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 884 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 885 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 886 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 887 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[1], SPRITEF) | |
| 888 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 889 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 890 | FW_WM_VLV(wm->pipe[PIPE_C].primary, PLANEC) | |
| 891 | FW_WM(wm->pipe[PIPE_C].cursor, CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 892 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 893 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 894 | FW_WM(wm->pipe[PIPE_C].sprite[1] >> 8, SPRITEF_HI) | |
| 895 | FW_WM(wm->pipe[PIPE_C].sprite[0] >> 8, SPRITEE_HI) | |
| 896 | FW_WM(wm->pipe[PIPE_C].primary >> 8, PLANEC_HI) | |
| 897 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 898 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 899 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 900 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 901 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 902 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 903 | } else { |
| 904 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 905 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 906 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 907 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 908 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 909 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 910 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 911 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 912 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 913 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 914 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 915 | } |
| 916 | |
Ville Syrjälä | 2cb389b | 2015-06-24 22:00:10 +0300 | [diff] [blame] | 917 | /* zero (unused) WM1 watermarks */ |
| 918 | I915_WRITE(DSPFW4, 0); |
| 919 | I915_WRITE(DSPFW5, 0); |
| 920 | I915_WRITE(DSPFW6, 0); |
| 921 | I915_WRITE(DSPHOWM1, 0); |
| 922 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 923 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 924 | } |
| 925 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 926 | #undef FW_WM_VLV |
| 927 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 928 | enum vlv_wm_level { |
| 929 | VLV_WM_LEVEL_PM2, |
| 930 | VLV_WM_LEVEL_PM5, |
| 931 | VLV_WM_LEVEL_DDR_DVFS, |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 932 | }; |
| 933 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 934 | /* latency must be in 0.1us units. */ |
| 935 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
| 936 | unsigned int pipe_htotal, |
| 937 | unsigned int horiz_pixels, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 938 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 939 | unsigned int latency) |
| 940 | { |
| 941 | unsigned int ret; |
| 942 | |
| 943 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 944 | ret = (ret + 1) * horiz_pixels * cpp; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 945 | ret = DIV_ROUND_UP(ret, 64); |
| 946 | |
| 947 | return ret; |
| 948 | } |
| 949 | |
| 950 | static void vlv_setup_wm_latency(struct drm_device *dev) |
| 951 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 952 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 953 | |
| 954 | /* all latencies in usec */ |
| 955 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 956 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 957 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 958 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 959 | if (IS_CHERRYVIEW(dev_priv)) { |
| 960 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 961 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 962 | |
| 963 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
| 967 | static uint16_t vlv_compute_wm_level(struct intel_plane *plane, |
| 968 | struct intel_crtc *crtc, |
| 969 | const struct intel_plane_state *state, |
| 970 | int level) |
| 971 | { |
| 972 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 973 | int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 974 | |
| 975 | if (dev_priv->wm.pri_latency[level] == 0) |
| 976 | return USHRT_MAX; |
| 977 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 978 | if (!state->base.visible) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 979 | return 0; |
| 980 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 981 | cpp = drm_format_plane_cpp(state->base.fb->pixel_format, 0); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 982 | clock = crtc->config->base.adjusted_mode.crtc_clock; |
| 983 | htotal = crtc->config->base.adjusted_mode.crtc_htotal; |
| 984 | width = crtc->config->pipe_src_w; |
| 985 | if (WARN_ON(htotal == 0)) |
| 986 | htotal = 1; |
| 987 | |
| 988 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) { |
| 989 | /* |
| 990 | * FIXME the formula gives values that are |
| 991 | * too big for the cursor FIFO, and hence we |
| 992 | * would never be able to use cursors. For |
| 993 | * now just hardcode the watermark. |
| 994 | */ |
| 995 | wm = 63; |
| 996 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 997 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 998 | dev_priv->wm.pri_latency[level] * 10); |
| 999 | } |
| 1000 | |
| 1001 | return min_t(int, wm, USHRT_MAX); |
| 1002 | } |
| 1003 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1004 | static void vlv_compute_fifo(struct intel_crtc *crtc) |
| 1005 | { |
| 1006 | struct drm_device *dev = crtc->base.dev; |
| 1007 | struct vlv_wm_state *wm_state = &crtc->wm_state; |
| 1008 | struct intel_plane *plane; |
| 1009 | unsigned int total_rate = 0; |
| 1010 | const int fifo_size = 512 - 1; |
| 1011 | int fifo_extra, fifo_left = fifo_size; |
| 1012 | |
| 1013 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 1014 | struct intel_plane_state *state = |
| 1015 | to_intel_plane_state(plane->base.state); |
| 1016 | |
| 1017 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 1018 | continue; |
| 1019 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1020 | if (state->base.visible) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1021 | wm_state->num_active_planes++; |
| 1022 | total_rate += drm_format_plane_cpp(state->base.fb->pixel_format, 0); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 1027 | struct intel_plane_state *state = |
| 1028 | to_intel_plane_state(plane->base.state); |
| 1029 | unsigned int rate; |
| 1030 | |
| 1031 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) { |
| 1032 | plane->wm.fifo_size = 63; |
| 1033 | continue; |
| 1034 | } |
| 1035 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1036 | if (!state->base.visible) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1037 | plane->wm.fifo_size = 0; |
| 1038 | continue; |
| 1039 | } |
| 1040 | |
| 1041 | rate = drm_format_plane_cpp(state->base.fb->pixel_format, 0); |
| 1042 | plane->wm.fifo_size = fifo_size * rate / total_rate; |
| 1043 | fifo_left -= plane->wm.fifo_size; |
| 1044 | } |
| 1045 | |
| 1046 | fifo_extra = DIV_ROUND_UP(fifo_left, wm_state->num_active_planes ?: 1); |
| 1047 | |
| 1048 | /* spread the remainder evenly */ |
| 1049 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 1050 | int plane_extra; |
| 1051 | |
| 1052 | if (fifo_left == 0) |
| 1053 | break; |
| 1054 | |
| 1055 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 1056 | continue; |
| 1057 | |
| 1058 | /* give it all to the first plane if none are active */ |
| 1059 | if (plane->wm.fifo_size == 0 && |
| 1060 | wm_state->num_active_planes) |
| 1061 | continue; |
| 1062 | |
| 1063 | plane_extra = min(fifo_extra, fifo_left); |
| 1064 | plane->wm.fifo_size += plane_extra; |
| 1065 | fifo_left -= plane_extra; |
| 1066 | } |
| 1067 | |
| 1068 | WARN_ON(fifo_left != 0); |
| 1069 | } |
| 1070 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1071 | static void vlv_invert_wms(struct intel_crtc *crtc) |
| 1072 | { |
| 1073 | struct vlv_wm_state *wm_state = &crtc->wm_state; |
| 1074 | int level; |
| 1075 | |
| 1076 | for (level = 0; level < wm_state->num_levels; level++) { |
| 1077 | struct drm_device *dev = crtc->base.dev; |
| 1078 | const int sr_fifo_size = INTEL_INFO(dev)->num_pipes * 512 - 1; |
| 1079 | struct intel_plane *plane; |
| 1080 | |
| 1081 | wm_state->sr[level].plane = sr_fifo_size - wm_state->sr[level].plane; |
| 1082 | wm_state->sr[level].cursor = 63 - wm_state->sr[level].cursor; |
| 1083 | |
| 1084 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 1085 | switch (plane->base.type) { |
| 1086 | int sprite; |
| 1087 | case DRM_PLANE_TYPE_CURSOR: |
| 1088 | wm_state->wm[level].cursor = plane->wm.fifo_size - |
| 1089 | wm_state->wm[level].cursor; |
| 1090 | break; |
| 1091 | case DRM_PLANE_TYPE_PRIMARY: |
| 1092 | wm_state->wm[level].primary = plane->wm.fifo_size - |
| 1093 | wm_state->wm[level].primary; |
| 1094 | break; |
| 1095 | case DRM_PLANE_TYPE_OVERLAY: |
| 1096 | sprite = plane->plane; |
| 1097 | wm_state->wm[level].sprite[sprite] = plane->wm.fifo_size - |
| 1098 | wm_state->wm[level].sprite[sprite]; |
| 1099 | break; |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
Ville Syrjälä | 26e1fe4 | 2015-06-24 22:00:06 +0300 | [diff] [blame] | 1105 | static void vlv_compute_wm(struct intel_crtc *crtc) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1106 | { |
| 1107 | struct drm_device *dev = crtc->base.dev; |
| 1108 | struct vlv_wm_state *wm_state = &crtc->wm_state; |
| 1109 | struct intel_plane *plane; |
| 1110 | int sr_fifo_size = INTEL_INFO(dev)->num_pipes * 512 - 1; |
| 1111 | int level; |
| 1112 | |
| 1113 | memset(wm_state, 0, sizeof(*wm_state)); |
| 1114 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 1115 | wm_state->cxsr = crtc->pipe != PIPE_C && crtc->wm.cxsr_allowed; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1116 | wm_state->num_levels = to_i915(dev)->wm.max_level + 1; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1117 | |
| 1118 | wm_state->num_active_planes = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1119 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1120 | vlv_compute_fifo(crtc); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1121 | |
| 1122 | if (wm_state->num_active_planes != 1) |
| 1123 | wm_state->cxsr = false; |
| 1124 | |
| 1125 | if (wm_state->cxsr) { |
| 1126 | for (level = 0; level < wm_state->num_levels; level++) { |
| 1127 | wm_state->sr[level].plane = sr_fifo_size; |
| 1128 | wm_state->sr[level].cursor = 63; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 1133 | struct intel_plane_state *state = |
| 1134 | to_intel_plane_state(plane->base.state); |
| 1135 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1136 | if (!state->base.visible) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1137 | continue; |
| 1138 | |
| 1139 | /* normal watermarks */ |
| 1140 | for (level = 0; level < wm_state->num_levels; level++) { |
| 1141 | int wm = vlv_compute_wm_level(plane, crtc, state, level); |
| 1142 | int max_wm = plane->base.type == DRM_PLANE_TYPE_CURSOR ? 63 : 511; |
| 1143 | |
| 1144 | /* hack */ |
| 1145 | if (WARN_ON(level == 0 && wm > max_wm)) |
| 1146 | wm = max_wm; |
| 1147 | |
| 1148 | if (wm > plane->wm.fifo_size) |
| 1149 | break; |
| 1150 | |
| 1151 | switch (plane->base.type) { |
| 1152 | int sprite; |
| 1153 | case DRM_PLANE_TYPE_CURSOR: |
| 1154 | wm_state->wm[level].cursor = wm; |
| 1155 | break; |
| 1156 | case DRM_PLANE_TYPE_PRIMARY: |
| 1157 | wm_state->wm[level].primary = wm; |
| 1158 | break; |
| 1159 | case DRM_PLANE_TYPE_OVERLAY: |
| 1160 | sprite = plane->plane; |
| 1161 | wm_state->wm[level].sprite[sprite] = wm; |
| 1162 | break; |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | wm_state->num_levels = level; |
| 1167 | |
| 1168 | if (!wm_state->cxsr) |
| 1169 | continue; |
| 1170 | |
| 1171 | /* maxfifo watermarks */ |
| 1172 | switch (plane->base.type) { |
| 1173 | int sprite, level; |
| 1174 | case DRM_PLANE_TYPE_CURSOR: |
| 1175 | for (level = 0; level < wm_state->num_levels; level++) |
| 1176 | wm_state->sr[level].cursor = |
Thomas Daniel | 5a37ed0 | 2015-10-23 14:55:38 +0100 | [diff] [blame] | 1177 | wm_state->wm[level].cursor; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1178 | break; |
| 1179 | case DRM_PLANE_TYPE_PRIMARY: |
| 1180 | for (level = 0; level < wm_state->num_levels; level++) |
| 1181 | wm_state->sr[level].plane = |
| 1182 | min(wm_state->sr[level].plane, |
| 1183 | wm_state->wm[level].primary); |
| 1184 | break; |
| 1185 | case DRM_PLANE_TYPE_OVERLAY: |
| 1186 | sprite = plane->plane; |
| 1187 | for (level = 0; level < wm_state->num_levels; level++) |
| 1188 | wm_state->sr[level].plane = |
| 1189 | min(wm_state->sr[level].plane, |
| 1190 | wm_state->wm[level].sprite[sprite]); |
| 1191 | break; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | /* clear any (partially) filled invalid levels */ |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1196 | for (level = wm_state->num_levels; level < to_i915(dev)->wm.max_level + 1; level++) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1197 | memset(&wm_state->wm[level], 0, sizeof(wm_state->wm[level])); |
| 1198 | memset(&wm_state->sr[level], 0, sizeof(wm_state->sr[level])); |
| 1199 | } |
| 1200 | |
| 1201 | vlv_invert_wms(crtc); |
| 1202 | } |
| 1203 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1204 | #define VLV_FIFO(plane, value) \ |
| 1205 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1206 | |
| 1207 | static void vlv_pipe_set_fifo_size(struct intel_crtc *crtc) |
| 1208 | { |
| 1209 | struct drm_device *dev = crtc->base.dev; |
| 1210 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 1211 | struct intel_plane *plane; |
| 1212 | int sprite0_start = 0, sprite1_start = 0, fifo_size = 0; |
| 1213 | |
| 1214 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 1215 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) { |
| 1216 | WARN_ON(plane->wm.fifo_size != 63); |
| 1217 | continue; |
| 1218 | } |
| 1219 | |
| 1220 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 1221 | sprite0_start = plane->wm.fifo_size; |
| 1222 | else if (plane->plane == 0) |
| 1223 | sprite1_start = sprite0_start + plane->wm.fifo_size; |
| 1224 | else |
| 1225 | fifo_size = sprite1_start + plane->wm.fifo_size; |
| 1226 | } |
| 1227 | |
| 1228 | WARN_ON(fifo_size != 512 - 1); |
| 1229 | |
| 1230 | DRM_DEBUG_KMS("Pipe %c FIFO split %d / %d / %d\n", |
| 1231 | pipe_name(crtc->pipe), sprite0_start, |
| 1232 | sprite1_start, fifo_size); |
| 1233 | |
| 1234 | switch (crtc->pipe) { |
| 1235 | uint32_t dsparb, dsparb2, dsparb3; |
| 1236 | case PIPE_A: |
| 1237 | dsparb = I915_READ(DSPARB); |
| 1238 | dsparb2 = I915_READ(DSPARB2); |
| 1239 | |
| 1240 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1241 | VLV_FIFO(SPRITEB, 0xff)); |
| 1242 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1243 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1244 | |
| 1245 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1246 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1247 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1248 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1249 | |
| 1250 | I915_WRITE(DSPARB, dsparb); |
| 1251 | I915_WRITE(DSPARB2, dsparb2); |
| 1252 | break; |
| 1253 | case PIPE_B: |
| 1254 | dsparb = I915_READ(DSPARB); |
| 1255 | dsparb2 = I915_READ(DSPARB2); |
| 1256 | |
| 1257 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 1258 | VLV_FIFO(SPRITED, 0xff)); |
| 1259 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 1260 | VLV_FIFO(SPRITED, sprite1_start)); |
| 1261 | |
| 1262 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 1263 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 1264 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 1265 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 1266 | |
| 1267 | I915_WRITE(DSPARB, dsparb); |
| 1268 | I915_WRITE(DSPARB2, dsparb2); |
| 1269 | break; |
| 1270 | case PIPE_C: |
| 1271 | dsparb3 = I915_READ(DSPARB3); |
| 1272 | dsparb2 = I915_READ(DSPARB2); |
| 1273 | |
| 1274 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 1275 | VLV_FIFO(SPRITEF, 0xff)); |
| 1276 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 1277 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 1278 | |
| 1279 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 1280 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 1281 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 1282 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 1283 | |
| 1284 | I915_WRITE(DSPARB3, dsparb3); |
| 1285 | I915_WRITE(DSPARB2, dsparb2); |
| 1286 | break; |
| 1287 | default: |
| 1288 | break; |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | #undef VLV_FIFO |
| 1293 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1294 | static void vlv_merge_wm(struct drm_device *dev, |
| 1295 | struct vlv_wm_values *wm) |
| 1296 | { |
| 1297 | struct intel_crtc *crtc; |
| 1298 | int num_active_crtcs = 0; |
| 1299 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1300 | wm->level = to_i915(dev)->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1301 | wm->cxsr = true; |
| 1302 | |
| 1303 | for_each_intel_crtc(dev, crtc) { |
| 1304 | const struct vlv_wm_state *wm_state = &crtc->wm_state; |
| 1305 | |
| 1306 | if (!crtc->active) |
| 1307 | continue; |
| 1308 | |
| 1309 | if (!wm_state->cxsr) |
| 1310 | wm->cxsr = false; |
| 1311 | |
| 1312 | num_active_crtcs++; |
| 1313 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 1314 | } |
| 1315 | |
| 1316 | if (num_active_crtcs != 1) |
| 1317 | wm->cxsr = false; |
| 1318 | |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 1319 | if (num_active_crtcs > 1) |
| 1320 | wm->level = VLV_WM_LEVEL_PM2; |
| 1321 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1322 | for_each_intel_crtc(dev, crtc) { |
| 1323 | struct vlv_wm_state *wm_state = &crtc->wm_state; |
| 1324 | enum pipe pipe = crtc->pipe; |
| 1325 | |
| 1326 | if (!crtc->active) |
| 1327 | continue; |
| 1328 | |
| 1329 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
| 1330 | if (wm->cxsr) |
| 1331 | wm->sr = wm_state->sr[wm->level]; |
| 1332 | |
| 1333 | wm->ddl[pipe].primary = DDL_PRECISION_HIGH | 2; |
| 1334 | wm->ddl[pipe].sprite[0] = DDL_PRECISION_HIGH | 2; |
| 1335 | wm->ddl[pipe].sprite[1] = DDL_PRECISION_HIGH | 2; |
| 1336 | wm->ddl[pipe].cursor = DDL_PRECISION_HIGH | 2; |
| 1337 | } |
| 1338 | } |
| 1339 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1340 | static void vlv_update_wm(struct intel_crtc *crtc) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1341 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1342 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1343 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1344 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1345 | struct vlv_wm_values wm = {}; |
| 1346 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1347 | vlv_compute_wm(crtc); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1348 | vlv_merge_wm(dev, &wm); |
| 1349 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1350 | if (memcmp(&dev_priv->wm.vlv, &wm, sizeof(wm)) == 0) { |
| 1351 | /* FIXME should be part of crtc atomic commit */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1352 | vlv_pipe_set_fifo_size(crtc); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1353 | return; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1354 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1355 | |
| 1356 | if (wm.level < VLV_WM_LEVEL_DDR_DVFS && |
| 1357 | dev_priv->wm.vlv.level >= VLV_WM_LEVEL_DDR_DVFS) |
| 1358 | chv_set_memory_dvfs(dev_priv, false); |
| 1359 | |
| 1360 | if (wm.level < VLV_WM_LEVEL_PM5 && |
| 1361 | dev_priv->wm.vlv.level >= VLV_WM_LEVEL_PM5) |
| 1362 | chv_set_memory_pm5(dev_priv, false); |
| 1363 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 1364 | if (!wm.cxsr && dev_priv->wm.vlv.cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1365 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1366 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1367 | /* FIXME should be part of crtc atomic commit */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1368 | vlv_pipe_set_fifo_size(crtc); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1369 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1370 | vlv_write_wm_values(crtc, &wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1371 | |
| 1372 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: plane=%d, cursor=%d, " |
| 1373 | "sprite0=%d, sprite1=%d, SR: plane=%d, cursor=%d level=%d cxsr=%d\n", |
| 1374 | pipe_name(pipe), wm.pipe[pipe].primary, wm.pipe[pipe].cursor, |
| 1375 | wm.pipe[pipe].sprite[0], wm.pipe[pipe].sprite[1], |
| 1376 | wm.sr.plane, wm.sr.cursor, wm.level, wm.cxsr); |
| 1377 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 1378 | if (wm.cxsr && !dev_priv->wm.vlv.cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1379 | intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1380 | |
| 1381 | if (wm.level >= VLV_WM_LEVEL_PM5 && |
| 1382 | dev_priv->wm.vlv.level < VLV_WM_LEVEL_PM5) |
| 1383 | chv_set_memory_pm5(dev_priv, true); |
| 1384 | |
| 1385 | if (wm.level >= VLV_WM_LEVEL_DDR_DVFS && |
| 1386 | dev_priv->wm.vlv.level < VLV_WM_LEVEL_DDR_DVFS) |
| 1387 | chv_set_memory_dvfs(dev_priv, true); |
| 1388 | |
| 1389 | dev_priv->wm.vlv = wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1390 | } |
| 1391 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1392 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1393 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1394 | static void g4x_update_wm(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1395 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 1396 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1397 | static const int sr_latency_ns = 12000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1398 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1399 | int plane_sr, cursor_sr; |
| 1400 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1401 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1402 | |
Ville Syrjälä | f0ce231 | 2016-10-31 22:37:08 +0200 | [diff] [blame] | 1403 | if (g4x_compute_wm0(dev_priv, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1404 | &g4x_wm_info, pessimal_latency_ns, |
| 1405 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1406 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1407 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1408 | |
Ville Syrjälä | f0ce231 | 2016-10-31 22:37:08 +0200 | [diff] [blame] | 1409 | if (g4x_compute_wm0(dev_priv, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1410 | &g4x_wm_info, pessimal_latency_ns, |
| 1411 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1412 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1413 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1414 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1415 | if (single_plane_enabled(enabled) && |
Ville Syrjälä | f0ce231 | 2016-10-31 22:37:08 +0200 | [diff] [blame] | 1416 | g4x_compute_srwm(dev_priv, ffs(enabled) - 1, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1417 | sr_latency_ns, |
| 1418 | &g4x_wm_info, |
| 1419 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1420 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1421 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1422 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1423 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1424 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1425 | plane_sr = cursor_sr = 0; |
| 1426 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1427 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1428 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1429 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1430 | planea_wm, cursora_wm, |
| 1431 | planeb_wm, cursorb_wm, |
| 1432 | plane_sr, cursor_sr); |
| 1433 | |
| 1434 | I915_WRITE(DSPFW1, |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1435 | FW_WM(plane_sr, SR) | |
| 1436 | FW_WM(cursorb_wm, CURSORB) | |
| 1437 | FW_WM(planeb_wm, PLANEB) | |
| 1438 | FW_WM(planea_wm, PLANEA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1439 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1440 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1441 | FW_WM(cursora_wm, CURSORA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1442 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1443 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1444 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1445 | FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1446 | |
| 1447 | if (cxsr_enabled) |
| 1448 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1449 | } |
| 1450 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1451 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1452 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1453 | struct drm_device *dev = unused_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1454 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1455 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1456 | int srwm = 1; |
| 1457 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1458 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1459 | |
| 1460 | /* Calc sr entries for one plane configs */ |
| 1461 | crtc = single_enabled_crtc(dev); |
| 1462 | if (crtc) { |
| 1463 | /* self-refresh has much higher latency */ |
| 1464 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1465 | const struct drm_display_mode *adjusted_mode = |
| 1466 | &crtc->config->base.adjusted_mode; |
| 1467 | const struct drm_framebuffer *fb = |
| 1468 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1469 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1470 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1471 | int hdisplay = crtc->config->pipe_src_w; |
| 1472 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1473 | unsigned long line_time_us; |
| 1474 | int entries; |
| 1475 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1476 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1477 | |
| 1478 | /* Use ns/us then divide to preserve precision */ |
| 1479 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1480 | cpp * hdisplay; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1481 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1482 | srwm = I965_FIFO_SIZE - entries; |
| 1483 | if (srwm < 0) |
| 1484 | srwm = 1; |
| 1485 | srwm &= 0x1ff; |
| 1486 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1487 | entries, srwm); |
| 1488 | |
| 1489 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1490 | cpp * crtc->base.cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1491 | entries = DIV_ROUND_UP(entries, |
| 1492 | i965_cursor_wm_info.cacheline_size); |
| 1493 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1494 | (entries + i965_cursor_wm_info.guard_size); |
| 1495 | |
| 1496 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1497 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1498 | |
| 1499 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1500 | "cursor %d\n", srwm, cursor_sr); |
| 1501 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1502 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1503 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1504 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1505 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1506 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1510 | srwm); |
| 1511 | |
| 1512 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1513 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 1514 | FW_WM(8, CURSORB) | |
| 1515 | FW_WM(8, PLANEB) | |
| 1516 | FW_WM(8, PLANEA)); |
| 1517 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 1518 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1519 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1520 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1521 | |
| 1522 | if (cxsr_enabled) |
| 1523 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1524 | } |
| 1525 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1526 | #undef FW_WM |
| 1527 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1528 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1529 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1530 | struct drm_device *dev = unused_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1531 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1532 | const struct intel_watermark_params *wm_info; |
| 1533 | uint32_t fwater_lo; |
| 1534 | uint32_t fwater_hi; |
| 1535 | int cwm, srwm = 1; |
| 1536 | int fifo_size; |
| 1537 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1538 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1539 | |
| 1540 | if (IS_I945GM(dev)) |
| 1541 | wm_info = &i945_wm_info; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1542 | else if (!IS_GEN2(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1543 | wm_info = &i915_wm_info; |
| 1544 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1545 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1546 | |
| 1547 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 1548 | crtc = intel_get_crtc_for_plane(dev_priv, 0); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1549 | if (intel_crtc_active(crtc)) { |
| 1550 | const struct drm_display_mode *adjusted_mode = |
| 1551 | &crtc->config->base.adjusted_mode; |
| 1552 | const struct drm_framebuffer *fb = |
| 1553 | crtc->base.primary->state->fb; |
| 1554 | int cpp; |
| 1555 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1556 | if (IS_GEN2(dev_priv)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1557 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1558 | else |
| 1559 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1560 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1561 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1562 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1563 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1564 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1565 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1566 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1567 | if (planea_wm > (long)wm_info->max_wm) |
| 1568 | planea_wm = wm_info->max_wm; |
| 1569 | } |
| 1570 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1571 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1572 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1573 | |
| 1574 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 1575 | crtc = intel_get_crtc_for_plane(dev_priv, 1); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1576 | if (intel_crtc_active(crtc)) { |
| 1577 | const struct drm_display_mode *adjusted_mode = |
| 1578 | &crtc->config->base.adjusted_mode; |
| 1579 | const struct drm_framebuffer *fb = |
| 1580 | crtc->base.primary->state->fb; |
| 1581 | int cpp; |
| 1582 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1583 | if (IS_GEN2(dev_priv)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1584 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1585 | else |
| 1586 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1587 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1588 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1589 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1590 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1591 | if (enabled == NULL) |
| 1592 | enabled = crtc; |
| 1593 | else |
| 1594 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1595 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1596 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1597 | if (planeb_wm > (long)wm_info->max_wm) |
| 1598 | planeb_wm = wm_info->max_wm; |
| 1599 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1600 | |
| 1601 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1602 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1603 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1604 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1605 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1606 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1607 | |
| 1608 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 1609 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1610 | enabled = NULL; |
| 1611 | } |
| 1612 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1613 | /* |
| 1614 | * Overlay gets an aggressive default since video jitter is bad. |
| 1615 | */ |
| 1616 | cwm = 2; |
| 1617 | |
| 1618 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1619 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1620 | |
| 1621 | /* Calc sr entries for one plane configs */ |
| 1622 | if (HAS_FW_BLC(dev) && enabled) { |
| 1623 | /* self-refresh has much higher latency */ |
| 1624 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1625 | const struct drm_display_mode *adjusted_mode = |
| 1626 | &enabled->config->base.adjusted_mode; |
| 1627 | const struct drm_framebuffer *fb = |
| 1628 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1629 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1630 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1631 | int hdisplay = enabled->config->pipe_src_w; |
| 1632 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1633 | unsigned long line_time_us; |
| 1634 | int entries; |
| 1635 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1636 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 1637 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1638 | else |
| 1639 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 1640 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1641 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1642 | |
| 1643 | /* Use ns/us then divide to preserve precision */ |
| 1644 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1645 | cpp * hdisplay; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1646 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1647 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1648 | srwm = wm_info->fifo_size - entries; |
| 1649 | if (srwm < 0) |
| 1650 | srwm = 1; |
| 1651 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1652 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1653 | I915_WRITE(FW_BLC_SELF, |
| 1654 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 1655 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1656 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1657 | } |
| 1658 | |
| 1659 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1660 | planea_wm, planeb_wm, cwm, srwm); |
| 1661 | |
| 1662 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1663 | fwater_hi = (cwm & 0x1f); |
| 1664 | |
| 1665 | /* Set request length to 8 cachelines per fetch */ |
| 1666 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1667 | fwater_hi = fwater_hi | (1 << 8); |
| 1668 | |
| 1669 | I915_WRITE(FW_BLC, fwater_lo); |
| 1670 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1671 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1672 | if (enabled) |
| 1673 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1674 | } |
| 1675 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1676 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1677 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 1678 | struct drm_device *dev = unused_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1679 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1680 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1681 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1682 | uint32_t fwater_lo; |
| 1683 | int planea_wm; |
| 1684 | |
| 1685 | crtc = single_enabled_crtc(dev); |
| 1686 | if (crtc == NULL) |
| 1687 | return; |
| 1688 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 1689 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1690 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1691 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1692 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1693 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1694 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1695 | fwater_lo |= (3<<8) | planea_wm; |
| 1696 | |
| 1697 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1698 | |
| 1699 | I915_WRITE(FW_BLC, fwater_lo); |
| 1700 | } |
| 1701 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 1702 | uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1703 | { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1704 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1705 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 1706 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1707 | |
| 1708 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1709 | * adjust the pixel_rate here. */ |
| 1710 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 1711 | if (pipe_config->pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1712 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 1713 | uint32_t pfit_size = pipe_config->pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1714 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 1715 | pipe_w = pipe_config->pipe_src_w; |
| 1716 | pipe_h = pipe_config->pipe_src_h; |
| 1717 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1718 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1719 | pfit_h = pfit_size & 0xFFFF; |
| 1720 | if (pipe_w < pfit_w) |
| 1721 | pipe_w = pfit_w; |
| 1722 | if (pipe_h < pfit_h) |
| 1723 | pipe_h = pfit_h; |
| 1724 | |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 1725 | if (WARN_ON(!pfit_w || !pfit_h)) |
| 1726 | return pixel_rate; |
| 1727 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1728 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1729 | pfit_w * pfit_h); |
| 1730 | } |
| 1731 | |
| 1732 | return pixel_rate; |
| 1733 | } |
| 1734 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1735 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1736 | static uint32_t ilk_wm_method1(uint32_t pixel_rate, uint8_t cpp, uint32_t latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1737 | { |
| 1738 | uint64_t ret; |
| 1739 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1740 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1741 | return UINT_MAX; |
| 1742 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1743 | ret = (uint64_t) pixel_rate * cpp * latency; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1744 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1745 | |
| 1746 | return ret; |
| 1747 | } |
| 1748 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1749 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1750 | static uint32_t ilk_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1751 | uint32_t horiz_pixels, uint8_t cpp, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1752 | uint32_t latency) |
| 1753 | { |
| 1754 | uint32_t ret; |
| 1755 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1756 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1757 | return UINT_MAX; |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 1758 | if (WARN_ON(!pipe_htotal)) |
| 1759 | return UINT_MAX; |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1760 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1761 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1762 | ret = (ret + 1) * horiz_pixels * cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1763 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1764 | return ret; |
| 1765 | } |
| 1766 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1767 | static uint32_t ilk_wm_fbc(uint32_t pri_val, uint32_t horiz_pixels, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1768 | uint8_t cpp) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1769 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 1770 | /* |
| 1771 | * Neither of these should be possible since this function shouldn't be |
| 1772 | * called if the CRTC is off or the plane is invisible. But let's be |
| 1773 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 1774 | * elsewhere in the driver. |
| 1775 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1776 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 1777 | return 0; |
| 1778 | if (WARN_ON(!horiz_pixels)) |
| 1779 | return 0; |
| 1780 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1781 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1782 | } |
| 1783 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1784 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1785 | uint16_t pri; |
| 1786 | uint16_t spr; |
| 1787 | uint16_t cur; |
| 1788 | uint16_t fbc; |
| 1789 | }; |
| 1790 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1791 | /* |
| 1792 | * For both WM_PIPE and WM_LP. |
| 1793 | * mem_value must be in 0.1us units. |
| 1794 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 1795 | static uint32_t ilk_compute_pri_wm(const struct intel_crtc_state *cstate, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 1796 | const struct intel_plane_state *pstate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1797 | uint32_t mem_value, |
| 1798 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1799 | { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1800 | int cpp = pstate->base.fb ? |
| 1801 | drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1802 | uint32_t method1, method2; |
| 1803 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1804 | if (!cstate->base.active || !pstate->base.visible) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1805 | return 0; |
| 1806 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1807 | method1 = ilk_wm_method1(ilk_pipe_pixel_rate(cstate), cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1808 | |
| 1809 | if (!is_lp) |
| 1810 | return method1; |
| 1811 | |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 1812 | method2 = ilk_wm_method2(ilk_pipe_pixel_rate(cstate), |
| 1813 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1814 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1815 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1816 | |
| 1817 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1818 | } |
| 1819 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1820 | /* |
| 1821 | * For both WM_PIPE and WM_LP. |
| 1822 | * mem_value must be in 0.1us units. |
| 1823 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 1824 | static uint32_t ilk_compute_spr_wm(const struct intel_crtc_state *cstate, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 1825 | const struct intel_plane_state *pstate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1826 | uint32_t mem_value) |
| 1827 | { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1828 | int cpp = pstate->base.fb ? |
| 1829 | drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1830 | uint32_t method1, method2; |
| 1831 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1832 | if (!cstate->base.active || !pstate->base.visible) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1833 | return 0; |
| 1834 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1835 | method1 = ilk_wm_method1(ilk_pipe_pixel_rate(cstate), cpp, mem_value); |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 1836 | method2 = ilk_wm_method2(ilk_pipe_pixel_rate(cstate), |
| 1837 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1838 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1839 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1840 | return min(method1, method2); |
| 1841 | } |
| 1842 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1843 | /* |
| 1844 | * For both WM_PIPE and WM_LP. |
| 1845 | * mem_value must be in 0.1us units. |
| 1846 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 1847 | static uint32_t ilk_compute_cur_wm(const struct intel_crtc_state *cstate, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 1848 | const struct intel_plane_state *pstate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1849 | uint32_t mem_value) |
| 1850 | { |
Matt Roper | b243569 | 2016-02-02 22:06:51 -0800 | [diff] [blame] | 1851 | /* |
| 1852 | * We treat the cursor plane as always-on for the purposes of watermark |
| 1853 | * calculation. Until we have two-stage watermark programming merged, |
| 1854 | * this is necessary to avoid flickering. |
| 1855 | */ |
| 1856 | int cpp = 4; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1857 | int width = pstate->base.visible ? pstate->base.crtc_w : 64; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 1858 | |
Matt Roper | b243569 | 2016-02-02 22:06:51 -0800 | [diff] [blame] | 1859 | if (!cstate->base.active) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1860 | return 0; |
| 1861 | |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 1862 | return ilk_wm_method2(ilk_pipe_pixel_rate(cstate), |
| 1863 | cstate->base.adjusted_mode.crtc_htotal, |
Matt Roper | b243569 | 2016-02-02 22:06:51 -0800 | [diff] [blame] | 1864 | width, cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1865 | } |
| 1866 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1867 | /* Only for WM_LP. */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 1868 | static uint32_t ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 1869 | const struct intel_plane_state *pstate, |
Ville Syrjälä | 1fda988 | 2013-07-05 11:57:19 +0300 | [diff] [blame] | 1870 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1871 | { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1872 | int cpp = pstate->base.fb ? |
| 1873 | drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 1874 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1875 | if (!cstate->base.active || !pstate->base.visible) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1876 | return 0; |
| 1877 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 1878 | return ilk_wm_fbc(pri_val, drm_rect_width(&pstate->base.dst), cpp); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1879 | } |
| 1880 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1881 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1882 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1883 | if (INTEL_INFO(dev)->gen >= 8) |
| 1884 | return 3072; |
| 1885 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1886 | return 768; |
| 1887 | else |
| 1888 | return 512; |
| 1889 | } |
| 1890 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1891 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1892 | int level, bool is_sprite) |
| 1893 | { |
| 1894 | if (INTEL_INFO(dev)->gen >= 8) |
| 1895 | /* BDW primary/sprite plane watermarks */ |
| 1896 | return level == 0 ? 255 : 2047; |
| 1897 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1898 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1899 | return level == 0 ? 127 : 1023; |
| 1900 | else if (!is_sprite) |
| 1901 | /* ILK/SNB primary plane watermarks */ |
| 1902 | return level == 0 ? 127 : 511; |
| 1903 | else |
| 1904 | /* ILK/SNB sprite plane watermarks */ |
| 1905 | return level == 0 ? 63 : 255; |
| 1906 | } |
| 1907 | |
| 1908 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1909 | int level) |
| 1910 | { |
| 1911 | if (INTEL_INFO(dev)->gen >= 7) |
| 1912 | return level == 0 ? 63 : 255; |
| 1913 | else |
| 1914 | return level == 0 ? 31 : 63; |
| 1915 | } |
| 1916 | |
| 1917 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1918 | { |
| 1919 | if (INTEL_INFO(dev)->gen >= 8) |
| 1920 | return 31; |
| 1921 | else |
| 1922 | return 15; |
| 1923 | } |
| 1924 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1925 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1926 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1927 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1928 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1929 | enum intel_ddb_partitioning ddb_partitioning, |
| 1930 | bool is_sprite) |
| 1931 | { |
| 1932 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1933 | |
| 1934 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1935 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1936 | return 0; |
| 1937 | |
| 1938 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1939 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1940 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1941 | |
| 1942 | /* |
| 1943 | * For some reason the non self refresh |
| 1944 | * FIFO size is only half of the self |
| 1945 | * refresh FIFO size on ILK/SNB. |
| 1946 | */ |
| 1947 | if (INTEL_INFO(dev)->gen <= 6) |
| 1948 | fifo_size /= 2; |
| 1949 | } |
| 1950 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1951 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1952 | /* level 0 is always calculated with 1:1 split */ |
| 1953 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1954 | if (is_sprite) |
| 1955 | fifo_size *= 5; |
| 1956 | fifo_size /= 6; |
| 1957 | } else { |
| 1958 | fifo_size /= 2; |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1963 | 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] | 1964 | } |
| 1965 | |
| 1966 | /* Calculate the maximum cursor plane watermark */ |
| 1967 | 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] | 1968 | int level, |
| 1969 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1970 | { |
| 1971 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1972 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1973 | return 64; |
| 1974 | |
| 1975 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1976 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1977 | } |
| 1978 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1979 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1980 | int level, |
| 1981 | const struct intel_wm_config *config, |
| 1982 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1983 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1984 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1985 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1986 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1987 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1988 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1989 | } |
| 1990 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1991 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1992 | int level, |
| 1993 | struct ilk_wm_maximums *max) |
| 1994 | { |
| 1995 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1996 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1997 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1998 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1999 | } |
| 2000 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2001 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2002 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2003 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2004 | { |
| 2005 | bool ret; |
| 2006 | |
| 2007 | /* already determined to be invalid? */ |
| 2008 | if (!result->enable) |
| 2009 | return false; |
| 2010 | |
| 2011 | result->enable = result->pri_val <= max->pri && |
| 2012 | result->spr_val <= max->spr && |
| 2013 | result->cur_val <= max->cur; |
| 2014 | |
| 2015 | ret = result->enable; |
| 2016 | |
| 2017 | /* |
| 2018 | * HACK until we can pre-compute everything, |
| 2019 | * and thus fail gracefully if LP0 watermarks |
| 2020 | * are exceeded... |
| 2021 | */ |
| 2022 | if (level == 0 && !result->enable) { |
| 2023 | if (result->pri_val > max->pri) |
| 2024 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2025 | level, result->pri_val, max->pri); |
| 2026 | if (result->spr_val > max->spr) |
| 2027 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2028 | level, result->spr_val, max->spr); |
| 2029 | if (result->cur_val > max->cur) |
| 2030 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2031 | level, result->cur_val, max->cur); |
| 2032 | |
| 2033 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2034 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2035 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2036 | result->enable = true; |
| 2037 | } |
| 2038 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2039 | return ret; |
| 2040 | } |
| 2041 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2042 | static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2043 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2044 | int level, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2045 | struct intel_crtc_state *cstate, |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2046 | struct intel_plane_state *pristate, |
| 2047 | struct intel_plane_state *sprstate, |
| 2048 | struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2049 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2050 | { |
| 2051 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2052 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2053 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2054 | |
| 2055 | /* WM1+ latency values stored in 0.5us units */ |
| 2056 | if (level > 0) { |
| 2057 | pri_latency *= 5; |
| 2058 | spr_latency *= 5; |
| 2059 | cur_latency *= 5; |
| 2060 | } |
| 2061 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2062 | if (pristate) { |
| 2063 | result->pri_val = ilk_compute_pri_wm(cstate, pristate, |
| 2064 | pri_latency, level); |
| 2065 | result->fbc_val = ilk_compute_fbc_wm(cstate, pristate, result->pri_val); |
| 2066 | } |
| 2067 | |
| 2068 | if (sprstate) |
| 2069 | result->spr_val = ilk_compute_spr_wm(cstate, sprstate, spr_latency); |
| 2070 | |
| 2071 | if (curstate) |
| 2072 | result->cur_val = ilk_compute_cur_wm(cstate, curstate, cur_latency); |
| 2073 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2074 | result->enable = true; |
| 2075 | } |
| 2076 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2077 | static uint32_t |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2078 | hsw_compute_linetime_wm(const struct intel_crtc_state *cstate) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2079 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2080 | const struct intel_atomic_state *intel_state = |
| 2081 | to_intel_atomic_state(cstate->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2082 | const struct drm_display_mode *adjusted_mode = |
| 2083 | &cstate->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2084 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2085 | |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2086 | if (!cstate->base.active) |
| 2087 | return 0; |
| 2088 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2089 | return 0; |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2090 | if (WARN_ON(intel_state->cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2091 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2092 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2093 | /* The WM are computed with base on how long it takes to fill a single |
| 2094 | * row at the given clock rate, multiplied by 8. |
| 2095 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2096 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2097 | adjusted_mode->crtc_clock); |
| 2098 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2099 | intel_state->cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2100 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2101 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2102 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2103 | } |
| 2104 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2105 | 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] | 2106 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2107 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2108 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2109 | if (IS_GEN9(dev_priv)) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2110 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2111 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2112 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2113 | |
| 2114 | /* read the first set of memory latencies[0:3] */ |
| 2115 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 2116 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2117 | ret = sandybridge_pcode_read(dev_priv, |
| 2118 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2119 | &val); |
| 2120 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2121 | |
| 2122 | if (ret) { |
| 2123 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2124 | return; |
| 2125 | } |
| 2126 | |
| 2127 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2128 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2129 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2130 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2131 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2132 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2133 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2134 | |
| 2135 | /* read the second set of memory latencies[4:7] */ |
| 2136 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 2137 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2138 | ret = sandybridge_pcode_read(dev_priv, |
| 2139 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2140 | &val); |
| 2141 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2142 | if (ret) { |
| 2143 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2144 | return; |
| 2145 | } |
| 2146 | |
| 2147 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2148 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2149 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2150 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2151 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2152 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2153 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2154 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2155 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2156 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2157 | * need to be disabled. We make sure to sanitize the values out |
| 2158 | * of the punit to satisfy this requirement. |
| 2159 | */ |
| 2160 | for (level = 1; level <= max_level; level++) { |
| 2161 | if (wm[level] == 0) { |
| 2162 | for (i = level + 1; i <= max_level; i++) |
| 2163 | wm[i] = 0; |
| 2164 | break; |
| 2165 | } |
| 2166 | } |
| 2167 | |
| 2168 | /* |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2169 | * WaWmMemoryReadLatency:skl |
| 2170 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2171 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2172 | * to add 2us to the various latency levels we retrieve from the |
| 2173 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2174 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2175 | if (wm[0] == 0) { |
| 2176 | wm[0] += 2; |
| 2177 | for (level = 1; level <= max_level; level++) { |
| 2178 | if (wm[level] == 0) |
| 2179 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2180 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2181 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2182 | } |
| 2183 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2184 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2185 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2186 | |
| 2187 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2188 | if (wm[0] == 0) |
| 2189 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2190 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2191 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2192 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2193 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2194 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 2195 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2196 | |
| 2197 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2198 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2199 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2200 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2201 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 2202 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2203 | |
| 2204 | /* ILK primary LP0 latency is 700 ns */ |
| 2205 | wm[0] = 7; |
| 2206 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2207 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2211 | static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv, |
| 2212 | uint16_t wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2213 | { |
| 2214 | /* ILK sprite LP0 latency is 1300 ns */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2215 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2216 | wm[0] = 13; |
| 2217 | } |
| 2218 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2219 | static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv, |
| 2220 | uint16_t wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2221 | { |
| 2222 | /* ILK cursor LP0 latency is 1300 ns */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2223 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2224 | wm[0] = 13; |
| 2225 | |
| 2226 | /* WaDoubleCursorLP3Latency:ivb */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2227 | if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2228 | wm[3] *= 2; |
| 2229 | } |
| 2230 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2231 | int ilk_wm_max_level(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2232 | { |
| 2233 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2234 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2235 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2236 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2237 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2238 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2239 | return 3; |
| 2240 | else |
| 2241 | return 2; |
| 2242 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2243 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2244 | static void intel_print_wm_latency(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2245 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2246 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2247 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2248 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2249 | |
| 2250 | for (level = 0; level <= max_level; level++) { |
| 2251 | unsigned int latency = wm[level]; |
| 2252 | |
| 2253 | if (latency == 0) { |
| 2254 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2255 | name, level); |
| 2256 | continue; |
| 2257 | } |
| 2258 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2259 | /* |
| 2260 | * - latencies are in us on gen9. |
| 2261 | * - before then, WM1+ latency values are in 0.5us units |
| 2262 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2263 | if (IS_GEN9(dev_priv)) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2264 | latency *= 10; |
| 2265 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2266 | latency *= 5; |
| 2267 | |
| 2268 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2269 | name, level, wm[level], |
| 2270 | latency / 10, latency % 10); |
| 2271 | } |
| 2272 | } |
| 2273 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2274 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2275 | uint16_t wm[5], uint16_t min) |
| 2276 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2277 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2278 | |
| 2279 | if (wm[0] >= min) |
| 2280 | return false; |
| 2281 | |
| 2282 | wm[0] = max(wm[0], min); |
| 2283 | for (level = 1; level <= max_level; level++) |
| 2284 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2285 | |
| 2286 | return true; |
| 2287 | } |
| 2288 | |
| 2289 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 2290 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2291 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2292 | bool changed; |
| 2293 | |
| 2294 | /* |
| 2295 | * The BIOS provided WM memory latency values are often |
| 2296 | * inadequate for high resolution displays. Adjust them. |
| 2297 | */ |
| 2298 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2299 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2300 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2301 | |
| 2302 | if (!changed) |
| 2303 | return; |
| 2304 | |
| 2305 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2306 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 2307 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 2308 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2309 | } |
| 2310 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2311 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2312 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2313 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2314 | |
| 2315 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2316 | |
| 2317 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2318 | sizeof(dev_priv->wm.pri_latency)); |
| 2319 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2320 | sizeof(dev_priv->wm.pri_latency)); |
| 2321 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2322 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2323 | intel_fixup_cur_wm_latency(dev_priv, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2324 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2325 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 2326 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 2327 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2328 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2329 | if (IS_GEN6(dev_priv)) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2330 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2331 | } |
| 2332 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2333 | static void skl_setup_wm_latency(struct drm_device *dev) |
| 2334 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2335 | struct drm_i915_private *dev_priv = to_i915(dev); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2336 | |
| 2337 | intel_read_wm_latency(dev, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2338 | intel_print_wm_latency(dev_priv, "Gen9 Plane", dev_priv->wm.skl_latency); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2341 | static bool ilk_validate_pipe_wm(struct drm_device *dev, |
| 2342 | struct intel_pipe_wm *pipe_wm) |
| 2343 | { |
| 2344 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2345 | const struct intel_wm_config config = { |
| 2346 | .num_pipes_active = 1, |
| 2347 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 2348 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 2349 | }; |
| 2350 | struct ilk_wm_maximums max; |
| 2351 | |
| 2352 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2353 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2354 | |
| 2355 | /* At least LP0 must be valid */ |
| 2356 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 2357 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 2358 | return false; |
| 2359 | } |
| 2360 | |
| 2361 | return true; |
| 2362 | } |
| 2363 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 2364 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2365 | static int ilk_compute_pipe_wm(struct intel_crtc_state *cstate) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 2366 | { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2367 | struct drm_atomic_state *state = cstate->base.state; |
| 2368 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2369 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2370 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2371 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2372 | struct intel_plane *intel_plane; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2373 | struct intel_plane_state *pristate = NULL; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2374 | struct intel_plane_state *sprstate = NULL; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2375 | struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2376 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2377 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2378 | |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 2379 | pipe_wm = &cstate->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2380 | |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2381 | for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2382 | struct intel_plane_state *ps; |
| 2383 | |
| 2384 | ps = intel_atomic_get_existing_plane_state(state, |
| 2385 | intel_plane); |
| 2386 | if (!ps) |
| 2387 | continue; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2388 | |
| 2389 | if (intel_plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2390 | pristate = ps; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2391 | else if (intel_plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2392 | sprstate = ps; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2393 | else if (intel_plane->base.type == DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2394 | curstate = ps; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2397 | pipe_wm->pipe_enabled = cstate->base.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2398 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2399 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 2400 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 2401 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 2402 | drm_rect_height(&sprstate->base.dst) != drm_rect_height(&sprstate->base.src) >> 16); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 2405 | usable_level = max_level; |
| 2406 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2407 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2408 | if (INTEL_INFO(dev)->gen <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 2409 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2410 | |
| 2411 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2412 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 2413 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2414 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2415 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, cstate, |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 2416 | pristate, sprstate, curstate, &pipe_wm->raw_wm[0]); |
| 2417 | |
| 2418 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
| 2419 | pipe_wm->wm[0] = pipe_wm->raw_wm[0]; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2420 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2421 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2422 | pipe_wm->linetime = hsw_compute_linetime_wm(cstate); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2423 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2424 | if (!ilk_validate_pipe_wm(dev, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 2425 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2426 | |
| 2427 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2428 | |
| 2429 | for (level = 1; level <= max_level; level++) { |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 2430 | struct intel_wm_level *wm = &pipe_wm->raw_wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2431 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2432 | ilk_compute_wm_level(dev_priv, intel_crtc, level, cstate, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 2433 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2434 | |
| 2435 | /* |
| 2436 | * Disable any watermark level that exceeds the |
| 2437 | * register maximums since such watermarks are |
| 2438 | * always invalid. |
| 2439 | */ |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 2440 | if (level > usable_level) |
| 2441 | continue; |
| 2442 | |
| 2443 | if (ilk_validate_wm_level(level, &max, wm)) |
| 2444 | pipe_wm->wm[level] = *wm; |
| 2445 | else |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 2446 | usable_level = level; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2447 | } |
| 2448 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2449 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2453 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 2454 | * state and the new state. These can be programmed to the hardware |
| 2455 | * immediately. |
| 2456 | */ |
| 2457 | static int ilk_compute_intermediate_wm(struct drm_device *dev, |
| 2458 | struct intel_crtc *intel_crtc, |
| 2459 | struct intel_crtc_state *newstate) |
| 2460 | { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 2461 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2462 | struct intel_pipe_wm *b = &intel_crtc->wm.active.ilk; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2463 | int level, max_level = ilk_wm_max_level(to_i915(dev)); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2464 | |
| 2465 | /* |
| 2466 | * Start with the final, target watermarks, then combine with the |
| 2467 | * currently active watermarks to get values that are safe both before |
| 2468 | * and after the vblank. |
| 2469 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 2470 | *a = newstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2471 | a->pipe_enabled |= b->pipe_enabled; |
| 2472 | a->sprites_enabled |= b->sprites_enabled; |
| 2473 | a->sprites_scaled |= b->sprites_scaled; |
| 2474 | |
| 2475 | for (level = 0; level <= max_level; level++) { |
| 2476 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 2477 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 2478 | |
| 2479 | a_wm->enable &= b_wm->enable; |
| 2480 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 2481 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 2482 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 2483 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 2484 | } |
| 2485 | |
| 2486 | /* |
| 2487 | * We need to make sure that these merged watermark values are |
| 2488 | * actually a valid configuration themselves. If they're not, |
| 2489 | * there's no safe way to transition from the old state to |
| 2490 | * the new state, so we need to fail the atomic transaction. |
| 2491 | */ |
| 2492 | if (!ilk_validate_pipe_wm(dev, a)) |
| 2493 | return -EINVAL; |
| 2494 | |
| 2495 | /* |
| 2496 | * If our intermediate WM are identical to the final WM, then we can |
| 2497 | * omit the post-vblank programming; only update if it's different. |
| 2498 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 2499 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) == 0) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2500 | newstate->wm.need_postvbl_update = false; |
| 2501 | |
| 2502 | return 0; |
| 2503 | } |
| 2504 | |
| 2505 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2506 | * Merge the watermarks from all active pipes for a specific level. |
| 2507 | */ |
| 2508 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2509 | int level, |
| 2510 | struct intel_wm_level *ret_wm) |
| 2511 | { |
| 2512 | const struct intel_crtc *intel_crtc; |
| 2513 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2514 | ret_wm->enable = true; |
| 2515 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2516 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2517 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2518 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2519 | |
| 2520 | if (!active->pipe_enabled) |
| 2521 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2522 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2523 | /* |
| 2524 | * The watermark values may have been used in the past, |
| 2525 | * so we must maintain them in the registers for some |
| 2526 | * time even if the level is now disabled. |
| 2527 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2528 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2529 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2530 | |
| 2531 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2532 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2533 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2534 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2535 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | /* |
| 2539 | * Merge all low power watermarks for all active pipes. |
| 2540 | */ |
| 2541 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2542 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2543 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2544 | struct intel_pipe_wm *merged) |
| 2545 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2546 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2547 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2548 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2549 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2550 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2551 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2552 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 2553 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2554 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2555 | /* ILK: FBC WM must be disabled always */ |
| 2556 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2557 | |
| 2558 | /* merge each WM1+ level */ |
| 2559 | for (level = 1; level <= max_level; level++) { |
| 2560 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2561 | |
| 2562 | ilk_merge_wm_level(dev, level, wm); |
| 2563 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2564 | if (level > last_enabled_level) |
| 2565 | wm->enable = false; |
| 2566 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2567 | /* make sure all following levels get disabled */ |
| 2568 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2569 | |
| 2570 | /* |
| 2571 | * The spec says it is preferred to disable |
| 2572 | * FBC WMs instead of disabling a WM level. |
| 2573 | */ |
| 2574 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2575 | if (wm->enable) |
| 2576 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2577 | wm->fbc_val = 0; |
| 2578 | } |
| 2579 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2580 | |
| 2581 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2582 | /* |
| 2583 | * FIXME this is racy. FBC might get enabled later. |
| 2584 | * What we should check here is whether FBC can be |
| 2585 | * enabled sometime later. |
| 2586 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2587 | if (IS_GEN5(dev_priv) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 2588 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2589 | for (level = 2; level <= max_level; level++) { |
| 2590 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2591 | |
| 2592 | wm->enable = false; |
| 2593 | } |
| 2594 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2595 | } |
| 2596 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2597 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2598 | { |
| 2599 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2600 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2601 | } |
| 2602 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2603 | /* The value we need to program into the WM_LPx latency field */ |
| 2604 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2605 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2606 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2607 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2608 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2609 | return 2 * level; |
| 2610 | else |
| 2611 | return dev_priv->wm.pri_latency[level]; |
| 2612 | } |
| 2613 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2614 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2615 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2616 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2617 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2618 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2619 | struct intel_crtc *intel_crtc; |
| 2620 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2621 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2622 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2623 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2624 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2625 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2626 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2627 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2628 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2629 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2630 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2631 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2632 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2633 | /* |
| 2634 | * Maintain the watermark values even if the level is |
| 2635 | * disabled. Doing otherwise could cause underruns. |
| 2636 | */ |
| 2637 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2638 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2639 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2640 | r->cur_val; |
| 2641 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2642 | if (r->enable) |
| 2643 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2644 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2645 | if (INTEL_INFO(dev)->gen >= 8) |
| 2646 | results->wm_lp[wm_lp - 1] |= |
| 2647 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2648 | else |
| 2649 | results->wm_lp[wm_lp - 1] |= |
| 2650 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2651 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2652 | /* |
| 2653 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2654 | * level is disabled. Doing otherwise could cause underruns. |
| 2655 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2656 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2657 | WARN_ON(wm_lp != 1); |
| 2658 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2659 | } else |
| 2660 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2661 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2662 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2663 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2664 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2665 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2666 | const struct intel_wm_level *r = |
| 2667 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2668 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2669 | if (WARN_ON(!r->enable)) |
| 2670 | continue; |
| 2671 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2672 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2673 | |
| 2674 | results->wm_pipe[pipe] = |
| 2675 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2676 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2677 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2678 | } |
| 2679 | } |
| 2680 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2681 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2682 | * 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] | 2683 | 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] | 2684 | struct intel_pipe_wm *r1, |
| 2685 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2686 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2687 | int level, max_level = ilk_wm_max_level(to_i915(dev)); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2688 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2689 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2690 | for (level = 1; level <= max_level; level++) { |
| 2691 | if (r1->wm[level].enable) |
| 2692 | level1 = level; |
| 2693 | if (r2->wm[level].enable) |
| 2694 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2695 | } |
| 2696 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2697 | if (level1 == level2) { |
| 2698 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2699 | return r2; |
| 2700 | else |
| 2701 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2702 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2703 | return r1; |
| 2704 | } else { |
| 2705 | return r2; |
| 2706 | } |
| 2707 | } |
| 2708 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2709 | /* dirty bits used to track which watermarks need changes */ |
| 2710 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2711 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2712 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2713 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2714 | #define WM_DIRTY_FBC (1 << 24) |
| 2715 | #define WM_DIRTY_DDB (1 << 25) |
| 2716 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2717 | 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] | 2718 | const struct ilk_wm_values *old, |
| 2719 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2720 | { |
| 2721 | unsigned int dirty = 0; |
| 2722 | enum pipe pipe; |
| 2723 | int wm_lp; |
| 2724 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2725 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2726 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2727 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2728 | /* Must disable LP1+ watermarks too */ |
| 2729 | dirty |= WM_DIRTY_LP_ALL; |
| 2730 | } |
| 2731 | |
| 2732 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2733 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2734 | /* Must disable LP1+ watermarks too */ |
| 2735 | dirty |= WM_DIRTY_LP_ALL; |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2740 | dirty |= WM_DIRTY_FBC; |
| 2741 | /* Must disable LP1+ watermarks too */ |
| 2742 | dirty |= WM_DIRTY_LP_ALL; |
| 2743 | } |
| 2744 | |
| 2745 | if (old->partitioning != new->partitioning) { |
| 2746 | dirty |= WM_DIRTY_DDB; |
| 2747 | /* Must disable LP1+ watermarks too */ |
| 2748 | dirty |= WM_DIRTY_LP_ALL; |
| 2749 | } |
| 2750 | |
| 2751 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2752 | if (dirty & WM_DIRTY_LP_ALL) |
| 2753 | return dirty; |
| 2754 | |
| 2755 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2756 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2757 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2758 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2759 | break; |
| 2760 | } |
| 2761 | |
| 2762 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2763 | for (; wm_lp <= 3; wm_lp++) |
| 2764 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2765 | |
| 2766 | return dirty; |
| 2767 | } |
| 2768 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2769 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2770 | unsigned int dirty) |
| 2771 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2772 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2773 | bool changed = false; |
| 2774 | |
| 2775 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2776 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2777 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2778 | changed = true; |
| 2779 | } |
| 2780 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2781 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2782 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2783 | changed = true; |
| 2784 | } |
| 2785 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2786 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2787 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2788 | changed = true; |
| 2789 | } |
| 2790 | |
| 2791 | /* |
| 2792 | * Don't touch WM1S_LP_EN here. |
| 2793 | * Doing so could cause underruns. |
| 2794 | */ |
| 2795 | |
| 2796 | return changed; |
| 2797 | } |
| 2798 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2799 | /* |
| 2800 | * The spec says we shouldn't write when we don't need, because every write |
| 2801 | * causes WMs to be re-evaluated, expending some power. |
| 2802 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2803 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2804 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2805 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 2806 | struct drm_device *dev = &dev_priv->drm; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2807 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2808 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2809 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2810 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2811 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2812 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2813 | return; |
| 2814 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2815 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2816 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2817 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2818 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2819 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2820 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2821 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2822 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2823 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2824 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2825 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2826 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2827 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2828 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2829 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2830 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2831 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2832 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2833 | val = I915_READ(WM_MISC); |
| 2834 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2835 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2836 | else |
| 2837 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2838 | I915_WRITE(WM_MISC, val); |
| 2839 | } else { |
| 2840 | val = I915_READ(DISP_ARB_CTL2); |
| 2841 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2842 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2843 | else |
| 2844 | val |= DISP_DATA_PARTITION_5_6; |
| 2845 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2846 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2847 | } |
| 2848 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2849 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2850 | val = I915_READ(DISP_ARB_CTL); |
| 2851 | if (results->enable_fbc_wm) |
| 2852 | val &= ~DISP_FBC_WM_DIS; |
| 2853 | else |
| 2854 | val |= DISP_FBC_WM_DIS; |
| 2855 | I915_WRITE(DISP_ARB_CTL, val); |
| 2856 | } |
| 2857 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2858 | if (dirty & WM_DIRTY_LP(1) && |
| 2859 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2860 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2861 | |
| 2862 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2863 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2864 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2865 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2866 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2867 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2868 | |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2869 | 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] | 2870 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2871 | 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] | 2872 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2873 | 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] | 2874 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2875 | |
| 2876 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2877 | } |
| 2878 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2879 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2880 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2881 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2882 | |
| 2883 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2884 | } |
| 2885 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 2886 | #define SKL_SAGV_BLOCK_TIME 30 /* µs */ |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2887 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 2888 | /* |
| 2889 | * Return the index of a plane in the SKL DDB and wm result arrays. Primary |
| 2890 | * plane is always in slot 0, cursor is always in slot I915_MAX_PLANES-1, and |
| 2891 | * other universal planes are in indices 1..n. Note that this may leave unused |
| 2892 | * indices between the top "sprite" plane and the cursor. |
| 2893 | */ |
| 2894 | static int |
| 2895 | skl_wm_plane_id(const struct intel_plane *plane) |
| 2896 | { |
| 2897 | switch (plane->base.type) { |
| 2898 | case DRM_PLANE_TYPE_PRIMARY: |
| 2899 | return 0; |
| 2900 | case DRM_PLANE_TYPE_CURSOR: |
| 2901 | return PLANE_CURSOR; |
| 2902 | case DRM_PLANE_TYPE_OVERLAY: |
| 2903 | return plane->plane + 1; |
| 2904 | default: |
| 2905 | MISSING_CASE(plane->base.type); |
| 2906 | return plane->plane; |
| 2907 | } |
| 2908 | } |
| 2909 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 2910 | /* |
| 2911 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 2912 | * so assume we'll always need it in order to avoid underruns. |
| 2913 | */ |
| 2914 | static bool skl_needs_memory_bw_wa(struct intel_atomic_state *state) |
| 2915 | { |
| 2916 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 2917 | |
| 2918 | if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv) || |
| 2919 | IS_KABYLAKE(dev_priv)) |
| 2920 | return true; |
| 2921 | |
| 2922 | return false; |
| 2923 | } |
| 2924 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 2925 | static bool |
| 2926 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 2927 | { |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 2928 | if (IS_KABYLAKE(dev_priv)) |
| 2929 | return true; |
| 2930 | |
| 2931 | if (IS_SKYLAKE(dev_priv) && |
| 2932 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED) |
| 2933 | return true; |
| 2934 | |
| 2935 | return false; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 2936 | } |
| 2937 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 2938 | /* |
| 2939 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 2940 | * depending on power and performance requirements. The display engine access |
| 2941 | * to system memory is blocked during the adjustment time. Because of the |
| 2942 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 2943 | * underruns if we don't meet all of the following requirements: |
| 2944 | * |
| 2945 | * - <= 1 pipe enabled |
| 2946 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 2947 | * - We're not using an interlaced display configuration |
| 2948 | */ |
| 2949 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 2950 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 2951 | { |
| 2952 | int ret; |
| 2953 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 2954 | if (!intel_has_sagv(dev_priv)) |
| 2955 | return 0; |
| 2956 | |
| 2957 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 2958 | return 0; |
| 2959 | |
| 2960 | DRM_DEBUG_KMS("Enabling the SAGV\n"); |
| 2961 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2962 | |
| 2963 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 2964 | GEN9_SAGV_ENABLE); |
| 2965 | |
| 2966 | /* We don't need to wait for the SAGV when enabling */ |
| 2967 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2968 | |
| 2969 | /* |
| 2970 | * Some skl systems, pre-release machines in particular, |
| 2971 | * don't actually have an SAGV. |
| 2972 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 2973 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 2974 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 2975 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 2976 | return 0; |
| 2977 | } else if (ret < 0) { |
| 2978 | DRM_ERROR("Failed to enable the SAGV\n"); |
| 2979 | return ret; |
| 2980 | } |
| 2981 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 2982 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 2983 | return 0; |
| 2984 | } |
| 2985 | |
| 2986 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 2987 | intel_do_sagv_disable(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 2988 | { |
| 2989 | int ret; |
| 2990 | uint32_t temp = GEN9_SAGV_DISABLE; |
| 2991 | |
| 2992 | ret = sandybridge_pcode_read(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 2993 | &temp); |
| 2994 | if (ret) |
| 2995 | return ret; |
| 2996 | else |
| 2997 | return temp & GEN9_SAGV_IS_DISABLED; |
| 2998 | } |
| 2999 | |
| 3000 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3001 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3002 | { |
| 3003 | int ret, result; |
| 3004 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3005 | if (!intel_has_sagv(dev_priv)) |
| 3006 | return 0; |
| 3007 | |
| 3008 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3009 | return 0; |
| 3010 | |
| 3011 | DRM_DEBUG_KMS("Disabling the SAGV\n"); |
| 3012 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3013 | |
| 3014 | /* bspec says to keep retrying for at least 1 ms */ |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3015 | ret = wait_for(result = intel_do_sagv_disable(dev_priv), 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3016 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3017 | |
| 3018 | if (ret == -ETIMEDOUT) { |
| 3019 | DRM_ERROR("Request to disable SAGV timed out\n"); |
| 3020 | return -ETIMEDOUT; |
| 3021 | } |
| 3022 | |
| 3023 | /* |
| 3024 | * Some skl systems, pre-release machines in particular, |
| 3025 | * don't actually have an SAGV. |
| 3026 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3027 | if (IS_SKYLAKE(dev_priv) && result == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3028 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3029 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3030 | return 0; |
| 3031 | } else if (result < 0) { |
| 3032 | DRM_ERROR("Failed to disable the SAGV\n"); |
| 3033 | return result; |
| 3034 | } |
| 3035 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3036 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3037 | return 0; |
| 3038 | } |
| 3039 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3040 | bool intel_can_enable_sagv(struct drm_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3041 | { |
| 3042 | struct drm_device *dev = state->dev; |
| 3043 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3044 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3045 | struct intel_crtc *crtc; |
| 3046 | struct intel_plane *plane; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3047 | struct intel_crtc_state *cstate; |
| 3048 | struct skl_plane_wm *wm; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3049 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3050 | int level, latency; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3051 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3052 | if (!intel_has_sagv(dev_priv)) |
| 3053 | return false; |
| 3054 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3055 | /* |
| 3056 | * SKL workaround: bspec recommends we disable the SAGV when we have |
| 3057 | * more then one pipe enabled |
| 3058 | * |
| 3059 | * If there are no active CRTCs, no additional checks need be performed |
| 3060 | */ |
| 3061 | if (hweight32(intel_state->active_crtcs) == 0) |
| 3062 | return true; |
| 3063 | else if (hweight32(intel_state->active_crtcs) > 1) |
| 3064 | return false; |
| 3065 | |
| 3066 | /* Since we're now guaranteed to only have one active CRTC... */ |
| 3067 | pipe = ffs(intel_state->active_crtcs) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame^] | 3068 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3069 | cstate = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3070 | |
Paulo Zanoni | c89cadd | 2016-10-10 17:30:59 -0300 | [diff] [blame] | 3071 | if (crtc->base.state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3072 | return false; |
| 3073 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3074 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3075 | wm = &cstate->wm.skl.optimal.planes[skl_wm_plane_id(plane)]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3076 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3077 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3078 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3079 | continue; |
| 3080 | |
| 3081 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3082 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3083 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3084 | { } |
| 3085 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3086 | latency = dev_priv->wm.skl_latency[level]; |
| 3087 | |
| 3088 | if (skl_needs_memory_bw_wa(intel_state) && |
| 3089 | plane->base.state->fb->modifier[0] == |
| 3090 | I915_FORMAT_MOD_X_TILED) |
| 3091 | latency += 15; |
| 3092 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3093 | /* |
| 3094 | * If any of the planes on this pipe don't enable wm levels |
| 3095 | * that incur memory latencies higher then 30µs we can't enable |
| 3096 | * the SAGV |
| 3097 | */ |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3098 | if (latency < SKL_SAGV_BLOCK_TIME) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3099 | return false; |
| 3100 | } |
| 3101 | |
| 3102 | return true; |
| 3103 | } |
| 3104 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3105 | static void |
| 3106 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3107 | const struct intel_crtc_state *cstate, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3108 | struct skl_ddb_entry *alloc, /* out */ |
| 3109 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3110 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3111 | struct drm_atomic_state *state = cstate->base.state; |
| 3112 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 3113 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3114 | struct drm_crtc *for_crtc = cstate->base.crtc; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3115 | unsigned int pipe_size, ddb_size; |
| 3116 | int nth_active_pipe; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3117 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3118 | if (WARN_ON(!state) || !cstate->base.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3119 | alloc->start = 0; |
| 3120 | alloc->end = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3121 | *num_active = hweight32(dev_priv->active_crtcs); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3122 | return; |
| 3123 | } |
| 3124 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3125 | if (intel_state->active_pipe_changes) |
| 3126 | *num_active = hweight32(intel_state->active_crtcs); |
| 3127 | else |
| 3128 | *num_active = hweight32(dev_priv->active_crtcs); |
| 3129 | |
Deepak M | 6f3fff6 | 2016-09-15 15:01:10 +0530 | [diff] [blame] | 3130 | ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3131 | WARN_ON(ddb_size == 0); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3132 | |
| 3133 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 3134 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3135 | /* |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3136 | * If the state doesn't change the active CRTC's, then there's |
| 3137 | * no need to recalculate; the existing pipe allocation limits |
| 3138 | * should remain unchanged. Note that we're safe from racing |
| 3139 | * commits since any racing commit that changes the active CRTC |
| 3140 | * list would need to grab _all_ crtc locks, including the one |
| 3141 | * we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3142 | */ |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3143 | if (!intel_state->active_pipe_changes) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 3144 | *alloc = to_intel_crtc(for_crtc)->hw_ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3145 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3146 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3147 | |
| 3148 | nth_active_pipe = hweight32(intel_state->active_crtcs & |
| 3149 | (drm_crtc_mask(for_crtc) - 1)); |
| 3150 | pipe_size = ddb_size / hweight32(intel_state->active_crtcs); |
| 3151 | alloc->start = nth_active_pipe * ddb_size / *num_active; |
| 3152 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3155 | static unsigned int skl_cursor_allocation(int num_active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3156 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3157 | if (num_active == 1) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3158 | return 32; |
| 3159 | |
| 3160 | return 8; |
| 3161 | } |
| 3162 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3163 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 3164 | { |
| 3165 | entry->start = reg & 0x3ff; |
| 3166 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3167 | if (entry->end) |
| 3168 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 3171 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 3172 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3173 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3174 | enum pipe pipe; |
| 3175 | int plane; |
| 3176 | u32 val; |
| 3177 | |
Maarten Lankhorst | b10f1b2 | 2015-10-22 13:56:34 +0200 | [diff] [blame] | 3178 | memset(ddb, 0, sizeof(*ddb)); |
| 3179 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3180 | for_each_pipe(dev_priv, pipe) { |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3181 | enum intel_display_power_domain power_domain; |
| 3182 | |
| 3183 | power_domain = POWER_DOMAIN_PIPE(pipe); |
| 3184 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Maarten Lankhorst | b10f1b2 | 2015-10-22 13:56:34 +0200 | [diff] [blame] | 3185 | continue; |
| 3186 | |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 3187 | for_each_universal_plane(dev_priv, pipe, plane) { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3188 | val = I915_READ(PLANE_BUF_CFG(pipe, plane)); |
| 3189 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane], |
| 3190 | val); |
| 3191 | } |
| 3192 | |
| 3193 | val = I915_READ(CUR_BUF_CFG(pipe)); |
Matt Roper | 4969d33 | 2015-09-24 15:53:10 -0700 | [diff] [blame] | 3194 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][PLANE_CURSOR], |
| 3195 | val); |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3196 | |
| 3197 | intel_display_power_put(dev_priv, power_domain); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3198 | } |
| 3199 | } |
| 3200 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3201 | /* |
| 3202 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 3203 | * The bspec defines downscale amount as: |
| 3204 | * |
| 3205 | * """ |
| 3206 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 3207 | * Horizontal destination size] |
| 3208 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 3209 | * Vertical destination size] |
| 3210 | * Total down scale amount = Horizontal down scale amount * |
| 3211 | * Vertical down scale amount |
| 3212 | * """ |
| 3213 | * |
| 3214 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 3215 | * Caller should take care of dividing & rounding off the value. |
| 3216 | */ |
| 3217 | static uint32_t |
| 3218 | skl_plane_downscale_amount(const struct intel_plane_state *pstate) |
| 3219 | { |
| 3220 | uint32_t downscale_h, downscale_w; |
| 3221 | uint32_t src_w, src_h, dst_w, dst_h; |
| 3222 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3223 | if (WARN_ON(!pstate->base.visible)) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3224 | return DRM_PLANE_HELPER_NO_SCALING; |
| 3225 | |
| 3226 | /* n.b., src is 16.16 fixed point, dst is whole integer */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3227 | src_w = drm_rect_width(&pstate->base.src); |
| 3228 | src_h = drm_rect_height(&pstate->base.src); |
| 3229 | dst_w = drm_rect_width(&pstate->base.dst); |
| 3230 | dst_h = drm_rect_height(&pstate->base.dst); |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3231 | if (drm_rotation_90_or_270(pstate->base.rotation)) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3232 | swap(dst_w, dst_h); |
| 3233 | |
| 3234 | downscale_h = max(src_h / dst_h, (uint32_t)DRM_PLANE_HELPER_NO_SCALING); |
| 3235 | downscale_w = max(src_w / dst_w, (uint32_t)DRM_PLANE_HELPER_NO_SCALING); |
| 3236 | |
| 3237 | /* Provide result in 16.16 fixed point */ |
| 3238 | return (uint64_t)downscale_w * downscale_h >> 16; |
| 3239 | } |
| 3240 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3241 | static unsigned int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3242 | skl_plane_relative_data_rate(const struct intel_crtc_state *cstate, |
| 3243 | const struct drm_plane_state *pstate, |
| 3244 | int y) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3245 | { |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3246 | struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3247 | struct drm_framebuffer *fb = pstate->fb; |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3248 | uint32_t down_scale_amount, data_rate; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3249 | uint32_t width = 0, height = 0; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3250 | unsigned format = fb ? fb->pixel_format : DRM_FORMAT_XRGB8888; |
| 3251 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3252 | if (!intel_pstate->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3253 | return 0; |
| 3254 | if (pstate->plane->type == DRM_PLANE_TYPE_CURSOR) |
| 3255 | return 0; |
| 3256 | if (y && format != DRM_FORMAT_NV12) |
| 3257 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3258 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3259 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 3260 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3261 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3262 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3263 | swap(width, height); |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3264 | |
| 3265 | /* for planar format */ |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3266 | if (format == DRM_FORMAT_NV12) { |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3267 | if (y) /* y-plane data rate */ |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3268 | data_rate = width * height * |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3269 | drm_format_plane_cpp(format, 0); |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3270 | else /* uv-plane data rate */ |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3271 | data_rate = (width / 2) * (height / 2) * |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3272 | drm_format_plane_cpp(format, 1); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3273 | } else { |
| 3274 | /* for packed formats */ |
| 3275 | data_rate = width * height * drm_format_plane_cpp(format, 0); |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3276 | } |
| 3277 | |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3278 | down_scale_amount = skl_plane_downscale_amount(intel_pstate); |
| 3279 | |
| 3280 | return (uint64_t)data_rate * down_scale_amount >> 16; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | /* |
| 3284 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 3285 | * a 8192x4096@32bpp framebuffer: |
| 3286 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 3287 | */ |
| 3288 | static unsigned int |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3289 | skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate, |
| 3290 | unsigned *plane_data_rate, |
| 3291 | unsigned *plane_y_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3292 | { |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 3293 | struct drm_crtc_state *cstate = &intel_cstate->base; |
| 3294 | struct drm_atomic_state *state = cstate->state; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 3295 | struct drm_plane *plane; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3296 | const struct intel_plane *intel_plane; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 3297 | const struct drm_plane_state *pstate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3298 | unsigned int rate, total_data_rate = 0; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 3299 | int id; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3300 | |
| 3301 | if (WARN_ON(!state)) |
| 3302 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3303 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3304 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 3305 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, cstate) { |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3306 | id = skl_wm_plane_id(to_intel_plane(plane)); |
| 3307 | intel_plane = to_intel_plane(plane); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3308 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3309 | /* packed/uv */ |
| 3310 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 3311 | pstate, 0); |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3312 | plane_data_rate[id] = rate; |
| 3313 | |
| 3314 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 3315 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3316 | /* y-plane */ |
| 3317 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 3318 | pstate, 1); |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3319 | plane_y_data_rate[id] = rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3320 | |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3321 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | return total_data_rate; |
| 3325 | } |
| 3326 | |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3327 | static uint16_t |
| 3328 | skl_ddb_min_alloc(const struct drm_plane_state *pstate, |
| 3329 | const int y) |
| 3330 | { |
| 3331 | struct drm_framebuffer *fb = pstate->fb; |
| 3332 | struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate); |
| 3333 | uint32_t src_w, src_h; |
| 3334 | uint32_t min_scanlines = 8; |
| 3335 | uint8_t plane_bpp; |
| 3336 | |
| 3337 | if (WARN_ON(!fb)) |
| 3338 | return 0; |
| 3339 | |
| 3340 | /* For packed formats, no y-plane, return 0 */ |
| 3341 | if (y && fb->pixel_format != DRM_FORMAT_NV12) |
| 3342 | return 0; |
| 3343 | |
| 3344 | /* For Non Y-tile return 8-blocks */ |
| 3345 | if (fb->modifier[0] != I915_FORMAT_MOD_Y_TILED && |
| 3346 | fb->modifier[0] != I915_FORMAT_MOD_Yf_TILED) |
| 3347 | return 8; |
| 3348 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3349 | src_w = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 3350 | src_h = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3351 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3352 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3353 | swap(src_w, src_h); |
| 3354 | |
| 3355 | /* Halve UV plane width and height for NV12 */ |
| 3356 | if (fb->pixel_format == DRM_FORMAT_NV12 && !y) { |
| 3357 | src_w /= 2; |
| 3358 | src_h /= 2; |
| 3359 | } |
| 3360 | |
| 3361 | if (fb->pixel_format == DRM_FORMAT_NV12 && !y) |
| 3362 | plane_bpp = drm_format_plane_cpp(fb->pixel_format, 1); |
| 3363 | else |
| 3364 | plane_bpp = drm_format_plane_cpp(fb->pixel_format, 0); |
| 3365 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3366 | if (drm_rotation_90_or_270(pstate->rotation)) { |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3367 | switch (plane_bpp) { |
| 3368 | case 1: |
| 3369 | min_scanlines = 32; |
| 3370 | break; |
| 3371 | case 2: |
| 3372 | min_scanlines = 16; |
| 3373 | break; |
| 3374 | case 4: |
| 3375 | min_scanlines = 8; |
| 3376 | break; |
| 3377 | case 8: |
| 3378 | min_scanlines = 4; |
| 3379 | break; |
| 3380 | default: |
| 3381 | WARN(1, "Unsupported pixel depth %u for rotation", |
| 3382 | plane_bpp); |
| 3383 | min_scanlines = 32; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | return DIV_ROUND_UP((4 * src_w * plane_bpp), 512) * min_scanlines/4 + 3; |
| 3388 | } |
| 3389 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 3390 | static void |
| 3391 | skl_ddb_calc_min(const struct intel_crtc_state *cstate, int num_active, |
| 3392 | uint16_t *minimum, uint16_t *y_minimum) |
| 3393 | { |
| 3394 | const struct drm_plane_state *pstate; |
| 3395 | struct drm_plane *plane; |
| 3396 | |
| 3397 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, &cstate->base) { |
| 3398 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 3399 | int id = skl_wm_plane_id(intel_plane); |
| 3400 | |
| 3401 | if (id == PLANE_CURSOR) |
| 3402 | continue; |
| 3403 | |
| 3404 | if (!pstate->visible) |
| 3405 | continue; |
| 3406 | |
| 3407 | minimum[id] = skl_ddb_min_alloc(pstate, 0); |
| 3408 | y_minimum[id] = skl_ddb_min_alloc(pstate, 1); |
| 3409 | } |
| 3410 | |
| 3411 | minimum[PLANE_CURSOR] = skl_cursor_allocation(num_active); |
| 3412 | } |
| 3413 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3414 | static int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3415 | skl_allocate_pipe_ddb(struct intel_crtc_state *cstate, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3416 | struct skl_ddb_allocation *ddb /* out */) |
| 3417 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3418 | struct drm_atomic_state *state = cstate->base.state; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3419 | struct drm_crtc *crtc = cstate->base.crtc; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3420 | struct drm_device *dev = crtc->dev; |
| 3421 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3422 | enum pipe pipe = intel_crtc->pipe; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 3423 | struct skl_ddb_entry *alloc = &cstate->wm.skl.ddb; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 3424 | uint16_t alloc_size, start; |
Maarten Lankhorst | fefdd81 | 2016-10-26 15:41:33 +0200 | [diff] [blame] | 3425 | uint16_t minimum[I915_MAX_PLANES] = {}; |
| 3426 | uint16_t y_minimum[I915_MAX_PLANES] = {}; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3427 | unsigned int total_data_rate; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3428 | int num_active; |
| 3429 | int id, i; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3430 | unsigned plane_data_rate[I915_MAX_PLANES] = {}; |
| 3431 | unsigned plane_y_data_rate[I915_MAX_PLANES] = {}; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3432 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 3433 | /* Clear the partitioning for disabled planes. */ |
| 3434 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 3435 | memset(ddb->y_plane[pipe], 0, sizeof(ddb->y_plane[pipe])); |
| 3436 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3437 | if (WARN_ON(!state)) |
| 3438 | return 0; |
| 3439 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3440 | if (!cstate->base.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 3441 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3442 | return 0; |
| 3443 | } |
| 3444 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3445 | skl_ddb_get_pipe_allocation_limits(dev, cstate, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 3446 | alloc_size = skl_ddb_entry_size(alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3447 | if (alloc_size == 0) { |
| 3448 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3449 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3450 | } |
| 3451 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 3452 | skl_ddb_calc_min(cstate, num_active, minimum, y_minimum); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3453 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 3454 | /* |
| 3455 | * 1. Allocate the mininum required blocks for each active plane |
| 3456 | * and allocate the cursor, it doesn't require extra allocation |
| 3457 | * proportional to the data rate. |
| 3458 | */ |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3459 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 3460 | for (i = 0; i < I915_MAX_PLANES; i++) { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3461 | alloc_size -= minimum[i]; |
| 3462 | alloc_size -= y_minimum[i]; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 3465 | ddb->plane[pipe][PLANE_CURSOR].start = alloc->end - minimum[PLANE_CURSOR]; |
| 3466 | ddb->plane[pipe][PLANE_CURSOR].end = alloc->end; |
| 3467 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3468 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 3469 | * 2. Distribute the remaining space in proportion to the amount of |
| 3470 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3471 | * |
| 3472 | * FIXME: we may not allocate every single block here. |
| 3473 | */ |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3474 | total_data_rate = skl_get_total_relative_data_rate(cstate, |
| 3475 | plane_data_rate, |
| 3476 | plane_y_data_rate); |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3477 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3478 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3479 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 3480 | start = alloc->start; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3481 | for (id = 0; id < I915_MAX_PLANES; id++) { |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3482 | unsigned int data_rate, y_data_rate; |
| 3483 | uint16_t plane_blocks, y_plane_blocks = 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3484 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 3485 | if (id == PLANE_CURSOR) |
| 3486 | continue; |
| 3487 | |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3488 | data_rate = plane_data_rate[id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3489 | |
| 3490 | /* |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3491 | * allocation for (packed formats) or (uv-plane part of planar format): |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3492 | * promote the expression to 64 bits to avoid overflowing, the |
| 3493 | * result is < available as data_rate / total_data_rate < 1 |
| 3494 | */ |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3495 | plane_blocks = minimum[id]; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 3496 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 3497 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3498 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3499 | /* Leave disabled planes at (0,0) */ |
| 3500 | if (data_rate) { |
| 3501 | ddb->plane[pipe][id].start = start; |
| 3502 | ddb->plane[pipe][id].end = start + plane_blocks; |
| 3503 | } |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3504 | |
| 3505 | start += plane_blocks; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3506 | |
| 3507 | /* |
| 3508 | * allocation for y_plane part of planar format: |
| 3509 | */ |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3510 | y_data_rate = plane_y_data_rate[id]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3511 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3512 | y_plane_blocks = y_minimum[id]; |
| 3513 | y_plane_blocks += div_u64((uint64_t)alloc_size * y_data_rate, |
| 3514 | total_data_rate); |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3515 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3516 | if (y_data_rate) { |
| 3517 | ddb->y_plane[pipe][id].start = start; |
| 3518 | ddb->y_plane[pipe][id].end = start + y_plane_blocks; |
| 3519 | } |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3520 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3521 | start += y_plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3524 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3527 | /* |
| 3528 | * The max latency should be 257 (max the punit can code is 255 and we add 2us |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 3529 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3530 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 3531 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 3532 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 3533 | static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t cpp, uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3534 | { |
| 3535 | uint32_t wm_intermediate_val, ret; |
| 3536 | |
| 3537 | if (latency == 0) |
| 3538 | return UINT_MAX; |
| 3539 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 3540 | wm_intermediate_val = latency * pixel_rate * cpp / 512; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3541 | ret = DIV_ROUND_UP(wm_intermediate_val, 1000); |
| 3542 | |
| 3543 | return ret; |
| 3544 | } |
| 3545 | |
| 3546 | static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 3547 | uint32_t latency, uint32_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3548 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 3549 | uint32_t ret; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 3550 | uint32_t wm_intermediate_val; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3551 | |
| 3552 | if (latency == 0) |
| 3553 | return UINT_MAX; |
| 3554 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3555 | wm_intermediate_val = latency * pixel_rate; |
| 3556 | ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) * |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 3557 | plane_blocks_per_line; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3558 | |
| 3559 | return ret; |
| 3560 | } |
| 3561 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3562 | static uint32_t skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *cstate, |
| 3563 | struct intel_plane_state *pstate) |
| 3564 | { |
| 3565 | uint64_t adjusted_pixel_rate; |
| 3566 | uint64_t downscale_amount; |
| 3567 | uint64_t pixel_rate; |
| 3568 | |
| 3569 | /* Shouldn't reach here on disabled planes... */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3570 | if (WARN_ON(!pstate->base.visible)) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3571 | return 0; |
| 3572 | |
| 3573 | /* |
| 3574 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 3575 | * with additional adjustments for plane-specific scaling. |
| 3576 | */ |
Paulo Zanoni | cfd7e3a | 2016-10-07 17:28:57 -0300 | [diff] [blame] | 3577 | adjusted_pixel_rate = ilk_pipe_pixel_rate(cstate); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3578 | downscale_amount = skl_plane_downscale_amount(pstate); |
| 3579 | |
| 3580 | pixel_rate = adjusted_pixel_rate * downscale_amount >> 16; |
| 3581 | WARN_ON(pixel_rate != clamp_t(uint32_t, pixel_rate, 0, ~0)); |
| 3582 | |
| 3583 | return pixel_rate; |
| 3584 | } |
| 3585 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3586 | static int skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 3587 | struct intel_crtc_state *cstate, |
| 3588 | struct intel_plane_state *intel_pstate, |
| 3589 | uint16_t ddb_allocation, |
| 3590 | int level, |
| 3591 | uint16_t *out_blocks, /* out */ |
| 3592 | uint8_t *out_lines, /* out */ |
| 3593 | bool *enabled /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3594 | { |
Matt Roper | 33815fa | 2016-05-12 07:06:05 -0700 | [diff] [blame] | 3595 | struct drm_plane_state *pstate = &intel_pstate->base; |
| 3596 | struct drm_framebuffer *fb = pstate->fb; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 3597 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
| 3598 | uint32_t method1, method2; |
| 3599 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 3600 | uint32_t res_blocks, res_lines; |
| 3601 | uint32_t selected_result; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 3602 | uint8_t cpp; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3603 | uint32_t width = 0, height = 0; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3604 | uint32_t plane_pixel_rate; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 3605 | uint32_t y_tile_minimum, y_min_scanlines; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3606 | struct intel_atomic_state *state = |
| 3607 | to_intel_atomic_state(cstate->base.state); |
| 3608 | bool apply_memory_bw_wa = skl_needs_memory_bw_wa(state); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3609 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3610 | if (latency == 0 || !cstate->base.active || !intel_pstate->base.visible) { |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3611 | *enabled = false; |
| 3612 | return 0; |
| 3613 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3614 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3615 | if (apply_memory_bw_wa && fb->modifier[0] == I915_FORMAT_MOD_X_TILED) |
| 3616 | latency += 15; |
| 3617 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3618 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 3619 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3620 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3621 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3622 | swap(width, height); |
| 3623 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 3624 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3625 | plane_pixel_rate = skl_adjusted_plane_pixel_rate(cstate, intel_pstate); |
| 3626 | |
Dave Airlie | 61d0a04 | 2016-10-25 16:35:20 +1000 | [diff] [blame] | 3627 | if (drm_rotation_90_or_270(pstate->rotation)) { |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 3628 | int cpp = (fb->pixel_format == DRM_FORMAT_NV12) ? |
| 3629 | drm_format_plane_cpp(fb->pixel_format, 1) : |
| 3630 | drm_format_plane_cpp(fb->pixel_format, 0); |
| 3631 | |
| 3632 | switch (cpp) { |
| 3633 | case 1: |
| 3634 | y_min_scanlines = 16; |
| 3635 | break; |
| 3636 | case 2: |
| 3637 | y_min_scanlines = 8; |
| 3638 | break; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 3639 | case 4: |
| 3640 | y_min_scanlines = 4; |
| 3641 | break; |
Paulo Zanoni | 86a462b | 2016-09-22 18:00:35 -0300 | [diff] [blame] | 3642 | default: |
| 3643 | MISSING_CASE(cpp); |
| 3644 | return -EINVAL; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 3645 | } |
| 3646 | } else { |
| 3647 | y_min_scanlines = 4; |
| 3648 | } |
| 3649 | |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 3650 | plane_bytes_per_line = width * cpp; |
| 3651 | if (fb->modifier[0] == I915_FORMAT_MOD_Y_TILED || |
| 3652 | fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED) { |
| 3653 | plane_blocks_per_line = |
| 3654 | DIV_ROUND_UP(plane_bytes_per_line * y_min_scanlines, 512); |
| 3655 | plane_blocks_per_line /= y_min_scanlines; |
| 3656 | } else if (fb->modifier[0] == DRM_FORMAT_MOD_NONE) { |
| 3657 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512) |
| 3658 | + 1; |
| 3659 | } else { |
| 3660 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 3661 | } |
| 3662 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3663 | method1 = skl_wm_method1(plane_pixel_rate, cpp, latency); |
| 3664 | method2 = skl_wm_method2(plane_pixel_rate, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3665 | cstate->base.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 3666 | latency, |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 3667 | plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3668 | |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 3669 | y_tile_minimum = plane_blocks_per_line * y_min_scanlines; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3670 | if (apply_memory_bw_wa) |
| 3671 | y_tile_minimum *= 2; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 3672 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3673 | if (fb->modifier[0] == I915_FORMAT_MOD_Y_TILED || |
| 3674 | fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED) { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3675 | selected_result = max(method2, y_tile_minimum); |
| 3676 | } else { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 3677 | if ((cpp * cstate->base.adjusted_mode.crtc_htotal / 512 < 1) && |
| 3678 | (plane_bytes_per_line / 512 < 1)) |
| 3679 | selected_result = method2; |
| 3680 | else if ((ddb_allocation / plane_blocks_per_line) >= 1) |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3681 | selected_result = min(method1, method2); |
| 3682 | else |
| 3683 | selected_result = method1; |
| 3684 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3685 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 3686 | res_blocks = selected_result + 1; |
| 3687 | res_lines = DIV_ROUND_UP(selected_result, plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 3688 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3689 | if (level >= 1 && level <= 7) { |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3690 | if (fb->modifier[0] == I915_FORMAT_MOD_Y_TILED || |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 3691 | fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED) { |
| 3692 | res_blocks += y_tile_minimum; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 3693 | res_lines += y_min_scanlines; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 3694 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3695 | res_blocks++; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 3696 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3697 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 3698 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3699 | if (res_blocks >= ddb_allocation || res_lines > 31) { |
| 3700 | *enabled = false; |
Matt Roper | 6b6bada | 2016-05-12 07:06:10 -0700 | [diff] [blame] | 3701 | |
| 3702 | /* |
| 3703 | * If there are no valid level 0 watermarks, then we can't |
| 3704 | * support this display configuration. |
| 3705 | */ |
| 3706 | if (level) { |
| 3707 | return 0; |
| 3708 | } else { |
| 3709 | DRM_DEBUG_KMS("Requested display configuration exceeds system watermark limitations\n"); |
| 3710 | DRM_DEBUG_KMS("Plane %d.%d: blocks required = %u/%u, lines required = %u/31\n", |
| 3711 | to_intel_crtc(cstate->base.crtc)->pipe, |
| 3712 | skl_wm_plane_id(to_intel_plane(pstate->plane)), |
| 3713 | res_blocks, ddb_allocation, res_lines); |
| 3714 | |
| 3715 | return -EINVAL; |
| 3716 | } |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3717 | } |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 3718 | |
| 3719 | *out_blocks = res_blocks; |
| 3720 | *out_lines = res_lines; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3721 | *enabled = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3722 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3723 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3724 | } |
| 3725 | |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3726 | static int |
| 3727 | skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 3728 | struct skl_ddb_allocation *ddb, |
| 3729 | struct intel_crtc_state *cstate, |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3730 | struct intel_plane *intel_plane, |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3731 | int level, |
| 3732 | struct skl_wm_level *result) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3733 | { |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3734 | struct drm_atomic_state *state = cstate->base.state; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3735 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3736 | struct drm_plane *plane = &intel_plane->base; |
| 3737 | struct intel_plane_state *intel_pstate = NULL; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3738 | uint16_t ddb_blocks; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3739 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3740 | int ret; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3741 | int i = skl_wm_plane_id(intel_plane); |
| 3742 | |
| 3743 | if (state) |
| 3744 | intel_pstate = |
| 3745 | intel_atomic_get_existing_plane_state(state, |
| 3746 | intel_plane); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3747 | |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3748 | /* |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3749 | * Note: If we start supporting multiple pending atomic commits against |
| 3750 | * the same planes/CRTC's in the future, plane->state will no longer be |
| 3751 | * the correct pre-state to use for the calculations here and we'll |
| 3752 | * need to change where we get the 'unchanged' plane data from. |
| 3753 | * |
| 3754 | * For now this is fine because we only allow one queued commit against |
| 3755 | * a CRTC. Even if the plane isn't modified by this transaction and we |
| 3756 | * don't have a plane lock, we still have the CRTC's lock, so we know |
| 3757 | * that no other transactions are racing with us to update it. |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3758 | */ |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3759 | if (!intel_pstate) |
| 3760 | intel_pstate = to_intel_plane_state(plane->state); |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3761 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3762 | WARN_ON(!intel_pstate->base.fb); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3763 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3764 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]); |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3765 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3766 | ret = skl_compute_plane_wm(dev_priv, |
| 3767 | cstate, |
| 3768 | intel_pstate, |
| 3769 | ddb_blocks, |
| 3770 | level, |
| 3771 | &result->plane_res_b, |
| 3772 | &result->plane_res_l, |
| 3773 | &result->plane_en); |
| 3774 | if (ret) |
| 3775 | return ret; |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3776 | |
| 3777 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3780 | static uint32_t |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3781 | skl_compute_linetime_wm(struct intel_crtc_state *cstate) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3782 | { |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 3783 | uint32_t pixel_rate; |
| 3784 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3785 | if (!cstate->base.active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3786 | return 0; |
| 3787 | |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 3788 | pixel_rate = ilk_pipe_pixel_rate(cstate); |
| 3789 | |
| 3790 | if (WARN_ON(pixel_rate == 0)) |
Mika Kuoppala | 661abfc | 2015-07-16 19:36:51 +0300 | [diff] [blame] | 3791 | return 0; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3792 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3793 | return DIV_ROUND_UP(8 * cstate->base.adjusted_mode.crtc_htotal * 1000, |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 3794 | pixel_rate); |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3797 | static void skl_compute_transition_wm(struct intel_crtc_state *cstate, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3798 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3799 | { |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3800 | if (!cstate->base.active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3801 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3802 | |
| 3803 | /* Until we know more, just disable transition WMs */ |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3804 | trans_wm->plane_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3805 | } |
| 3806 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3807 | static int skl_build_pipe_wm(struct intel_crtc_state *cstate, |
| 3808 | struct skl_ddb_allocation *ddb, |
| 3809 | struct skl_pipe_wm *pipe_wm) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3810 | { |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3811 | struct drm_device *dev = cstate->base.crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3812 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3813 | struct intel_plane *intel_plane; |
| 3814 | struct skl_plane_wm *wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3815 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3816 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3817 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 3818 | /* |
| 3819 | * We'll only calculate watermarks for planes that are actually |
| 3820 | * enabled, so make sure all other planes are set as disabled. |
| 3821 | */ |
| 3822 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 3823 | |
| 3824 | for_each_intel_plane_mask(&dev_priv->drm, |
| 3825 | intel_plane, |
| 3826 | cstate->base.plane_mask) { |
| 3827 | wm = &pipe_wm->planes[skl_wm_plane_id(intel_plane)]; |
| 3828 | |
| 3829 | for (level = 0; level <= max_level; level++) { |
| 3830 | ret = skl_compute_wm_level(dev_priv, ddb, cstate, |
| 3831 | intel_plane, level, |
| 3832 | &wm->wm[level]); |
| 3833 | if (ret) |
| 3834 | return ret; |
| 3835 | } |
| 3836 | skl_compute_transition_wm(cstate, &wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3837 | } |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3838 | pipe_wm->linetime = skl_compute_linetime_wm(cstate); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3839 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3840 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3841 | } |
| 3842 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3843 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 3844 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3845 | const struct skl_ddb_entry *entry) |
| 3846 | { |
| 3847 | if (entry->end) |
| 3848 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 3849 | else |
| 3850 | I915_WRITE(reg, 0); |
| 3851 | } |
| 3852 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3853 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 3854 | i915_reg_t reg, |
| 3855 | const struct skl_wm_level *level) |
| 3856 | { |
| 3857 | uint32_t val = 0; |
| 3858 | |
| 3859 | if (level->plane_en) { |
| 3860 | val |= PLANE_WM_EN; |
| 3861 | val |= level->plane_res_b; |
| 3862 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
| 3863 | } |
| 3864 | |
| 3865 | I915_WRITE(reg, val); |
| 3866 | } |
| 3867 | |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3868 | void skl_write_plane_wm(struct intel_crtc *intel_crtc, |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3869 | const struct skl_plane_wm *wm, |
| 3870 | const struct skl_ddb_allocation *ddb, |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3871 | int plane) |
| 3872 | { |
| 3873 | struct drm_crtc *crtc = &intel_crtc->base; |
| 3874 | struct drm_device *dev = crtc->dev; |
| 3875 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3876 | int level, max_level = ilk_wm_max_level(dev_priv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3877 | enum pipe pipe = intel_crtc->pipe; |
| 3878 | |
| 3879 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3880 | skl_write_wm_level(dev_priv, PLANE_WM(pipe, plane, level), |
| 3881 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3882 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3883 | skl_write_wm_level(dev_priv, PLANE_WM_TRANS(pipe, plane), |
| 3884 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 3885 | |
| 3886 | skl_ddb_entry_write(dev_priv, PLANE_BUF_CFG(pipe, plane), |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3887 | &ddb->plane[pipe][plane]); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 3888 | skl_ddb_entry_write(dev_priv, PLANE_NV12_BUF_CFG(pipe, plane), |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3889 | &ddb->y_plane[pipe][plane]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | void skl_write_cursor_wm(struct intel_crtc *intel_crtc, |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3893 | const struct skl_plane_wm *wm, |
| 3894 | const struct skl_ddb_allocation *ddb) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3895 | { |
| 3896 | struct drm_crtc *crtc = &intel_crtc->base; |
| 3897 | struct drm_device *dev = crtc->dev; |
| 3898 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3899 | int level, max_level = ilk_wm_max_level(dev_priv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3900 | enum pipe pipe = intel_crtc->pipe; |
| 3901 | |
| 3902 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3903 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 3904 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3905 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3906 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 3907 | |
| 3908 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3909 | &ddb->plane[pipe][PLANE_CURSOR]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3910 | } |
| 3911 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 3912 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 3913 | const struct skl_wm_level *l2) |
| 3914 | { |
| 3915 | if (l1->plane_en != l2->plane_en) |
| 3916 | return false; |
| 3917 | |
| 3918 | /* If both planes aren't enabled, the rest shouldn't matter */ |
| 3919 | if (!l1->plane_en) |
| 3920 | return true; |
| 3921 | |
| 3922 | return (l1->plane_res_l == l2->plane_res_l && |
| 3923 | l1->plane_res_b == l2->plane_res_b); |
| 3924 | } |
| 3925 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 3926 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 3927 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3928 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 3929 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 3932 | bool skl_ddb_allocation_overlaps(struct drm_atomic_state *state, |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 3933 | struct intel_crtc *intel_crtc) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3934 | { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 3935 | struct drm_crtc *other_crtc; |
| 3936 | struct drm_crtc_state *other_cstate; |
| 3937 | struct intel_crtc *other_intel_crtc; |
| 3938 | const struct skl_ddb_entry *ddb = |
| 3939 | &to_intel_crtc_state(intel_crtc->base.state)->wm.skl.ddb; |
| 3940 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3941 | |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 3942 | for_each_crtc_in_state(state, other_crtc, other_cstate, i) { |
| 3943 | other_intel_crtc = to_intel_crtc(other_crtc); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3944 | |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 3945 | if (other_intel_crtc == intel_crtc) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3946 | continue; |
| 3947 | |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 3948 | if (skl_ddb_entries_overlap(ddb, &other_intel_crtc->hw_ddb)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 3949 | return true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 3952 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3955 | static int skl_update_pipe_wm(struct drm_crtc_state *cstate, |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 3956 | const struct skl_pipe_wm *old_pipe_wm, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3957 | struct skl_pipe_wm *pipe_wm, /* out */ |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 3958 | struct skl_ddb_allocation *ddb, /* out */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3959 | bool *changed /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3960 | { |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 3961 | struct intel_crtc_state *intel_cstate = to_intel_crtc_state(cstate); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3962 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3963 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3964 | ret = skl_build_pipe_wm(intel_cstate, ddb, pipe_wm); |
| 3965 | if (ret) |
| 3966 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3967 | |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 3968 | if (!memcmp(old_pipe_wm, pipe_wm, sizeof(*pipe_wm))) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3969 | *changed = false; |
| 3970 | else |
| 3971 | *changed = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3972 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 3973 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3974 | } |
| 3975 | |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 3976 | static uint32_t |
| 3977 | pipes_modified(struct drm_atomic_state *state) |
| 3978 | { |
| 3979 | struct drm_crtc *crtc; |
| 3980 | struct drm_crtc_state *cstate; |
| 3981 | uint32_t i, ret = 0; |
| 3982 | |
| 3983 | for_each_crtc_in_state(state, crtc, cstate, i) |
| 3984 | ret |= drm_crtc_mask(crtc); |
| 3985 | |
| 3986 | return ret; |
| 3987 | } |
| 3988 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 3989 | static int |
Paulo Zanoni | 7f60e20 | 2016-09-29 16:36:48 -0300 | [diff] [blame] | 3990 | skl_ddb_add_affected_planes(struct intel_crtc_state *cstate) |
| 3991 | { |
| 3992 | struct drm_atomic_state *state = cstate->base.state; |
| 3993 | struct drm_device *dev = state->dev; |
| 3994 | struct drm_crtc *crtc = cstate->base.crtc; |
| 3995 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3996 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3997 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 3998 | struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb; |
| 3999 | struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 4000 | struct drm_plane_state *plane_state; |
| 4001 | struct drm_plane *plane; |
| 4002 | enum pipe pipe = intel_crtc->pipe; |
| 4003 | int id; |
| 4004 | |
| 4005 | WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc)); |
| 4006 | |
Maarten Lankhorst | 220b096 | 2016-10-26 15:41:30 +0200 | [diff] [blame] | 4007 | drm_for_each_plane_mask(plane, dev, cstate->base.plane_mask) { |
Paulo Zanoni | 7f60e20 | 2016-09-29 16:36:48 -0300 | [diff] [blame] | 4008 | id = skl_wm_plane_id(to_intel_plane(plane)); |
| 4009 | |
| 4010 | if (skl_ddb_entry_equal(&cur_ddb->plane[pipe][id], |
| 4011 | &new_ddb->plane[pipe][id]) && |
| 4012 | skl_ddb_entry_equal(&cur_ddb->y_plane[pipe][id], |
| 4013 | &new_ddb->y_plane[pipe][id])) |
| 4014 | continue; |
| 4015 | |
| 4016 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 4017 | if (IS_ERR(plane_state)) |
| 4018 | return PTR_ERR(plane_state); |
| 4019 | } |
| 4020 | |
| 4021 | return 0; |
| 4022 | } |
| 4023 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4024 | static int |
| 4025 | skl_compute_ddb(struct drm_atomic_state *state) |
| 4026 | { |
| 4027 | struct drm_device *dev = state->dev; |
| 4028 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 4029 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4030 | struct intel_crtc *intel_crtc; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4031 | struct skl_ddb_allocation *ddb = &intel_state->wm_results.ddb; |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4032 | uint32_t realloc_pipes = pipes_modified(state); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4033 | int ret; |
| 4034 | |
| 4035 | /* |
| 4036 | * If this is our first atomic update following hardware readout, |
| 4037 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 4038 | * pretend that all pipes switched active status so that we'll |
| 4039 | * ensure a full DDB recompute. |
| 4040 | */ |
Matt Roper | 1b54a88 | 2016-06-17 13:42:18 -0700 | [diff] [blame] | 4041 | if (dev_priv->wm.distrust_bios_wm) { |
| 4042 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
| 4043 | state->acquire_ctx); |
| 4044 | if (ret) |
| 4045 | return ret; |
| 4046 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4047 | intel_state->active_pipe_changes = ~0; |
| 4048 | |
Matt Roper | 1b54a88 | 2016-06-17 13:42:18 -0700 | [diff] [blame] | 4049 | /* |
| 4050 | * We usually only initialize intel_state->active_crtcs if we |
| 4051 | * we're doing a modeset; make sure this field is always |
| 4052 | * initialized during the sanitization process that happens |
| 4053 | * on the first commit too. |
| 4054 | */ |
| 4055 | if (!intel_state->modeset) |
| 4056 | intel_state->active_crtcs = dev_priv->active_crtcs; |
| 4057 | } |
| 4058 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4059 | /* |
| 4060 | * If the modeset changes which CRTC's are active, we need to |
| 4061 | * recompute the DDB allocation for *all* active pipes, even |
| 4062 | * those that weren't otherwise being modified in any way by this |
| 4063 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 4064 | * when new active CRTC's are added, it's possible for a pipe that |
| 4065 | * we were already using and aren't changing at all here to suddenly |
| 4066 | * become invalid if its DDB needs exceeds its new allocation. |
| 4067 | * |
| 4068 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 4069 | * any other display updates race with this transaction, so we need |
| 4070 | * to grab the lock on *all* CRTC's. |
| 4071 | */ |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4072 | if (intel_state->active_pipe_changes) { |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4073 | realloc_pipes = ~0; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4074 | intel_state->wm_results.dirty_pipes = ~0; |
| 4075 | } |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4076 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4077 | /* |
| 4078 | * We're not recomputing for the pipes not included in the commit, so |
| 4079 | * make sure we start with the current state. |
| 4080 | */ |
| 4081 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 4082 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4083 | for_each_intel_crtc_mask(dev, intel_crtc, realloc_pipes) { |
| 4084 | struct intel_crtc_state *cstate; |
| 4085 | |
| 4086 | cstate = intel_atomic_get_crtc_state(state, intel_crtc); |
| 4087 | if (IS_ERR(cstate)) |
| 4088 | return PTR_ERR(cstate); |
| 4089 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4090 | ret = skl_allocate_pipe_ddb(cstate, ddb); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4091 | if (ret) |
| 4092 | return ret; |
Lyude | 05a76d3 | 2016-08-17 15:55:57 -0400 | [diff] [blame] | 4093 | |
Paulo Zanoni | 7f60e20 | 2016-09-29 16:36:48 -0300 | [diff] [blame] | 4094 | ret = skl_ddb_add_affected_planes(cstate); |
Lyude | 05a76d3 | 2016-08-17 15:55:57 -0400 | [diff] [blame] | 4095 | if (ret) |
| 4096 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | return 0; |
| 4100 | } |
| 4101 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4102 | static void |
| 4103 | skl_copy_wm_for_pipe(struct skl_wm_values *dst, |
| 4104 | struct skl_wm_values *src, |
| 4105 | enum pipe pipe) |
| 4106 | { |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4107 | memcpy(dst->ddb.y_plane[pipe], src->ddb.y_plane[pipe], |
| 4108 | sizeof(dst->ddb.y_plane[pipe])); |
| 4109 | memcpy(dst->ddb.plane[pipe], src->ddb.plane[pipe], |
| 4110 | sizeof(dst->ddb.plane[pipe])); |
| 4111 | } |
| 4112 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4113 | static void |
| 4114 | skl_print_wm_changes(const struct drm_atomic_state *state) |
| 4115 | { |
| 4116 | const struct drm_device *dev = state->dev; |
| 4117 | const struct drm_i915_private *dev_priv = to_i915(dev); |
| 4118 | const struct intel_atomic_state *intel_state = |
| 4119 | to_intel_atomic_state(state); |
| 4120 | const struct drm_crtc *crtc; |
| 4121 | const struct drm_crtc_state *cstate; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4122 | const struct intel_plane *intel_plane; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4123 | const struct skl_ddb_allocation *old_ddb = &dev_priv->wm.skl_hw.ddb; |
| 4124 | const struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4125 | int id; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4126 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4127 | |
| 4128 | for_each_crtc_in_state(state, crtc, cstate, i) { |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4129 | const struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4130 | enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4131 | |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4132 | for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) { |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4133 | const struct skl_ddb_entry *old, *new; |
| 4134 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4135 | id = skl_wm_plane_id(intel_plane); |
| 4136 | old = &old_ddb->plane[pipe][id]; |
| 4137 | new = &new_ddb->plane[pipe][id]; |
| 4138 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4139 | if (skl_ddb_entry_equal(old, new)) |
| 4140 | continue; |
| 4141 | |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4142 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] ddb (%d - %d) -> (%d - %d)\n", |
| 4143 | intel_plane->base.base.id, |
| 4144 | intel_plane->base.name, |
| 4145 | old->start, old->end, |
| 4146 | new->start, new->end); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | } |
| 4150 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4151 | static int |
| 4152 | skl_compute_wm(struct drm_atomic_state *state) |
| 4153 | { |
| 4154 | struct drm_crtc *crtc; |
| 4155 | struct drm_crtc_state *cstate; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4156 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4157 | struct skl_wm_values *results = &intel_state->wm_results; |
| 4158 | struct skl_pipe_wm *pipe_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4159 | bool changed = false; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4160 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4161 | |
| 4162 | /* |
| 4163 | * If this transaction isn't actually touching any CRTC's, don't |
| 4164 | * bother with watermark calculation. Note that if we pass this |
| 4165 | * test, we're guaranteed to hold at least one CRTC state mutex, |
| 4166 | * which means we can safely use values like dev_priv->active_crtcs |
| 4167 | * since any racing commits that want to update them would need to |
| 4168 | * hold _all_ CRTC state mutexes. |
| 4169 | */ |
| 4170 | for_each_crtc_in_state(state, crtc, cstate, i) |
| 4171 | changed = true; |
| 4172 | if (!changed) |
| 4173 | return 0; |
| 4174 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4175 | /* Clear all dirty flags */ |
| 4176 | results->dirty_pipes = 0; |
| 4177 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4178 | ret = skl_compute_ddb(state); |
| 4179 | if (ret) |
| 4180 | return ret; |
| 4181 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4182 | /* |
| 4183 | * Calculate WM's for all pipes that are part of this transaction. |
| 4184 | * Note that the DDB allocation above may have added more CRTC's that |
| 4185 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 4186 | * pipe allocations had to change. |
| 4187 | * |
| 4188 | * FIXME: Now that we're doing this in the atomic check phase, we |
| 4189 | * should allow skl_update_pipe_wm() to return failure in cases where |
| 4190 | * no suitable watermark values can be found. |
| 4191 | */ |
| 4192 | for_each_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4193 | struct intel_crtc_state *intel_cstate = |
| 4194 | to_intel_crtc_state(cstate); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4195 | const struct skl_pipe_wm *old_pipe_wm = |
| 4196 | &to_intel_crtc_state(crtc->state)->wm.skl.optimal; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4197 | |
| 4198 | pipe_wm = &intel_cstate->wm.skl.optimal; |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4199 | ret = skl_update_pipe_wm(cstate, old_pipe_wm, pipe_wm, |
| 4200 | &results->ddb, &changed); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4201 | if (ret) |
| 4202 | return ret; |
| 4203 | |
| 4204 | if (changed) |
| 4205 | results->dirty_pipes |= drm_crtc_mask(crtc); |
| 4206 | |
| 4207 | if ((results->dirty_pipes & drm_crtc_mask(crtc)) == 0) |
| 4208 | /* This pipe's WM's did not change */ |
| 4209 | continue; |
| 4210 | |
| 4211 | intel_cstate->update_wm_pre = true; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4212 | } |
| 4213 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4214 | skl_print_wm_changes(state); |
| 4215 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4216 | return 0; |
| 4217 | } |
| 4218 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4219 | static void skl_update_wm(struct intel_crtc *intel_crtc) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4220 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4221 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4222 | struct drm_i915_private *dev_priv = to_i915(dev); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4223 | struct skl_wm_values *results = &dev_priv->wm.skl_results; |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4224 | struct skl_wm_values *hw_vals = &dev_priv->wm.skl_hw; |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4225 | struct intel_crtc_state *cstate = to_intel_crtc_state(intel_crtc->base.state); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 4226 | struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4227 | enum pipe pipe = intel_crtc->pipe; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 4228 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4229 | if ((results->dirty_pipes & drm_crtc_mask(&intel_crtc->base)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4230 | return; |
| 4231 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4232 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 4233 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4234 | /* |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4235 | * If this pipe isn't active already, we're going to be enabling it |
| 4236 | * very soon. Since it's safe to update a pipe's ddb allocation while |
| 4237 | * the pipe's shut off, just do so here. Already active pipes will have |
| 4238 | * their watermarks updated once we update their planes. |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4239 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4240 | if (intel_crtc->base.state->active_changed) { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4241 | int plane; |
| 4242 | |
Matt Roper | 2c4b49a | 2016-10-26 15:51:29 -0700 | [diff] [blame] | 4243 | for_each_universal_plane(dev_priv, pipe, plane) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4244 | skl_write_plane_wm(intel_crtc, &pipe_wm->planes[plane], |
| 4245 | &results->ddb, plane); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4246 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4247 | skl_write_cursor_wm(intel_crtc, &pipe_wm->planes[PLANE_CURSOR], |
| 4248 | &results->ddb); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | skl_copy_wm_for_pipe(hw_vals, results, pipe); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4252 | |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4253 | intel_crtc->hw_ddb = cstate->wm.skl.ddb; |
| 4254 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4255 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4256 | } |
| 4257 | |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 4258 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 4259 | struct intel_wm_config *config) |
| 4260 | { |
| 4261 | struct intel_crtc *crtc; |
| 4262 | |
| 4263 | /* Compute the currently _active_ config */ |
| 4264 | for_each_intel_crtc(dev, crtc) { |
| 4265 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 4266 | |
| 4267 | if (!wm->pipe_enabled) |
| 4268 | continue; |
| 4269 | |
| 4270 | config->sprites_enabled |= wm->sprites_enabled; |
| 4271 | config->sprites_scaled |= wm->sprites_scaled; |
| 4272 | config->num_pipes_active++; |
| 4273 | } |
| 4274 | } |
| 4275 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4276 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 4277 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 4278 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4279 | struct intel_pipe_wm lp_wm_1_2 = {}, lp_wm_5_6 = {}, *best_lp_wm; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4280 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 4281 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4282 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 4283 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 4284 | |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 4285 | ilk_compute_wm_config(dev, &config); |
| 4286 | |
| 4287 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 4288 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 4289 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 4290 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 4291 | if (INTEL_INFO(dev)->gen >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 4292 | config.num_pipes_active == 1 && config.sprites_enabled) { |
| 4293 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 4294 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 4295 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4296 | 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] | 4297 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 4298 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 4299 | } |
| 4300 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 4301 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 4302 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 4303 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4304 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 4305 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4306 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 4307 | } |
| 4308 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4309 | static void ilk_initial_watermarks(struct intel_crtc_state *cstate) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4310 | { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4311 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 4312 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4313 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4314 | mutex_lock(&dev_priv->wm.wm_mutex); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 4315 | intel_crtc->wm.active.ilk = cstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4316 | ilk_program_watermarks(dev_priv); |
| 4317 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 4318 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4319 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4320 | static void ilk_optimize_watermarks(struct intel_crtc_state *cstate) |
| 4321 | { |
| 4322 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 4323 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
| 4324 | |
| 4325 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 4326 | if (cstate->wm.need_postvbl_update) { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 4327 | intel_crtc->wm.active.ilk = cstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4328 | ilk_program_watermarks(dev_priv); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4329 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4330 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4331 | } |
| 4332 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4333 | static inline void skl_wm_level_from_reg_val(uint32_t val, |
| 4334 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4335 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4336 | level->plane_en = val & PLANE_WM_EN; |
| 4337 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 4338 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 4339 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4340 | } |
| 4341 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4342 | void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc, |
| 4343 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4344 | { |
| 4345 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4346 | struct drm_i915_private *dev_priv = to_i915(dev); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4347 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4348 | struct intel_plane *intel_plane; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4349 | struct skl_plane_wm *wm; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4350 | enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4351 | int level, id, max_level; |
| 4352 | uint32_t val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4353 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4354 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4355 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4356 | for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) { |
| 4357 | id = skl_wm_plane_id(intel_plane); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4358 | wm = &out->planes[id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4359 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4360 | for (level = 0; level <= max_level; level++) { |
| 4361 | if (id != PLANE_CURSOR) |
| 4362 | val = I915_READ(PLANE_WM(pipe, id, level)); |
| 4363 | else |
| 4364 | val = I915_READ(CUR_WM(pipe, level)); |
| 4365 | |
| 4366 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 4367 | } |
| 4368 | |
| 4369 | if (id != PLANE_CURSOR) |
| 4370 | val = I915_READ(PLANE_WM_TRANS(pipe, id)); |
| 4371 | else |
| 4372 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 4373 | |
| 4374 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 4375 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4376 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 4377 | if (!intel_crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4378 | return; |
| 4379 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4380 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 4384 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4385 | struct drm_i915_private *dev_priv = to_i915(dev); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4386 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4387 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4388 | struct drm_crtc *crtc; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4389 | struct intel_crtc *intel_crtc; |
| 4390 | struct intel_crtc_state *cstate; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4391 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4392 | skl_ddb_get_hw_state(dev_priv, ddb); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4393 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 4394 | intel_crtc = to_intel_crtc(crtc); |
| 4395 | cstate = to_intel_crtc_state(crtc->state); |
| 4396 | |
| 4397 | skl_pipe_wm_get_hw_state(crtc, &cstate->wm.skl.optimal); |
| 4398 | |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4399 | if (intel_crtc->active) |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4400 | hw->dirty_pipes |= drm_crtc_mask(crtc); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4401 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4402 | |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 4403 | if (dev_priv->active_crtcs) { |
| 4404 | /* Fully recompute DDB on first atomic commit */ |
| 4405 | dev_priv->wm.distrust_bios_wm = true; |
| 4406 | } else { |
| 4407 | /* Easy/common case; just sanitize DDB now if everything off */ |
| 4408 | memset(ddb, 0, sizeof(*ddb)); |
| 4409 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4412 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 4413 | { |
| 4414 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4415 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4416 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4417 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 4418 | struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 4419 | struct intel_pipe_wm *active = &cstate->wm.ilk.optimal; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4420 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4421 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4422 | [PIPE_A] = WM0_PIPEA_ILK, |
| 4423 | [PIPE_B] = WM0_PIPEB_ILK, |
| 4424 | [PIPE_C] = WM0_PIPEC_IVB, |
| 4425 | }; |
| 4426 | |
| 4427 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 4428 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 4429 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4430 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 4431 | memset(active, 0, sizeof(*active)); |
| 4432 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 4433 | active->pipe_enabled = intel_crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 4434 | |
| 4435 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4436 | u32 tmp = hw->wm_pipe[pipe]; |
| 4437 | |
| 4438 | /* |
| 4439 | * For active pipes LP0 watermark is marked as |
| 4440 | * enabled, and LP1+ watermaks as disabled since |
| 4441 | * we can't really reverse compute them in case |
| 4442 | * multiple pipes are active. |
| 4443 | */ |
| 4444 | active->wm[0].enable = true; |
| 4445 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 4446 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 4447 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 4448 | active->linetime = hw->wm_linetime[pipe]; |
| 4449 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4450 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4451 | |
| 4452 | /* |
| 4453 | * For inactive pipes, all watermark levels |
| 4454 | * should be marked as enabled but zeroed, |
| 4455 | * which is what we'd compute them to. |
| 4456 | */ |
| 4457 | for (level = 0; level <= max_level; level++) |
| 4458 | active->wm[level].enable = true; |
| 4459 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 4460 | |
| 4461 | intel_crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4462 | } |
| 4463 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 4464 | #define _FW_WM(value, plane) \ |
| 4465 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 4466 | #define _FW_WM_VLV(value, plane) \ |
| 4467 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 4468 | |
| 4469 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 4470 | struct vlv_wm_values *wm) |
| 4471 | { |
| 4472 | enum pipe pipe; |
| 4473 | uint32_t tmp; |
| 4474 | |
| 4475 | for_each_pipe(dev_priv, pipe) { |
| 4476 | tmp = I915_READ(VLV_DDL(pipe)); |
| 4477 | |
| 4478 | wm->ddl[pipe].primary = |
| 4479 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 4480 | wm->ddl[pipe].cursor = |
| 4481 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 4482 | wm->ddl[pipe].sprite[0] = |
| 4483 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 4484 | wm->ddl[pipe].sprite[1] = |
| 4485 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 4486 | } |
| 4487 | |
| 4488 | tmp = I915_READ(DSPFW1); |
| 4489 | wm->sr.plane = _FW_WM(tmp, SR); |
| 4490 | wm->pipe[PIPE_B].cursor = _FW_WM(tmp, CURSORB); |
| 4491 | wm->pipe[PIPE_B].primary = _FW_WM_VLV(tmp, PLANEB); |
| 4492 | wm->pipe[PIPE_A].primary = _FW_WM_VLV(tmp, PLANEA); |
| 4493 | |
| 4494 | tmp = I915_READ(DSPFW2); |
| 4495 | wm->pipe[PIPE_A].sprite[1] = _FW_WM_VLV(tmp, SPRITEB); |
| 4496 | wm->pipe[PIPE_A].cursor = _FW_WM(tmp, CURSORA); |
| 4497 | wm->pipe[PIPE_A].sprite[0] = _FW_WM_VLV(tmp, SPRITEA); |
| 4498 | |
| 4499 | tmp = I915_READ(DSPFW3); |
| 4500 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 4501 | |
| 4502 | if (IS_CHERRYVIEW(dev_priv)) { |
| 4503 | tmp = I915_READ(DSPFW7_CHV); |
| 4504 | wm->pipe[PIPE_B].sprite[1] = _FW_WM_VLV(tmp, SPRITED); |
| 4505 | wm->pipe[PIPE_B].sprite[0] = _FW_WM_VLV(tmp, SPRITEC); |
| 4506 | |
| 4507 | tmp = I915_READ(DSPFW8_CHV); |
| 4508 | wm->pipe[PIPE_C].sprite[1] = _FW_WM_VLV(tmp, SPRITEF); |
| 4509 | wm->pipe[PIPE_C].sprite[0] = _FW_WM_VLV(tmp, SPRITEE); |
| 4510 | |
| 4511 | tmp = I915_READ(DSPFW9_CHV); |
| 4512 | wm->pipe[PIPE_C].primary = _FW_WM_VLV(tmp, PLANEC); |
| 4513 | wm->pipe[PIPE_C].cursor = _FW_WM(tmp, CURSORC); |
| 4514 | |
| 4515 | tmp = I915_READ(DSPHOWM); |
| 4516 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
| 4517 | wm->pipe[PIPE_C].sprite[1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 4518 | wm->pipe[PIPE_C].sprite[0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 4519 | wm->pipe[PIPE_C].primary |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 4520 | wm->pipe[PIPE_B].sprite[1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 4521 | wm->pipe[PIPE_B].sprite[0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 4522 | wm->pipe[PIPE_B].primary |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 4523 | wm->pipe[PIPE_A].sprite[1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 4524 | wm->pipe[PIPE_A].sprite[0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 4525 | wm->pipe[PIPE_A].primary |= _FW_WM(tmp, PLANEA_HI) << 8; |
| 4526 | } else { |
| 4527 | tmp = I915_READ(DSPFW7); |
| 4528 | wm->pipe[PIPE_B].sprite[1] = _FW_WM_VLV(tmp, SPRITED); |
| 4529 | wm->pipe[PIPE_B].sprite[0] = _FW_WM_VLV(tmp, SPRITEC); |
| 4530 | |
| 4531 | tmp = I915_READ(DSPHOWM); |
| 4532 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
| 4533 | wm->pipe[PIPE_B].sprite[1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 4534 | wm->pipe[PIPE_B].sprite[0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 4535 | wm->pipe[PIPE_B].primary |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 4536 | wm->pipe[PIPE_A].sprite[1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 4537 | wm->pipe[PIPE_A].sprite[0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 4538 | wm->pipe[PIPE_A].primary |= _FW_WM(tmp, PLANEA_HI) << 8; |
| 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | #undef _FW_WM |
| 4543 | #undef _FW_WM_VLV |
| 4544 | |
| 4545 | void vlv_wm_get_hw_state(struct drm_device *dev) |
| 4546 | { |
| 4547 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 4548 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
| 4549 | struct intel_plane *plane; |
| 4550 | enum pipe pipe; |
| 4551 | u32 val; |
| 4552 | |
| 4553 | vlv_read_wm_values(dev_priv, wm); |
| 4554 | |
| 4555 | for_each_intel_plane(dev, plane) { |
| 4556 | switch (plane->base.type) { |
| 4557 | int sprite; |
| 4558 | case DRM_PLANE_TYPE_CURSOR: |
| 4559 | plane->wm.fifo_size = 63; |
| 4560 | break; |
| 4561 | case DRM_PLANE_TYPE_PRIMARY: |
| 4562 | plane->wm.fifo_size = vlv_get_fifo_size(dev, plane->pipe, 0); |
| 4563 | break; |
| 4564 | case DRM_PLANE_TYPE_OVERLAY: |
| 4565 | sprite = plane->plane; |
| 4566 | plane->wm.fifo_size = vlv_get_fifo_size(dev, plane->pipe, sprite + 1); |
| 4567 | break; |
| 4568 | } |
| 4569 | } |
| 4570 | |
| 4571 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 4572 | wm->level = VLV_WM_LEVEL_PM2; |
| 4573 | |
| 4574 | if (IS_CHERRYVIEW(dev_priv)) { |
| 4575 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4576 | |
| 4577 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 4578 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 4579 | wm->level = VLV_WM_LEVEL_PM5; |
| 4580 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 4581 | /* |
| 4582 | * If DDR DVFS is disabled in the BIOS, Punit |
| 4583 | * will never ack the request. So if that happens |
| 4584 | * assume we don't have to enable/disable DDR DVFS |
| 4585 | * dynamically. To test that just set the REQ_ACK |
| 4586 | * bit to poke the Punit, but don't change the |
| 4587 | * HIGH/LOW bits so that we don't actually change |
| 4588 | * the current state. |
| 4589 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 4590 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 4591 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 4592 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 4593 | |
| 4594 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 4595 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 4596 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 4597 | "assuming DDR DVFS is disabled\n"); |
| 4598 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 4599 | } else { |
| 4600 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 4601 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 4602 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 4603 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 4604 | |
| 4605 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4606 | } |
| 4607 | |
| 4608 | for_each_pipe(dev_priv, pipe) |
| 4609 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n", |
| 4610 | pipe_name(pipe), wm->pipe[pipe].primary, wm->pipe[pipe].cursor, |
| 4611 | wm->pipe[pipe].sprite[0], wm->pipe[pipe].sprite[1]); |
| 4612 | |
| 4613 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 4614 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 4615 | } |
| 4616 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4617 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 4618 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4619 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4620 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4621 | struct drm_crtc *crtc; |
| 4622 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 4623 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4624 | ilk_pipe_wm_get_hw_state(crtc); |
| 4625 | |
| 4626 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 4627 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 4628 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 4629 | |
| 4630 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 4631 | if (INTEL_INFO(dev)->gen >= 7) { |
| 4632 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 4633 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 4634 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4635 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 4636 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 4637 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 4638 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4639 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 4640 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 4641 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 4642 | |
| 4643 | hw->enable_fbc_wm = |
| 4644 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 4645 | } |
| 4646 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 4647 | /** |
| 4648 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 4649 | * |
| 4650 | * Calculate watermark values for the various WM regs based on current mode |
| 4651 | * and plane configuration. |
| 4652 | * |
| 4653 | * There are several cases to deal with here: |
| 4654 | * - normal (i.e. non-self-refresh) |
| 4655 | * - self-refresh (SR) mode |
| 4656 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 4657 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 4658 | * lines), so need to account for TLB latency |
| 4659 | * |
| 4660 | * The normal calculation is: |
| 4661 | * watermark = dotclock * bytes per pixel * latency |
| 4662 | * where latency is platform & configuration dependent (we assume pessimal |
| 4663 | * values here). |
| 4664 | * |
| 4665 | * The SR calculation is: |
| 4666 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 4667 | * bytes per pixel |
| 4668 | * where |
| 4669 | * line time = htotal / dotclock |
| 4670 | * surface width = hdisplay for normal plane and 64 for cursor |
| 4671 | * and latency is assumed to be high, as above. |
| 4672 | * |
| 4673 | * The final value programmed to the register should always be rounded up, |
| 4674 | * and include an extra 2 entries to account for clock crossings. |
| 4675 | * |
| 4676 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 4677 | * to set the non-SR watermarks to 8. |
| 4678 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4679 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 4680 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4681 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 4682 | |
| 4683 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4684 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 4685 | } |
| 4686 | |
Jani Nikula | e282891 | 2016-01-18 09:19:47 +0200 | [diff] [blame] | 4687 | /* |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4688 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4689 | */ |
| 4690 | DEFINE_SPINLOCK(mchdev_lock); |
| 4691 | |
| 4692 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 4693 | * mchdev_lock. */ |
| 4694 | static struct drm_i915_private *i915_mch_dev; |
| 4695 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4696 | bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4697 | { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4698 | u16 rgvswctl; |
| 4699 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4700 | assert_spin_locked(&mchdev_lock); |
| 4701 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4702 | rgvswctl = I915_READ16(MEMSWCTL); |
| 4703 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 4704 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 4705 | return false; /* still busy with another command */ |
| 4706 | } |
| 4707 | |
| 4708 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 4709 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 4710 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 4711 | POSTING_READ16(MEMSWCTL); |
| 4712 | |
| 4713 | rgvswctl |= MEMCTL_CMD_STS; |
| 4714 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 4715 | |
| 4716 | return true; |
| 4717 | } |
| 4718 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4719 | static void ironlake_enable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4720 | { |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 4721 | u32 rgvmodectl; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4722 | u8 fmax, fmin, fstart, vstart; |
| 4723 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4724 | spin_lock_irq(&mchdev_lock); |
| 4725 | |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 4726 | rgvmodectl = I915_READ(MEMMODECTL); |
| 4727 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4728 | /* Enable temp reporting */ |
| 4729 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 4730 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 4731 | |
| 4732 | /* 100ms RC evaluation intervals */ |
| 4733 | I915_WRITE(RCUPEI, 100000); |
| 4734 | I915_WRITE(RCDNEI, 100000); |
| 4735 | |
| 4736 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 4737 | I915_WRITE(RCBMAXAVG, 90000); |
| 4738 | I915_WRITE(RCBMINAVG, 80000); |
| 4739 | |
| 4740 | I915_WRITE(MEMIHYST, 1); |
| 4741 | |
| 4742 | /* Set up min, max, and cur for interrupt handling */ |
| 4743 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 4744 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 4745 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 4746 | MEMMODE_FSTART_SHIFT; |
| 4747 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 4748 | vstart = (I915_READ(PXVFREQ(fstart)) & PXVFREQ_PX_MASK) >> |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4749 | PXVFREQ_PX_SHIFT; |
| 4750 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4751 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 4752 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4753 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4754 | dev_priv->ips.max_delay = fstart; |
| 4755 | dev_priv->ips.min_delay = fmin; |
| 4756 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4757 | |
| 4758 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 4759 | fmax, fmin, fstart); |
| 4760 | |
| 4761 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 4762 | |
| 4763 | /* |
| 4764 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 4765 | */ |
| 4766 | |
| 4767 | I915_WRITE(VIDSTART, vstart); |
| 4768 | POSTING_READ(VIDSTART); |
| 4769 | |
| 4770 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 4771 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 4772 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4773 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4774 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 4775 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4776 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4777 | ironlake_set_drps(dev_priv, fstart); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4778 | |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 4779 | dev_priv->ips.last_count1 = I915_READ(DMIEC) + |
| 4780 | I915_READ(DDREC) + I915_READ(CSIEC); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4781 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 4782 | dev_priv->ips.last_count2 = I915_READ(GFXEC); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 4783 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4784 | |
| 4785 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4786 | } |
| 4787 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4788 | static void ironlake_disable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4789 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4790 | u16 rgvswctl; |
| 4791 | |
| 4792 | spin_lock_irq(&mchdev_lock); |
| 4793 | |
| 4794 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4795 | |
| 4796 | /* Ack interrupts, disable EFC interrupt */ |
| 4797 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 4798 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 4799 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 4800 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 4801 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 4802 | |
| 4803 | /* Go back to the starting frequency */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 4804 | ironlake_set_drps(dev_priv, dev_priv->ips.fstart); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 4805 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4806 | rgvswctl |= MEMCTL_CMD_STS; |
| 4807 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 4808 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4809 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4810 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4811 | } |
| 4812 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 4813 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 4814 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 4815 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 4816 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 4817 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 4818 | static u32 intel_rps_limits(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4819 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4820 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4821 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 4822 | /* Only set the down limit when we've reached the lowest level to avoid |
| 4823 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 4824 | * race in the hw when coming out of rc6: There's a tiny window where |
| 4825 | * the hw runs at the minimal clock before selecting the desired |
| 4826 | * frequency, if the down threshold expires in that window we will not |
| 4827 | * receive a down interrupt. */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 4828 | if (IS_GEN9(dev_priv)) { |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 4829 | limits = (dev_priv->rps.max_freq_softlimit) << 23; |
| 4830 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 4831 | limits |= (dev_priv->rps.min_freq_softlimit) << 14; |
| 4832 | } else { |
| 4833 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 4834 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 4835 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
| 4836 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 4837 | |
| 4838 | return limits; |
| 4839 | } |
| 4840 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4841 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 4842 | { |
| 4843 | int new_power; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4844 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 4845 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4846 | |
| 4847 | new_power = dev_priv->rps.power; |
| 4848 | switch (dev_priv->rps.power) { |
| 4849 | case LOW_POWER: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4850 | if (val > dev_priv->rps.efficient_freq + 1 && |
| 4851 | val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4852 | new_power = BETWEEN; |
| 4853 | break; |
| 4854 | |
| 4855 | case BETWEEN: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4856 | if (val <= dev_priv->rps.efficient_freq && |
| 4857 | val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4858 | new_power = LOW_POWER; |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4859 | else if (val >= dev_priv->rps.rp0_freq && |
| 4860 | val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4861 | new_power = HIGH_POWER; |
| 4862 | break; |
| 4863 | |
| 4864 | case HIGH_POWER: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4865 | if (val < (dev_priv->rps.rp1_freq + dev_priv->rps.rp0_freq) >> 1 && |
| 4866 | val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4867 | new_power = BETWEEN; |
| 4868 | break; |
| 4869 | } |
| 4870 | /* Max/min bins are special */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4871 | if (val <= dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4872 | new_power = LOW_POWER; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4873 | if (val >= dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4874 | new_power = HIGH_POWER; |
| 4875 | if (new_power == dev_priv->rps.power) |
| 4876 | return; |
| 4877 | |
| 4878 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 4879 | switch (new_power) { |
| 4880 | case LOW_POWER: |
| 4881 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4882 | ei_up = 16000; |
| 4883 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4884 | |
| 4885 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4886 | ei_down = 32000; |
| 4887 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4888 | break; |
| 4889 | |
| 4890 | case BETWEEN: |
| 4891 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4892 | ei_up = 13000; |
| 4893 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4894 | |
| 4895 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4896 | ei_down = 32000; |
| 4897 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4898 | break; |
| 4899 | |
| 4900 | case HIGH_POWER: |
| 4901 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4902 | ei_up = 10000; |
| 4903 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4904 | |
| 4905 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4906 | ei_down = 32000; |
| 4907 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4908 | break; |
| 4909 | } |
| 4910 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4911 | I915_WRITE(GEN6_RP_UP_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4912 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4913 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4914 | GT_INTERVAL_FROM_US(dev_priv, |
| 4915 | ei_up * threshold_up / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4916 | |
| 4917 | I915_WRITE(GEN6_RP_DOWN_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4918 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4919 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4920 | GT_INTERVAL_FROM_US(dev_priv, |
| 4921 | ei_down * threshold_down / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4922 | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 4923 | I915_WRITE(GEN6_RP_CONTROL, |
| 4924 | GEN6_RP_MEDIA_TURBO | |
| 4925 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4926 | GEN6_RP_MEDIA_IS_GFX | |
| 4927 | GEN6_RP_ENABLE | |
| 4928 | GEN6_RP_UP_BUSY_AVG | |
| 4929 | GEN6_RP_DOWN_IDLE_AVG); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 4930 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4931 | dev_priv->rps.power = new_power; |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 4932 | dev_priv->rps.up_threshold = threshold_up; |
| 4933 | dev_priv->rps.down_threshold = threshold_down; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4934 | dev_priv->rps.last_adj = 0; |
| 4935 | } |
| 4936 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4937 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 4938 | { |
| 4939 | u32 mask = 0; |
| 4940 | |
| 4941 | if (val > dev_priv->rps.min_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 4942 | mask |= GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4943 | if (val < dev_priv->rps.max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 4944 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4945 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 4946 | mask &= dev_priv->pm_rps_events; |
| 4947 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 4948 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4949 | } |
| 4950 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 4951 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 4952 | * called when the range (min_delay and max_delay) is modified so that we can |
| 4953 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 4954 | static void gen6_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 4955 | { |
Sagar Arun Kamble | 23eafea | 2015-08-23 17:52:48 +0530 | [diff] [blame] | 4956 | /* WaGsvDisableTurbo: Workaround to disable turbo on BXT A* */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 4957 | if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) |
Sagar Arun Kamble | 23eafea | 2015-08-23 17:52:48 +0530 | [diff] [blame] | 4958 | return; |
| 4959 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4960 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4961 | WARN_ON(val > dev_priv->rps.max_freq); |
| 4962 | WARN_ON(val < dev_priv->rps.min_freq); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 4963 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 4964 | /* min/max delay may still have been modified so be sure to |
| 4965 | * write the limits value. |
| 4966 | */ |
| 4967 | if (val != dev_priv->rps.cur_freq) { |
| 4968 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 4969 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 4970 | if (IS_GEN9(dev_priv)) |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 4971 | I915_WRITE(GEN6_RPNSWREQ, |
| 4972 | GEN9_FREQUENCY(val)); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 4973 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 4974 | I915_WRITE(GEN6_RPNSWREQ, |
| 4975 | HSW_FREQUENCY(val)); |
| 4976 | else |
| 4977 | I915_WRITE(GEN6_RPNSWREQ, |
| 4978 | GEN6_FREQUENCY(val) | |
| 4979 | GEN6_OFFSET(0) | |
| 4980 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 4981 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4982 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4983 | /* Make sure we continue to get interrupts |
| 4984 | * until we hit the minimum or maximum frequencies. |
| 4985 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 4986 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4987 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4988 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 4989 | POSTING_READ(GEN6_RPNSWREQ); |
| 4990 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4991 | dev_priv->rps.cur_freq = val; |
Mika Kuoppala | 0f94592 | 2015-11-17 18:14:26 +0200 | [diff] [blame] | 4992 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4993 | } |
| 4994 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 4995 | static void valleyview_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4996 | { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4997 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4998 | WARN_ON(val > dev_priv->rps.max_freq); |
| 4999 | WARN_ON(val < dev_priv->rps.min_freq); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5000 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5001 | if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1), |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5002 | "Odd GPU freq value\n")) |
| 5003 | val &= ~1; |
| 5004 | |
Deepak S | cd25dd5 | 2015-07-10 18:31:40 +0530 | [diff] [blame] | 5005 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 5006 | |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 5007 | if (val != dev_priv->rps.cur_freq) { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5008 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 5009 | if (!IS_CHERRYVIEW(dev_priv)) |
| 5010 | gen6_set_rps_thresholds(dev_priv, val); |
| 5011 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5012 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5013 | dev_priv->rps.cur_freq = val; |
| 5014 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
| 5015 | } |
| 5016 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 5017 | /* vlv_set_rps_idle: Set the frequency to idle, if Gfx clocks are down |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5018 | * |
| 5019 | * * If Gfx is Idle, then |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 5020 | * 1. Forcewake Media well. |
| 5021 | * 2. Request idle freq. |
| 5022 | * 3. Release Forcewake of Media well. |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5023 | */ |
| 5024 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 5025 | { |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5026 | u32 val = dev_priv->rps.idle_freq; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 5027 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5028 | if (dev_priv->rps.cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5029 | return; |
| 5030 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 5031 | /* Wake up the media well, as that takes a lot less |
| 5032 | * power than the Render well. */ |
| 5033 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5034 | valleyview_set_rps(dev_priv, val); |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 5035 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_MEDIA); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5036 | } |
| 5037 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 5038 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 5039 | { |
| 5040 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5041 | if (dev_priv->rps.enabled) { |
| 5042 | if (dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) |
| 5043 | gen6_rps_reset_ei(dev_priv); |
| 5044 | I915_WRITE(GEN6_PMINTRMSK, |
| 5045 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 5046 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 5047 | gen6_enable_rps_interrupts(dev_priv); |
| 5048 | |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 5049 | /* Ensure we start at the user's desired frequency */ |
| 5050 | intel_set_rps(dev_priv, |
| 5051 | clamp(dev_priv->rps.cur_freq, |
| 5052 | dev_priv->rps.min_freq_softlimit, |
| 5053 | dev_priv->rps.max_freq_softlimit)); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 5054 | } |
| 5055 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5056 | } |
| 5057 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 5058 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 5059 | { |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 5060 | /* Flush our bottom-half so that it does not race with us |
| 5061 | * setting the idle frequency and so that it is bounded by |
| 5062 | * our rpm wakeref. And then disable the interrupts to stop any |
| 5063 | * futher RPS reclocking whilst we are asleep. |
| 5064 | */ |
| 5065 | gen6_disable_rps_interrupts(dev_priv); |
| 5066 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 5067 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5068 | if (dev_priv->rps.enabled) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5069 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5070 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5071 | else |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5072 | gen6_set_rps(dev_priv, dev_priv->rps.idle_freq); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5073 | dev_priv->rps.last_adj = 0; |
Ville Syrjälä | 12c100b | 2016-05-23 17:42:48 +0300 | [diff] [blame] | 5074 | I915_WRITE(GEN6_PMINTRMSK, |
| 5075 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5076 | } |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5077 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 5078 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5079 | spin_lock(&dev_priv->rps.client_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 5080 | while (!list_empty(&dev_priv->rps.clients)) |
| 5081 | list_del_init(dev_priv->rps.clients.next); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5082 | spin_unlock(&dev_priv->rps.client_lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 5083 | } |
| 5084 | |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 5085 | void gen6_rps_boost(struct drm_i915_private *dev_priv, |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 5086 | struct intel_rps_client *rps, |
| 5087 | unsigned long submitted) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 5088 | { |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5089 | /* This is intentionally racy! We peek at the state here, then |
| 5090 | * validate inside the RPS worker. |
| 5091 | */ |
Chris Wilson | 67d97da | 2016-07-04 08:08:31 +0100 | [diff] [blame] | 5092 | if (!(dev_priv->gt.awake && |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5093 | dev_priv->rps.enabled && |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 5094 | dev_priv->rps.cur_freq < dev_priv->rps.boost_freq)) |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5095 | return; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 5096 | |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 5097 | /* Force a RPS boost (and don't count it against the client) if |
| 5098 | * the GPU is severely congested. |
| 5099 | */ |
Chris Wilson | d0bc54f | 2015-05-21 21:01:48 +0100 | [diff] [blame] | 5100 | if (rps && time_after(jiffies, submitted + DRM_I915_THROTTLE_JIFFIES)) |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 5101 | rps = NULL; |
| 5102 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5103 | spin_lock(&dev_priv->rps.client_lock); |
| 5104 | if (rps == NULL || list_empty(&rps->link)) { |
| 5105 | spin_lock_irq(&dev_priv->irq_lock); |
| 5106 | if (dev_priv->rps.interrupts_enabled) { |
| 5107 | dev_priv->rps.client_boost = true; |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 5108 | schedule_work(&dev_priv->rps.work); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5109 | } |
| 5110 | spin_unlock_irq(&dev_priv->irq_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 5111 | |
Chris Wilson | 2e1b873 | 2015-04-27 13:41:22 +0100 | [diff] [blame] | 5112 | if (rps != NULL) { |
| 5113 | list_add(&rps->link, &dev_priv->rps.clients); |
| 5114 | rps->boosts++; |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 5115 | } else |
| 5116 | dev_priv->rps.boosts++; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5117 | } |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5118 | spin_unlock(&dev_priv->rps.client_lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 5119 | } |
| 5120 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5121 | void intel_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5122 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5123 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 5124 | valleyview_set_rps(dev_priv, val); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5125 | else |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5126 | gen6_set_rps(dev_priv, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5129 | static void gen9_disable_rc6(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5130 | { |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5131 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 5132 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5133 | } |
| 5134 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5135 | static void gen9_disable_rps(struct drm_i915_private *dev_priv) |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 5136 | { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 5137 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 5138 | } |
| 5139 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5140 | static void gen6_disable_rps(struct drm_i915_private *dev_priv) |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 5141 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 5142 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5143 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 5144 | I915_WRITE(GEN6_RP_CONTROL, 0); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 5145 | } |
| 5146 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5147 | static void cherryview_disable_rps(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5148 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5149 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5150 | } |
| 5151 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5152 | static void valleyview_disable_rps(struct drm_i915_private *dev_priv) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5153 | { |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 5154 | /* we're doing forcewake before Disabling RC6, |
| 5155 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5156 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 5157 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5158 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5159 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5160 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5163 | static void intel_print_rc6_info(struct drm_i915_private *dev_priv, u32 mode) |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 5164 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5165 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 5166 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 5167 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 5168 | else |
| 5169 | mode = 0; |
| 5170 | } |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5171 | if (HAS_RC6p(dev_priv)) |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 5172 | DRM_DEBUG_DRIVER("Enabling RC6 states: " |
| 5173 | "RC6 %s RC6p %s RC6pp %s\n", |
| 5174 | onoff(mode & GEN6_RC_CTL_RC6_ENABLE), |
| 5175 | onoff(mode & GEN6_RC_CTL_RC6p_ENABLE), |
| 5176 | onoff(mode & GEN6_RC_CTL_RC6pp_ENABLE)); |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 5177 | |
| 5178 | else |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 5179 | DRM_DEBUG_DRIVER("Enabling RC6 states: RC6 %s\n", |
| 5180 | onoff(mode & GEN6_RC_CTL_RC6_ENABLE)); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 5181 | } |
| 5182 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5183 | static bool bxt_check_bios_rc6_setup(struct drm_i915_private *dev_priv) |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5184 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 5185 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5186 | bool enable_rc6 = true; |
| 5187 | unsigned long rc6_ctx_base; |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 5188 | u32 rc_ctl; |
| 5189 | int rc_sw_target; |
| 5190 | |
| 5191 | rc_ctl = I915_READ(GEN6_RC_CONTROL); |
| 5192 | rc_sw_target = (I915_READ(GEN6_RC_STATE) & RC_SW_TARGET_STATE_MASK) >> |
| 5193 | RC_SW_TARGET_STATE_SHIFT; |
| 5194 | DRM_DEBUG_DRIVER("BIOS enabled RC states: " |
| 5195 | "HW_CTRL %s HW_RC6 %s SW_TARGET_STATE %x\n", |
| 5196 | onoff(rc_ctl & GEN6_RC_CTL_HW_ENABLE), |
| 5197 | onoff(rc_ctl & GEN6_RC_CTL_RC6_ENABLE), |
| 5198 | rc_sw_target); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5199 | |
| 5200 | if (!(I915_READ(RC6_LOCATION) & RC6_CTX_IN_DRAM)) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 5201 | DRM_DEBUG_DRIVER("RC6 Base location not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5202 | enable_rc6 = false; |
| 5203 | } |
| 5204 | |
| 5205 | /* |
| 5206 | * The exact context size is not known for BXT, so assume a page size |
| 5207 | * for this check. |
| 5208 | */ |
| 5209 | rc6_ctx_base = I915_READ(RC6_CTX_BASE) & RC6_CTX_BASE_MASK; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 5210 | if (!((rc6_ctx_base >= ggtt->stolen_reserved_base) && |
| 5211 | (rc6_ctx_base + PAGE_SIZE <= ggtt->stolen_reserved_base + |
| 5212 | ggtt->stolen_reserved_size))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 5213 | DRM_DEBUG_DRIVER("RC6 Base address not as expected.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5214 | enable_rc6 = false; |
| 5215 | } |
| 5216 | |
| 5217 | if (!(((I915_READ(PWRCTX_MAXCNT_RCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 5218 | ((I915_READ(PWRCTX_MAXCNT_VCSUNIT0) & IDLE_TIME_MASK) > 1) && |
| 5219 | ((I915_READ(PWRCTX_MAXCNT_BCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 5220 | ((I915_READ(PWRCTX_MAXCNT_VECSUNIT) & IDLE_TIME_MASK) > 1))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 5221 | DRM_DEBUG_DRIVER("Engine Idle wait time not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5222 | enable_rc6 = false; |
| 5223 | } |
| 5224 | |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 5225 | if (!I915_READ(GEN8_PUSHBUS_CONTROL) || |
| 5226 | !I915_READ(GEN8_PUSHBUS_ENABLE) || |
| 5227 | !I915_READ(GEN8_PUSHBUS_SHIFT)) { |
| 5228 | DRM_DEBUG_DRIVER("Pushbus not setup properly.\n"); |
| 5229 | enable_rc6 = false; |
| 5230 | } |
| 5231 | |
| 5232 | if (!I915_READ(GEN6_GFXPAUSE)) { |
| 5233 | DRM_DEBUG_DRIVER("GFX pause not setup properly.\n"); |
| 5234 | enable_rc6 = false; |
| 5235 | } |
| 5236 | |
| 5237 | if (!I915_READ(GEN8_MISC_CTRL0)) { |
| 5238 | DRM_DEBUG_DRIVER("GPM control not setup properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5239 | enable_rc6 = false; |
| 5240 | } |
| 5241 | |
| 5242 | return enable_rc6; |
| 5243 | } |
| 5244 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5245 | int sanitize_rc6_option(struct drm_i915_private *dev_priv, int enable_rc6) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5246 | { |
Daniel Vetter | e7d66d8 | 2015-06-15 23:23:54 +0200 | [diff] [blame] | 5247 | /* No RC6 before Ironlake and code is gone for ilk. */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5248 | if (INTEL_INFO(dev_priv)->gen < 6) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5249 | return 0; |
| 5250 | |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5251 | if (!enable_rc6) |
| 5252 | return 0; |
| 5253 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5254 | if (IS_BROXTON(dev_priv) && !bxt_check_bios_rc6_setup(dev_priv)) { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 5255 | DRM_INFO("RC6 disabled by BIOS\n"); |
| 5256 | return 0; |
| 5257 | } |
| 5258 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 5259 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5260 | if (enable_rc6 >= 0) { |
| 5261 | int mask; |
| 5262 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5263 | if (HAS_RC6p(dev_priv)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5264 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 5265 | INTEL_RC6pp_ENABLE; |
| 5266 | else |
| 5267 | mask = INTEL_RC6_ENABLE; |
| 5268 | |
| 5269 | if ((enable_rc6 & mask) != enable_rc6) |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 5270 | DRM_DEBUG_DRIVER("Adjusting RC6 mask to %d " |
| 5271 | "(requested %d, valid %d)\n", |
| 5272 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5273 | |
| 5274 | return enable_rc6 & mask; |
| 5275 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5276 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5277 | if (IS_IVYBRIDGE(dev_priv)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 5278 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 5279 | |
| 5280 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5281 | } |
| 5282 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5283 | static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5284 | { |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 5285 | /* All of these values are in units of 50MHz */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 5286 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 5287 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5288 | if (IS_BROXTON(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 5289 | u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP); |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 5290 | dev_priv->rps.rp0_freq = (rp_state_cap >> 16) & 0xff; |
| 5291 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 5292 | dev_priv->rps.min_freq = (rp_state_cap >> 0) & 0xff; |
| 5293 | } else { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 5294 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 5295 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 5296 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 5297 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 5298 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 5299 | /* hw_max = RP0 until we check for overclocking */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 5300 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 5301 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 5302 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5303 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) || |
| 5304 | IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 5305 | u32 ddcc_status = 0; |
| 5306 | |
| 5307 | if (sandybridge_pcode_read(dev_priv, |
| 5308 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 5309 | &ddcc_status) == 0) |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 5310 | dev_priv->rps.efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 5311 | clamp_t(u8, |
| 5312 | ((ddcc_status >> 8) & 0xff), |
| 5313 | dev_priv->rps.min_freq, |
| 5314 | dev_priv->rps.max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 5315 | } |
| 5316 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5317 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 5318 | /* Store the frequency values in 16.66 MHZ units, which is |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 5319 | * the natural hardware unit for SKL |
| 5320 | */ |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 5321 | dev_priv->rps.rp0_freq *= GEN9_FREQ_SCALER; |
| 5322 | dev_priv->rps.rp1_freq *= GEN9_FREQ_SCALER; |
| 5323 | dev_priv->rps.min_freq *= GEN9_FREQ_SCALER; |
| 5324 | dev_priv->rps.max_freq *= GEN9_FREQ_SCALER; |
| 5325 | dev_priv->rps.efficient_freq *= GEN9_FREQ_SCALER; |
| 5326 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 5327 | } |
| 5328 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 5329 | static void reset_rps(struct drm_i915_private *dev_priv, |
| 5330 | void (*set)(struct drm_i915_private *, u8)) |
| 5331 | { |
| 5332 | u8 freq = dev_priv->rps.cur_freq; |
| 5333 | |
| 5334 | /* force a reset */ |
| 5335 | dev_priv->rps.power = -1; |
| 5336 | dev_priv->rps.cur_freq = -1; |
| 5337 | |
| 5338 | set(dev_priv, freq); |
| 5339 | } |
| 5340 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5341 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5342 | static void gen9_enable_rps(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5343 | { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5344 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 5345 | |
Sagar Arun Kamble | 23eafea | 2015-08-23 17:52:48 +0530 | [diff] [blame] | 5346 | /* WaGsvDisableTurbo: Workaround to disable turbo on BXT A* */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5347 | if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 5348 | /* |
| 5349 | * BIOS could leave the Hw Turbo enabled, so need to explicitly |
| 5350 | * clear out the Control register just to avoid inconsitency |
| 5351 | * with debugfs interface, which will show Turbo as enabled |
| 5352 | * only and that is not expected by the User after adding the |
| 5353 | * WaGsvDisableTurbo. Apart from this there is no problem even |
| 5354 | * if the Turbo is left enabled in the Control register, as the |
| 5355 | * Up/Down interrupts would remain masked. |
| 5356 | */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5357 | gen9_disable_rps(dev_priv); |
Sagar Arun Kamble | 23eafea | 2015-08-23 17:52:48 +0530 | [diff] [blame] | 5358 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 5359 | return; |
| 5360 | } |
| 5361 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 5362 | /* Program defaults and thresholds for RPS*/ |
| 5363 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 5364 | GEN9_FREQUENCY(dev_priv->rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5365 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 5366 | /* 1 second timeout*/ |
| 5367 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 5368 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 5369 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5370 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5371 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 5372 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 5373 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 5374 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 5375 | reset_rps(dev_priv, gen6_set_rps); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5376 | |
| 5377 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 5378 | } |
| 5379 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5380 | static void gen9_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5381 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 5382 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 5383 | enum intel_engine_id id; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5384 | uint32_t rc6_mask = 0; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5385 | |
| 5386 | /* 1a: Software RC state - RC0 */ |
| 5387 | I915_WRITE(GEN6_RC_STATE, 0); |
| 5388 | |
| 5389 | /* 1b: Get forcewake during program sequence. Although the driver |
| 5390 | * 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] | 5391 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5392 | |
| 5393 | /* 2a: Disable RC states. */ |
| 5394 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5395 | |
| 5396 | /* 2b: Program RC6 thresholds.*/ |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 5397 | |
| 5398 | /* WaRsDoubleRc6WrlWithCoarsePowerGating: Doubling WRL only when CPG is enabled */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5399 | if (IS_SKYLAKE(dev_priv)) |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 5400 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 108 << 16); |
| 5401 | else |
| 5402 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5403 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 5404 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 5405 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 5406 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 5407 | |
Dave Gordon | 1a3d189 | 2016-05-13 15:36:30 +0100 | [diff] [blame] | 5408 | if (HAS_GUC(dev_priv)) |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 5409 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 5410 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5411 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5412 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 5413 | /* 2c: Program Coarse Power Gating Policies. */ |
| 5414 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 5415 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 5416 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5417 | /* 3a: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5418 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5419 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 5420 | DRM_INFO("RC6 %s\n", onoff(rc6_mask & GEN6_RC_CTL_RC6_ENABLE)); |
Jani Nikula | 4ff40a4 | 2016-09-26 15:07:51 +0300 | [diff] [blame] | 5421 | /* WaRsUseTimeoutMode:bxt */ |
Jani Nikula | 9fc736e | 2016-09-16 16:59:46 +0300 | [diff] [blame] | 5422 | if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) { |
Sagar Arun Kamble | 3e7732a | 2015-10-01 20:29:27 +0530 | [diff] [blame] | 5423 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us */ |
Sagar Arun Kamble | e3429cd | 2015-09-12 10:17:52 +0530 | [diff] [blame] | 5424 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 5425 | GEN7_RC_CTL_TO_MODE | |
| 5426 | rc6_mask); |
Sagar Arun Kamble | 3e7732a | 2015-10-01 20:29:27 +0530 | [diff] [blame] | 5427 | } else { |
| 5428 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
Sagar Arun Kamble | e3429cd | 2015-09-12 10:17:52 +0530 | [diff] [blame] | 5429 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 5430 | GEN6_RC_CTL_EI_MODE(1) | |
| 5431 | rc6_mask); |
Sagar Arun Kamble | 3e7732a | 2015-10-01 20:29:27 +0530 | [diff] [blame] | 5432 | } |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5433 | |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 5434 | /* |
| 5435 | * 3b: Enable Coarse Power Gating only when RC6 is enabled. |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 5436 | * WaRsDisableCoarsePowerGating:skl,bxt - Render/Media PG need to be disabled with RC6. |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 5437 | */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5438 | if (NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 5439 | I915_WRITE(GEN9_PG_ENABLE, 0); |
| 5440 | else |
| 5441 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 5442 | (GEN9_RENDER_PG_ENABLE | GEN9_MEDIA_PG_ENABLE) : 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 5443 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5444 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5447 | static void gen8_enable_rps(struct drm_i915_private *dev_priv) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5448 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 5449 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 5450 | enum intel_engine_id id; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 5451 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5452 | |
| 5453 | /* 1a: Software RC state - RC0 */ |
| 5454 | I915_WRITE(GEN6_RC_STATE, 0); |
| 5455 | |
| 5456 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 5457 | * 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] | 5458 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5459 | |
| 5460 | /* 2a: Disable RC states. */ |
| 5461 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5462 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5463 | /* 2b: Program RC6 thresholds.*/ |
| 5464 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 5465 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 5466 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 5467 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 5468 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5469 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5470 | if (IS_BROADWELL(dev_priv)) |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 5471 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 5472 | else |
| 5473 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5474 | |
| 5475 | /* 3: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5476 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5477 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5478 | intel_print_rc6_info(dev_priv, rc6_mask); |
| 5479 | if (IS_BROADWELL(dev_priv)) |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 5480 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 5481 | GEN7_RC_CTL_TO_MODE | |
| 5482 | rc6_mask); |
| 5483 | else |
| 5484 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 5485 | GEN6_RC_CTL_EI_MODE(1) | |
| 5486 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5487 | |
| 5488 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 5489 | I915_WRITE(GEN6_RPNSWREQ, |
| 5490 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 5491 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 5492 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5493 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 5494 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5495 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5496 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 5497 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 5498 | dev_priv->rps.max_freq_softlimit << 24 | |
| 5499 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5500 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5501 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 5502 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 5503 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 5504 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5505 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5506 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5507 | |
| 5508 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5509 | I915_WRITE(GEN6_RP_CONTROL, |
| 5510 | GEN6_RP_MEDIA_TURBO | |
| 5511 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 5512 | GEN6_RP_MEDIA_IS_GFX | |
| 5513 | GEN6_RP_ENABLE | |
| 5514 | GEN6_RP_UP_BUSY_AVG | |
| 5515 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5516 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5517 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5518 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 5519 | reset_rps(dev_priv, gen6_set_rps); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5520 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5521 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5522 | } |
| 5523 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5524 | static void gen6_enable_rps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5525 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 5526 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 5527 | enum intel_engine_id id; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 5528 | u32 rc6vids, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5529 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5530 | int rc6_mode; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 5531 | int ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5532 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5533 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 5534 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5535 | /* Here begins a magic sequence of register writes to enable |
| 5536 | * auto-downclocking. |
| 5537 | * |
| 5538 | * Perhaps there might be some value in exposing these to |
| 5539 | * userspace... |
| 5540 | */ |
| 5541 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5542 | |
| 5543 | /* Clear the DBG now so we don't confuse earlier errors */ |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 5544 | gtfifodbg = I915_READ(GTFIFODBG); |
| 5545 | if (gtfifodbg) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5546 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 5547 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5548 | } |
| 5549 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5550 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5551 | |
| 5552 | /* disable the counters and set deterministic thresholds */ |
| 5553 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5554 | |
| 5555 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 5556 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 5557 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 5558 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 5559 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 5560 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 5561 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 5562 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5563 | |
| 5564 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 5565 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5566 | if (IS_IVYBRIDGE(dev_priv)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 5567 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 5568 | else |
| 5569 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 5570 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5571 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 5572 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 5573 | /* Check if we are enabling RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5574 | rc6_mode = intel_enable_rc6(); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5575 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 5576 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 5577 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 5578 | /* We don't use those on Haswell */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5579 | if (!IS_HASWELL(dev_priv)) { |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 5580 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 5581 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5582 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 5583 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 5584 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 5585 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5586 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5587 | intel_print_rc6_info(dev_priv, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5588 | |
| 5589 | I915_WRITE(GEN6_RC_CONTROL, |
| 5590 | rc6_mask | |
| 5591 | GEN6_RC_CTL_EI_MODE(1) | |
| 5592 | GEN6_RC_CTL_HW_ENABLE); |
| 5593 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5594 | /* Power down if completely idle for over 50ms */ |
| 5595 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5596 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5597 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 5598 | reset_rps(dev_priv, gen6_set_rps); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5599 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 5600 | rc6vids = 0; |
| 5601 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5602 | if (IS_GEN6(dev_priv) && ret) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 5603 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5604 | } else if (IS_GEN6(dev_priv) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 5605 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 5606 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 5607 | rc6vids &= 0xffff00; |
| 5608 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 5609 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 5610 | if (ret) |
| 5611 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 5612 | } |
| 5613 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5614 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5615 | } |
| 5616 | |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 5617 | static void gen6_update_ring_freq(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5618 | { |
| 5619 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 5620 | unsigned int gpu_freq; |
| 5621 | unsigned int max_ia_freq, min_ring_freq; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 5622 | unsigned int max_gpu_freq, min_gpu_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5623 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 5624 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5625 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5626 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 5627 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 5628 | policy = cpufreq_cpu_get(0); |
| 5629 | if (policy) { |
| 5630 | max_ia_freq = policy->cpuinfo.max_freq; |
| 5631 | cpufreq_cpu_put(policy); |
| 5632 | } else { |
| 5633 | /* |
| 5634 | * Default to measured freq if none found, PCU will ensure we |
| 5635 | * don't go over |
| 5636 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5637 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 5638 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5639 | |
| 5640 | /* Convert from kHz to MHz */ |
| 5641 | max_ia_freq /= 1000; |
| 5642 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 5643 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 5644 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 5645 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 5646 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5647 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 5648 | /* Convert GT frequency to 50 HZ units */ |
| 5649 | min_gpu_freq = dev_priv->rps.min_freq / GEN9_FREQ_SCALER; |
| 5650 | max_gpu_freq = dev_priv->rps.max_freq / GEN9_FREQ_SCALER; |
| 5651 | } else { |
| 5652 | min_gpu_freq = dev_priv->rps.min_freq; |
| 5653 | max_gpu_freq = dev_priv->rps.max_freq; |
| 5654 | } |
| 5655 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5656 | /* |
| 5657 | * For each potential GPU frequency, load a ring frequency we'd like |
| 5658 | * to use for memory access. We do this by specifying the IA frequency |
| 5659 | * the PCU should use as a reference to determine the ring frequency. |
| 5660 | */ |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 5661 | for (gpu_freq = max_gpu_freq; gpu_freq >= min_gpu_freq; gpu_freq--) { |
| 5662 | int diff = max_gpu_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 5663 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5664 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5665 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 5666 | /* |
| 5667 | * ring_freq = 2 * GT. ring_freq is in 100MHz units |
| 5668 | * No floor required for ring frequency on SKL. |
| 5669 | */ |
| 5670 | ring_freq = gpu_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5671 | } else if (INTEL_INFO(dev_priv)->gen >= 8) { |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 5672 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 5673 | ring_freq = max(min_ring_freq, gpu_freq); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5674 | } else if (IS_HASWELL(dev_priv)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 5675 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 5676 | ring_freq = max(min_ring_freq, ring_freq); |
| 5677 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 5678 | } else { |
| 5679 | /* On older processors, there is no separate ring |
| 5680 | * clock domain, so in order to boost the bandwidth |
| 5681 | * of the ring, we need to upclock the CPU (ia_freq). |
| 5682 | * |
| 5683 | * For GPU frequencies less than 750MHz, |
| 5684 | * just use the lowest ring freq. |
| 5685 | */ |
| 5686 | if (gpu_freq < min_freq) |
| 5687 | ia_freq = 800; |
| 5688 | else |
| 5689 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 5690 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 5691 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5692 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 5693 | sandybridge_pcode_write(dev_priv, |
| 5694 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 5695 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 5696 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 5697 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5698 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5699 | } |
| 5700 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 5701 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5702 | { |
| 5703 | u32 val, rp0; |
| 5704 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 5705 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5706 | |
Imre Deak | 43b6799 | 2016-08-31 19:13:02 +0300 | [diff] [blame] | 5707 | switch (INTEL_INFO(dev_priv)->sseu.eu_total) { |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 5708 | case 8: |
| 5709 | /* (2 * 4) config */ |
| 5710 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 5711 | break; |
| 5712 | case 12: |
| 5713 | /* (2 * 6) config */ |
| 5714 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 5715 | break; |
| 5716 | case 16: |
| 5717 | /* (2 * 8) config */ |
| 5718 | default: |
| 5719 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 5720 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 5721 | break; |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 5722 | } |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 5723 | |
| 5724 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 5725 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5726 | return rp0; |
| 5727 | } |
| 5728 | |
| 5729 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 5730 | { |
| 5731 | u32 val, rpe; |
| 5732 | |
| 5733 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 5734 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 5735 | |
| 5736 | return rpe; |
| 5737 | } |
| 5738 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 5739 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 5740 | { |
| 5741 | u32 val, rp1; |
| 5742 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 5743 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 5744 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 5745 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 5746 | return rp1; |
| 5747 | } |
| 5748 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 5749 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 5750 | { |
| 5751 | u32 val, rp1; |
| 5752 | |
| 5753 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 5754 | |
| 5755 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 5756 | |
| 5757 | return rp1; |
| 5758 | } |
| 5759 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 5760 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5761 | { |
| 5762 | u32 val, rp0; |
| 5763 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 5764 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5765 | |
| 5766 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 5767 | /* Clamp to max */ |
| 5768 | rp0 = min_t(u32, rp0, 0xea); |
| 5769 | |
| 5770 | return rp0; |
| 5771 | } |
| 5772 | |
| 5773 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 5774 | { |
| 5775 | u32 val, rpe; |
| 5776 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 5777 | 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] | 5778 | 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] | 5779 | 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] | 5780 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 5781 | |
| 5782 | return rpe; |
| 5783 | } |
| 5784 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 5785 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5786 | { |
Imre Deak | 3614603 | 2014-12-04 18:39:35 +0200 | [diff] [blame] | 5787 | u32 val; |
| 5788 | |
| 5789 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
| 5790 | /* |
| 5791 | * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value |
| 5792 | * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on |
| 5793 | * a BYT-M B0 the above register contains 0xbf. Moreover when setting |
| 5794 | * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0 |
| 5795 | * to make sure it matches what Punit accepts. |
| 5796 | */ |
| 5797 | return max_t(u32, val, 0xc0); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5798 | } |
| 5799 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5800 | /* Check that the pctx buffer wasn't move under us. */ |
| 5801 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 5802 | { |
| 5803 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 5804 | |
| 5805 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 5806 | dev_priv->vlv_pctx->stolen->start); |
| 5807 | } |
| 5808 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5809 | |
| 5810 | /* Check that the pcbr address is not empty. */ |
| 5811 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 5812 | { |
| 5813 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 5814 | |
| 5815 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 5816 | } |
| 5817 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5818 | static void cherryview_setup_pctx(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5819 | { |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 5820 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 5821 | unsigned long pctx_paddr, paddr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5822 | u32 pcbr; |
| 5823 | int pctx_size = 32*1024; |
| 5824 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5825 | pcbr = I915_READ(VLV_PCBR); |
| 5826 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 5827 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5828 | paddr = (dev_priv->mm.stolen_base + |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 5829 | (ggtt->stolen_size - pctx_size)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5830 | |
| 5831 | pctx_paddr = (paddr & (~4095)); |
| 5832 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 5833 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 5834 | |
| 5835 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5836 | } |
| 5837 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5838 | static void valleyview_setup_pctx(struct drm_i915_private *dev_priv) |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 5839 | { |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 5840 | struct drm_i915_gem_object *pctx; |
| 5841 | unsigned long pctx_paddr; |
| 5842 | u32 pcbr; |
| 5843 | int pctx_size = 24*1024; |
| 5844 | |
| 5845 | pcbr = I915_READ(VLV_PCBR); |
| 5846 | if (pcbr) { |
| 5847 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 5848 | int pcbr_offset; |
| 5849 | |
| 5850 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 5851 | pctx = i915_gem_object_create_stolen_for_preallocated(&dev_priv->drm, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 5852 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 5853 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 5854 | pctx_size); |
| 5855 | goto out; |
| 5856 | } |
| 5857 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 5858 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 5859 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 5860 | /* |
| 5861 | * From the Gunit register HAS: |
| 5862 | * The Gfx driver is expected to program this register and ensure |
| 5863 | * proper allocation within Gfx stolen memory. For example, this |
| 5864 | * register should be programmed such than the PCBR range does not |
| 5865 | * overlap with other ranges, such as the frame buffer, protected |
| 5866 | * memory, or any other relevant ranges. |
| 5867 | */ |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 5868 | pctx = i915_gem_object_create_stolen(&dev_priv->drm, pctx_size); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 5869 | if (!pctx) { |
| 5870 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
Tvrtko Ursulin | ee50489 | 2016-02-11 10:27:30 +0000 | [diff] [blame] | 5871 | goto out; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 5875 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 5876 | |
| 5877 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 5878 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 5879 | dev_priv->vlv_pctx = pctx; |
| 5880 | } |
| 5881 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5882 | static void valleyview_cleanup_pctx(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5883 | { |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5884 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 5885 | return; |
| 5886 | |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 5887 | i915_gem_object_put(dev_priv->vlv_pctx); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5888 | dev_priv->vlv_pctx = NULL; |
| 5889 | } |
| 5890 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 5891 | static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv) |
| 5892 | { |
| 5893 | dev_priv->rps.gpll_ref_freq = |
| 5894 | vlv_get_cck_clock(dev_priv, "GPLL ref", |
| 5895 | CCK_GPLL_CLOCK_CONTROL, |
| 5896 | dev_priv->czclk_freq); |
| 5897 | |
| 5898 | DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n", |
| 5899 | dev_priv->rps.gpll_ref_freq); |
| 5900 | } |
| 5901 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5902 | static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5903 | { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5904 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5905 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5906 | valleyview_setup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5907 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 5908 | vlv_init_gpll_ref_freq(dev_priv); |
| 5909 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5910 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5911 | switch ((val >> 6) & 3) { |
| 5912 | case 0: |
| 5913 | case 1: |
| 5914 | dev_priv->mem_freq = 800; |
| 5915 | break; |
| 5916 | case 2: |
| 5917 | dev_priv->mem_freq = 1066; |
| 5918 | break; |
| 5919 | case 3: |
| 5920 | dev_priv->mem_freq = 1333; |
| 5921 | break; |
| 5922 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 5923 | 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] | 5924 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5925 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 5926 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 5927 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5928 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5929 | dev_priv->rps.max_freq); |
| 5930 | |
| 5931 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 5932 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5933 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5934 | dev_priv->rps.efficient_freq); |
| 5935 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 5936 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 5937 | 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] | 5938 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 5939 | dev_priv->rps.rp1_freq); |
| 5940 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5941 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 5942 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5943 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5944 | dev_priv->rps.min_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5945 | } |
| 5946 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5947 | static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5948 | { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5949 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5950 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5951 | cherryview_setup_pctx(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5952 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 5953 | vlv_init_gpll_ref_freq(dev_priv); |
| 5954 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 5955 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 5956 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 5957 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 5958 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5959 | switch ((val >> 2) & 0x7) { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5960 | case 3: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5961 | dev_priv->mem_freq = 2000; |
| 5962 | break; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 5963 | default: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5964 | dev_priv->mem_freq = 1600; |
| 5965 | break; |
| 5966 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 5967 | 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] | 5968 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5969 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 5970 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 5971 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5972 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5973 | dev_priv->rps.max_freq); |
| 5974 | |
| 5975 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 5976 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5977 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5978 | dev_priv->rps.efficient_freq); |
| 5979 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 5980 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 5981 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5982 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 5983 | dev_priv->rps.rp1_freq); |
| 5984 | |
Deepak S | 5b7c91b | 2015-05-09 18:15:46 +0530 | [diff] [blame] | 5985 | /* PUnit validated range is only [RPe, RP0] */ |
| 5986 | dev_priv->rps.min_freq = dev_priv->rps.efficient_freq; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5987 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5988 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5989 | dev_priv->rps.min_freq); |
| 5990 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 5991 | WARN_ONCE((dev_priv->rps.max_freq | |
| 5992 | dev_priv->rps.efficient_freq | |
| 5993 | dev_priv->rps.rp1_freq | |
| 5994 | dev_priv->rps.min_freq) & 1, |
| 5995 | "Odd GPU freq values\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5996 | } |
| 5997 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5998 | static void valleyview_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5999 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6000 | valleyview_cleanup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6001 | } |
| 6002 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6003 | static void cherryview_enable_rps(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6004 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6005 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6006 | enum intel_engine_id id; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6007 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6008 | |
| 6009 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 6010 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 6011 | gtfifodbg = I915_READ(GTFIFODBG) & ~(GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV | |
| 6012 | GT_FIFO_FREE_ENTRIES_CHV); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6013 | if (gtfifodbg) { |
| 6014 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 6015 | gtfifodbg); |
| 6016 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 6017 | } |
| 6018 | |
| 6019 | cherryview_check_pctx(dev_priv); |
| 6020 | |
| 6021 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 6022 | * 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] | 6023 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6024 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 6025 | /* Disable RC states. */ |
| 6026 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6027 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6028 | /* 2a: Program RC6 thresholds.*/ |
| 6029 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 6030 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 6031 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 6032 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6033 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6034 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6035 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 6036 | |
Deepak S | f4f71c7 | 2015-03-28 15:23:35 +0530 | [diff] [blame] | 6037 | /* TO threshold set to 500 us ( 0x186 * 1.28 us) */ |
| 6038 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x186); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6039 | |
| 6040 | /* allows RC6 residency counter to work */ |
| 6041 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 6042 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 6043 | VLV_MEDIA_RC6_COUNT_EN | |
| 6044 | VLV_RENDER_RC6_COUNT_EN)); |
| 6045 | |
| 6046 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 6047 | pcbr = I915_READ(VLV_PCBR); |
| 6048 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6049 | /* 3: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6050 | if ((intel_enable_rc6() & INTEL_RC6_ENABLE) && |
| 6051 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 6052 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6053 | |
| 6054 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 6055 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6056 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 6057 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6058 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 6059 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 6060 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 6061 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 6062 | |
| 6063 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 6064 | |
| 6065 | /* 5: Enable RPS */ |
| 6066 | I915_WRITE(GEN6_RP_CONTROL, |
| 6067 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 6068 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6069 | GEN6_RP_ENABLE | |
| 6070 | GEN6_RP_UP_BUSY_AVG | |
| 6071 | GEN6_RP_DOWN_IDLE_AVG); |
| 6072 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 6073 | /* Setting Fixed Bias */ |
| 6074 | val = VLV_OVERRIDE_EN | |
| 6075 | VLV_SOC_TDP_EN | |
| 6076 | CHV_BIAS_CPU_50_SOC_50; |
| 6077 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 6078 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6079 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 6080 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 6081 | /* RPS code assumes GPLL is used */ |
| 6082 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 6083 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 6084 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6085 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 6086 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6087 | reset_rps(dev_priv, valleyview_set_rps); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6088 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6089 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6090 | } |
| 6091 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6092 | static void valleyview_enable_rps(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6093 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6094 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6095 | enum intel_engine_id id; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 6096 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6097 | |
| 6098 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 6099 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6100 | valleyview_check_pctx(dev_priv); |
| 6101 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 6102 | gtfifodbg = I915_READ(GTFIFODBG); |
| 6103 | if (gtfifodbg) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 6104 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 6105 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6106 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 6107 | } |
| 6108 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 6109 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6110 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6111 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 6112 | /* Disable RC states. */ |
| 6113 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6114 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 6115 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6116 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 6117 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 6118 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 6119 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 6120 | |
| 6121 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 6122 | |
| 6123 | I915_WRITE(GEN6_RP_CONTROL, |
| 6124 | GEN6_RP_MEDIA_TURBO | |
| 6125 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6126 | GEN6_RP_MEDIA_IS_GFX | |
| 6127 | GEN6_RP_ENABLE | |
| 6128 | GEN6_RP_UP_BUSY_AVG | |
| 6129 | GEN6_RP_DOWN_IDLE_CONT); |
| 6130 | |
| 6131 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 6132 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 6133 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 6134 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6135 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6136 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6137 | |
Jesse Barnes | 2f0aa30 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 6138 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6139 | |
| 6140 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 6141 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 6142 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 6143 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 6144 | VLV_MEDIA_RC6_COUNT_EN | |
| 6145 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 6146 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6147 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 6148 | 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] | 6149 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6150 | intel_print_rc6_info(dev_priv, rc6_mode); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 6151 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 6152 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6153 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 6154 | /* Setting Fixed Bias */ |
| 6155 | val = VLV_OVERRIDE_EN | |
| 6156 | VLV_SOC_TDP_EN | |
| 6157 | VLV_BIAS_CPU_125_SOC_875; |
| 6158 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 6159 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 6160 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6161 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 6162 | /* RPS code assumes GPLL is used */ |
| 6163 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 6164 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 6165 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6166 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 6167 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6168 | reset_rps(dev_priv, valleyview_set_rps); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6169 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6170 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6171 | } |
| 6172 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6173 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 6174 | { |
| 6175 | unsigned long freq; |
| 6176 | int div = (vidfreq & 0x3f0000) >> 16; |
| 6177 | int post = (vidfreq & 0x3000) >> 12; |
| 6178 | int pre = (vidfreq & 0x7); |
| 6179 | |
| 6180 | if (!pre) |
| 6181 | return 0; |
| 6182 | |
| 6183 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 6184 | |
| 6185 | return freq; |
| 6186 | } |
| 6187 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6188 | static const struct cparams { |
| 6189 | u16 i; |
| 6190 | u16 t; |
| 6191 | u16 m; |
| 6192 | u16 c; |
| 6193 | } cparams[] = { |
| 6194 | { 1, 1333, 301, 28664 }, |
| 6195 | { 1, 1066, 294, 24460 }, |
| 6196 | { 1, 800, 294, 25192 }, |
| 6197 | { 0, 1333, 276, 27605 }, |
| 6198 | { 0, 1066, 276, 27605 }, |
| 6199 | { 0, 800, 231, 23784 }, |
| 6200 | }; |
| 6201 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 6202 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6203 | { |
| 6204 | u64 total_count, diff, ret; |
| 6205 | u32 count1, count2, count3, m = 0, c = 0; |
| 6206 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 6207 | int i; |
| 6208 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6209 | assert_spin_locked(&mchdev_lock); |
| 6210 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6211 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6212 | |
| 6213 | /* Prevent division-by-zero if we are asking too fast. |
| 6214 | * Also, we don't get interesting results if we are polling |
| 6215 | * faster than once in 10ms, so just return the saved value |
| 6216 | * in such cases. |
| 6217 | */ |
| 6218 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6219 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6220 | |
| 6221 | count1 = I915_READ(DMIEC); |
| 6222 | count2 = I915_READ(DDREC); |
| 6223 | count3 = I915_READ(CSIEC); |
| 6224 | |
| 6225 | total_count = count1 + count2 + count3; |
| 6226 | |
| 6227 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6228 | if (total_count < dev_priv->ips.last_count1) { |
| 6229 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6230 | diff += total_count; |
| 6231 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6232 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6236 | if (cparams[i].i == dev_priv->ips.c_m && |
| 6237 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6238 | m = cparams[i].m; |
| 6239 | c = cparams[i].c; |
| 6240 | break; |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | diff = div_u64(diff, diff1); |
| 6245 | ret = ((m * diff) + c); |
| 6246 | ret = div_u64(ret, 10); |
| 6247 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6248 | dev_priv->ips.last_count1 = total_count; |
| 6249 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6250 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6251 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6252 | |
| 6253 | return ret; |
| 6254 | } |
| 6255 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 6256 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 6257 | { |
| 6258 | unsigned long val; |
| 6259 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6260 | if (INTEL_INFO(dev_priv)->gen != 5) |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 6261 | return 0; |
| 6262 | |
| 6263 | spin_lock_irq(&mchdev_lock); |
| 6264 | |
| 6265 | val = __i915_chipset_val(dev_priv); |
| 6266 | |
| 6267 | spin_unlock_irq(&mchdev_lock); |
| 6268 | |
| 6269 | return val; |
| 6270 | } |
| 6271 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6272 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 6273 | { |
| 6274 | unsigned long m, x, b; |
| 6275 | u32 tsfs; |
| 6276 | |
| 6277 | tsfs = I915_READ(TSFS); |
| 6278 | |
| 6279 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 6280 | x = I915_READ8(TR1); |
| 6281 | |
| 6282 | b = tsfs & TSFS_INTR_MASK; |
| 6283 | |
| 6284 | return ((m * x) / 127) - b; |
| 6285 | } |
| 6286 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 6287 | static int _pxvid_to_vd(u8 pxvid) |
| 6288 | { |
| 6289 | if (pxvid == 0) |
| 6290 | return 0; |
| 6291 | |
| 6292 | if (pxvid >= 8 && pxvid < 31) |
| 6293 | pxvid = 31; |
| 6294 | |
| 6295 | return (pxvid + 2) * 125; |
| 6296 | } |
| 6297 | |
| 6298 | 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] | 6299 | { |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 6300 | const int vd = _pxvid_to_vd(pxvid); |
| 6301 | const int vm = vd - 1125; |
| 6302 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6303 | if (INTEL_INFO(dev_priv)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 6304 | return vm > 0 ? vm : 0; |
| 6305 | |
| 6306 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6307 | } |
| 6308 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6309 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6310 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 6311 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6312 | u32 count; |
| 6313 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6314 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6315 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 6316 | now = ktime_get_raw_ns(); |
| 6317 | diffms = now - dev_priv->ips.last_time2; |
| 6318 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6319 | |
| 6320 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6321 | if (!diffms) |
| 6322 | return; |
| 6323 | |
| 6324 | count = I915_READ(GFXEC); |
| 6325 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6326 | if (count < dev_priv->ips.last_count2) { |
| 6327 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6328 | diff += count; |
| 6329 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6330 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6331 | } |
| 6332 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6333 | dev_priv->ips.last_count2 = count; |
| 6334 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6335 | |
| 6336 | /* More magic constants... */ |
| 6337 | diff = diff * 1181; |
| 6338 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6339 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6340 | } |
| 6341 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6342 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 6343 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6344 | if (INTEL_INFO(dev_priv)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6345 | return; |
| 6346 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6347 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6348 | |
| 6349 | __i915_update_gfx_val(dev_priv); |
| 6350 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6351 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6352 | } |
| 6353 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 6354 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6355 | { |
| 6356 | unsigned long t, corr, state1, corr2, state2; |
| 6357 | u32 pxvid, ext_v; |
| 6358 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6359 | assert_spin_locked(&mchdev_lock); |
| 6360 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 6361 | pxvid = I915_READ(PXVFREQ(dev_priv->rps.cur_freq)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6362 | pxvid = (pxvid >> 24) & 0x7f; |
| 6363 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 6364 | |
| 6365 | state1 = ext_v; |
| 6366 | |
| 6367 | t = i915_mch_val(dev_priv); |
| 6368 | |
| 6369 | /* Revel in the empirically derived constants */ |
| 6370 | |
| 6371 | /* Correction factor in 1/100000 units */ |
| 6372 | if (t > 80) |
| 6373 | corr = ((t * 2349) + 135940); |
| 6374 | else if (t >= 50) |
| 6375 | corr = ((t * 964) + 29317); |
| 6376 | else /* < 50 */ |
| 6377 | corr = ((t * 301) + 1004); |
| 6378 | |
| 6379 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 6380 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6381 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6382 | |
| 6383 | state2 = (corr2 * state1) / 10000; |
| 6384 | state2 /= 100; /* convert to mW */ |
| 6385 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6386 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6387 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6388 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6389 | } |
| 6390 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 6391 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 6392 | { |
| 6393 | unsigned long val; |
| 6394 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6395 | if (INTEL_INFO(dev_priv)->gen != 5) |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 6396 | return 0; |
| 6397 | |
| 6398 | spin_lock_irq(&mchdev_lock); |
| 6399 | |
| 6400 | val = __i915_gfx_val(dev_priv); |
| 6401 | |
| 6402 | spin_unlock_irq(&mchdev_lock); |
| 6403 | |
| 6404 | return val; |
| 6405 | } |
| 6406 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6407 | /** |
| 6408 | * i915_read_mch_val - return value for IPS use |
| 6409 | * |
| 6410 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 6411 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 6412 | */ |
| 6413 | unsigned long i915_read_mch_val(void) |
| 6414 | { |
| 6415 | struct drm_i915_private *dev_priv; |
| 6416 | unsigned long chipset_val, graphics_val, ret = 0; |
| 6417 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6418 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6419 | if (!i915_mch_dev) |
| 6420 | goto out_unlock; |
| 6421 | dev_priv = i915_mch_dev; |
| 6422 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 6423 | chipset_val = __i915_chipset_val(dev_priv); |
| 6424 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6425 | |
| 6426 | ret = chipset_val + graphics_val; |
| 6427 | |
| 6428 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6429 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6430 | |
| 6431 | return ret; |
| 6432 | } |
| 6433 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 6434 | |
| 6435 | /** |
| 6436 | * i915_gpu_raise - raise GPU frequency limit |
| 6437 | * |
| 6438 | * Raise the limit; IPS indicates we have thermal headroom. |
| 6439 | */ |
| 6440 | bool i915_gpu_raise(void) |
| 6441 | { |
| 6442 | struct drm_i915_private *dev_priv; |
| 6443 | bool ret = true; |
| 6444 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6445 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6446 | if (!i915_mch_dev) { |
| 6447 | ret = false; |
| 6448 | goto out_unlock; |
| 6449 | } |
| 6450 | dev_priv = i915_mch_dev; |
| 6451 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6452 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 6453 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6454 | |
| 6455 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6456 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6457 | |
| 6458 | return ret; |
| 6459 | } |
| 6460 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 6461 | |
| 6462 | /** |
| 6463 | * i915_gpu_lower - lower GPU frequency limit |
| 6464 | * |
| 6465 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 6466 | * frequency maximum. |
| 6467 | */ |
| 6468 | bool i915_gpu_lower(void) |
| 6469 | { |
| 6470 | struct drm_i915_private *dev_priv; |
| 6471 | bool ret = true; |
| 6472 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6473 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6474 | if (!i915_mch_dev) { |
| 6475 | ret = false; |
| 6476 | goto out_unlock; |
| 6477 | } |
| 6478 | dev_priv = i915_mch_dev; |
| 6479 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6480 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 6481 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6482 | |
| 6483 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6484 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6485 | |
| 6486 | return ret; |
| 6487 | } |
| 6488 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 6489 | |
| 6490 | /** |
| 6491 | * i915_gpu_busy - indicate GPU business to IPS |
| 6492 | * |
| 6493 | * Tell the IPS driver whether or not the GPU is busy. |
| 6494 | */ |
| 6495 | bool i915_gpu_busy(void) |
| 6496 | { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6497 | bool ret = false; |
| 6498 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6499 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | dcff85c | 2016-08-05 10:14:11 +0100 | [diff] [blame] | 6500 | if (i915_mch_dev) |
| 6501 | ret = i915_mch_dev->gt.awake; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6502 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6503 | |
| 6504 | return ret; |
| 6505 | } |
| 6506 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 6507 | |
| 6508 | /** |
| 6509 | * i915_gpu_turbo_disable - disable graphics turbo |
| 6510 | * |
| 6511 | * Disable graphics turbo by resetting the max frequency and setting the |
| 6512 | * current frequency to the default. |
| 6513 | */ |
| 6514 | bool i915_gpu_turbo_disable(void) |
| 6515 | { |
| 6516 | struct drm_i915_private *dev_priv; |
| 6517 | bool ret = true; |
| 6518 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6519 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6520 | if (!i915_mch_dev) { |
| 6521 | ret = false; |
| 6522 | goto out_unlock; |
| 6523 | } |
| 6524 | dev_priv = i915_mch_dev; |
| 6525 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6526 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6527 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6528 | if (!ironlake_set_drps(dev_priv, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6529 | ret = false; |
| 6530 | |
| 6531 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6532 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6533 | |
| 6534 | return ret; |
| 6535 | } |
| 6536 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 6537 | |
| 6538 | /** |
| 6539 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 6540 | * IPS got loaded first. |
| 6541 | * |
| 6542 | * This awkward dance is so that neither module has to depend on the |
| 6543 | * other in order for IPS to do the appropriate communication of |
| 6544 | * GPU turbo limits to i915. |
| 6545 | */ |
| 6546 | static void |
| 6547 | ips_ping_for_i915_load(void) |
| 6548 | { |
| 6549 | void (*link)(void); |
| 6550 | |
| 6551 | link = symbol_get(ips_link_to_i915_driver); |
| 6552 | if (link) { |
| 6553 | link(); |
| 6554 | symbol_put(ips_link_to_i915_driver); |
| 6555 | } |
| 6556 | } |
| 6557 | |
| 6558 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 6559 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 6560 | /* We only register the i915 ips part with intel-ips once everything is |
| 6561 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6562 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6563 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6564 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6565 | |
| 6566 | ips_ping_for_i915_load(); |
| 6567 | } |
| 6568 | |
| 6569 | void intel_gpu_ips_teardown(void) |
| 6570 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6571 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6572 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6573 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 6574 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6575 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6576 | static void intel_init_emon(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6577 | { |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6578 | u32 lcfuse; |
| 6579 | u8 pxw[16]; |
| 6580 | int i; |
| 6581 | |
| 6582 | /* Disable to program */ |
| 6583 | I915_WRITE(ECR, 0); |
| 6584 | POSTING_READ(ECR); |
| 6585 | |
| 6586 | /* Program energy weights for various events */ |
| 6587 | I915_WRITE(SDEW, 0x15040d00); |
| 6588 | I915_WRITE(CSIEW0, 0x007f0000); |
| 6589 | I915_WRITE(CSIEW1, 0x1e220004); |
| 6590 | I915_WRITE(CSIEW2, 0x04000004); |
| 6591 | |
| 6592 | for (i = 0; i < 5; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 6593 | I915_WRITE(PEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6594 | for (i = 0; i < 3; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 6595 | I915_WRITE(DEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6596 | |
| 6597 | /* Program P-state weights to account for frequency power adjustment */ |
| 6598 | for (i = 0; i < 16; i++) { |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 6599 | u32 pxvidfreq = I915_READ(PXVFREQ(i)); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6600 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 6601 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 6602 | PXVFREQ_PX_SHIFT; |
| 6603 | unsigned long val; |
| 6604 | |
| 6605 | val = vid * vid; |
| 6606 | val *= (freq / 1000); |
| 6607 | val *= 255; |
| 6608 | val /= (127*127*900); |
| 6609 | if (val > 0xff) |
| 6610 | DRM_ERROR("bad pxval: %ld\n", val); |
| 6611 | pxw[i] = val; |
| 6612 | } |
| 6613 | /* Render standby states get 0 weight */ |
| 6614 | pxw[14] = 0; |
| 6615 | pxw[15] = 0; |
| 6616 | |
| 6617 | for (i = 0; i < 4; i++) { |
| 6618 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 6619 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 6620 | I915_WRITE(PXW(i), val); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | /* Adjust magic regs to magic values (more experimental results) */ |
| 6624 | I915_WRITE(OGW0, 0); |
| 6625 | I915_WRITE(OGW1, 0); |
| 6626 | I915_WRITE(EG0, 0x00007f00); |
| 6627 | I915_WRITE(EG1, 0x0000000e); |
| 6628 | I915_WRITE(EG2, 0x000e0000); |
| 6629 | I915_WRITE(EG3, 0x68000300); |
| 6630 | I915_WRITE(EG4, 0x42000000); |
| 6631 | I915_WRITE(EG5, 0x00140031); |
| 6632 | I915_WRITE(EG6, 0); |
| 6633 | I915_WRITE(EG7, 0); |
| 6634 | |
| 6635 | for (i = 0; i < 8; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 6636 | I915_WRITE(PXWL(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6637 | |
| 6638 | /* Enable PMON + select events */ |
| 6639 | I915_WRITE(ECR, 0x80000019); |
| 6640 | |
| 6641 | lcfuse = I915_READ(LCFUSE02); |
| 6642 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6643 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6644 | } |
| 6645 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6646 | void intel_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6647 | { |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 6648 | /* |
| 6649 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 6650 | * requirement. |
| 6651 | */ |
| 6652 | if (!i915.enable_rc6) { |
| 6653 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 6654 | intel_runtime_pm_get(dev_priv); |
| 6655 | } |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6656 | |
Chris Wilson | b5163db | 2016-08-10 13:58:24 +0100 | [diff] [blame] | 6657 | mutex_lock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6658 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6659 | |
| 6660 | /* Initialize RPS limits (for userspace) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6661 | if (IS_CHERRYVIEW(dev_priv)) |
| 6662 | cherryview_init_gt_powersave(dev_priv); |
| 6663 | else if (IS_VALLEYVIEW(dev_priv)) |
| 6664 | valleyview_init_gt_powersave(dev_priv); |
Chris Wilson | 2a13ae7 | 2016-08-02 11:15:27 +0100 | [diff] [blame] | 6665 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6666 | gen6_init_rps_frequencies(dev_priv); |
| 6667 | |
| 6668 | /* Derive initial user preferences/limits from the hardware limits */ |
| 6669 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 6670 | dev_priv->rps.cur_freq = dev_priv->rps.idle_freq; |
| 6671 | |
| 6672 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 6673 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 6674 | |
| 6675 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 6676 | dev_priv->rps.min_freq_softlimit = |
| 6677 | max_t(int, |
| 6678 | dev_priv->rps.efficient_freq, |
| 6679 | intel_freq_opcode(dev_priv, 450)); |
| 6680 | |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 6681 | /* After setting max-softlimit, find the overclock max freq */ |
| 6682 | if (IS_GEN6(dev_priv) || |
| 6683 | IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
| 6684 | u32 params = 0; |
| 6685 | |
| 6686 | sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, ¶ms); |
| 6687 | if (params & BIT(31)) { /* OC supported */ |
| 6688 | DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n", |
| 6689 | (dev_priv->rps.max_freq & 0xff) * 50, |
| 6690 | (params & 0xff) * 50); |
| 6691 | dev_priv->rps.max_freq = params & 0xff; |
| 6692 | } |
| 6693 | } |
| 6694 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 6695 | /* Finally allow us to boost to max by default */ |
| 6696 | dev_priv->rps.boost_freq = dev_priv->rps.max_freq; |
| 6697 | |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6698 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | b5163db | 2016-08-10 13:58:24 +0100 | [diff] [blame] | 6699 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6700 | |
| 6701 | intel_autoenable_gt_powersave(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6702 | } |
| 6703 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6704 | void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6705 | { |
Ville Syrjälä | 8dac1e1 | 2016-08-02 14:07:33 +0300 | [diff] [blame] | 6706 | if (IS_VALLEYVIEW(dev_priv)) |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6707 | valleyview_cleanup_gt_powersave(dev_priv); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 6708 | |
| 6709 | if (!i915.enable_rc6) |
| 6710 | intel_runtime_pm_put(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6711 | } |
| 6712 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6713 | /** |
| 6714 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 6715 | * @dev_priv: i915 device |
| 6716 | * |
| 6717 | * We don't want to disable RC6 or other features here, we just want |
| 6718 | * to make sure any work we've queued has finished and won't bother |
| 6719 | * us while we're suspended. |
| 6720 | */ |
| 6721 | void intel_suspend_gt_powersave(struct drm_i915_private *dev_priv) |
| 6722 | { |
| 6723 | if (INTEL_GEN(dev_priv) < 6) |
| 6724 | return; |
| 6725 | |
| 6726 | if (cancel_delayed_work_sync(&dev_priv->rps.autoenable_work)) |
| 6727 | intel_runtime_pm_put(dev_priv); |
| 6728 | |
| 6729 | /* gen6_rps_idle() will be called later to disable interrupts */ |
| 6730 | } |
| 6731 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 6732 | void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv) |
| 6733 | { |
| 6734 | dev_priv->rps.enabled = true; /* force disabling */ |
| 6735 | intel_disable_gt_powersave(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6736 | |
| 6737 | gen6_reset_rps_interrupts(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 6738 | } |
| 6739 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6740 | void intel_disable_gt_powersave(struct drm_i915_private *dev_priv) |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 6741 | { |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 6742 | if (!READ_ONCE(dev_priv->rps.enabled)) |
| 6743 | return; |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 6744 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6745 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6746 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 6747 | if (INTEL_GEN(dev_priv) >= 9) { |
| 6748 | gen9_disable_rc6(dev_priv); |
| 6749 | gen9_disable_rps(dev_priv); |
| 6750 | } else if (IS_CHERRYVIEW(dev_priv)) { |
| 6751 | cherryview_disable_rps(dev_priv); |
| 6752 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 6753 | valleyview_disable_rps(dev_priv); |
| 6754 | } else if (INTEL_GEN(dev_priv) >= 6) { |
| 6755 | gen6_disable_rps(dev_priv); |
| 6756 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 6757 | ironlake_disable_drps(dev_priv); |
| 6758 | } |
| 6759 | |
| 6760 | dev_priv->rps.enabled = false; |
| 6761 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6762 | } |
| 6763 | |
| 6764 | void intel_enable_gt_powersave(struct drm_i915_private *dev_priv) |
| 6765 | { |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6766 | /* We shouldn't be disabling as we submit, so this should be less |
| 6767 | * racy than it appears! |
| 6768 | */ |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 6769 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 6770 | return; |
| 6771 | |
| 6772 | /* Powersaving is controlled by the host when inside a VM */ |
| 6773 | if (intel_vgpu_active(dev_priv)) |
| 6774 | return; |
| 6775 | |
| 6776 | mutex_lock(&dev_priv->rps.hw_lock); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 6777 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6778 | if (IS_CHERRYVIEW(dev_priv)) { |
| 6779 | cherryview_enable_rps(dev_priv); |
| 6780 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 6781 | valleyview_enable_rps(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 6782 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6783 | gen9_enable_rc6(dev_priv); |
| 6784 | gen9_enable_rps(dev_priv); |
| 6785 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 6786 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6787 | } else if (IS_BROADWELL(dev_priv)) { |
| 6788 | gen8_enable_rps(dev_priv); |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 6789 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 6790 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6791 | gen6_enable_rps(dev_priv); |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 6792 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 6793 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 6794 | ironlake_enable_drps(dev_priv); |
| 6795 | intel_init_emon(dev_priv); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6796 | } |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 6797 | |
| 6798 | WARN_ON(dev_priv->rps.max_freq < dev_priv->rps.min_freq); |
| 6799 | WARN_ON(dev_priv->rps.idle_freq > dev_priv->rps.max_freq); |
| 6800 | |
| 6801 | WARN_ON(dev_priv->rps.efficient_freq < dev_priv->rps.min_freq); |
| 6802 | WARN_ON(dev_priv->rps.efficient_freq > dev_priv->rps.max_freq); |
| 6803 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6804 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6805 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 6806 | } |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 6807 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6808 | static void __intel_autoenable_gt_powersave(struct work_struct *work) |
| 6809 | { |
| 6810 | struct drm_i915_private *dev_priv = |
| 6811 | container_of(work, typeof(*dev_priv), rps.autoenable_work.work); |
| 6812 | struct intel_engine_cs *rcs; |
| 6813 | struct drm_i915_gem_request *req; |
| 6814 | |
| 6815 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 6816 | goto out; |
| 6817 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6818 | rcs = dev_priv->engine[RCS]; |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6819 | if (rcs->last_context) |
| 6820 | goto out; |
| 6821 | |
| 6822 | if (!rcs->init_context) |
| 6823 | goto out; |
| 6824 | |
| 6825 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 6826 | |
| 6827 | req = i915_gem_request_alloc(rcs, dev_priv->kernel_context); |
| 6828 | if (IS_ERR(req)) |
| 6829 | goto unlock; |
| 6830 | |
| 6831 | if (!i915.enable_execlists && i915_switch_context(req) == 0) |
| 6832 | rcs->init_context(req); |
| 6833 | |
| 6834 | /* Mark the device busy, calling intel_enable_gt_powersave() */ |
| 6835 | i915_add_request_no_flush(req); |
| 6836 | |
| 6837 | unlock: |
| 6838 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 6839 | out: |
| 6840 | intel_runtime_pm_put(dev_priv); |
| 6841 | } |
| 6842 | |
| 6843 | void intel_autoenable_gt_powersave(struct drm_i915_private *dev_priv) |
| 6844 | { |
| 6845 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 6846 | return; |
| 6847 | |
| 6848 | if (IS_IRONLAKE_M(dev_priv)) { |
| 6849 | ironlake_enable_drps(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6850 | intel_init_emon(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 6851 | } else if (INTEL_INFO(dev_priv)->gen >= 6) { |
| 6852 | /* |
| 6853 | * PCU communication is slow and this doesn't need to be |
| 6854 | * done at any specific time, so do this out of our fast path |
| 6855 | * to make resume and init faster. |
| 6856 | * |
| 6857 | * We depend on the HW RC6 power context save/restore |
| 6858 | * mechanism when entering D3 through runtime PM suspend. So |
| 6859 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 6860 | * get here via the driver load/system resume/runtime resume |
| 6861 | * paths, so the _noresume version is enough (and in case of |
| 6862 | * runtime resume it's necessary). |
| 6863 | */ |
| 6864 | if (queue_delayed_work(dev_priv->wq, |
| 6865 | &dev_priv->rps.autoenable_work, |
| 6866 | round_jiffies_up_relative(HZ))) |
| 6867 | intel_runtime_pm_get_noresume(dev_priv); |
| 6868 | } |
| 6869 | } |
| 6870 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6871 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 6872 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6873 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6874 | |
| 6875 | /* |
| 6876 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6877 | * gating for the panel power sequencer or it will fail to |
| 6878 | * start up when no ports are active. |
| 6879 | */ |
| 6880 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 6881 | } |
| 6882 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6883 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 6884 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6885 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 6886 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6887 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6888 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6889 | I915_WRITE(DSPCNTR(pipe), |
| 6890 | I915_READ(DSPCNTR(pipe)) | |
| 6891 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 6892 | |
| 6893 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 6894 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6895 | } |
| 6896 | } |
| 6897 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6898 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 6899 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6900 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6901 | |
| 6902 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 6903 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 6904 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 6905 | |
| 6906 | /* |
| 6907 | * Don't touch WM1S_LP_EN here. |
| 6908 | * Doing so could cause underruns. |
| 6909 | */ |
| 6910 | } |
| 6911 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6912 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6913 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6914 | struct drm_i915_private *dev_priv = to_i915(dev); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6915 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6916 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 6917 | /* |
| 6918 | * Required for FBC |
| 6919 | * WaFbcDisableDpfcClockGating:ilk |
| 6920 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6921 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 6922 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 6923 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6924 | |
| 6925 | I915_WRITE(PCH_3DCGDIS0, |
| 6926 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 6927 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 6928 | I915_WRITE(PCH_3DCGDIS1, |
| 6929 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 6930 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6931 | /* |
| 6932 | * According to the spec the following bits should be set in |
| 6933 | * order to enable memory self-refresh |
| 6934 | * The bit 22/21 of 0x42004 |
| 6935 | * The bit 5 of 0x42020 |
| 6936 | * The bit 15 of 0x45000 |
| 6937 | */ |
| 6938 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6939 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6940 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6941 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6942 | I915_WRITE(DISP_ARB_CTL, |
| 6943 | (I915_READ(DISP_ARB_CTL) | |
| 6944 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6945 | |
| 6946 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6947 | |
| 6948 | /* |
| 6949 | * Based on the document from hardware guys the following bits |
| 6950 | * should be set unconditionally in order to enable FBC. |
| 6951 | * The bit 22 of 0x42000 |
| 6952 | * The bit 22 of 0x42004 |
| 6953 | * The bit 7,8,9 of 0x42020. |
| 6954 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6955 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6956 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6957 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6958 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6959 | ILK_FBCQ_DIS); |
| 6960 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6961 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6962 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6963 | } |
| 6964 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6965 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 6966 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6967 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6968 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6969 | ILK_ELPIN_409_SELECT); |
| 6970 | I915_WRITE(_3D_CHICKEN2, |
| 6971 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 6972 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6973 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6974 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6975 | I915_WRITE(CACHE_MODE_0, |
| 6976 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6977 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6978 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 6979 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6980 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6981 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 6982 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6983 | ibx_init_clock_gating(dev); |
| 6984 | } |
| 6985 | |
| 6986 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 6987 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6988 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6989 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 6990 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6991 | |
| 6992 | /* |
| 6993 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6994 | * gating for the panel power sequencer or it will fail to |
| 6995 | * start up when no ports are active. |
| 6996 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 6997 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 6998 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 6999 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7000 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 7001 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 7002 | /* The below fixes the weird display corruption, a few pixels shifted |
| 7003 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 7004 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7005 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7006 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 7007 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 7008 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7009 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7010 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7011 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 7012 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 7013 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7014 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 7015 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7016 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7017 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7018 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 7019 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 7020 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7021 | } |
| 7022 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7023 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 7024 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7025 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7026 | uint32_t tmp; |
| 7027 | |
| 7028 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 7029 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 7030 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 7031 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7032 | } |
| 7033 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7034 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7035 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7036 | struct drm_i915_private *dev_priv = to_i915(dev); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7037 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7038 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7039 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7040 | |
| 7041 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 7042 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 7043 | ILK_ELPIN_409_SELECT); |
| 7044 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7045 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 7046 | I915_WRITE(_3D_CHICKEN, |
| 7047 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 7048 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7049 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 7050 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 7051 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 7052 | /* |
| 7053 | * BSpec recoomends 8x4 when MSAA is used, |
| 7054 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 7055 | * |
| 7056 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 7057 | * disable bit, which we don't touch here, but it's good |
| 7058 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 7059 | */ |
| 7060 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 7061 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 7062 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7063 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7064 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7065 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 7066 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7067 | |
| 7068 | I915_WRITE(GEN6_UCGCTL1, |
| 7069 | I915_READ(GEN6_UCGCTL1) | |
| 7070 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 7071 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 7072 | |
| 7073 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 7074 | * gating disable must be set. Failure to set it results in |
| 7075 | * flickering pixels due to Z write ordering failures after |
| 7076 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 7077 | * Sanctuary and Tropics, and apparently anything else with |
| 7078 | * alpha test or pixel discard. |
| 7079 | * |
| 7080 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 7081 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7082 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 7083 | * WaDisableRCCUnitClockGating:snb |
| 7084 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7085 | */ |
| 7086 | I915_WRITE(GEN6_UCGCTL2, |
| 7087 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 7088 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 7089 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 7090 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 7091 | I915_WRITE(_3D_CHICKEN3, |
| 7092 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7093 | |
| 7094 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 7095 | * Bspec says: |
| 7096 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 7097 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 7098 | */ |
| 7099 | I915_WRITE(_3D_CHICKEN3, |
| 7100 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 7101 | |
| 7102 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7103 | * According to the spec the following bits should be |
| 7104 | * set in order to enable memory self-refresh and fbc: |
| 7105 | * The bit21 and bit22 of 0x42000 |
| 7106 | * The bit21 and bit22 of 0x42004 |
| 7107 | * The bit5 and bit7 of 0x42020 |
| 7108 | * The bit14 of 0x70180 |
| 7109 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7110 | * |
| 7111 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7112 | */ |
| 7113 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 7114 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 7115 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 7116 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 7117 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 7118 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7119 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 7120 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 7121 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 7122 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7123 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7124 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 7125 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7126 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7127 | |
| 7128 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7129 | } |
| 7130 | |
| 7131 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 7132 | { |
| 7133 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 7134 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 7135 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 7136 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 7137 | * |
| 7138 | * This actually overrides the dispatch |
| 7139 | * mode for all thread types. |
| 7140 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7141 | reg &= ~GEN7_FF_SCHED_MASK; |
| 7142 | reg |= GEN7_FF_TS_SCHED_HW; |
| 7143 | reg |= GEN7_FF_VS_SCHED_HW; |
| 7144 | reg |= GEN7_FF_DS_SCHED_HW; |
| 7145 | |
| 7146 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 7147 | } |
| 7148 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7149 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 7150 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7151 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7152 | |
| 7153 | /* |
| 7154 | * TODO: this bit should only be enabled when really needed, then |
| 7155 | * disabled when not needed anymore in order to save power. |
| 7156 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7157 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7158 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 7159 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 7160 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7161 | |
| 7162 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 7163 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 7164 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7165 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7166 | } |
| 7167 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7168 | static void lpt_suspend_hw(struct drm_device *dev) |
| 7169 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7170 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7171 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7172 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7173 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 7174 | |
| 7175 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 7176 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 7177 | } |
| 7178 | } |
| 7179 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7180 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 7181 | int general_prio_credits, |
| 7182 | int high_prio_credits) |
| 7183 | { |
| 7184 | u32 misccpctl; |
| 7185 | |
| 7186 | /* WaTempDisableDOPClkGating:bdw */ |
| 7187 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 7188 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 7189 | |
| 7190 | I915_WRITE(GEN8_L3SQCREG1, |
| 7191 | L3_GENERAL_PRIO_CREDITS(general_prio_credits) | |
| 7192 | L3_HIGH_PRIO_CREDITS(high_prio_credits)); |
| 7193 | |
| 7194 | /* |
| 7195 | * Wait at least 100 clocks before re-enabling clock gating. |
| 7196 | * See the definition of L3SQCREG1 in BSpec. |
| 7197 | */ |
| 7198 | POSTING_READ(GEN8_L3SQCREG1); |
| 7199 | udelay(1); |
| 7200 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 7201 | } |
| 7202 | |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7203 | static void kabylake_init_clock_gating(struct drm_device *dev) |
| 7204 | { |
Mika Kuoppala | 9146f30 | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7205 | struct drm_i915_private *dev_priv = dev->dev_private; |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7206 | |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 7207 | gen9_init_clock_gating(dev); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7208 | |
| 7209 | /* WaDisableSDEUnitClockGating:kbl */ |
| 7210 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 7211 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 7212 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 7213 | |
| 7214 | /* WaDisableGamClockGating:kbl */ |
| 7215 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 7216 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 7217 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7218 | |
| 7219 | /* WaFbcNukeOnHostModify:kbl */ |
| 7220 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 7221 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7222 | } |
| 7223 | |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7224 | static void skylake_init_clock_gating(struct drm_device *dev) |
| 7225 | { |
Mika Kuoppala | c584e2d | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7226 | struct drm_i915_private *dev_priv = dev->dev_private; |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7227 | |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 7228 | gen9_init_clock_gating(dev); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7229 | |
| 7230 | /* WAC6entrylatency:skl */ |
| 7231 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 7232 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7233 | |
| 7234 | /* WaFbcNukeOnHostModify:skl */ |
| 7235 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 7236 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7237 | } |
| 7238 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 7239 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7240 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7241 | struct drm_i915_private *dev_priv = to_i915(dev); |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 7242 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7243 | |
Ville Syrjälä | 7ad0dba | 2015-05-19 20:32:55 +0300 | [diff] [blame] | 7244 | ilk_init_lp_watermarks(dev); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 7245 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7246 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 7247 | 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] | 7248 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7249 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7250 | I915_WRITE(CHICKEN_PAR1_1, |
| 7251 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 7252 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7253 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7254 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 7255 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 7256 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 7257 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7258 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 7259 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7260 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 7261 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 7262 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 7263 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 7264 | ~(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] | 7265 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 7266 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 7267 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 7268 | |
| 7269 | /* WaDisableSDEUnitClockGating:bdw */ |
| 7270 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 7271 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 7272 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7273 | /* WaProgramL3SqcReg1Default:bdw */ |
| 7274 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 7275 | |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 7276 | /* |
| 7277 | * WaGttCachingOffByDefault:bdw |
| 7278 | * GTT cache may not work with big pages, so if those |
| 7279 | * are ever enabled GTT cache may need to be disabled. |
| 7280 | */ |
| 7281 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
| 7282 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 7283 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 7284 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 7285 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 7286 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 7287 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7288 | } |
| 7289 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7290 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 7291 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7292 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7293 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7294 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7295 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 7296 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 7297 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 7298 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 7299 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 7300 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7301 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7302 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7303 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 7304 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7305 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 7306 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 7307 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 7308 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7309 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7310 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 7311 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 7312 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 7313 | /* enable HiZ Raw Stall Optimization */ |
| 7314 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 7315 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 7316 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7317 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7318 | I915_WRITE(CACHE_MODE_1, |
| 7319 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 7320 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 7321 | /* |
| 7322 | * BSpec recommends 8x4 when MSAA is used, |
| 7323 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 7324 | * |
| 7325 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 7326 | * disable bit, which we don't touch here, but it's good |
| 7327 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 7328 | */ |
| 7329 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 7330 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 7331 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 7332 | /* WaSampleCChickenBitEnable:hsw */ |
| 7333 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 7334 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 7335 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7336 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 7337 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 7338 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 7339 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 7340 | I915_WRITE(CHICKEN_PAR1_1, |
| 7341 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 7342 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7343 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7344 | } |
| 7345 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7346 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7347 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7348 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 7349 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7350 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7351 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7352 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7353 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7354 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7355 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 7356 | I915_WRITE(_3D_CHICKEN3, |
| 7357 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 7358 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7359 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7360 | I915_WRITE(IVB_CHICKEN3, |
| 7361 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7362 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7363 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7364 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7365 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 7366 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 7367 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 7368 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7369 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 7370 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 7371 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7372 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7373 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 7374 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 7375 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7376 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7377 | I915_WRITE(GEN7_L3CNTLREG1, |
| 7378 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 7379 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7380 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7381 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7382 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 7383 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7384 | else { |
| 7385 | /* must write both registers */ |
| 7386 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 7387 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7388 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 7389 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7390 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7391 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7392 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 7393 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 7394 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 7395 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 7396 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7397 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7398 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7399 | */ |
| 7400 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 7401 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7402 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7403 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7404 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7405 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 7406 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7407 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7408 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7409 | |
| 7410 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 7411 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 7412 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 7413 | /* enable HiZ Raw Stall Optimization */ |
| 7414 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 7415 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 7416 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 7417 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7418 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 7419 | I915_WRITE(CACHE_MODE_1, |
| 7420 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 7421 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 7422 | /* |
| 7423 | * BSpec recommends 8x4 when MSAA is used, |
| 7424 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 7425 | * |
| 7426 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 7427 | * disable bit, which we don't touch here, but it's good |
| 7428 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 7429 | */ |
| 7430 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 7431 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 7432 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 7433 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 7434 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 7435 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 7436 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7437 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7438 | if (!HAS_PCH_NOP(dev_priv)) |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 7439 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7440 | |
| 7441 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7442 | } |
| 7443 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7444 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7445 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7446 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7447 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7448 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 7449 | I915_WRITE(_3D_CHICKEN3, |
| 7450 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 7451 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7452 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7453 | I915_WRITE(IVB_CHICKEN3, |
| 7454 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7455 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7456 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 7457 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7458 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 7459 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 7460 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 7461 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 7462 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7463 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 7464 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 7465 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7466 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 7467 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 7468 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 7469 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7470 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7471 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 7472 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 7473 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7474 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7475 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7476 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 7477 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7478 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 7479 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 7480 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7481 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7482 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7483 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7484 | */ |
| 7485 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7486 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7487 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 7488 | /* WaDisableL3Bank2xClockGate:vlv |
| 7489 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 7490 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 7491 | I915_WRITE(GEN7_UCGCTL4, |
| 7492 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 7493 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 7494 | /* |
| 7495 | * BSpec says this must be set, even though |
| 7496 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 7497 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 7498 | I915_WRITE(CACHE_MODE_1, |
| 7499 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 7500 | |
| 7501 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 7502 | * BSpec recommends 8x4 when MSAA is used, |
| 7503 | * however in practice 16x4 seems fastest. |
| 7504 | * |
| 7505 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 7506 | * disable bit, which we don't touch here, but it's good |
| 7507 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 7508 | */ |
| 7509 | I915_WRITE(GEN7_GT_MODE, |
| 7510 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 7511 | |
| 7512 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 7513 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 7514 | * This is the hardware default actually. |
| 7515 | */ |
| 7516 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 7517 | |
| 7518 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7519 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 7520 | * Disable clock gating on th GCFG unit to prevent a delay |
| 7521 | * in the reporting of vblank events. |
| 7522 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 7523 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7524 | } |
| 7525 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7526 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 7527 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7528 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7529 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 7530 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 7531 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 7532 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 7533 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 7534 | ~(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] | 7535 | |
| 7536 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 7537 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 7538 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 7539 | |
| 7540 | /* WaDisableCSUnitClockGating:chv */ |
| 7541 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 7542 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 7543 | |
| 7544 | /* WaDisableSDEUnitClockGating:chv */ |
| 7545 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 7546 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 7547 | |
| 7548 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7549 | * WaProgramL3SqcReg1Default:chv |
| 7550 | * See gfxspecs/Related Documents/Performance Guide/ |
| 7551 | * LSQC Setting Recommendations. |
| 7552 | */ |
| 7553 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
| 7554 | |
| 7555 | /* |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 7556 | * GTT cache may not work with big pages, so if those |
| 7557 | * are ever enabled GTT cache may need to be disabled. |
| 7558 | */ |
| 7559 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7560 | } |
| 7561 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7562 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7563 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7564 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7565 | uint32_t dspclk_gate; |
| 7566 | |
| 7567 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 7568 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 7569 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 7570 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 7571 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 7572 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 7573 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 7574 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7575 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7576 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 7577 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 7578 | |
| 7579 | /* WaDisableRenderCachePipelinedFlush */ |
| 7580 | I915_WRITE(CACHE_MODE_0, |
| 7581 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 7582 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7583 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 7584 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 7585 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7586 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7587 | } |
| 7588 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7589 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7590 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7591 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7592 | |
| 7593 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 7594 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 7595 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 7596 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 7597 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 7598 | I915_WRITE(MI_ARB_STATE, |
| 7599 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7600 | |
| 7601 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 7602 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7603 | } |
| 7604 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7605 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7606 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7607 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7608 | |
| 7609 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 7610 | I965_RCC_CLOCK_GATE_DISABLE | |
| 7611 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 7612 | I965_ISC_CLOCK_GATE_DISABLE | |
| 7613 | I965_FBC_CLOCK_GATE_DISABLE); |
| 7614 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 7615 | I915_WRITE(MI_ARB_STATE, |
| 7616 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7617 | |
| 7618 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 7619 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7620 | } |
| 7621 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7622 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7623 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7624 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7625 | u32 dstate = I915_READ(D_STATE); |
| 7626 | |
| 7627 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 7628 | DSTATE_DOT_CLOCK_GATING; |
| 7629 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 7630 | |
| 7631 | if (IS_PINEVIEW(dev)) |
| 7632 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 7633 | |
| 7634 | /* IIR "flip pending" means done if this bit is set */ |
| 7635 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 7636 | |
| 7637 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 7638 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 7639 | |
| 7640 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 7641 | 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] | 7642 | |
| 7643 | I915_WRITE(MI_ARB_STATE, |
| 7644 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7645 | } |
| 7646 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7647 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7648 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7649 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7650 | |
| 7651 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 7652 | |
| 7653 | /* interrupts should cause a wake up from C3 */ |
| 7654 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 7655 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7656 | |
| 7657 | I915_WRITE(MEM_MODE, |
| 7658 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7659 | } |
| 7660 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7661 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7662 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7663 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7664 | |
| 7665 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7666 | |
| 7667 | I915_WRITE(MEM_MODE, |
| 7668 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 7669 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7670 | } |
| 7671 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7672 | void intel_init_clock_gating(struct drm_device *dev) |
| 7673 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7674 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7675 | |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7676 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7677 | } |
| 7678 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7679 | void intel_suspend_hw(struct drm_device *dev) |
| 7680 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7681 | if (HAS_PCH_LPT(to_i915(dev))) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7682 | lpt_suspend_hw(dev); |
| 7683 | } |
| 7684 | |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7685 | static void nop_init_clock_gating(struct drm_device *dev) |
| 7686 | { |
| 7687 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 7688 | } |
| 7689 | |
| 7690 | /** |
| 7691 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 7692 | * @dev_priv: device private |
| 7693 | * |
| 7694 | * Setup the hooks that configure which clocks of a given platform can be |
| 7695 | * gated and also apply various GT and display specific workarounds for these |
| 7696 | * platforms. Note that some GT specific workarounds are applied separately |
| 7697 | * when GPU contexts or batchbuffers start their execution. |
| 7698 | */ |
| 7699 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 7700 | { |
| 7701 | if (IS_SKYLAKE(dev_priv)) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7702 | dev_priv->display.init_clock_gating = skylake_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7703 | else if (IS_KABYLAKE(dev_priv)) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7704 | dev_priv->display.init_clock_gating = kabylake_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7705 | else if (IS_BROXTON(dev_priv)) |
| 7706 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
| 7707 | else if (IS_BROADWELL(dev_priv)) |
| 7708 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
| 7709 | else if (IS_CHERRYVIEW(dev_priv)) |
| 7710 | dev_priv->display.init_clock_gating = cherryview_init_clock_gating; |
| 7711 | else if (IS_HASWELL(dev_priv)) |
| 7712 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
| 7713 | else if (IS_IVYBRIDGE(dev_priv)) |
| 7714 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
| 7715 | else if (IS_VALLEYVIEW(dev_priv)) |
| 7716 | dev_priv->display.init_clock_gating = valleyview_init_clock_gating; |
| 7717 | else if (IS_GEN6(dev_priv)) |
| 7718 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
| 7719 | else if (IS_GEN5(dev_priv)) |
| 7720 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
| 7721 | else if (IS_G4X(dev_priv)) |
| 7722 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 7723 | else if (IS_CRESTLINE(dev_priv)) |
| 7724 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 7725 | else if (IS_BROADWATER(dev_priv)) |
| 7726 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 7727 | else if (IS_GEN3(dev_priv)) |
| 7728 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 7729 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 7730 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 7731 | else if (IS_GEN2(dev_priv)) |
| 7732 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 7733 | else { |
| 7734 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 7735 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 7736 | } |
| 7737 | } |
| 7738 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7739 | /* Set up chip specific power management-related functions */ |
| 7740 | void intel_init_pm(struct drm_device *dev) |
| 7741 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7742 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7743 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 7744 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7745 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7746 | /* For cxsr */ |
| 7747 | if (IS_PINEVIEW(dev)) |
| 7748 | i915_pineview_get_mem_freq(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 7749 | else if (IS_GEN5(dev_priv)) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7750 | i915_ironlake_get_mem_freq(dev); |
| 7751 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7752 | /* For FIFO watermark updates */ |
Damien Lespiau | f5ed50c | 2014-11-13 17:51:52 +0000 | [diff] [blame] | 7753 | if (INTEL_INFO(dev)->gen >= 9) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 7754 | skl_setup_wm_latency(dev); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 7755 | dev_priv->display.update_wm = skl_update_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 7756 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7757 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 7758 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 7759 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 7760 | if ((IS_GEN5(dev_priv) && dev_priv->wm.pri_latency[1] && |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7761 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 7762 | (!IS_GEN5(dev_priv) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7763 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 7764 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 7765 | dev_priv->display.compute_intermediate_wm = |
| 7766 | ilk_compute_intermediate_wm; |
| 7767 | dev_priv->display.initial_watermarks = |
| 7768 | ilk_initial_watermarks; |
| 7769 | dev_priv->display.optimize_watermarks = |
| 7770 | ilk_optimize_watermarks; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7771 | } else { |
| 7772 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 7773 | "Disable CxSR\n"); |
| 7774 | } |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7775 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 7776 | vlv_setup_wm_latency(dev); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 7777 | dev_priv->display.update_wm = vlv_update_wm; |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 7778 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Ville Syrjälä | 26e1fe4 | 2015-06-24 22:00:06 +0300 | [diff] [blame] | 7779 | vlv_setup_wm_latency(dev); |
Ville Syrjälä | 26e1fe4 | 2015-06-24 22:00:06 +0300 | [diff] [blame] | 7780 | dev_priv->display.update_wm = vlv_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7781 | } else if (IS_PINEVIEW(dev)) { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7782 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7783 | dev_priv->is_ddr3, |
| 7784 | dev_priv->fsb_freq, |
| 7785 | dev_priv->mem_freq)) { |
| 7786 | DRM_INFO("failed to find known CxSR latency " |
| 7787 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 7788 | "disabling CxSR\n", |
| 7789 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 7790 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 7791 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 7792 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7793 | dev_priv->display.update_wm = NULL; |
| 7794 | } else |
| 7795 | dev_priv->display.update_wm = pineview_update_wm; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7796 | } else if (IS_G4X(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7797 | dev_priv->display.update_wm = g4x_update_wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 7798 | } else if (IS_GEN4(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7799 | dev_priv->display.update_wm = i965_update_wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 7800 | } else if (IS_GEN3(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7801 | dev_priv->display.update_wm = i9xx_update_wm; |
| 7802 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 7803 | } else if (IS_GEN2(dev_priv)) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7804 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 7805 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7806 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7807 | } else { |
| 7808 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7809 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7810 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7811 | } else { |
| 7812 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7813 | } |
| 7814 | } |
| 7815 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 7816 | static inline int gen6_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 7817 | { |
| 7818 | uint32_t flags = |
| 7819 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 7820 | |
| 7821 | switch (flags) { |
| 7822 | case GEN6_PCODE_SUCCESS: |
| 7823 | return 0; |
| 7824 | case GEN6_PCODE_UNIMPLEMENTED_CMD: |
| 7825 | case GEN6_PCODE_ILLEGAL_CMD: |
| 7826 | return -ENXIO; |
| 7827 | case GEN6_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Chris Wilson | 7850d1c | 2016-08-26 11:59:26 +0100 | [diff] [blame] | 7828 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 7829 | return -EOVERFLOW; |
| 7830 | case GEN6_PCODE_TIMEOUT: |
| 7831 | return -ETIMEDOUT; |
| 7832 | default: |
| 7833 | MISSING_CASE(flags) |
| 7834 | return 0; |
| 7835 | } |
| 7836 | } |
| 7837 | |
| 7838 | static inline int gen7_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 7839 | { |
| 7840 | uint32_t flags = |
| 7841 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 7842 | |
| 7843 | switch (flags) { |
| 7844 | case GEN6_PCODE_SUCCESS: |
| 7845 | return 0; |
| 7846 | case GEN6_PCODE_ILLEGAL_CMD: |
| 7847 | return -ENXIO; |
| 7848 | case GEN7_PCODE_TIMEOUT: |
| 7849 | return -ETIMEDOUT; |
| 7850 | case GEN7_PCODE_ILLEGAL_DATA: |
| 7851 | return -EINVAL; |
| 7852 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
| 7853 | return -EOVERFLOW; |
| 7854 | default: |
| 7855 | MISSING_CASE(flags); |
| 7856 | return 0; |
| 7857 | } |
| 7858 | } |
| 7859 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 7860 | 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] | 7861 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 7862 | int status; |
| 7863 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7864 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7865 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7866 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 7867 | * use te fw I915_READ variants to reduce the amount of work |
| 7868 | * required when reading/writing. |
| 7869 | */ |
| 7870 | |
| 7871 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7872 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 7873 | return -EAGAIN; |
| 7874 | } |
| 7875 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7876 | I915_WRITE_FW(GEN6_PCODE_DATA, *val); |
| 7877 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
| 7878 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7879 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7880 | if (intel_wait_for_register_fw(dev_priv, |
| 7881 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 7882 | 500)) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7883 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 7884 | return -ETIMEDOUT; |
| 7885 | } |
| 7886 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7887 | *val = I915_READ_FW(GEN6_PCODE_DATA); |
| 7888 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7889 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 7890 | if (INTEL_GEN(dev_priv) > 6) |
| 7891 | status = gen7_check_mailbox_status(dev_priv); |
| 7892 | else |
| 7893 | status = gen6_check_mailbox_status(dev_priv); |
| 7894 | |
| 7895 | if (status) { |
| 7896 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed: %d\n", |
| 7897 | status); |
| 7898 | return status; |
| 7899 | } |
| 7900 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7901 | return 0; |
| 7902 | } |
| 7903 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7904 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 7905 | u32 mbox, u32 val) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7906 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 7907 | int status; |
| 7908 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7909 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7910 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7911 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 7912 | * use te fw I915_READ variants to reduce the amount of work |
| 7913 | * required when reading/writing. |
| 7914 | */ |
| 7915 | |
| 7916 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7917 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 7918 | return -EAGAIN; |
| 7919 | } |
| 7920 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7921 | I915_WRITE_FW(GEN6_PCODE_DATA, val); |
| 7922 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7923 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7924 | if (intel_wait_for_register_fw(dev_priv, |
| 7925 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 7926 | 500)) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7927 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 7928 | return -ETIMEDOUT; |
| 7929 | } |
| 7930 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 7931 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7932 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 7933 | if (INTEL_GEN(dev_priv) > 6) |
| 7934 | status = gen7_check_mailbox_status(dev_priv); |
| 7935 | else |
| 7936 | status = gen6_check_mailbox_status(dev_priv); |
| 7937 | |
| 7938 | if (status) { |
| 7939 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed: %d\n", |
| 7940 | status); |
| 7941 | return status; |
| 7942 | } |
| 7943 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7944 | return 0; |
| 7945 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 7946 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 7947 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 7948 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7949 | /* |
| 7950 | * N = val - 0xb7 |
| 7951 | * Slow = Fast = GPLL ref * N |
| 7952 | */ |
| 7953 | return DIV_ROUND_CLOSEST(dev_priv->rps.gpll_ref_freq * (val - 0xb7), 1000); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7954 | } |
| 7955 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7956 | 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] | 7957 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7958 | return DIV_ROUND_CLOSEST(1000 * val, dev_priv->rps.gpll_ref_freq) + 0xb7; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7959 | } |
| 7960 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7961 | 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] | 7962 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7963 | /* |
| 7964 | * N = val / 2 |
| 7965 | * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2 |
| 7966 | */ |
| 7967 | return DIV_ROUND_CLOSEST(dev_priv->rps.gpll_ref_freq * val, 2 * 2 * 1000); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 7968 | } |
| 7969 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7970 | 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] | 7971 | { |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7972 | /* CHV needs even values */ |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7973 | return DIV_ROUND_CLOSEST(2 * 1000 * val, dev_priv->rps.gpll_ref_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 7974 | } |
| 7975 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 7976 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 7977 | { |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 7978 | if (IS_GEN9(dev_priv)) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 7979 | return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, |
| 7980 | GEN9_FREQ_SCALER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 7981 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 7982 | return chv_gpu_freq(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 7983 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 7984 | return byt_gpu_freq(dev_priv, val); |
| 7985 | else |
| 7986 | return val * GT_FREQUENCY_MULTIPLIER; |
| 7987 | } |
| 7988 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 7989 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 7990 | { |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 7991 | if (IS_GEN9(dev_priv)) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 7992 | return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, |
| 7993 | GT_FREQUENCY_MULTIPLIER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 7994 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 7995 | return chv_freq_opcode(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 7996 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 7997 | return byt_freq_opcode(dev_priv, val); |
| 7998 | else |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 7999 | return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 8000 | } |
| 8001 | |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8002 | struct request_boost { |
| 8003 | struct work_struct work; |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 8004 | struct drm_i915_gem_request *req; |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8005 | }; |
| 8006 | |
| 8007 | static void __intel_rps_boost_work(struct work_struct *work) |
| 8008 | { |
| 8009 | struct request_boost *boost = container_of(work, struct request_boost, work); |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 8010 | struct drm_i915_gem_request *req = boost->req; |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8011 | |
Chris Wilson | f69a02c | 2016-07-01 17:23:16 +0100 | [diff] [blame] | 8012 | if (!i915_gem_request_completed(req)) |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 8013 | gen6_rps_boost(req->i915, NULL, req->emitted_jiffies); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8014 | |
Chris Wilson | e8a261e | 2016-07-20 13:31:49 +0100 | [diff] [blame] | 8015 | i915_gem_request_put(req); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8016 | kfree(boost); |
| 8017 | } |
| 8018 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 8019 | void intel_queue_rps_boost_for_request(struct drm_i915_gem_request *req) |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8020 | { |
| 8021 | struct request_boost *boost; |
| 8022 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 8023 | if (req == NULL || INTEL_GEN(req->i915) < 6) |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8024 | return; |
| 8025 | |
Chris Wilson | f69a02c | 2016-07-01 17:23:16 +0100 | [diff] [blame] | 8026 | if (i915_gem_request_completed(req)) |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 8027 | return; |
| 8028 | |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8029 | boost = kmalloc(sizeof(*boost), GFP_ATOMIC); |
| 8030 | if (boost == NULL) |
| 8031 | return; |
| 8032 | |
Chris Wilson | e8a261e | 2016-07-20 13:31:49 +0100 | [diff] [blame] | 8033 | boost->req = i915_gem_request_get(req); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8034 | |
| 8035 | INIT_WORK(&boost->work, __intel_rps_boost_work); |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 8036 | queue_work(req->i915->wq, &boost->work); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8037 | } |
| 8038 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 8039 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8040 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8041 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8042 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 8043 | mutex_init(&dev_priv->rps.hw_lock); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 8044 | spin_lock_init(&dev_priv->rps.client_lock); |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 8045 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 8046 | INIT_DELAYED_WORK(&dev_priv->rps.autoenable_work, |
| 8047 | __intel_autoenable_gt_powersave); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 8048 | INIT_LIST_HEAD(&dev_priv->rps.clients); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 8049 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 8050 | dev_priv->pm.suspended = false; |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 8051 | atomic_set(&dev_priv->pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8052 | } |