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 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 59 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 60 | { |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 61 | /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl */ |
| 62 | I915_WRITE(CHICKEN_PAR1_1, |
| 63 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 64 | |
| 65 | I915_WRITE(GEN8_CONFIG0, |
| 66 | I915_READ(GEN8_CONFIG0) | GEN9_DEFAULT_FIXES); |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 67 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 68 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk */ |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 69 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 70 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 71 | |
| 72 | /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl */ |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 73 | /* WaFbcWakeMemOn:skl,bxt,kbl,glk */ |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 74 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 75 | DISP_FBC_WM_DIS | |
| 76 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 77 | |
| 78 | /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl */ |
| 79 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 80 | ILK_DPFC_DISABLE_DUMMY0); |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 81 | } |
| 82 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 83 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 84 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 85 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 86 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 87 | /* WaDisableSDEUnitClockGating:bxt */ |
| 88 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 89 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 90 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 91 | /* |
| 92 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 93 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 94 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 95 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 96 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 100 | * to stay fully on. |
| 101 | */ |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 102 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 103 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 106 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 107 | { |
| 108 | gen9_init_clock_gating(dev_priv); |
| 109 | |
| 110 | /* |
| 111 | * WaDisablePWMClockGating:glk |
| 112 | * Backlight PWM may stop in the asserted state, causing backlight |
| 113 | * to stay fully on. |
| 114 | */ |
| 115 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 116 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Ander Conselvan de Oliveira | f4f4b59 | 2017-02-22 08:34:29 +0200 | [diff] [blame] | 117 | |
| 118 | /* WaDDIIOTimeout:glk */ |
| 119 | if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1)) { |
| 120 | u32 val = I915_READ(CHICKEN_MISC_2); |
| 121 | val &= ~(GLK_CL0_PWR_DOWN | |
| 122 | GLK_CL1_PWR_DOWN | |
| 123 | GLK_CL2_PWR_DOWN); |
| 124 | I915_WRITE(CHICKEN_MISC_2, val); |
| 125 | } |
| 126 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 129 | static void i915_pineview_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 130 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 131 | u32 tmp; |
| 132 | |
| 133 | tmp = I915_READ(CLKCFG); |
| 134 | |
| 135 | switch (tmp & CLKCFG_FSB_MASK) { |
| 136 | case CLKCFG_FSB_533: |
| 137 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 138 | break; |
| 139 | case CLKCFG_FSB_800: |
| 140 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 141 | break; |
| 142 | case CLKCFG_FSB_667: |
| 143 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 144 | break; |
| 145 | case CLKCFG_FSB_400: |
| 146 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 147 | break; |
| 148 | } |
| 149 | |
| 150 | switch (tmp & CLKCFG_MEM_MASK) { |
| 151 | case CLKCFG_MEM_533: |
| 152 | dev_priv->mem_freq = 533; |
| 153 | break; |
| 154 | case CLKCFG_MEM_667: |
| 155 | dev_priv->mem_freq = 667; |
| 156 | break; |
| 157 | case CLKCFG_MEM_800: |
| 158 | dev_priv->mem_freq = 800; |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | /* detect pineview DDR3 setting */ |
| 163 | tmp = I915_READ(CSHRDDR3CTL); |
| 164 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 165 | } |
| 166 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 167 | static void i915_ironlake_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 168 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 169 | u16 ddrpll, csipll; |
| 170 | |
| 171 | ddrpll = I915_READ16(DDRMPLL1); |
| 172 | csipll = I915_READ16(CSIPLL0); |
| 173 | |
| 174 | switch (ddrpll & 0xff) { |
| 175 | case 0xc: |
| 176 | dev_priv->mem_freq = 800; |
| 177 | break; |
| 178 | case 0x10: |
| 179 | dev_priv->mem_freq = 1066; |
| 180 | break; |
| 181 | case 0x14: |
| 182 | dev_priv->mem_freq = 1333; |
| 183 | break; |
| 184 | case 0x18: |
| 185 | dev_priv->mem_freq = 1600; |
| 186 | break; |
| 187 | default: |
| 188 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 189 | ddrpll & 0xff); |
| 190 | dev_priv->mem_freq = 0; |
| 191 | break; |
| 192 | } |
| 193 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 194 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 195 | |
| 196 | switch (csipll & 0x3ff) { |
| 197 | case 0x00c: |
| 198 | dev_priv->fsb_freq = 3200; |
| 199 | break; |
| 200 | case 0x00e: |
| 201 | dev_priv->fsb_freq = 3733; |
| 202 | break; |
| 203 | case 0x010: |
| 204 | dev_priv->fsb_freq = 4266; |
| 205 | break; |
| 206 | case 0x012: |
| 207 | dev_priv->fsb_freq = 4800; |
| 208 | break; |
| 209 | case 0x014: |
| 210 | dev_priv->fsb_freq = 5333; |
| 211 | break; |
| 212 | case 0x016: |
| 213 | dev_priv->fsb_freq = 5866; |
| 214 | break; |
| 215 | case 0x018: |
| 216 | dev_priv->fsb_freq = 6400; |
| 217 | break; |
| 218 | default: |
| 219 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 220 | csipll & 0x3ff); |
| 221 | dev_priv->fsb_freq = 0; |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 226 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 227 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 228 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 229 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 230 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 234 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 235 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 236 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 237 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 238 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 239 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 240 | |
| 241 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 242 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 243 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 244 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 245 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 246 | |
| 247 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 248 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 249 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 250 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 251 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 252 | |
| 253 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 254 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 255 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 256 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 257 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 258 | |
| 259 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 260 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 261 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 262 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 263 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 264 | |
| 265 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 266 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 267 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 268 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 269 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 270 | }; |
| 271 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 272 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 273 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 274 | int fsb, |
| 275 | int mem) |
| 276 | { |
| 277 | const struct cxsr_latency *latency; |
| 278 | int i; |
| 279 | |
| 280 | if (fsb == 0 || mem == 0) |
| 281 | return NULL; |
| 282 | |
| 283 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 284 | latency = &cxsr_latency_table[i]; |
| 285 | if (is_desktop == latency->is_desktop && |
| 286 | is_ddr3 == latency->is_ddr3 && |
| 287 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 288 | return latency; |
| 289 | } |
| 290 | |
| 291 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 292 | |
| 293 | return NULL; |
| 294 | } |
| 295 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 296 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 297 | { |
| 298 | u32 val; |
| 299 | |
| 300 | mutex_lock(&dev_priv->rps.hw_lock); |
| 301 | |
| 302 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 303 | if (enable) |
| 304 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 305 | else |
| 306 | val |= FORCE_DDR_HIGH_FREQ; |
| 307 | val &= ~FORCE_DDR_LOW_FREQ; |
| 308 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 309 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 310 | |
| 311 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 312 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 313 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 314 | |
| 315 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 316 | } |
| 317 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 318 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 319 | { |
| 320 | u32 val; |
| 321 | |
| 322 | mutex_lock(&dev_priv->rps.hw_lock); |
| 323 | |
| 324 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 325 | if (enable) |
| 326 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 327 | else |
| 328 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
| 329 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 330 | |
| 331 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 332 | } |
| 333 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 334 | #define FW_WM(value, plane) \ |
| 335 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 336 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 337 | static bool _intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 338 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 339 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 340 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 341 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 342 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 343 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 344 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 345 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 346 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 347 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 348 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 349 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 350 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 351 | val = I915_READ(DSPFW3); |
| 352 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 353 | if (enable) |
| 354 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 355 | else |
| 356 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 357 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 358 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 359 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 360 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 361 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 362 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 363 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 364 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 365 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 366 | /* |
| 367 | * FIXME can't find a bit like this for 915G, and |
| 368 | * and yet it does have the related watermark in |
| 369 | * FW_BLC_SELF. What's going on? |
| 370 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 371 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 372 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 373 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 374 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 375 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 376 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 377 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 378 | } |
| 379 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 380 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 381 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 382 | DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", |
| 383 | enableddisabled(enable), |
| 384 | enableddisabled(was_enabled)); |
| 385 | |
| 386 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 387 | } |
| 388 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 389 | /** |
| 390 | * intel_set_memory_cxsr - Configure CxSR state |
| 391 | * @dev_priv: i915 device |
| 392 | * @enable: Allow vs. disallow CxSR |
| 393 | * |
| 394 | * Allow or disallow the system to enter a special CxSR |
| 395 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 396 | * is that several display FIFOs may get combined into a single larger |
| 397 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 398 | * system to defer memory fetches longer, and the memory will enter |
| 399 | * self refresh. |
| 400 | * |
| 401 | * Note that enabling CxSR does not guarantee that the system enter |
| 402 | * this special mode, nor does it guarantee that the system stays |
| 403 | * in that mode once entered. So this just allows/disallows the system |
| 404 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 405 | * C-states will affect when/if the system actually enters/exits the |
| 406 | * CxSR mode. |
| 407 | * |
| 408 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 409 | * and the system is free to enter/exit memory self refresh at any time |
| 410 | * even when the use of CxSR has been disallowed. |
| 411 | * |
| 412 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 413 | * control registers will not get latched on vblank. Thus in order to |
| 414 | * guarantee the system will respond to changes in the plane registers |
| 415 | * we must always disallow CxSR prior to making changes to those registers. |
| 416 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 417 | * frame start which happens after vblank start (which is when the plane |
| 418 | * registers would get latched), so we can't proceed with the plane update |
| 419 | * during the same frame where we disallowed CxSR. |
| 420 | * |
| 421 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 422 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 423 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 424 | * Disallowing just CxSR is sufficient. |
| 425 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 426 | bool intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 427 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 428 | bool ret; |
| 429 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 430 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 431 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 432 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 433 | dev_priv->wm.vlv.cxsr = enable; |
| 434 | else if (IS_G4X(dev_priv)) |
| 435 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 436 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 437 | |
| 438 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 439 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 440 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 441 | /* |
| 442 | * Latency for FIFO fetches is dependent on several factors: |
| 443 | * - memory configuration (speed, channels) |
| 444 | * - chipset |
| 445 | * - current MCH state |
| 446 | * It can be fairly high in some situations, so here we assume a fairly |
| 447 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 448 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 449 | * and power consumption (set it too low to save power and we might see |
| 450 | * FIFO underruns and display "flicker"). |
| 451 | * |
| 452 | * A value of 5us seems to be a good balance; safe for very low end |
| 453 | * platforms but not overly aggressive on lower latency configs. |
| 454 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 455 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 456 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 457 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 458 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 459 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 460 | static void vlv_get_fifo_size(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 461 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 462 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 463 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 464 | struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 465 | enum pipe pipe = crtc->pipe; |
| 466 | int sprite0_start, sprite1_start; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 467 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 468 | switch (pipe) { |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 469 | uint32_t dsparb, dsparb2, dsparb3; |
| 470 | case PIPE_A: |
| 471 | dsparb = I915_READ(DSPARB); |
| 472 | dsparb2 = I915_READ(DSPARB2); |
| 473 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 474 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 475 | break; |
| 476 | case PIPE_B: |
| 477 | dsparb = I915_READ(DSPARB); |
| 478 | dsparb2 = I915_READ(DSPARB2); |
| 479 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 480 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 481 | break; |
| 482 | case PIPE_C: |
| 483 | dsparb2 = I915_READ(DSPARB2); |
| 484 | dsparb3 = I915_READ(DSPARB3); |
| 485 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 486 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 487 | break; |
| 488 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 489 | MISSING_CASE(pipe); |
| 490 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 491 | } |
| 492 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 493 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 494 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 495 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 496 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 497 | } |
| 498 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 499 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 500 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 501 | uint32_t dsparb = I915_READ(DSPARB); |
| 502 | int size; |
| 503 | |
| 504 | size = dsparb & 0x7f; |
| 505 | if (plane) |
| 506 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 507 | |
| 508 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 509 | plane ? "B" : "A", size); |
| 510 | |
| 511 | return size; |
| 512 | } |
| 513 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 514 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 515 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 516 | uint32_t dsparb = I915_READ(DSPARB); |
| 517 | int size; |
| 518 | |
| 519 | size = dsparb & 0x1ff; |
| 520 | if (plane) |
| 521 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 522 | size >>= 1; /* Convert to cachelines */ |
| 523 | |
| 524 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 525 | plane ? "B" : "A", size); |
| 526 | |
| 527 | return size; |
| 528 | } |
| 529 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 530 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 531 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 532 | uint32_t dsparb = I915_READ(DSPARB); |
| 533 | int size; |
| 534 | |
| 535 | size = dsparb & 0x7f; |
| 536 | size >>= 2; /* Convert to cachelines */ |
| 537 | |
| 538 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 539 | plane ? "B" : "A", |
| 540 | size); |
| 541 | |
| 542 | return size; |
| 543 | } |
| 544 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 545 | /* Pineview has different values for various configs */ |
| 546 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 547 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 548 | .max_wm = PINEVIEW_MAX_WM, |
| 549 | .default_wm = PINEVIEW_DFT_WM, |
| 550 | .guard_size = PINEVIEW_GUARD_WM, |
| 551 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 552 | }; |
| 553 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 554 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 555 | .max_wm = PINEVIEW_MAX_WM, |
| 556 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 557 | .guard_size = PINEVIEW_GUARD_WM, |
| 558 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 559 | }; |
| 560 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 561 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 562 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 563 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 564 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 565 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 566 | }; |
| 567 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 568 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 569 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 570 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 571 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 572 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 573 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 574 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 575 | .fifo_size = I965_CURSOR_FIFO, |
| 576 | .max_wm = I965_CURSOR_MAX_WM, |
| 577 | .default_wm = I965_CURSOR_DFT_WM, |
| 578 | .guard_size = 2, |
| 579 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 580 | }; |
| 581 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 582 | .fifo_size = I945_FIFO_SIZE, |
| 583 | .max_wm = I915_MAX_WM, |
| 584 | .default_wm = 1, |
| 585 | .guard_size = 2, |
| 586 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 587 | }; |
| 588 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 589 | .fifo_size = I915_FIFO_SIZE, |
| 590 | .max_wm = I915_MAX_WM, |
| 591 | .default_wm = 1, |
| 592 | .guard_size = 2, |
| 593 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 594 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 595 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 596 | .fifo_size = I855GM_FIFO_SIZE, |
| 597 | .max_wm = I915_MAX_WM, |
| 598 | .default_wm = 1, |
| 599 | .guard_size = 2, |
| 600 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 601 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 602 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 603 | .fifo_size = I855GM_FIFO_SIZE, |
| 604 | .max_wm = I915_MAX_WM/2, |
| 605 | .default_wm = 1, |
| 606 | .guard_size = 2, |
| 607 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 608 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 609 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 610 | .fifo_size = I830_FIFO_SIZE, |
| 611 | .max_wm = I915_MAX_WM, |
| 612 | .default_wm = 1, |
| 613 | .guard_size = 2, |
| 614 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 615 | }; |
| 616 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 617 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 618 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 619 | * @pixel_rate: Pipe pixel rate in kHz |
| 620 | * @cpp: Plane bytes per pixel |
| 621 | * @latency: Memory wakeup latency in 0.1us units |
| 622 | * |
| 623 | * Compute the watermark using the method 1 or "small buffer" |
| 624 | * formula. The caller may additonally add extra cachelines |
| 625 | * to account for TLB misses and clock crossings. |
| 626 | * |
| 627 | * This method is concerned with the short term drain rate |
| 628 | * of the FIFO, ie. it does not account for blanking periods |
| 629 | * which would effectively reduce the average drain rate across |
| 630 | * a longer period. The name "small" refers to the fact the |
| 631 | * FIFO is relatively small compared to the amount of data |
| 632 | * fetched. |
| 633 | * |
| 634 | * The FIFO level vs. time graph might look something like: |
| 635 | * |
| 636 | * |\ |\ |
| 637 | * | \ | \ |
| 638 | * __---__---__ (- plane active, _ blanking) |
| 639 | * -> time |
| 640 | * |
| 641 | * or perhaps like this: |
| 642 | * |
| 643 | * |\|\ |\|\ |
| 644 | * __----__----__ (- plane active, _ blanking) |
| 645 | * -> time |
| 646 | * |
| 647 | * Returns: |
| 648 | * The watermark in bytes |
| 649 | */ |
| 650 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 651 | unsigned int cpp, |
| 652 | unsigned int latency) |
| 653 | { |
| 654 | uint64_t ret; |
| 655 | |
| 656 | ret = (uint64_t) pixel_rate * cpp * latency; |
| 657 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 658 | |
| 659 | return ret; |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 664 | * @pixel_rate: Pipe pixel rate in kHz |
| 665 | * @htotal: Pipe horizontal total |
| 666 | * @width: Plane width in pixels |
| 667 | * @cpp: Plane bytes per pixel |
| 668 | * @latency: Memory wakeup latency in 0.1us units |
| 669 | * |
| 670 | * Compute the watermark using the method 2 or "large buffer" |
| 671 | * formula. The caller may additonally add extra cachelines |
| 672 | * to account for TLB misses and clock crossings. |
| 673 | * |
| 674 | * This method is concerned with the long term drain rate |
| 675 | * of the FIFO, ie. it does account for blanking periods |
| 676 | * which effectively reduce the average drain rate across |
| 677 | * a longer period. The name "large" refers to the fact the |
| 678 | * FIFO is relatively large compared to the amount of data |
| 679 | * fetched. |
| 680 | * |
| 681 | * The FIFO level vs. time graph might look something like: |
| 682 | * |
| 683 | * |\___ |\___ |
| 684 | * | \___ | \___ |
| 685 | * | \ | \ |
| 686 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 687 | * -> time |
| 688 | * |
| 689 | * Returns: |
| 690 | * The watermark in bytes |
| 691 | */ |
| 692 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 693 | unsigned int htotal, |
| 694 | unsigned int width, |
| 695 | unsigned int cpp, |
| 696 | unsigned int latency) |
| 697 | { |
| 698 | unsigned int ret; |
| 699 | |
| 700 | /* |
| 701 | * FIXME remove once all users are computing |
| 702 | * watermarks in the correct place. |
| 703 | */ |
| 704 | if (WARN_ON_ONCE(htotal == 0)) |
| 705 | htotal = 1; |
| 706 | |
| 707 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 708 | ret = (ret + 1) * width * cpp; |
| 709 | |
| 710 | return ret; |
| 711 | } |
| 712 | |
| 713 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 714 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 715 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 716 | * @wm: chip FIFO params |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 717 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 718 | * @latency_ns: memory latency for the platform |
| 719 | * |
| 720 | * Calculate the watermark level (the level at which the display plane will |
| 721 | * start fetching from memory again). Each chip has a different display |
| 722 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 723 | * in the correct intel_watermark_params structure. |
| 724 | * |
| 725 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 726 | * on the pixel size. When it reaches the watermark level, it'll start |
| 727 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 728 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 729 | * will occur, and a display engine hang could result. |
| 730 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 731 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 732 | const struct intel_watermark_params *wm, |
| 733 | int fifo_size, int cpp, |
| 734 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 735 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 736 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 737 | |
| 738 | /* |
| 739 | * Note: we need to make sure we don't overflow for various clock & |
| 740 | * latency values. |
| 741 | * clocks go from a few thousand to several hundred thousand. |
| 742 | * latency is usually a few thousand |
| 743 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 744 | entries = intel_wm_method1(pixel_rate, cpp, |
| 745 | latency_ns / 100); |
| 746 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 747 | wm->guard_size; |
| 748 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 749 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 750 | wm_size = fifo_size - entries; |
| 751 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 752 | |
| 753 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 754 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 755 | wm_size = wm->max_wm; |
| 756 | if (wm_size <= 0) |
| 757 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 758 | |
| 759 | /* |
| 760 | * Bspec seems to indicate that the value shouldn't be lower than |
| 761 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 762 | * Lets go for 8 which is the burst size since certain platforms |
| 763 | * already use a hardcoded 8 (which is what the spec says should be |
| 764 | * done). |
| 765 | */ |
| 766 | if (wm_size <= 8) |
| 767 | wm_size = 8; |
| 768 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 769 | return wm_size; |
| 770 | } |
| 771 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 772 | static bool is_disabling(int old, int new, int threshold) |
| 773 | { |
| 774 | return old >= threshold && new < threshold; |
| 775 | } |
| 776 | |
| 777 | static bool is_enabling(int old, int new, int threshold) |
| 778 | { |
| 779 | return old < threshold && new >= threshold; |
| 780 | } |
| 781 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 782 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 783 | { |
| 784 | return dev_priv->wm.max_level + 1; |
| 785 | } |
| 786 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 787 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 788 | const struct intel_plane_state *plane_state) |
| 789 | { |
| 790 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 791 | |
| 792 | /* FIXME check the 'enable' instead */ |
| 793 | if (!crtc_state->base.active) |
| 794 | return false; |
| 795 | |
| 796 | /* |
| 797 | * Treat cursor with fb as always visible since cursor updates |
| 798 | * can happen faster than the vrefresh rate, and the current |
| 799 | * watermark code doesn't handle that correctly. Cursor updates |
| 800 | * which set/clear the fb or change the cursor size are going |
| 801 | * to get throttled by intel_legacy_cursor_update() to work |
| 802 | * around this problem with the watermark code. |
| 803 | */ |
| 804 | if (plane->id == PLANE_CURSOR) |
| 805 | return plane_state->base.fb != NULL; |
| 806 | else |
| 807 | return plane_state->base.visible; |
| 808 | } |
| 809 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 810 | static struct intel_crtc *single_enabled_crtc(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 811 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 812 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 813 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 814 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 815 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 816 | if (enabled) |
| 817 | return NULL; |
| 818 | enabled = crtc; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | return enabled; |
| 823 | } |
| 824 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 825 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 826 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 827 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 828 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 829 | const struct cxsr_latency *latency; |
| 830 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 831 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 832 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 833 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
| 834 | dev_priv->is_ddr3, |
| 835 | dev_priv->fsb_freq, |
| 836 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 837 | if (!latency) { |
| 838 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 839 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 840 | return; |
| 841 | } |
| 842 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 843 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 844 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 845 | const struct drm_display_mode *adjusted_mode = |
| 846 | &crtc->config->base.adjusted_mode; |
| 847 | const struct drm_framebuffer *fb = |
| 848 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 849 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 850 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 851 | |
| 852 | /* Display SR */ |
| 853 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 854 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 855 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 856 | reg = I915_READ(DSPFW1); |
| 857 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 858 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 859 | I915_WRITE(DSPFW1, reg); |
| 860 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 861 | |
| 862 | /* cursor SR */ |
| 863 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 864 | pineview_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 865 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 866 | reg = I915_READ(DSPFW3); |
| 867 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 868 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 869 | I915_WRITE(DSPFW3, reg); |
| 870 | |
| 871 | /* Display HPLL off SR */ |
| 872 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 873 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 874 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 875 | reg = I915_READ(DSPFW3); |
| 876 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 877 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 878 | I915_WRITE(DSPFW3, reg); |
| 879 | |
| 880 | /* cursor HPLL off SR */ |
| 881 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 882 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 883 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 884 | reg = I915_READ(DSPFW3); |
| 885 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 886 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 887 | I915_WRITE(DSPFW3, reg); |
| 888 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 889 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 890 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 891 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 892 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 896 | /* |
| 897 | * Documentation says: |
| 898 | * "If the line size is small, the TLB fetches can get in the way of the |
| 899 | * data fetches, causing some lag in the pixel data return which is not |
| 900 | * accounted for in the above formulas. The following adjustment only |
| 901 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 902 | * The WM is adjusted upwards by the difference between the FIFO size |
| 903 | * and the size of 8 whole lines. This adjustment is always performed |
| 904 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 905 | */ |
| 906 | static int g4x_tlb_miss_wa(int fifo_size, int width, int cpp) |
| 907 | { |
| 908 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 909 | |
| 910 | return max(0, tlb_miss); |
| 911 | } |
| 912 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 913 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 914 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 915 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 916 | enum pipe pipe; |
| 917 | |
| 918 | for_each_pipe(dev_priv, pipe) |
| 919 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 920 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 921 | I915_WRITE(DSPFW1, |
| 922 | FW_WM(wm->sr.plane, SR) | |
| 923 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 924 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 925 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 926 | I915_WRITE(DSPFW2, |
| 927 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 928 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 929 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 930 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 931 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 932 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 933 | I915_WRITE(DSPFW3, |
| 934 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 935 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 936 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 937 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 938 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 939 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 940 | } |
| 941 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 942 | #define FW_WM_VLV(value, plane) \ |
| 943 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 944 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 945 | static void vlv_write_wm_values(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 946 | const struct vlv_wm_values *wm) |
| 947 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 948 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 949 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 950 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 951 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 952 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 953 | I915_WRITE(VLV_DDL(pipe), |
| 954 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 955 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 956 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 957 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 958 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 959 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 960 | /* |
| 961 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 962 | * high order bits so that there are no out of bounds values |
| 963 | * present in the registers during the reprogramming. |
| 964 | */ |
| 965 | I915_WRITE(DSPHOWM, 0); |
| 966 | I915_WRITE(DSPHOWM1, 0); |
| 967 | I915_WRITE(DSPFW4, 0); |
| 968 | I915_WRITE(DSPFW5, 0); |
| 969 | I915_WRITE(DSPFW6, 0); |
| 970 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 971 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 972 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 973 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 974 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 975 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 976 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 977 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 978 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 979 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 980 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 981 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 982 | |
| 983 | if (IS_CHERRYVIEW(dev_priv)) { |
| 984 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 985 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 986 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 987 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 988 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 989 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 990 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 991 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 992 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 993 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 994 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 995 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 996 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 997 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 998 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 999 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1000 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1001 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1002 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1003 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY] >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1004 | } else { |
| 1005 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1006 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1007 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1008 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1009 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1010 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1011 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1012 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1013 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1014 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1015 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY] >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1019 | } |
| 1020 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1021 | #undef FW_WM_VLV |
| 1022 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1023 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1024 | { |
| 1025 | /* all latencies in usec */ |
| 1026 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1027 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1028 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1029 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1030 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1034 | { |
| 1035 | /* |
| 1036 | * DSPCNTR[13] supposedly controls whether the |
| 1037 | * primary plane can use the FIFO space otherwise |
| 1038 | * reserved for the sprite plane. It's not 100% clear |
| 1039 | * what the actual FIFO size is, but it looks like we |
| 1040 | * can happily set both primary and sprite watermarks |
| 1041 | * up to 127 cachelines. So that would seem to mean |
| 1042 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1043 | * the total FIFO is >= 256 cachelines in size. Either |
| 1044 | * way, we don't seem to have to worry about this |
| 1045 | * repartitioning as the maximum watermark value the |
| 1046 | * register can hold for each plane is lower than the |
| 1047 | * minimum FIFO size. |
| 1048 | */ |
| 1049 | switch (plane_id) { |
| 1050 | case PLANE_CURSOR: |
| 1051 | return 63; |
| 1052 | case PLANE_PRIMARY: |
| 1053 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1054 | case PLANE_SPRITE0: |
| 1055 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1056 | default: |
| 1057 | MISSING_CASE(plane_id); |
| 1058 | return 0; |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | static int g4x_fbc_fifo_size(int level) |
| 1063 | { |
| 1064 | switch (level) { |
| 1065 | case G4X_WM_LEVEL_SR: |
| 1066 | return 7; |
| 1067 | case G4X_WM_LEVEL_HPLL: |
| 1068 | return 15; |
| 1069 | default: |
| 1070 | MISSING_CASE(level); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | static uint16_t g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1076 | const struct intel_plane_state *plane_state, |
| 1077 | int level) |
| 1078 | { |
| 1079 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1080 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 1081 | const struct drm_display_mode *adjusted_mode = |
| 1082 | &crtc_state->base.adjusted_mode; |
| 1083 | int clock, htotal, cpp, width, wm; |
| 1084 | int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1085 | |
| 1086 | if (latency == 0) |
| 1087 | return USHRT_MAX; |
| 1088 | |
| 1089 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1090 | return 0; |
| 1091 | |
| 1092 | /* |
| 1093 | * Not 100% sure which way ELK should go here as the |
| 1094 | * spec only says CL/CTG should assume 32bpp and BW |
| 1095 | * doesn't need to. But as these things followed the |
| 1096 | * mobile vs. desktop lines on gen3 as well, let's |
| 1097 | * assume ELK doesn't need this. |
| 1098 | * |
| 1099 | * The spec also fails to list such a restriction for |
| 1100 | * the HPLL watermark, which seems a little strange. |
| 1101 | * Let's use 32bpp for the HPLL watermark as well. |
| 1102 | */ |
| 1103 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1104 | level != G4X_WM_LEVEL_NORMAL) |
| 1105 | cpp = 4; |
| 1106 | else |
| 1107 | cpp = plane_state->base.fb->format->cpp[0]; |
| 1108 | |
| 1109 | clock = adjusted_mode->crtc_clock; |
| 1110 | htotal = adjusted_mode->crtc_htotal; |
| 1111 | |
| 1112 | if (plane->id == PLANE_CURSOR) |
| 1113 | width = plane_state->base.crtc_w; |
| 1114 | else |
| 1115 | width = drm_rect_width(&plane_state->base.dst); |
| 1116 | |
| 1117 | if (plane->id == PLANE_CURSOR) { |
| 1118 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1119 | } else if (plane->id == PLANE_PRIMARY && |
| 1120 | level == G4X_WM_LEVEL_NORMAL) { |
| 1121 | wm = intel_wm_method1(clock, cpp, latency); |
| 1122 | } else { |
| 1123 | int small, large; |
| 1124 | |
| 1125 | small = intel_wm_method1(clock, cpp, latency); |
| 1126 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1127 | |
| 1128 | wm = min(small, large); |
| 1129 | } |
| 1130 | |
| 1131 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1132 | width, cpp); |
| 1133 | |
| 1134 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1135 | |
| 1136 | return min_t(int, wm, USHRT_MAX); |
| 1137 | } |
| 1138 | |
| 1139 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1140 | int level, enum plane_id plane_id, u16 value) |
| 1141 | { |
| 1142 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1143 | bool dirty = false; |
| 1144 | |
| 1145 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1146 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1147 | |
| 1148 | dirty |= raw->plane[plane_id] != value; |
| 1149 | raw->plane[plane_id] = value; |
| 1150 | } |
| 1151 | |
| 1152 | return dirty; |
| 1153 | } |
| 1154 | |
| 1155 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1156 | int level, u16 value) |
| 1157 | { |
| 1158 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1159 | bool dirty = false; |
| 1160 | |
| 1161 | /* NORMAL level doesn't have an FBC watermark */ |
| 1162 | level = max(level, G4X_WM_LEVEL_SR); |
| 1163 | |
| 1164 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1165 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1166 | |
| 1167 | dirty |= raw->fbc != value; |
| 1168 | raw->fbc = value; |
| 1169 | } |
| 1170 | |
| 1171 | return dirty; |
| 1172 | } |
| 1173 | |
| 1174 | static uint32_t ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
| 1175 | const struct intel_plane_state *pstate, |
| 1176 | uint32_t pri_val); |
| 1177 | |
| 1178 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1179 | const struct intel_plane_state *plane_state) |
| 1180 | { |
| 1181 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1182 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1183 | enum plane_id plane_id = plane->id; |
| 1184 | bool dirty = false; |
| 1185 | int level; |
| 1186 | |
| 1187 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1188 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1189 | if (plane_id == PLANE_PRIMARY) |
| 1190 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1191 | goto out; |
| 1192 | } |
| 1193 | |
| 1194 | for (level = 0; level < num_levels; level++) { |
| 1195 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1196 | int wm, max_wm; |
| 1197 | |
| 1198 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1199 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1200 | |
| 1201 | if (wm > max_wm) |
| 1202 | break; |
| 1203 | |
| 1204 | dirty |= raw->plane[plane_id] != wm; |
| 1205 | raw->plane[plane_id] = wm; |
| 1206 | |
| 1207 | if (plane_id != PLANE_PRIMARY || |
| 1208 | level == G4X_WM_LEVEL_NORMAL) |
| 1209 | continue; |
| 1210 | |
| 1211 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1212 | raw->plane[plane_id]); |
| 1213 | max_wm = g4x_fbc_fifo_size(level); |
| 1214 | |
| 1215 | /* |
| 1216 | * FBC wm is not mandatory as we |
| 1217 | * can always just disable its use. |
| 1218 | */ |
| 1219 | if (wm > max_wm) |
| 1220 | wm = USHRT_MAX; |
| 1221 | |
| 1222 | dirty |= raw->fbc != wm; |
| 1223 | raw->fbc = wm; |
| 1224 | } |
| 1225 | |
| 1226 | /* mark watermarks as invalid */ |
| 1227 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1228 | |
| 1229 | if (plane_id == PLANE_PRIMARY) |
| 1230 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1231 | |
| 1232 | out: |
| 1233 | if (dirty) { |
| 1234 | DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1235 | plane->base.name, |
| 1236 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1237 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1238 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
| 1239 | |
| 1240 | if (plane_id == PLANE_PRIMARY) |
| 1241 | DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", |
| 1242 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1243 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
| 1244 | } |
| 1245 | |
| 1246 | return dirty; |
| 1247 | } |
| 1248 | |
| 1249 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1250 | enum plane_id plane_id, int level) |
| 1251 | { |
| 1252 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1253 | |
| 1254 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1255 | } |
| 1256 | |
| 1257 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1258 | int level) |
| 1259 | { |
| 1260 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1261 | |
| 1262 | if (level > dev_priv->wm.max_level) |
| 1263 | return false; |
| 1264 | |
| 1265 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1266 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1267 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1268 | } |
| 1269 | |
| 1270 | /* mark all levels starting from 'level' as invalid */ |
| 1271 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1272 | struct g4x_wm_state *wm_state, int level) |
| 1273 | { |
| 1274 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1275 | enum plane_id plane_id; |
| 1276 | |
| 1277 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1278 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1279 | } |
| 1280 | |
| 1281 | if (level <= G4X_WM_LEVEL_SR) { |
| 1282 | wm_state->cxsr = false; |
| 1283 | wm_state->sr.cursor = USHRT_MAX; |
| 1284 | wm_state->sr.plane = USHRT_MAX; |
| 1285 | wm_state->sr.fbc = USHRT_MAX; |
| 1286 | } |
| 1287 | |
| 1288 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1289 | wm_state->hpll_en = false; |
| 1290 | wm_state->hpll.cursor = USHRT_MAX; |
| 1291 | wm_state->hpll.plane = USHRT_MAX; |
| 1292 | wm_state->hpll.fbc = USHRT_MAX; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1297 | { |
| 1298 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1299 | struct intel_atomic_state *state = |
| 1300 | to_intel_atomic_state(crtc_state->base.state); |
| 1301 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 1302 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1303 | ~BIT(PLANE_CURSOR)); |
| 1304 | const struct g4x_pipe_wm *raw; |
| 1305 | struct intel_plane_state *plane_state; |
| 1306 | struct intel_plane *plane; |
| 1307 | enum plane_id plane_id; |
| 1308 | int i, level; |
| 1309 | unsigned int dirty = 0; |
| 1310 | |
| 1311 | for_each_intel_plane_in_state(state, plane, plane_state, i) { |
| 1312 | const struct intel_plane_state *old_plane_state = |
| 1313 | to_intel_plane_state(plane->base.state); |
| 1314 | |
| 1315 | if (plane_state->base.crtc != &crtc->base && |
| 1316 | old_plane_state->base.crtc != &crtc->base) |
| 1317 | continue; |
| 1318 | |
| 1319 | if (g4x_raw_plane_wm_compute(crtc_state, plane_state)) |
| 1320 | dirty |= BIT(plane->id); |
| 1321 | } |
| 1322 | |
| 1323 | if (!dirty) |
| 1324 | return 0; |
| 1325 | |
| 1326 | level = G4X_WM_LEVEL_NORMAL; |
| 1327 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1328 | goto out; |
| 1329 | |
| 1330 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1331 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1332 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1333 | |
| 1334 | level = G4X_WM_LEVEL_SR; |
| 1335 | |
| 1336 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1337 | goto out; |
| 1338 | |
| 1339 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1340 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1341 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1342 | wm_state->sr.fbc = raw->fbc; |
| 1343 | |
| 1344 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1345 | |
| 1346 | level = G4X_WM_LEVEL_HPLL; |
| 1347 | |
| 1348 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1349 | goto out; |
| 1350 | |
| 1351 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1352 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1353 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1354 | wm_state->hpll.fbc = raw->fbc; |
| 1355 | |
| 1356 | wm_state->hpll_en = wm_state->cxsr; |
| 1357 | |
| 1358 | level++; |
| 1359 | |
| 1360 | out: |
| 1361 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1362 | return -EINVAL; |
| 1363 | |
| 1364 | /* invalidate the higher levels */ |
| 1365 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1366 | |
| 1367 | /* |
| 1368 | * Determine if the FBC watermark(s) can be used. IF |
| 1369 | * this isn't the case we prefer to disable the FBC |
| 1370 | ( watermark(s) rather than disable the SR/HPLL |
| 1371 | * level(s) entirely. |
| 1372 | */ |
| 1373 | wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL; |
| 1374 | |
| 1375 | if (level >= G4X_WM_LEVEL_SR && |
| 1376 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1377 | wm_state->fbc_en = false; |
| 1378 | else if (level >= G4X_WM_LEVEL_HPLL && |
| 1379 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1380 | wm_state->fbc_en = false; |
| 1381 | |
| 1382 | return 0; |
| 1383 | } |
| 1384 | |
| 1385 | static int g4x_compute_intermediate_wm(struct drm_device *dev, |
| 1386 | struct intel_crtc *crtc, |
| 1387 | struct intel_crtc_state *crtc_state) |
| 1388 | { |
| 1389 | struct g4x_wm_state *intermediate = &crtc_state->wm.g4x.intermediate; |
| 1390 | const struct g4x_wm_state *optimal = &crtc_state->wm.g4x.optimal; |
| 1391 | const struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 1392 | enum plane_id plane_id; |
| 1393 | |
| 1394 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
| 1395 | !crtc_state->disable_cxsr; |
| 1396 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
| 1397 | !crtc_state->disable_cxsr; |
| 1398 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1399 | |
| 1400 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1401 | intermediate->wm.plane[plane_id] = |
| 1402 | max(optimal->wm.plane[plane_id], |
| 1403 | active->wm.plane[plane_id]); |
| 1404 | |
| 1405 | WARN_ON(intermediate->wm.plane[plane_id] > |
| 1406 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
| 1407 | } |
| 1408 | |
| 1409 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1410 | active->sr.plane); |
| 1411 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1412 | active->sr.cursor); |
| 1413 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1414 | active->sr.fbc); |
| 1415 | |
| 1416 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1417 | active->hpll.plane); |
| 1418 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1419 | active->hpll.cursor); |
| 1420 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1421 | active->hpll.fbc); |
| 1422 | |
| 1423 | WARN_ON((intermediate->sr.plane > |
| 1424 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1425 | intermediate->sr.cursor > |
| 1426 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1427 | intermediate->cxsr); |
| 1428 | WARN_ON((intermediate->sr.plane > |
| 1429 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1430 | intermediate->sr.cursor > |
| 1431 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1432 | intermediate->hpll_en); |
| 1433 | |
| 1434 | WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1435 | intermediate->fbc_en && intermediate->cxsr); |
| 1436 | WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1437 | intermediate->fbc_en && intermediate->hpll_en); |
| 1438 | |
| 1439 | /* |
| 1440 | * If our intermediate WM are identical to the final WM, then we can |
| 1441 | * omit the post-vblank programming; only update if it's different. |
| 1442 | */ |
| 1443 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
| 1444 | crtc_state->wm.need_postvbl_update = true; |
| 1445 | |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
| 1449 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1450 | struct g4x_wm_values *wm) |
| 1451 | { |
| 1452 | struct intel_crtc *crtc; |
| 1453 | int num_active_crtcs = 0; |
| 1454 | |
| 1455 | wm->cxsr = true; |
| 1456 | wm->hpll_en = true; |
| 1457 | wm->fbc_en = true; |
| 1458 | |
| 1459 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1460 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1461 | |
| 1462 | if (!crtc->active) |
| 1463 | continue; |
| 1464 | |
| 1465 | if (!wm_state->cxsr) |
| 1466 | wm->cxsr = false; |
| 1467 | if (!wm_state->hpll_en) |
| 1468 | wm->hpll_en = false; |
| 1469 | if (!wm_state->fbc_en) |
| 1470 | wm->fbc_en = false; |
| 1471 | |
| 1472 | num_active_crtcs++; |
| 1473 | } |
| 1474 | |
| 1475 | if (num_active_crtcs != 1) { |
| 1476 | wm->cxsr = false; |
| 1477 | wm->hpll_en = false; |
| 1478 | wm->fbc_en = false; |
| 1479 | } |
| 1480 | |
| 1481 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1482 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1483 | enum pipe pipe = crtc->pipe; |
| 1484 | |
| 1485 | wm->pipe[pipe] = wm_state->wm; |
| 1486 | if (crtc->active && wm->cxsr) |
| 1487 | wm->sr = wm_state->sr; |
| 1488 | if (crtc->active && wm->hpll_en) |
| 1489 | wm->hpll = wm_state->hpll; |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1494 | { |
| 1495 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1496 | struct g4x_wm_values new_wm = {}; |
| 1497 | |
| 1498 | g4x_merge_wm(dev_priv, &new_wm); |
| 1499 | |
| 1500 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1501 | return; |
| 1502 | |
| 1503 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1504 | _intel_set_memory_cxsr(dev_priv, false); |
| 1505 | |
| 1506 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1507 | |
| 1508 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1509 | _intel_set_memory_cxsr(dev_priv, true); |
| 1510 | |
| 1511 | *old_wm = new_wm; |
| 1512 | } |
| 1513 | |
| 1514 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
| 1515 | struct intel_crtc_state *crtc_state) |
| 1516 | { |
| 1517 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1518 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1519 | |
| 1520 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1521 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1522 | g4x_program_watermarks(dev_priv); |
| 1523 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1524 | } |
| 1525 | |
| 1526 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
| 1527 | struct intel_crtc_state *crtc_state) |
| 1528 | { |
| 1529 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1530 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1531 | |
| 1532 | if (!crtc_state->wm.need_postvbl_update) |
| 1533 | return; |
| 1534 | |
| 1535 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1536 | intel_crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 1537 | g4x_program_watermarks(dev_priv); |
| 1538 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1539 | } |
| 1540 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1541 | /* latency must be in 0.1us units. */ |
| 1542 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1543 | unsigned int htotal, |
| 1544 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1545 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1546 | unsigned int latency) |
| 1547 | { |
| 1548 | unsigned int ret; |
| 1549 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1550 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1551 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1552 | ret = DIV_ROUND_UP(ret, 64); |
| 1553 | |
| 1554 | return ret; |
| 1555 | } |
| 1556 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1557 | static void vlv_setup_wm_latency(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1558 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1559 | /* all latencies in usec */ |
| 1560 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1561 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1562 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1563 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1564 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1565 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1566 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1567 | |
| 1568 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1572 | static uint16_t vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1573 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1574 | int level) |
| 1575 | { |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1576 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1577 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1578 | const struct drm_display_mode *adjusted_mode = |
| 1579 | &crtc_state->base.adjusted_mode; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1580 | int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1581 | |
| 1582 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1583 | return USHRT_MAX; |
| 1584 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1585 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1586 | return 0; |
| 1587 | |
Daniel Vetter | ef426c1 | 2017-01-04 11:41:10 +0100 | [diff] [blame] | 1588 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1589 | clock = adjusted_mode->crtc_clock; |
| 1590 | htotal = adjusted_mode->crtc_htotal; |
| 1591 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1592 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1593 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1594 | /* |
| 1595 | * FIXME the formula gives values that are |
| 1596 | * too big for the cursor FIFO, and hence we |
| 1597 | * would never be able to use cursors. For |
| 1598 | * now just hardcode the watermark. |
| 1599 | */ |
| 1600 | wm = 63; |
| 1601 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1602 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1603 | dev_priv->wm.pri_latency[level] * 10); |
| 1604 | } |
| 1605 | |
| 1606 | return min_t(int, wm, USHRT_MAX); |
| 1607 | } |
| 1608 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1609 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1610 | { |
| 1611 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1612 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1613 | } |
| 1614 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1615 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1616 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1617 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1618 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1619 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1620 | struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1621 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1622 | int num_active_planes = hweight32(active_planes); |
| 1623 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1624 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1625 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1626 | unsigned int total_rate; |
| 1627 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1628 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1629 | /* |
| 1630 | * When enabling sprite0 after sprite1 has already been enabled |
| 1631 | * we tend to get an underrun unless sprite0 already has some |
| 1632 | * FIFO space allcoated. Hence we always allocate at least one |
| 1633 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1634 | * |
| 1635 | * All other plane enable sequences appear immune to this problem. |
| 1636 | */ |
| 1637 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1638 | sprite0_fifo_extra = 1; |
| 1639 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1640 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1641 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1642 | raw->plane[PLANE_SPRITE1] + |
| 1643 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1644 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1645 | if (total_rate > fifo_size) |
| 1646 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1647 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1648 | if (total_rate == 0) |
| 1649 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1650 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1651 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1652 | unsigned int rate; |
| 1653 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1654 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1655 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1656 | continue; |
| 1657 | } |
| 1658 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1659 | rate = raw->plane[plane_id]; |
| 1660 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1661 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1662 | } |
| 1663 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1664 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1665 | fifo_left -= sprite0_fifo_extra; |
| 1666 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1667 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1668 | |
| 1669 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1670 | |
| 1671 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1672 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1673 | int plane_extra; |
| 1674 | |
| 1675 | if (fifo_left == 0) |
| 1676 | break; |
| 1677 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1678 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1679 | continue; |
| 1680 | |
| 1681 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1682 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1683 | fifo_left -= plane_extra; |
| 1684 | } |
| 1685 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1686 | WARN_ON(active_planes != 0 && fifo_left != 0); |
| 1687 | |
| 1688 | /* give it all to the first plane if none are active */ |
| 1689 | if (active_planes == 0) { |
| 1690 | WARN_ON(fifo_left != fifo_size); |
| 1691 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1692 | } |
| 1693 | |
| 1694 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1695 | } |
| 1696 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1697 | /* mark all levels starting from 'level' as invalid */ |
| 1698 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1699 | struct vlv_wm_state *wm_state, int level) |
| 1700 | { |
| 1701 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1702 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1703 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1704 | enum plane_id plane_id; |
| 1705 | |
| 1706 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1707 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1708 | |
| 1709 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1710 | wm_state->sr[level].plane = USHRT_MAX; |
| 1711 | } |
| 1712 | } |
| 1713 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1714 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1715 | { |
| 1716 | if (wm > fifo_size) |
| 1717 | return USHRT_MAX; |
| 1718 | else |
| 1719 | return fifo_size - wm; |
| 1720 | } |
| 1721 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1722 | /* |
| 1723 | * Starting from 'level' set all higher |
| 1724 | * levels to 'value' in the "raw" watermarks. |
| 1725 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1726 | static bool vlv_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1727 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1728 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1729 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1730 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1731 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1732 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1733 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1734 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1735 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1736 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1737 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1738 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1739 | |
| 1740 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1741 | } |
| 1742 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1743 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1744 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1745 | { |
| 1746 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1747 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1748 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1749 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1750 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1751 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1752 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1753 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1754 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1758 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1759 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1760 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1761 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1762 | if (wm > max_wm) |
| 1763 | break; |
| 1764 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1765 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1766 | raw->plane[plane_id] = wm; |
| 1767 | } |
| 1768 | |
| 1769 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1770 | dirty |= vlv_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1771 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1772 | out: |
| 1773 | if (dirty) |
Ville Syrjälä | 57a6528 | 2017-04-21 21:14:22 +0300 | [diff] [blame] | 1774 | DRM_DEBUG_KMS("%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n", |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1775 | plane->base.name, |
| 1776 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1777 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1778 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
| 1779 | |
| 1780 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1781 | } |
| 1782 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1783 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1784 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1785 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1786 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1787 | &crtc_state->wm.vlv.raw[level]; |
| 1788 | const struct vlv_fifo_state *fifo_state = |
| 1789 | &crtc_state->wm.vlv.fifo_state; |
| 1790 | |
| 1791 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1792 | } |
| 1793 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1794 | static bool vlv_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1795 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1796 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1797 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1798 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1799 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static int vlv_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1803 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1804 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1805 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1806 | struct intel_atomic_state *state = |
| 1807 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1808 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1809 | const struct vlv_fifo_state *fifo_state = |
| 1810 | &crtc_state->wm.vlv.fifo_state; |
| 1811 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1812 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1813 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->base); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1814 | struct intel_plane_state *plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1815 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1816 | enum plane_id plane_id; |
| 1817 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1818 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1819 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1820 | for_each_intel_plane_in_state(state, plane, plane_state, i) { |
| 1821 | const struct intel_plane_state *old_plane_state = |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1822 | to_intel_plane_state(plane->base.state); |
| 1823 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1824 | if (plane_state->base.crtc != &crtc->base && |
| 1825 | old_plane_state->base.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1826 | continue; |
| 1827 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1828 | if (vlv_raw_plane_wm_compute(crtc_state, plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1829 | dirty |= BIT(plane->id); |
| 1830 | } |
| 1831 | |
| 1832 | /* |
| 1833 | * DSPARB registers may have been reset due to the |
| 1834 | * power well being turned off. Make sure we restore |
| 1835 | * them to a consistent state even if no primary/sprite |
| 1836 | * planes are initially active. |
| 1837 | */ |
| 1838 | if (needs_modeset) |
| 1839 | crtc_state->fifo_changed = true; |
| 1840 | |
| 1841 | if (!dirty) |
| 1842 | return 0; |
| 1843 | |
| 1844 | /* cursor changes don't warrant a FIFO recompute */ |
| 1845 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1846 | const struct intel_crtc_state *old_crtc_state = |
| 1847 | to_intel_crtc_state(crtc->base.state); |
| 1848 | const struct vlv_fifo_state *old_fifo_state = |
| 1849 | &old_crtc_state->wm.vlv.fifo_state; |
| 1850 | |
| 1851 | ret = vlv_compute_fifo(crtc_state); |
| 1852 | if (ret) |
| 1853 | return ret; |
| 1854 | |
| 1855 | if (needs_modeset || |
| 1856 | memcmp(old_fifo_state, fifo_state, |
| 1857 | sizeof(*fifo_state)) != 0) |
| 1858 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1859 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1860 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1861 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1862 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1863 | /* |
| 1864 | * Note that enabling cxsr with no primary/sprite planes |
| 1865 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1866 | * with exactly one enabled primary/sprite plane. |
| 1867 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1868 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1869 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1870 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1871 | const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1872 | const int sr_fifo_size = INTEL_INFO(dev_priv)->num_pipes * 512 - 1; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1873 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1874 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1875 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1876 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1877 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1878 | wm_state->wm[level].plane[plane_id] = |
| 1879 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1880 | fifo_state->plane[plane_id]); |
| 1881 | } |
| 1882 | |
| 1883 | wm_state->sr[level].plane = |
| 1884 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1885 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1886 | raw->plane[PLANE_SPRITE1]), |
| 1887 | sr_fifo_size); |
| 1888 | |
| 1889 | wm_state->sr[level].cursor = |
| 1890 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1891 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1892 | } |
| 1893 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1894 | if (level == 0) |
| 1895 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1896 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1897 | /* limit to only levels we can actually handle */ |
| 1898 | wm_state->num_levels = level; |
| 1899 | |
| 1900 | /* invalidate the higher levels */ |
| 1901 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1902 | |
| 1903 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1904 | } |
| 1905 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1906 | #define VLV_FIFO(plane, value) \ |
| 1907 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1908 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1909 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
| 1910 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1911 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1912 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1913 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1914 | const struct vlv_fifo_state *fifo_state = |
| 1915 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1916 | int sprite0_start, sprite1_start, fifo_size; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1917 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1918 | if (!crtc_state->fifo_changed) |
| 1919 | return; |
| 1920 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1921 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 1922 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 1923 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1924 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1925 | WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63); |
| 1926 | WARN_ON(fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1927 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1928 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 1929 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1930 | /* |
| 1931 | * uncore.lock serves a double purpose here. It allows us to |
| 1932 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 1933 | * it protects the DSPARB registers from getting clobbered by |
| 1934 | * parallel updates from multiple pipes. |
| 1935 | * |
| 1936 | * intel_pipe_update_start() has already disabled interrupts |
| 1937 | * for us, so a plain spin_lock() is sufficient here. |
| 1938 | */ |
| 1939 | spin_lock(&dev_priv->uncore.lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1940 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1941 | switch (crtc->pipe) { |
| 1942 | uint32_t dsparb, dsparb2, dsparb3; |
| 1943 | case PIPE_A: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1944 | dsparb = I915_READ_FW(DSPARB); |
| 1945 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1946 | |
| 1947 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1948 | VLV_FIFO(SPRITEB, 0xff)); |
| 1949 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1950 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1951 | |
| 1952 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1953 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1954 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1955 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1956 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1957 | I915_WRITE_FW(DSPARB, dsparb); |
| 1958 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1959 | break; |
| 1960 | case PIPE_B: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1961 | dsparb = I915_READ_FW(DSPARB); |
| 1962 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1963 | |
| 1964 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 1965 | VLV_FIFO(SPRITED, 0xff)); |
| 1966 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 1967 | VLV_FIFO(SPRITED, sprite1_start)); |
| 1968 | |
| 1969 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 1970 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 1971 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 1972 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 1973 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1974 | I915_WRITE_FW(DSPARB, dsparb); |
| 1975 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1976 | break; |
| 1977 | case PIPE_C: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1978 | dsparb3 = I915_READ_FW(DSPARB3); |
| 1979 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1980 | |
| 1981 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 1982 | VLV_FIFO(SPRITEF, 0xff)); |
| 1983 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 1984 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 1985 | |
| 1986 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 1987 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 1988 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 1989 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 1990 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1991 | I915_WRITE_FW(DSPARB3, dsparb3); |
| 1992 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1993 | break; |
| 1994 | default: |
| 1995 | break; |
| 1996 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1997 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1998 | POSTING_READ_FW(DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1999 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2000 | spin_unlock(&dev_priv->uncore.lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | #undef VLV_FIFO |
| 2004 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2005 | static int vlv_compute_intermediate_wm(struct drm_device *dev, |
| 2006 | struct intel_crtc *crtc, |
| 2007 | struct intel_crtc_state *crtc_state) |
| 2008 | { |
| 2009 | struct vlv_wm_state *intermediate = &crtc_state->wm.vlv.intermediate; |
| 2010 | const struct vlv_wm_state *optimal = &crtc_state->wm.vlv.optimal; |
| 2011 | const struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 2012 | int level; |
| 2013 | |
| 2014 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2015 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
| 2016 | !crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2017 | |
| 2018 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2019 | enum plane_id plane_id; |
| 2020 | |
| 2021 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2022 | intermediate->wm[level].plane[plane_id] = |
| 2023 | min(optimal->wm[level].plane[plane_id], |
| 2024 | active->wm[level].plane[plane_id]); |
| 2025 | } |
| 2026 | |
| 2027 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2028 | active->sr[level].plane); |
| 2029 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2030 | active->sr[level].cursor); |
| 2031 | } |
| 2032 | |
| 2033 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2034 | |
| 2035 | /* |
| 2036 | * If our intermediate WM are identical to the final WM, then we can |
| 2037 | * omit the post-vblank programming; only update if it's different. |
| 2038 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2039 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
| 2040 | crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2041 | |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2045 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2046 | struct vlv_wm_values *wm) |
| 2047 | { |
| 2048 | struct intel_crtc *crtc; |
| 2049 | int num_active_crtcs = 0; |
| 2050 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2051 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2052 | wm->cxsr = true; |
| 2053 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2054 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2055 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2056 | |
| 2057 | if (!crtc->active) |
| 2058 | continue; |
| 2059 | |
| 2060 | if (!wm_state->cxsr) |
| 2061 | wm->cxsr = false; |
| 2062 | |
| 2063 | num_active_crtcs++; |
| 2064 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2065 | } |
| 2066 | |
| 2067 | if (num_active_crtcs != 1) |
| 2068 | wm->cxsr = false; |
| 2069 | |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2070 | if (num_active_crtcs > 1) |
| 2071 | wm->level = VLV_WM_LEVEL_PM2; |
| 2072 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2073 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2074 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2075 | enum pipe pipe = crtc->pipe; |
| 2076 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2077 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2078 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2079 | wm->sr = wm_state->sr[wm->level]; |
| 2080 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2081 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2082 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2083 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2084 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2085 | } |
| 2086 | } |
| 2087 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2088 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2089 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2090 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2091 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2092 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2093 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2094 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2095 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2096 | return; |
| 2097 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2098 | if (is_disabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_DDR_DVFS)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2099 | chv_set_memory_dvfs(dev_priv, false); |
| 2100 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2101 | if (is_disabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_PM5)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2102 | chv_set_memory_pm5(dev_priv, false); |
| 2103 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2104 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2105 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2106 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2107 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2108 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2109 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2110 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2111 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2112 | if (is_enabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_PM5)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2113 | chv_set_memory_pm5(dev_priv, true); |
| 2114 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2115 | if (is_enabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_DDR_DVFS)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2116 | chv_set_memory_dvfs(dev_priv, true); |
| 2117 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2118 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2119 | } |
| 2120 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2121 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
| 2122 | struct intel_crtc_state *crtc_state) |
| 2123 | { |
| 2124 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2125 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2126 | |
| 2127 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2128 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2129 | vlv_program_watermarks(dev_priv); |
| 2130 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2131 | } |
| 2132 | |
| 2133 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
| 2134 | struct intel_crtc_state *crtc_state) |
| 2135 | { |
| 2136 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2137 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2138 | |
| 2139 | if (!crtc_state->wm.need_postvbl_update) |
| 2140 | return; |
| 2141 | |
| 2142 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 2143 | intel_crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2144 | vlv_program_watermarks(dev_priv); |
| 2145 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2146 | } |
| 2147 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2148 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2149 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2150 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2151 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2152 | int srwm = 1; |
| 2153 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2154 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2155 | |
| 2156 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2157 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2158 | if (crtc) { |
| 2159 | /* self-refresh has much higher latency */ |
| 2160 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2161 | const struct drm_display_mode *adjusted_mode = |
| 2162 | &crtc->config->base.adjusted_mode; |
| 2163 | const struct drm_framebuffer *fb = |
| 2164 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2165 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2166 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2167 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2168 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2169 | int entries; |
| 2170 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2171 | entries = intel_wm_method2(clock, htotal, |
| 2172 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2173 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2174 | srwm = I965_FIFO_SIZE - entries; |
| 2175 | if (srwm < 0) |
| 2176 | srwm = 1; |
| 2177 | srwm &= 0x1ff; |
| 2178 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 2179 | entries, srwm); |
| 2180 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2181 | entries = intel_wm_method2(clock, htotal, |
| 2182 | crtc->base.cursor->state->crtc_w, 4, |
| 2183 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2184 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2185 | i965_cursor_wm_info.cacheline_size) + |
| 2186 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2187 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2188 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2189 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2190 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2191 | |
| 2192 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 2193 | "cursor %d\n", srwm, cursor_sr); |
| 2194 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2195 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2196 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2197 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2198 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2199 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2203 | srwm); |
| 2204 | |
| 2205 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2206 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2207 | FW_WM(8, CURSORB) | |
| 2208 | FW_WM(8, PLANEB) | |
| 2209 | FW_WM(8, PLANEA)); |
| 2210 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2211 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2212 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2213 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2214 | |
| 2215 | if (cxsr_enabled) |
| 2216 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2217 | } |
| 2218 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2219 | #undef FW_WM |
| 2220 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2221 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2222 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2223 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2224 | const struct intel_watermark_params *wm_info; |
| 2225 | uint32_t fwater_lo; |
| 2226 | uint32_t fwater_hi; |
| 2227 | int cwm, srwm = 1; |
| 2228 | int fifo_size; |
| 2229 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2230 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2231 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2232 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2233 | wm_info = &i945_wm_info; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2234 | else if (!IS_GEN2(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2235 | wm_info = &i915_wm_info; |
| 2236 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2237 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2238 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2239 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, 0); |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 2240 | crtc = intel_get_crtc_for_plane(dev_priv, 0); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2241 | if (intel_crtc_active(crtc)) { |
| 2242 | const struct drm_display_mode *adjusted_mode = |
| 2243 | &crtc->config->base.adjusted_mode; |
| 2244 | const struct drm_framebuffer *fb = |
| 2245 | crtc->base.primary->state->fb; |
| 2246 | int cpp; |
| 2247 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2248 | if (IS_GEN2(dev_priv)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2249 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2250 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2251 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2252 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2253 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2254 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2255 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2256 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2257 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2258 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2259 | if (planea_wm > (long)wm_info->max_wm) |
| 2260 | planea_wm = wm_info->max_wm; |
| 2261 | } |
| 2262 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2263 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2264 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2265 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2266 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, 1); |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 2267 | crtc = intel_get_crtc_for_plane(dev_priv, 1); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2268 | if (intel_crtc_active(crtc)) { |
| 2269 | const struct drm_display_mode *adjusted_mode = |
| 2270 | &crtc->config->base.adjusted_mode; |
| 2271 | const struct drm_framebuffer *fb = |
| 2272 | crtc->base.primary->state->fb; |
| 2273 | int cpp; |
| 2274 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2275 | if (IS_GEN2(dev_priv)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2276 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2277 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2278 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2279 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2280 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2281 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2282 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2283 | if (enabled == NULL) |
| 2284 | enabled = crtc; |
| 2285 | else |
| 2286 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2287 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2288 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2289 | if (planeb_wm > (long)wm_info->max_wm) |
| 2290 | planeb_wm = wm_info->max_wm; |
| 2291 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2292 | |
| 2293 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2294 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2295 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2296 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2297 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2298 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2299 | |
| 2300 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2301 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2302 | enabled = NULL; |
| 2303 | } |
| 2304 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2305 | /* |
| 2306 | * Overlay gets an aggressive default since video jitter is bad. |
| 2307 | */ |
| 2308 | cwm = 2; |
| 2309 | |
| 2310 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2311 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2312 | |
| 2313 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2314 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2315 | /* self-refresh has much higher latency */ |
| 2316 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2317 | const struct drm_display_mode *adjusted_mode = |
| 2318 | &enabled->config->base.adjusted_mode; |
| 2319 | const struct drm_framebuffer *fb = |
| 2320 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2321 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2322 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2323 | int hdisplay = enabled->config->pipe_src_w; |
| 2324 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2325 | int entries; |
| 2326 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2327 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2328 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2329 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2330 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2331 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2332 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2333 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2334 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 2335 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 2336 | srwm = wm_info->fifo_size - entries; |
| 2337 | if (srwm < 0) |
| 2338 | srwm = 1; |
| 2339 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2340 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2341 | I915_WRITE(FW_BLC_SELF, |
| 2342 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2343 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2344 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2345 | } |
| 2346 | |
| 2347 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2348 | planea_wm, planeb_wm, cwm, srwm); |
| 2349 | |
| 2350 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2351 | fwater_hi = (cwm & 0x1f); |
| 2352 | |
| 2353 | /* Set request length to 8 cachelines per fetch */ |
| 2354 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2355 | fwater_hi = fwater_hi | (1 << 8); |
| 2356 | |
| 2357 | I915_WRITE(FW_BLC, fwater_lo); |
| 2358 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2359 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2360 | if (enabled) |
| 2361 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2362 | } |
| 2363 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2364 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2365 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2366 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2367 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2368 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2369 | uint32_t fwater_lo; |
| 2370 | int planea_wm; |
| 2371 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2372 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2373 | if (crtc == NULL) |
| 2374 | return; |
| 2375 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2376 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2377 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2378 | &i845_wm_info, |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2379 | dev_priv->display.get_fifo_size(dev_priv, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2380 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2381 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2382 | fwater_lo |= (3<<8) | planea_wm; |
| 2383 | |
| 2384 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 2385 | |
| 2386 | I915_WRITE(FW_BLC, fwater_lo); |
| 2387 | } |
| 2388 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2389 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2390 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2391 | unsigned int cpp, |
| 2392 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2393 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2394 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2395 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2396 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2397 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2398 | |
| 2399 | return ret; |
| 2400 | } |
| 2401 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2402 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2403 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2404 | unsigned int htotal, |
| 2405 | unsigned int width, |
| 2406 | unsigned int cpp, |
| 2407 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2408 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2409 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2410 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2411 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2412 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2413 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2414 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2415 | return ret; |
| 2416 | } |
| 2417 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2418 | 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] | 2419 | uint8_t cpp) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2420 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2421 | /* |
| 2422 | * Neither of these should be possible since this function shouldn't be |
| 2423 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2424 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2425 | * elsewhere in the driver. |
| 2426 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2427 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2428 | return 0; |
| 2429 | if (WARN_ON(!horiz_pixels)) |
| 2430 | return 0; |
| 2431 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2432 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2433 | } |
| 2434 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2435 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2436 | uint16_t pri; |
| 2437 | uint16_t spr; |
| 2438 | uint16_t cur; |
| 2439 | uint16_t fbc; |
| 2440 | }; |
| 2441 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2442 | /* |
| 2443 | * For both WM_PIPE and WM_LP. |
| 2444 | * mem_value must be in 0.1us units. |
| 2445 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2446 | 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] | 2447 | const struct intel_plane_state *pstate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2448 | uint32_t mem_value, |
| 2449 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2450 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2451 | uint32_t method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2452 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2453 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2454 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2455 | return 0; |
| 2456 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2457 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2458 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2459 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2460 | |
| 2461 | if (!is_lp) |
| 2462 | return method1; |
| 2463 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2464 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2465 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2466 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2467 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2468 | |
| 2469 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2470 | } |
| 2471 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2472 | /* |
| 2473 | * For both WM_PIPE and WM_LP. |
| 2474 | * mem_value must be in 0.1us units. |
| 2475 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2476 | 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] | 2477 | const struct intel_plane_state *pstate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2478 | uint32_t mem_value) |
| 2479 | { |
| 2480 | uint32_t method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2481 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2482 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2483 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2484 | return 0; |
| 2485 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2486 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2487 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2488 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
| 2489 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2490 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2491 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2492 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2493 | return min(method1, method2); |
| 2494 | } |
| 2495 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2496 | /* |
| 2497 | * For both WM_PIPE and WM_LP. |
| 2498 | * mem_value must be in 0.1us units. |
| 2499 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2500 | 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] | 2501 | const struct intel_plane_state *pstate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2502 | uint32_t mem_value) |
| 2503 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2504 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2505 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2506 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2507 | return 0; |
| 2508 | |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2509 | cpp = pstate->base.fb->format->cpp[0]; |
| 2510 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2511 | return ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2512 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2513 | pstate->base.crtc_w, cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2514 | } |
| 2515 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2516 | /* Only for WM_LP. */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2517 | 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] | 2518 | const struct intel_plane_state *pstate, |
Ville Syrjälä | 1fda988 | 2013-07-05 11:57:19 +0300 | [diff] [blame] | 2519 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2520 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2521 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2522 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2523 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2524 | return 0; |
| 2525 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2526 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2527 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2528 | 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] | 2529 | } |
| 2530 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2531 | static unsigned int |
| 2532 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2533 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2534 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2535 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2536 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2537 | return 768; |
| 2538 | else |
| 2539 | return 512; |
| 2540 | } |
| 2541 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2542 | static unsigned int |
| 2543 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2544 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2545 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2546 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2547 | /* BDW primary/sprite plane watermarks */ |
| 2548 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2549 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2550 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2551 | return level == 0 ? 127 : 1023; |
| 2552 | else if (!is_sprite) |
| 2553 | /* ILK/SNB primary plane watermarks */ |
| 2554 | return level == 0 ? 127 : 511; |
| 2555 | else |
| 2556 | /* ILK/SNB sprite plane watermarks */ |
| 2557 | return level == 0 ? 63 : 255; |
| 2558 | } |
| 2559 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2560 | static unsigned int |
| 2561 | ilk_cursor_wm_reg_max(const struct drm_i915_private *dev_priv, int level) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2562 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2563 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2564 | return level == 0 ? 63 : 255; |
| 2565 | else |
| 2566 | return level == 0 ? 31 : 63; |
| 2567 | } |
| 2568 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2569 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2570 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2571 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2572 | return 31; |
| 2573 | else |
| 2574 | return 15; |
| 2575 | } |
| 2576 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2577 | /* Calculate the maximum primary/sprite plane watermark */ |
| 2578 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 2579 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2580 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2581 | enum intel_ddb_partitioning ddb_partitioning, |
| 2582 | bool is_sprite) |
| 2583 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2584 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 2585 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2586 | |
| 2587 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2588 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2589 | return 0; |
| 2590 | |
| 2591 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2592 | if (level == 0 || config->num_pipes_active > 1) { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2593 | fifo_size /= INTEL_INFO(dev_priv)->num_pipes; |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2594 | |
| 2595 | /* |
| 2596 | * For some reason the non self refresh |
| 2597 | * FIFO size is only half of the self |
| 2598 | * refresh FIFO size on ILK/SNB. |
| 2599 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2600 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2601 | fifo_size /= 2; |
| 2602 | } |
| 2603 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2604 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2605 | /* level 0 is always calculated with 1:1 split */ |
| 2606 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2607 | if (is_sprite) |
| 2608 | fifo_size *= 5; |
| 2609 | fifo_size /= 6; |
| 2610 | } else { |
| 2611 | fifo_size /= 2; |
| 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2616 | return min(fifo_size, ilk_plane_wm_reg_max(dev_priv, level, is_sprite)); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | /* Calculate the maximum cursor plane watermark */ |
| 2620 | 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] | 2621 | int level, |
| 2622 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2623 | { |
| 2624 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2625 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2626 | return 64; |
| 2627 | |
| 2628 | /* otherwise just report max that registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2629 | return ilk_cursor_wm_reg_max(to_i915(dev), level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2630 | } |
| 2631 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2632 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2633 | int level, |
| 2634 | const struct intel_wm_config *config, |
| 2635 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2636 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2637 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2638 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 2639 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 2640 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2641 | max->fbc = ilk_fbc_wm_reg_max(to_i915(dev)); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2642 | } |
| 2643 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2644 | static void ilk_compute_wm_reg_maximums(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2645 | int level, |
| 2646 | struct ilk_wm_maximums *max) |
| 2647 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2648 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2649 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2650 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2651 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2652 | } |
| 2653 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2654 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2655 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2656 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2657 | { |
| 2658 | bool ret; |
| 2659 | |
| 2660 | /* already determined to be invalid? */ |
| 2661 | if (!result->enable) |
| 2662 | return false; |
| 2663 | |
| 2664 | result->enable = result->pri_val <= max->pri && |
| 2665 | result->spr_val <= max->spr && |
| 2666 | result->cur_val <= max->cur; |
| 2667 | |
| 2668 | ret = result->enable; |
| 2669 | |
| 2670 | /* |
| 2671 | * HACK until we can pre-compute everything, |
| 2672 | * and thus fail gracefully if LP0 watermarks |
| 2673 | * are exceeded... |
| 2674 | */ |
| 2675 | if (level == 0 && !result->enable) { |
| 2676 | if (result->pri_val > max->pri) |
| 2677 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2678 | level, result->pri_val, max->pri); |
| 2679 | if (result->spr_val > max->spr) |
| 2680 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2681 | level, result->spr_val, max->spr); |
| 2682 | if (result->cur_val > max->cur) |
| 2683 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2684 | level, result->cur_val, max->cur); |
| 2685 | |
| 2686 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2687 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2688 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2689 | result->enable = true; |
| 2690 | } |
| 2691 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2692 | return ret; |
| 2693 | } |
| 2694 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2695 | 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] | 2696 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2697 | int level, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2698 | struct intel_crtc_state *cstate, |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2699 | struct intel_plane_state *pristate, |
| 2700 | struct intel_plane_state *sprstate, |
| 2701 | struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2702 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2703 | { |
| 2704 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2705 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2706 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2707 | |
| 2708 | /* WM1+ latency values stored in 0.5us units */ |
| 2709 | if (level > 0) { |
| 2710 | pri_latency *= 5; |
| 2711 | spr_latency *= 5; |
| 2712 | cur_latency *= 5; |
| 2713 | } |
| 2714 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2715 | if (pristate) { |
| 2716 | result->pri_val = ilk_compute_pri_wm(cstate, pristate, |
| 2717 | pri_latency, level); |
| 2718 | result->fbc_val = ilk_compute_fbc_wm(cstate, pristate, result->pri_val); |
| 2719 | } |
| 2720 | |
| 2721 | if (sprstate) |
| 2722 | result->spr_val = ilk_compute_spr_wm(cstate, sprstate, spr_latency); |
| 2723 | |
| 2724 | if (curstate) |
| 2725 | result->cur_val = ilk_compute_cur_wm(cstate, curstate, cur_latency); |
| 2726 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2727 | result->enable = true; |
| 2728 | } |
| 2729 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2730 | static uint32_t |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2731 | hsw_compute_linetime_wm(const struct intel_crtc_state *cstate) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2732 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2733 | const struct intel_atomic_state *intel_state = |
| 2734 | to_intel_atomic_state(cstate->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2735 | const struct drm_display_mode *adjusted_mode = |
| 2736 | &cstate->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2737 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2738 | |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2739 | if (!cstate->base.active) |
| 2740 | return 0; |
| 2741 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2742 | return 0; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2743 | if (WARN_ON(intel_state->cdclk.logical.cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2744 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2745 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2746 | /* The WM are computed with base on how long it takes to fill a single |
| 2747 | * row at the given clock rate, multiplied by 8. |
| 2748 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2749 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2750 | adjusted_mode->crtc_clock); |
| 2751 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2752 | intel_state->cdclk.logical.cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2753 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2754 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2755 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2756 | } |
| 2757 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2758 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
| 2759 | uint16_t wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2760 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2761 | if (IS_GEN9(dev_priv)) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2762 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2763 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2764 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2765 | |
| 2766 | /* read the first set of memory latencies[0:3] */ |
| 2767 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 2768 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2769 | ret = sandybridge_pcode_read(dev_priv, |
| 2770 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2771 | &val); |
| 2772 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2773 | |
| 2774 | if (ret) { |
| 2775 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2776 | return; |
| 2777 | } |
| 2778 | |
| 2779 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2780 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2781 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2782 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2783 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2784 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2785 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2786 | |
| 2787 | /* read the second set of memory latencies[4:7] */ |
| 2788 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 2789 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2790 | ret = sandybridge_pcode_read(dev_priv, |
| 2791 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2792 | &val); |
| 2793 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2794 | if (ret) { |
| 2795 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2796 | return; |
| 2797 | } |
| 2798 | |
| 2799 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2800 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2801 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2802 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2803 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2804 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2805 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2806 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2807 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2808 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2809 | * need to be disabled. We make sure to sanitize the values out |
| 2810 | * of the punit to satisfy this requirement. |
| 2811 | */ |
| 2812 | for (level = 1; level <= max_level; level++) { |
| 2813 | if (wm[level] == 0) { |
| 2814 | for (i = level + 1; i <= max_level; i++) |
| 2815 | wm[i] = 0; |
| 2816 | break; |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | /* |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 2821 | * WaWmMemoryReadLatency:skl,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2822 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2823 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2824 | * to add 2us to the various latency levels we retrieve from the |
| 2825 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2826 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2827 | if (wm[0] == 0) { |
| 2828 | wm[0] += 2; |
| 2829 | for (level = 1; level <= max_level; level++) { |
| 2830 | if (wm[level] == 0) |
| 2831 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2832 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2833 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2834 | } |
| 2835 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2836 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2837 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2838 | |
| 2839 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2840 | if (wm[0] == 0) |
| 2841 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2842 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2843 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2844 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2845 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2846 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2847 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2848 | |
| 2849 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2850 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2851 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2852 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2853 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2854 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2855 | |
| 2856 | /* ILK primary LP0 latency is 700 ns */ |
| 2857 | wm[0] = 7; |
| 2858 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2859 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2860 | } |
| 2861 | } |
| 2862 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2863 | static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv, |
| 2864 | uint16_t wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2865 | { |
| 2866 | /* ILK sprite LP0 latency is 1300 ns */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2867 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2868 | wm[0] = 13; |
| 2869 | } |
| 2870 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2871 | static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv, |
| 2872 | uint16_t wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2873 | { |
| 2874 | /* ILK cursor LP0 latency is 1300 ns */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2875 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2876 | wm[0] = 13; |
| 2877 | |
| 2878 | /* WaDoubleCursorLP3Latency:ivb */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2879 | if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2880 | wm[3] *= 2; |
| 2881 | } |
| 2882 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2883 | 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] | 2884 | { |
| 2885 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2886 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2887 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2888 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2889 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2890 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2891 | return 3; |
| 2892 | else |
| 2893 | return 2; |
| 2894 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2895 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2896 | 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] | 2897 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2898 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2899 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2900 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2901 | |
| 2902 | for (level = 0; level <= max_level; level++) { |
| 2903 | unsigned int latency = wm[level]; |
| 2904 | |
| 2905 | if (latency == 0) { |
| 2906 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2907 | name, level); |
| 2908 | continue; |
| 2909 | } |
| 2910 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2911 | /* |
| 2912 | * - latencies are in us on gen9. |
| 2913 | * - before then, WM1+ latency values are in 0.5us units |
| 2914 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2915 | if (IS_GEN9(dev_priv)) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2916 | latency *= 10; |
| 2917 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2918 | latency *= 5; |
| 2919 | |
| 2920 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2921 | name, level, wm[level], |
| 2922 | latency / 10, latency % 10); |
| 2923 | } |
| 2924 | } |
| 2925 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2926 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2927 | uint16_t wm[5], uint16_t min) |
| 2928 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2929 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2930 | |
| 2931 | if (wm[0] >= min) |
| 2932 | return false; |
| 2933 | |
| 2934 | wm[0] = max(wm[0], min); |
| 2935 | for (level = 1; level <= max_level; level++) |
| 2936 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2937 | |
| 2938 | return true; |
| 2939 | } |
| 2940 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2941 | static void snb_wm_latency_quirk(struct drm_i915_private *dev_priv) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2942 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2943 | bool changed; |
| 2944 | |
| 2945 | /* |
| 2946 | * The BIOS provided WM memory latency values are often |
| 2947 | * inadequate for high resolution displays. Adjust them. |
| 2948 | */ |
| 2949 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2950 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2951 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2952 | |
| 2953 | if (!changed) |
| 2954 | return; |
| 2955 | |
| 2956 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2957 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 2958 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 2959 | 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] | 2960 | } |
| 2961 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2962 | static void ilk_setup_wm_latency(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2963 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2964 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2965 | |
| 2966 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2967 | sizeof(dev_priv->wm.pri_latency)); |
| 2968 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2969 | sizeof(dev_priv->wm.pri_latency)); |
| 2970 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2971 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2972 | 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] | 2973 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2974 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 2975 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 2976 | 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] | 2977 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2978 | if (IS_GEN6(dev_priv)) |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2979 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2980 | } |
| 2981 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2982 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2983 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2984 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2985 | 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] | 2986 | } |
| 2987 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2988 | static bool ilk_validate_pipe_wm(struct drm_device *dev, |
| 2989 | struct intel_pipe_wm *pipe_wm) |
| 2990 | { |
| 2991 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2992 | const struct intel_wm_config config = { |
| 2993 | .num_pipes_active = 1, |
| 2994 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 2995 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 2996 | }; |
| 2997 | struct ilk_wm_maximums max; |
| 2998 | |
| 2999 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 3000 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 3001 | |
| 3002 | /* At least LP0 must be valid */ |
| 3003 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 3004 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 3005 | return false; |
| 3006 | } |
| 3007 | |
| 3008 | return true; |
| 3009 | } |
| 3010 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3011 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3012 | static int ilk_compute_pipe_wm(struct intel_crtc_state *cstate) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3013 | { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3014 | struct drm_atomic_state *state = cstate->base.state; |
| 3015 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3016 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3017 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3018 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3019 | struct intel_plane *intel_plane; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3020 | struct intel_plane_state *pristate = NULL; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3021 | struct intel_plane_state *sprstate = NULL; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3022 | struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3023 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3024 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3025 | |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3026 | pipe_wm = &cstate->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3027 | |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3028 | for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3029 | struct intel_plane_state *ps; |
| 3030 | |
| 3031 | ps = intel_atomic_get_existing_plane_state(state, |
| 3032 | intel_plane); |
| 3033 | if (!ps) |
| 3034 | continue; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3035 | |
| 3036 | if (intel_plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3037 | pristate = ps; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3038 | else if (intel_plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3039 | sprstate = ps; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3040 | else if (intel_plane->base.type == DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3041 | curstate = ps; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3042 | } |
| 3043 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3044 | pipe_wm->pipe_enabled = cstate->base.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3045 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3046 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 3047 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 3048 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 3049 | 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] | 3050 | } |
| 3051 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3052 | usable_level = max_level; |
| 3053 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3054 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3055 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3056 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3057 | |
| 3058 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3059 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3060 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3061 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3062 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, cstate, |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3063 | pristate, sprstate, curstate, &pipe_wm->raw_wm[0]); |
| 3064 | |
| 3065 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
| 3066 | pipe_wm->wm[0] = pipe_wm->raw_wm[0]; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3067 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3068 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 3069 | pipe_wm->linetime = hsw_compute_linetime_wm(cstate); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3070 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3071 | if (!ilk_validate_pipe_wm(dev, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3072 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3073 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3074 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3075 | |
| 3076 | for (level = 1; level <= max_level; level++) { |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3077 | struct intel_wm_level *wm = &pipe_wm->raw_wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3078 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3079 | ilk_compute_wm_level(dev_priv, intel_crtc, level, cstate, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3080 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3081 | |
| 3082 | /* |
| 3083 | * Disable any watermark level that exceeds the |
| 3084 | * register maximums since such watermarks are |
| 3085 | * always invalid. |
| 3086 | */ |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3087 | if (level > usable_level) |
| 3088 | continue; |
| 3089 | |
| 3090 | if (ilk_validate_wm_level(level, &max, wm)) |
| 3091 | pipe_wm->wm[level] = *wm; |
| 3092 | else |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3093 | usable_level = level; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3094 | } |
| 3095 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3096 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3100 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3101 | * state and the new state. These can be programmed to the hardware |
| 3102 | * immediately. |
| 3103 | */ |
| 3104 | static int ilk_compute_intermediate_wm(struct drm_device *dev, |
| 3105 | struct intel_crtc *intel_crtc, |
| 3106 | struct intel_crtc_state *newstate) |
| 3107 | { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3108 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3109 | struct intel_pipe_wm *b = &intel_crtc->wm.active.ilk; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3110 | int level, max_level = ilk_wm_max_level(to_i915(dev)); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3111 | |
| 3112 | /* |
| 3113 | * Start with the final, target watermarks, then combine with the |
| 3114 | * currently active watermarks to get values that are safe both before |
| 3115 | * and after the vblank. |
| 3116 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3117 | *a = newstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3118 | a->pipe_enabled |= b->pipe_enabled; |
| 3119 | a->sprites_enabled |= b->sprites_enabled; |
| 3120 | a->sprites_scaled |= b->sprites_scaled; |
| 3121 | |
| 3122 | for (level = 0; level <= max_level; level++) { |
| 3123 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3124 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3125 | |
| 3126 | a_wm->enable &= b_wm->enable; |
| 3127 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3128 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3129 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3130 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3131 | } |
| 3132 | |
| 3133 | /* |
| 3134 | * We need to make sure that these merged watermark values are |
| 3135 | * actually a valid configuration themselves. If they're not, |
| 3136 | * there's no safe way to transition from the old state to |
| 3137 | * the new state, so we need to fail the atomic transaction. |
| 3138 | */ |
| 3139 | if (!ilk_validate_pipe_wm(dev, a)) |
| 3140 | return -EINVAL; |
| 3141 | |
| 3142 | /* |
| 3143 | * If our intermediate WM are identical to the final WM, then we can |
| 3144 | * omit the post-vblank programming; only update if it's different. |
| 3145 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3146 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3147 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3148 | |
| 3149 | return 0; |
| 3150 | } |
| 3151 | |
| 3152 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3153 | * Merge the watermarks from all active pipes for a specific level. |
| 3154 | */ |
| 3155 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 3156 | int level, |
| 3157 | struct intel_wm_level *ret_wm) |
| 3158 | { |
| 3159 | const struct intel_crtc *intel_crtc; |
| 3160 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3161 | ret_wm->enable = true; |
| 3162 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3163 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3164 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3165 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3166 | |
| 3167 | if (!active->pipe_enabled) |
| 3168 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3169 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3170 | /* |
| 3171 | * The watermark values may have been used in the past, |
| 3172 | * so we must maintain them in the registers for some |
| 3173 | * time even if the level is now disabled. |
| 3174 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3175 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3176 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3177 | |
| 3178 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3179 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3180 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3181 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3182 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | /* |
| 3186 | * Merge all low power watermarks for all active pipes. |
| 3187 | */ |
| 3188 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3189 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3190 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3191 | struct intel_pipe_wm *merged) |
| 3192 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3193 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3194 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3195 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3196 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3197 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3198 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3199 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3200 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3201 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3202 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3203 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3204 | |
| 3205 | /* merge each WM1+ level */ |
| 3206 | for (level = 1; level <= max_level; level++) { |
| 3207 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3208 | |
| 3209 | ilk_merge_wm_level(dev, level, wm); |
| 3210 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3211 | if (level > last_enabled_level) |
| 3212 | wm->enable = false; |
| 3213 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3214 | /* make sure all following levels get disabled */ |
| 3215 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3216 | |
| 3217 | /* |
| 3218 | * The spec says it is preferred to disable |
| 3219 | * FBC WMs instead of disabling a WM level. |
| 3220 | */ |
| 3221 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3222 | if (wm->enable) |
| 3223 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3224 | wm->fbc_val = 0; |
| 3225 | } |
| 3226 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3227 | |
| 3228 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3229 | /* |
| 3230 | * FIXME this is racy. FBC might get enabled later. |
| 3231 | * What we should check here is whether FBC can be |
| 3232 | * enabled sometime later. |
| 3233 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3234 | if (IS_GEN5(dev_priv) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3235 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3236 | for (level = 2; level <= max_level; level++) { |
| 3237 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3238 | |
| 3239 | wm->enable = false; |
| 3240 | } |
| 3241 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3242 | } |
| 3243 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3244 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3245 | { |
| 3246 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3247 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3248 | } |
| 3249 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3250 | /* The value we need to program into the WM_LPx latency field */ |
| 3251 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 3252 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3253 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3254 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3255 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3256 | return 2 * level; |
| 3257 | else |
| 3258 | return dev_priv->wm.pri_latency[level]; |
| 3259 | } |
| 3260 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3261 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3262 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3263 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3264 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3265 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3266 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3267 | struct intel_crtc *intel_crtc; |
| 3268 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3269 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3270 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3271 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3272 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3273 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3274 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3275 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3276 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3277 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3278 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3279 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3280 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3281 | /* |
| 3282 | * Maintain the watermark values even if the level is |
| 3283 | * disabled. Doing otherwise could cause underruns. |
| 3284 | */ |
| 3285 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3286 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3287 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3288 | r->cur_val; |
| 3289 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3290 | if (r->enable) |
| 3291 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3292 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3293 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3294 | results->wm_lp[wm_lp - 1] |= |
| 3295 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3296 | else |
| 3297 | results->wm_lp[wm_lp - 1] |= |
| 3298 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3299 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3300 | /* |
| 3301 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3302 | * level is disabled. Doing otherwise could cause underruns. |
| 3303 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3304 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3305 | WARN_ON(wm_lp != 1); |
| 3306 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3307 | } else |
| 3308 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3309 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3310 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3311 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3312 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3313 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3314 | const struct intel_wm_level *r = |
| 3315 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3316 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3317 | if (WARN_ON(!r->enable)) |
| 3318 | continue; |
| 3319 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3320 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3321 | |
| 3322 | results->wm_pipe[pipe] = |
| 3323 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3324 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3325 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3326 | } |
| 3327 | } |
| 3328 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3329 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3330 | * 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] | 3331 | 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] | 3332 | struct intel_pipe_wm *r1, |
| 3333 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3334 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3335 | int level, max_level = ilk_wm_max_level(to_i915(dev)); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3336 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3337 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3338 | for (level = 1; level <= max_level; level++) { |
| 3339 | if (r1->wm[level].enable) |
| 3340 | level1 = level; |
| 3341 | if (r2->wm[level].enable) |
| 3342 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3343 | } |
| 3344 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3345 | if (level1 == level2) { |
| 3346 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3347 | return r2; |
| 3348 | else |
| 3349 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3350 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3351 | return r1; |
| 3352 | } else { |
| 3353 | return r2; |
| 3354 | } |
| 3355 | } |
| 3356 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3357 | /* dirty bits used to track which watermarks need changes */ |
| 3358 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 3359 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 3360 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3361 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3362 | #define WM_DIRTY_FBC (1 << 24) |
| 3363 | #define WM_DIRTY_DDB (1 << 25) |
| 3364 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3365 | 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] | 3366 | const struct ilk_wm_values *old, |
| 3367 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3368 | { |
| 3369 | unsigned int dirty = 0; |
| 3370 | enum pipe pipe; |
| 3371 | int wm_lp; |
| 3372 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3373 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3374 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 3375 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 3376 | /* Must disable LP1+ watermarks too */ |
| 3377 | dirty |= WM_DIRTY_LP_ALL; |
| 3378 | } |
| 3379 | |
| 3380 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3381 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3382 | /* Must disable LP1+ watermarks too */ |
| 3383 | dirty |= WM_DIRTY_LP_ALL; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3388 | dirty |= WM_DIRTY_FBC; |
| 3389 | /* Must disable LP1+ watermarks too */ |
| 3390 | dirty |= WM_DIRTY_LP_ALL; |
| 3391 | } |
| 3392 | |
| 3393 | if (old->partitioning != new->partitioning) { |
| 3394 | dirty |= WM_DIRTY_DDB; |
| 3395 | /* Must disable LP1+ watermarks too */ |
| 3396 | dirty |= WM_DIRTY_LP_ALL; |
| 3397 | } |
| 3398 | |
| 3399 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3400 | if (dirty & WM_DIRTY_LP_ALL) |
| 3401 | return dirty; |
| 3402 | |
| 3403 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3404 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3405 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3406 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3407 | break; |
| 3408 | } |
| 3409 | |
| 3410 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3411 | for (; wm_lp <= 3; wm_lp++) |
| 3412 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3413 | |
| 3414 | return dirty; |
| 3415 | } |
| 3416 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3417 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3418 | unsigned int dirty) |
| 3419 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3420 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3421 | bool changed = false; |
| 3422 | |
| 3423 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3424 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3425 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3426 | changed = true; |
| 3427 | } |
| 3428 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3429 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3430 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3431 | changed = true; |
| 3432 | } |
| 3433 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3434 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3435 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3436 | changed = true; |
| 3437 | } |
| 3438 | |
| 3439 | /* |
| 3440 | * Don't touch WM1S_LP_EN here. |
| 3441 | * Doing so could cause underruns. |
| 3442 | */ |
| 3443 | |
| 3444 | return changed; |
| 3445 | } |
| 3446 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3447 | /* |
| 3448 | * The spec says we shouldn't write when we don't need, because every write |
| 3449 | * causes WMs to be re-evaluated, expending some power. |
| 3450 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3451 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3452 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3453 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3454 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3455 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3456 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3457 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3458 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3459 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3460 | return; |
| 3461 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3462 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3463 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3464 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3465 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3466 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3467 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3468 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3469 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 3470 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3471 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3472 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3473 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3474 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3475 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3476 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 3477 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3478 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3479 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3480 | val = I915_READ(WM_MISC); |
| 3481 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3482 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3483 | else |
| 3484 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3485 | I915_WRITE(WM_MISC, val); |
| 3486 | } else { |
| 3487 | val = I915_READ(DISP_ARB_CTL2); |
| 3488 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3489 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3490 | else |
| 3491 | val |= DISP_DATA_PARTITION_5_6; |
| 3492 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3493 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3494 | } |
| 3495 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3496 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3497 | val = I915_READ(DISP_ARB_CTL); |
| 3498 | if (results->enable_fbc_wm) |
| 3499 | val &= ~DISP_FBC_WM_DIS; |
| 3500 | else |
| 3501 | val |= DISP_FBC_WM_DIS; |
| 3502 | I915_WRITE(DISP_ARB_CTL, val); |
| 3503 | } |
| 3504 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3505 | if (dirty & WM_DIRTY_LP(1) && |
| 3506 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3507 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3508 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3509 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3510 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3511 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3512 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3513 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3514 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3515 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3516 | 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] | 3517 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3518 | 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] | 3519 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3520 | 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] | 3521 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3522 | |
| 3523 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3524 | } |
| 3525 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3526 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3527 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3528 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3529 | |
| 3530 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3531 | } |
| 3532 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3533 | #define SKL_SAGV_BLOCK_TIME 30 /* µs */ |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3534 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3535 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3536 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3537 | * so assume we'll always need it in order to avoid underruns. |
| 3538 | */ |
| 3539 | static bool skl_needs_memory_bw_wa(struct intel_atomic_state *state) |
| 3540 | { |
| 3541 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 3542 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 3543 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3544 | return true; |
| 3545 | |
| 3546 | return false; |
| 3547 | } |
| 3548 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3549 | static bool |
| 3550 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3551 | { |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3552 | if (IS_KABYLAKE(dev_priv)) |
| 3553 | return true; |
| 3554 | |
| 3555 | if (IS_SKYLAKE(dev_priv) && |
| 3556 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED) |
| 3557 | return true; |
| 3558 | |
| 3559 | return false; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3560 | } |
| 3561 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3562 | /* |
| 3563 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3564 | * depending on power and performance requirements. The display engine access |
| 3565 | * to system memory is blocked during the adjustment time. Because of the |
| 3566 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3567 | * underruns if we don't meet all of the following requirements: |
| 3568 | * |
| 3569 | * - <= 1 pipe enabled |
| 3570 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3571 | * - We're not using an interlaced display configuration |
| 3572 | */ |
| 3573 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3574 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3575 | { |
| 3576 | int ret; |
| 3577 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3578 | if (!intel_has_sagv(dev_priv)) |
| 3579 | return 0; |
| 3580 | |
| 3581 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3582 | return 0; |
| 3583 | |
| 3584 | DRM_DEBUG_KMS("Enabling the SAGV\n"); |
| 3585 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3586 | |
| 3587 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3588 | GEN9_SAGV_ENABLE); |
| 3589 | |
| 3590 | /* We don't need to wait for the SAGV when enabling */ |
| 3591 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3592 | |
| 3593 | /* |
| 3594 | * Some skl systems, pre-release machines in particular, |
| 3595 | * don't actually have an SAGV. |
| 3596 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3597 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3598 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3599 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3600 | return 0; |
| 3601 | } else if (ret < 0) { |
| 3602 | DRM_ERROR("Failed to enable the SAGV\n"); |
| 3603 | return ret; |
| 3604 | } |
| 3605 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3606 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3607 | return 0; |
| 3608 | } |
| 3609 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3610 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3611 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3612 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3613 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3614 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3615 | if (!intel_has_sagv(dev_priv)) |
| 3616 | return 0; |
| 3617 | |
| 3618 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3619 | return 0; |
| 3620 | |
| 3621 | DRM_DEBUG_KMS("Disabling the SAGV\n"); |
| 3622 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3623 | |
| 3624 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3625 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3626 | GEN9_SAGV_DISABLE, |
| 3627 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3628 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3629 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3630 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3631 | /* |
| 3632 | * Some skl systems, pre-release machines in particular, |
| 3633 | * don't actually have an SAGV. |
| 3634 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3635 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3636 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3637 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3638 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3639 | } else if (ret < 0) { |
| 3640 | DRM_ERROR("Failed to disable the SAGV (%d)\n", ret); |
| 3641 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3642 | } |
| 3643 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3644 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3645 | return 0; |
| 3646 | } |
| 3647 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3648 | bool intel_can_enable_sagv(struct drm_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3649 | { |
| 3650 | struct drm_device *dev = state->dev; |
| 3651 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3652 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3653 | struct intel_crtc *crtc; |
| 3654 | struct intel_plane *plane; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3655 | struct intel_crtc_state *cstate; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3656 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3657 | int level, latency; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3658 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3659 | if (!intel_has_sagv(dev_priv)) |
| 3660 | return false; |
| 3661 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3662 | /* |
| 3663 | * SKL workaround: bspec recommends we disable the SAGV when we have |
| 3664 | * more then one pipe enabled |
| 3665 | * |
| 3666 | * If there are no active CRTCs, no additional checks need be performed |
| 3667 | */ |
| 3668 | if (hweight32(intel_state->active_crtcs) == 0) |
| 3669 | return true; |
| 3670 | else if (hweight32(intel_state->active_crtcs) > 1) |
| 3671 | return false; |
| 3672 | |
| 3673 | /* Since we're now guaranteed to only have one active CRTC... */ |
| 3674 | pipe = ffs(intel_state->active_crtcs) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 3675 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3676 | cstate = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3677 | |
Paulo Zanoni | c89cadd | 2016-10-10 17:30:59 -0300 | [diff] [blame] | 3678 | if (crtc->base.state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3679 | return false; |
| 3680 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3681 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3682 | struct skl_plane_wm *wm = |
| 3683 | &cstate->wm.skl.optimal.planes[plane->id]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3684 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3685 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3686 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3687 | continue; |
| 3688 | |
| 3689 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3690 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3691 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3692 | { } |
| 3693 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3694 | latency = dev_priv->wm.skl_latency[level]; |
| 3695 | |
| 3696 | if (skl_needs_memory_bw_wa(intel_state) && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3697 | plane->base.state->fb->modifier == |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3698 | I915_FORMAT_MOD_X_TILED) |
| 3699 | latency += 15; |
| 3700 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3701 | /* |
| 3702 | * If any of the planes on this pipe don't enable wm levels |
| 3703 | * that incur memory latencies higher then 30µs we can't enable |
| 3704 | * the SAGV |
| 3705 | */ |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3706 | if (latency < SKL_SAGV_BLOCK_TIME) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3707 | return false; |
| 3708 | } |
| 3709 | |
| 3710 | return true; |
| 3711 | } |
| 3712 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3713 | static void |
| 3714 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3715 | const struct intel_crtc_state *cstate, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3716 | struct skl_ddb_entry *alloc, /* out */ |
| 3717 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3718 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3719 | struct drm_atomic_state *state = cstate->base.state; |
| 3720 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 3721 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3722 | struct drm_crtc *for_crtc = cstate->base.crtc; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3723 | unsigned int pipe_size, ddb_size; |
| 3724 | int nth_active_pipe; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3725 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3726 | if (WARN_ON(!state) || !cstate->base.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3727 | alloc->start = 0; |
| 3728 | alloc->end = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3729 | *num_active = hweight32(dev_priv->active_crtcs); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3730 | return; |
| 3731 | } |
| 3732 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3733 | if (intel_state->active_pipe_changes) |
| 3734 | *num_active = hweight32(intel_state->active_crtcs); |
| 3735 | else |
| 3736 | *num_active = hweight32(dev_priv->active_crtcs); |
| 3737 | |
Deepak M | 6f3fff6 | 2016-09-15 15:01:10 +0530 | [diff] [blame] | 3738 | ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3739 | WARN_ON(ddb_size == 0); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3740 | |
| 3741 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 3742 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3743 | /* |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3744 | * If the state doesn't change the active CRTC's, then there's |
| 3745 | * no need to recalculate; the existing pipe allocation limits |
| 3746 | * should remain unchanged. Note that we're safe from racing |
| 3747 | * commits since any racing commit that changes the active CRTC |
| 3748 | * list would need to grab _all_ crtc locks, including the one |
| 3749 | * we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3750 | */ |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3751 | if (!intel_state->active_pipe_changes) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 3752 | /* |
| 3753 | * alloc may be cleared by clear_intel_crtc_state, |
| 3754 | * copy from old state to be sure |
| 3755 | */ |
| 3756 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3757 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3758 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3759 | |
| 3760 | nth_active_pipe = hweight32(intel_state->active_crtcs & |
| 3761 | (drm_crtc_mask(for_crtc) - 1)); |
| 3762 | pipe_size = ddb_size / hweight32(intel_state->active_crtcs); |
| 3763 | alloc->start = nth_active_pipe * ddb_size / *num_active; |
| 3764 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3767 | static unsigned int skl_cursor_allocation(int num_active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3768 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3769 | if (num_active == 1) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3770 | return 32; |
| 3771 | |
| 3772 | return 8; |
| 3773 | } |
| 3774 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3775 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 3776 | { |
| 3777 | entry->start = reg & 0x3ff; |
| 3778 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3779 | if (entry->end) |
| 3780 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3781 | } |
| 3782 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 3783 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 3784 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3785 | { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3786 | struct intel_crtc *crtc; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3787 | |
Maarten Lankhorst | b10f1b2 | 2015-10-22 13:56:34 +0200 | [diff] [blame] | 3788 | memset(ddb, 0, sizeof(*ddb)); |
| 3789 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3790 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3791 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3792 | enum plane_id plane_id; |
| 3793 | enum pipe pipe = crtc->pipe; |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3794 | |
| 3795 | power_domain = POWER_DOMAIN_PIPE(pipe); |
| 3796 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Maarten Lankhorst | b10f1b2 | 2015-10-22 13:56:34 +0200 | [diff] [blame] | 3797 | continue; |
| 3798 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3799 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 3800 | u32 val; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3801 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3802 | if (plane_id != PLANE_CURSOR) |
| 3803 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 3804 | else |
| 3805 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 3806 | |
| 3807 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane_id], val); |
| 3808 | } |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3809 | |
| 3810 | intel_display_power_put(dev_priv, power_domain); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3811 | } |
| 3812 | } |
| 3813 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3814 | /* |
| 3815 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 3816 | * The bspec defines downscale amount as: |
| 3817 | * |
| 3818 | * """ |
| 3819 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 3820 | * Horizontal destination size] |
| 3821 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 3822 | * Vertical destination size] |
| 3823 | * Total down scale amount = Horizontal down scale amount * |
| 3824 | * Vertical down scale amount |
| 3825 | * """ |
| 3826 | * |
| 3827 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 3828 | * Caller should take care of dividing & rounding off the value. |
| 3829 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3830 | static uint_fixed_16_16_t |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3831 | skl_plane_downscale_amount(const struct intel_crtc_state *cstate, |
| 3832 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3833 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3834 | struct intel_plane *plane = to_intel_plane(pstate->base.plane); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3835 | uint32_t src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3836 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 3837 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3838 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3839 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3840 | return u32_to_fixed_16_16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3841 | |
| 3842 | /* n.b., src is 16.16 fixed point, dst is whole integer */ |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3843 | if (plane->id == PLANE_CURSOR) { |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3844 | src_w = pstate->base.src_w >> 16; |
| 3845 | src_h = pstate->base.src_h >> 16; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3846 | dst_w = pstate->base.crtc_w; |
| 3847 | dst_h = pstate->base.crtc_h; |
| 3848 | } else { |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3849 | src_w = drm_rect_width(&pstate->base.src) >> 16; |
| 3850 | src_h = drm_rect_height(&pstate->base.src) >> 16; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3851 | dst_w = drm_rect_width(&pstate->base.dst); |
| 3852 | dst_h = drm_rect_height(&pstate->base.dst); |
| 3853 | } |
| 3854 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3855 | if (drm_rotation_90_or_270(pstate->base.rotation)) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3856 | swap(dst_w, dst_h); |
| 3857 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3858 | fp_w_ratio = fixed_16_16_div(src_w, dst_w); |
| 3859 | fp_h_ratio = fixed_16_16_div(src_h, dst_h); |
| 3860 | downscale_w = max_fixed_16_16(fp_w_ratio, u32_to_fixed_16_16(1)); |
| 3861 | downscale_h = max_fixed_16_16(fp_h_ratio, u32_to_fixed_16_16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3862 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3863 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3864 | } |
| 3865 | |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3866 | static uint_fixed_16_16_t |
| 3867 | skl_pipe_downscale_amount(const struct intel_crtc_state *crtc_state) |
| 3868 | { |
| 3869 | uint_fixed_16_16_t pipe_downscale = u32_to_fixed_16_16(1); |
| 3870 | |
| 3871 | if (!crtc_state->base.enable) |
| 3872 | return pipe_downscale; |
| 3873 | |
| 3874 | if (crtc_state->pch_pfit.enabled) { |
| 3875 | uint32_t src_w, src_h, dst_w, dst_h; |
| 3876 | uint32_t pfit_size = crtc_state->pch_pfit.size; |
| 3877 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 3878 | uint_fixed_16_16_t downscale_h, downscale_w; |
| 3879 | |
| 3880 | src_w = crtc_state->pipe_src_w; |
| 3881 | src_h = crtc_state->pipe_src_h; |
| 3882 | dst_w = pfit_size >> 16; |
| 3883 | dst_h = pfit_size & 0xffff; |
| 3884 | |
| 3885 | if (!dst_w || !dst_h) |
| 3886 | return pipe_downscale; |
| 3887 | |
| 3888 | fp_w_ratio = fixed_16_16_div(src_w, dst_w); |
| 3889 | fp_h_ratio = fixed_16_16_div(src_h, dst_h); |
| 3890 | downscale_w = max_fixed_16_16(fp_w_ratio, u32_to_fixed_16_16(1)); |
| 3891 | downscale_h = max_fixed_16_16(fp_h_ratio, u32_to_fixed_16_16(1)); |
| 3892 | |
| 3893 | pipe_downscale = mul_fixed16(downscale_w, downscale_h); |
| 3894 | } |
| 3895 | |
| 3896 | return pipe_downscale; |
| 3897 | } |
| 3898 | |
| 3899 | int skl_check_pipe_max_pixel_rate(struct intel_crtc *intel_crtc, |
| 3900 | struct intel_crtc_state *cstate) |
| 3901 | { |
| 3902 | struct drm_crtc_state *crtc_state = &cstate->base; |
| 3903 | struct drm_atomic_state *state = crtc_state->state; |
| 3904 | struct drm_plane *plane; |
| 3905 | const struct drm_plane_state *pstate; |
| 3906 | struct intel_plane_state *intel_pstate; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame^] | 3907 | int crtc_clock, dotclk; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3908 | uint32_t pipe_max_pixel_rate; |
| 3909 | uint_fixed_16_16_t pipe_downscale; |
| 3910 | uint_fixed_16_16_t max_downscale = u32_to_fixed_16_16(1); |
| 3911 | |
| 3912 | if (!cstate->base.enable) |
| 3913 | return 0; |
| 3914 | |
| 3915 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { |
| 3916 | uint_fixed_16_16_t plane_downscale; |
| 3917 | uint_fixed_16_16_t fp_9_div_8 = fixed_16_16_div(9, 8); |
| 3918 | int bpp; |
| 3919 | |
| 3920 | if (!intel_wm_plane_visible(cstate, |
| 3921 | to_intel_plane_state(pstate))) |
| 3922 | continue; |
| 3923 | |
| 3924 | if (WARN_ON(!pstate->fb)) |
| 3925 | return -EINVAL; |
| 3926 | |
| 3927 | intel_pstate = to_intel_plane_state(pstate); |
| 3928 | plane_downscale = skl_plane_downscale_amount(cstate, |
| 3929 | intel_pstate); |
| 3930 | bpp = pstate->fb->format->cpp[0] * 8; |
| 3931 | if (bpp == 64) |
| 3932 | plane_downscale = mul_fixed16(plane_downscale, |
| 3933 | fp_9_div_8); |
| 3934 | |
| 3935 | max_downscale = max_fixed_16_16(plane_downscale, max_downscale); |
| 3936 | } |
| 3937 | pipe_downscale = skl_pipe_downscale_amount(cstate); |
| 3938 | |
| 3939 | pipe_downscale = mul_fixed16(pipe_downscale, max_downscale); |
| 3940 | |
| 3941 | crtc_clock = crtc_state->adjusted_mode.crtc_clock; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame^] | 3942 | dotclk = to_intel_atomic_state(state)->cdclk.logical.cdclk; |
| 3943 | |
| 3944 | if (IS_GEMINILAKE(to_i915(intel_crtc->base.dev))) |
| 3945 | dotclk *= 2; |
| 3946 | |
| 3947 | pipe_max_pixel_rate = div_round_up_u32_fixed16(dotclk, pipe_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3948 | |
| 3949 | if (pipe_max_pixel_rate < crtc_clock) { |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame^] | 3950 | DRM_DEBUG_KMS("Max supported pixel clock with scaling exceeded\n"); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3951 | return -EINVAL; |
| 3952 | } |
| 3953 | |
| 3954 | return 0; |
| 3955 | } |
| 3956 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3957 | static unsigned int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3958 | skl_plane_relative_data_rate(const struct intel_crtc_state *cstate, |
| 3959 | const struct drm_plane_state *pstate, |
| 3960 | int y) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3961 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3962 | struct intel_plane *plane = to_intel_plane(pstate->plane); |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3963 | struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate); |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3964 | uint32_t data_rate; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3965 | uint32_t width = 0, height = 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 3966 | struct drm_framebuffer *fb; |
| 3967 | u32 format; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3968 | uint_fixed_16_16_t down_scale_amount; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3969 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3970 | if (!intel_pstate->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3971 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 3972 | |
| 3973 | fb = pstate->fb; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3974 | format = fb->format->format; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 3975 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3976 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3977 | return 0; |
| 3978 | if (y && format != DRM_FORMAT_NV12) |
| 3979 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3980 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3981 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 3982 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3983 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3984 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3985 | swap(width, height); |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3986 | |
| 3987 | /* for planar format */ |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3988 | if (format == DRM_FORMAT_NV12) { |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3989 | if (y) /* y-plane data rate */ |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3990 | data_rate = width * height * |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3991 | fb->format->cpp[0]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3992 | else /* uv-plane data rate */ |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3993 | data_rate = (width / 2) * (height / 2) * |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3994 | fb->format->cpp[1]; |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3995 | } else { |
| 3996 | /* for packed formats */ |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3997 | data_rate = width * height * fb->format->cpp[0]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4000 | down_scale_amount = skl_plane_downscale_amount(cstate, intel_pstate); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4001 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4002 | return mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | /* |
| 4006 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 4007 | * a 8192x4096@32bpp framebuffer: |
| 4008 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 4009 | */ |
| 4010 | static unsigned int |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4011 | skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate, |
| 4012 | unsigned *plane_data_rate, |
| 4013 | unsigned *plane_y_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4014 | { |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4015 | struct drm_crtc_state *cstate = &intel_cstate->base; |
| 4016 | struct drm_atomic_state *state = cstate->state; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4017 | struct drm_plane *plane; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4018 | const struct drm_plane_state *pstate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4019 | unsigned int total_data_rate = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4020 | |
| 4021 | if (WARN_ON(!state)) |
| 4022 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4023 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4024 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4025 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, cstate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4026 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 4027 | unsigned int rate; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4028 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4029 | /* packed/uv */ |
| 4030 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4031 | pstate, 0); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4032 | plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4033 | |
| 4034 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4035 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4036 | /* y-plane */ |
| 4037 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4038 | pstate, 1); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4039 | plane_y_data_rate[plane_id] = rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4040 | |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4041 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | return total_data_rate; |
| 4045 | } |
| 4046 | |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4047 | static uint16_t |
| 4048 | skl_ddb_min_alloc(const struct drm_plane_state *pstate, |
| 4049 | const int y) |
| 4050 | { |
| 4051 | struct drm_framebuffer *fb = pstate->fb; |
| 4052 | struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate); |
| 4053 | uint32_t src_w, src_h; |
| 4054 | uint32_t min_scanlines = 8; |
| 4055 | uint8_t plane_bpp; |
| 4056 | |
| 4057 | if (WARN_ON(!fb)) |
| 4058 | return 0; |
| 4059 | |
| 4060 | /* For packed formats, no y-plane, return 0 */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4061 | if (y && fb->format->format != DRM_FORMAT_NV12) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4062 | return 0; |
| 4063 | |
| 4064 | /* For Non Y-tile return 8-blocks */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 4065 | if (fb->modifier != I915_FORMAT_MOD_Y_TILED && |
| 4066 | fb->modifier != I915_FORMAT_MOD_Yf_TILED) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4067 | return 8; |
| 4068 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4069 | src_w = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4070 | src_h = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4071 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 4072 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4073 | swap(src_w, src_h); |
| 4074 | |
| 4075 | /* Halve UV plane width and height for NV12 */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4076 | if (fb->format->format == DRM_FORMAT_NV12 && !y) { |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4077 | src_w /= 2; |
| 4078 | src_h /= 2; |
| 4079 | } |
| 4080 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4081 | if (fb->format->format == DRM_FORMAT_NV12 && !y) |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4082 | plane_bpp = fb->format->cpp[1]; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4083 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4084 | plane_bpp = fb->format->cpp[0]; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4085 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 4086 | if (drm_rotation_90_or_270(pstate->rotation)) { |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4087 | switch (plane_bpp) { |
| 4088 | case 1: |
| 4089 | min_scanlines = 32; |
| 4090 | break; |
| 4091 | case 2: |
| 4092 | min_scanlines = 16; |
| 4093 | break; |
| 4094 | case 4: |
| 4095 | min_scanlines = 8; |
| 4096 | break; |
| 4097 | case 8: |
| 4098 | min_scanlines = 4; |
| 4099 | break; |
| 4100 | default: |
| 4101 | WARN(1, "Unsupported pixel depth %u for rotation", |
| 4102 | plane_bpp); |
| 4103 | min_scanlines = 32; |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | return DIV_ROUND_UP((4 * src_w * plane_bpp), 512) * min_scanlines/4 + 3; |
| 4108 | } |
| 4109 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4110 | static void |
| 4111 | skl_ddb_calc_min(const struct intel_crtc_state *cstate, int num_active, |
| 4112 | uint16_t *minimum, uint16_t *y_minimum) |
| 4113 | { |
| 4114 | const struct drm_plane_state *pstate; |
| 4115 | struct drm_plane *plane; |
| 4116 | |
| 4117 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, &cstate->base) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4118 | enum plane_id plane_id = to_intel_plane(plane)->id; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4119 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4120 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4121 | continue; |
| 4122 | |
| 4123 | if (!pstate->visible) |
| 4124 | continue; |
| 4125 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4126 | minimum[plane_id] = skl_ddb_min_alloc(pstate, 0); |
| 4127 | y_minimum[plane_id] = skl_ddb_min_alloc(pstate, 1); |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | minimum[PLANE_CURSOR] = skl_cursor_allocation(num_active); |
| 4131 | } |
| 4132 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4133 | static void |
| 4134 | skl_enable_plane_wm_levels(const struct drm_i915_private *dev_priv, |
| 4135 | uint16_t plane_ddb, |
| 4136 | uint16_t max_level, |
| 4137 | struct skl_plane_wm *wm) |
| 4138 | { |
| 4139 | int level; |
| 4140 | /* |
| 4141 | * Now enable all levels in WM structure which can be enabled |
| 4142 | * using current DDB allocation |
| 4143 | */ |
| 4144 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
| 4145 | struct skl_wm_level *level_wm = &wm->wm[level]; |
| 4146 | |
| 4147 | if (level > max_level || level_wm->plane_res_b == 0 |
| 4148 | || level_wm->plane_res_l >= 31 |
| 4149 | || level_wm->plane_res_b >= plane_ddb) { |
| 4150 | level_wm->plane_en = false; |
| 4151 | level_wm->plane_res_b = 0; |
| 4152 | level_wm->plane_res_l = 0; |
| 4153 | } else { |
| 4154 | level_wm->plane_en = true; |
| 4155 | } |
| 4156 | } |
| 4157 | } |
| 4158 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4159 | static int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4160 | skl_allocate_pipe_ddb(struct intel_crtc_state *cstate, |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4161 | struct skl_pipe_wm *pipe_wm, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4162 | struct skl_ddb_allocation *ddb /* out */) |
| 4163 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4164 | struct drm_atomic_state *state = cstate->base.state; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4165 | struct drm_crtc *crtc = cstate->base.crtc; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4166 | struct drm_device *dev = crtc->dev; |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4167 | struct drm_i915_private *dev_priv = to_i915(dev); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4168 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4169 | enum pipe pipe = intel_crtc->pipe; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4170 | struct skl_ddb_entry *alloc = &cstate->wm.skl.ddb; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4171 | uint16_t alloc_size, start; |
Maarten Lankhorst | fefdd81 | 2016-10-26 15:41:33 +0200 | [diff] [blame] | 4172 | uint16_t minimum[I915_MAX_PLANES] = {}; |
| 4173 | uint16_t y_minimum[I915_MAX_PLANES] = {}; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4174 | unsigned int total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4175 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4176 | int num_active; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4177 | unsigned plane_data_rate[I915_MAX_PLANES] = {}; |
| 4178 | unsigned plane_y_data_rate[I915_MAX_PLANES] = {}; |
Kumar, Mahesh | 5ba6faa | 2017-05-17 17:28:26 +0530 | [diff] [blame] | 4179 | uint16_t total_min_blocks = 0; |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4180 | uint16_t total_level_ddb; |
| 4181 | uint16_t plane_blocks = 0; |
| 4182 | int max_level, level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4183 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4184 | /* Clear the partitioning for disabled planes. */ |
| 4185 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 4186 | memset(ddb->y_plane[pipe], 0, sizeof(ddb->y_plane[pipe])); |
| 4187 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4188 | if (WARN_ON(!state)) |
| 4189 | return 0; |
| 4190 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4191 | if (!cstate->base.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4192 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4193 | return 0; |
| 4194 | } |
| 4195 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4196 | skl_ddb_get_pipe_allocation_limits(dev, cstate, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4197 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 4198 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4199 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4200 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4201 | skl_ddb_calc_min(cstate, num_active, minimum, y_minimum); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4202 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4203 | /* |
| 4204 | * 1. Allocate the mininum required blocks for each active plane |
| 4205 | * and allocate the cursor, it doesn't require extra allocation |
| 4206 | * proportional to the data rate. |
| 4207 | */ |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4208 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4209 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Kumar, Mahesh | 5ba6faa | 2017-05-17 17:28:26 +0530 | [diff] [blame] | 4210 | total_min_blocks += minimum[plane_id]; |
| 4211 | total_min_blocks += y_minimum[plane_id]; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 4212 | } |
| 4213 | |
Kumar, Mahesh | 5ba6faa | 2017-05-17 17:28:26 +0530 | [diff] [blame] | 4214 | if (total_min_blocks > alloc_size) { |
| 4215 | DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); |
| 4216 | DRM_DEBUG_KMS("minimum required %d/%d\n", total_min_blocks, |
| 4217 | alloc_size); |
| 4218 | return -EINVAL; |
| 4219 | } |
| 4220 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4221 | alloc_size -= minimum[PLANE_CURSOR]; |
| 4222 | ddb->plane[pipe][PLANE_CURSOR].start = alloc->end - |
| 4223 | minimum[PLANE_CURSOR]; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4224 | ddb->plane[pipe][PLANE_CURSOR].end = alloc->end; |
| 4225 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4226 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
| 4227 | total_level_ddb = 0; |
| 4228 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 4229 | /* |
| 4230 | * TODO: We should calculate watermark values for Y/UV |
| 4231 | * plane both in case of NV12 format and use both values |
| 4232 | * for ddb calculation. NV12 is disabled as of now, So |
| 4233 | * using only single/UV plane value here. |
| 4234 | */ |
| 4235 | struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 4236 | uint16_t plane_res_b = wm->wm[level].plane_res_b; |
| 4237 | uint16_t min = minimum[plane_id] + y_minimum[plane_id]; |
| 4238 | |
| 4239 | if (plane_id == PLANE_CURSOR) |
| 4240 | continue; |
| 4241 | |
| 4242 | total_level_ddb += max(plane_res_b, min); |
| 4243 | } |
| 4244 | |
| 4245 | /* |
| 4246 | * If This level can successfully be enabled with the |
| 4247 | * pipe's current DDB allocation, then all lower levels are |
| 4248 | * guaranteed to succeed as well. |
| 4249 | */ |
| 4250 | if (total_level_ddb <= alloc_size) |
| 4251 | break; |
| 4252 | } |
| 4253 | |
| 4254 | if ((level < 0) || (total_min_blocks > alloc_size)) { |
| 4255 | DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); |
| 4256 | DRM_DEBUG_KMS("minimum required %d/%d\n", (level < 0) ? |
| 4257 | total_level_ddb : total_min_blocks, alloc_size); |
| 4258 | return -EINVAL; |
| 4259 | } |
| 4260 | max_level = level; |
| 4261 | alloc_size -= total_level_ddb; |
| 4262 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4263 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 4264 | * 2. Distribute the remaining space in proportion to the amount of |
| 4265 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4266 | * |
| 4267 | * FIXME: we may not allocate every single block here. |
| 4268 | */ |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4269 | total_data_rate = skl_get_total_relative_data_rate(cstate, |
| 4270 | plane_data_rate, |
| 4271 | plane_y_data_rate); |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4272 | /* |
| 4273 | * PLANE_CURSOR data rate is not included in total_data_rate. |
| 4274 | * If only cursor plane is enabled we have to enable its WM levels |
| 4275 | * explicitly before returning. Cursor has fixed ddb allocation, |
| 4276 | * So it's ok to always check cursor WM enabling before return. |
| 4277 | */ |
| 4278 | plane_blocks = skl_ddb_entry_size(&ddb->plane[pipe][PLANE_CURSOR]); |
| 4279 | skl_enable_plane_wm_levels(dev_priv, plane_blocks, max_level, |
| 4280 | &pipe_wm->planes[PLANE_CURSOR]); |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4281 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4282 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4283 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4284 | start = alloc->start; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4285 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4286 | unsigned int data_rate, y_data_rate; |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4287 | uint16_t plane_blocks = 0, y_plane_blocks = 0; |
| 4288 | struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 4289 | uint16_t plane_res_b = wm->wm[max_level].plane_res_b; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4290 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4291 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4292 | continue; |
| 4293 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4294 | data_rate = plane_data_rate[plane_id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4295 | |
| 4296 | /* |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4297 | * allocation for (packed formats) or (uv-plane part of planar format): |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4298 | * promote the expression to 64 bits to avoid overflowing, the |
| 4299 | * result is < available as data_rate / total_data_rate < 1 |
| 4300 | */ |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4301 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4302 | /* Leave disabled planes at (0,0) */ |
| 4303 | if (data_rate) { |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4304 | plane_blocks = max(minimum[plane_id], plane_res_b); |
| 4305 | plane_blocks += div_u64((uint64_t)alloc_size * |
| 4306 | data_rate, total_data_rate); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4307 | ddb->plane[pipe][plane_id].start = start; |
| 4308 | ddb->plane[pipe][plane_id].end = start + plane_blocks; |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4309 | start += plane_blocks; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4310 | } |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4311 | |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4312 | /* |
| 4313 | * allocation for y_plane part of planar format: |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4314 | * TODO: Once we start calculating watermark values for Y/UV |
| 4315 | * plane both consider it for initial allowed wm blocks. |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4316 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4317 | y_data_rate = plane_y_data_rate[plane_id]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4318 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4319 | if (y_data_rate) { |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4320 | y_plane_blocks = y_minimum[plane_id]; |
| 4321 | y_plane_blocks += div_u64((uint64_t)alloc_size * |
| 4322 | y_data_rate, total_data_rate); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4323 | ddb->y_plane[pipe][plane_id].start = start; |
| 4324 | ddb->y_plane[pipe][plane_id].end = start + y_plane_blocks; |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4325 | start += y_plane_blocks; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4326 | } |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4327 | skl_enable_plane_wm_levels(dev_priv, |
| 4328 | plane_blocks, |
| 4329 | max_level, |
| 4330 | wm); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4331 | } |
| 4332 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4333 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4334 | } |
| 4335 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4336 | /* |
| 4337 | * 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] | 4338 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4339 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 4340 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 4341 | */ |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4342 | static uint_fixed_16_16_t skl_wm_method1(uint32_t pixel_rate, uint8_t cpp, |
| 4343 | uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4344 | { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4345 | uint32_t wm_intermediate_val; |
| 4346 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4347 | |
| 4348 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4349 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4350 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4351 | wm_intermediate_val = latency * pixel_rate * cpp; |
Kumar, Mahesh | afbc95c | 2017-05-17 17:28:20 +0530 | [diff] [blame] | 4352 | ret = fixed_16_16_div_u64(wm_intermediate_val, 1000 * 512); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4353 | return ret; |
| 4354 | } |
| 4355 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4356 | static uint_fixed_16_16_t skl_wm_method2(uint32_t pixel_rate, |
| 4357 | uint32_t pipe_htotal, |
| 4358 | uint32_t latency, |
| 4359 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4360 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4361 | uint32_t wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4362 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4363 | |
| 4364 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4365 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4366 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4367 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4368 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 4369 | pipe_htotal * 1000); |
| 4370 | ret = mul_u32_fixed_16_16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4371 | return ret; |
| 4372 | } |
| 4373 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4374 | static uint_fixed_16_16_t |
| 4375 | intel_get_linetime_us(struct intel_crtc_state *cstate) |
| 4376 | { |
| 4377 | uint32_t pixel_rate; |
| 4378 | uint32_t crtc_htotal; |
| 4379 | uint_fixed_16_16_t linetime_us; |
| 4380 | |
| 4381 | if (!cstate->base.active) |
| 4382 | return u32_to_fixed_16_16(0); |
| 4383 | |
| 4384 | pixel_rate = cstate->pixel_rate; |
| 4385 | |
| 4386 | if (WARN_ON(pixel_rate == 0)) |
| 4387 | return u32_to_fixed_16_16(0); |
| 4388 | |
| 4389 | crtc_htotal = cstate->base.adjusted_mode.crtc_htotal; |
| 4390 | linetime_us = fixed_16_16_div_u64(crtc_htotal * 1000, pixel_rate); |
| 4391 | |
| 4392 | return linetime_us; |
| 4393 | } |
| 4394 | |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4395 | static uint32_t |
| 4396 | skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *cstate, |
| 4397 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4398 | { |
| 4399 | uint64_t adjusted_pixel_rate; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4400 | uint_fixed_16_16_t downscale_amount; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4401 | |
| 4402 | /* Shouldn't reach here on disabled planes... */ |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4403 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4404 | return 0; |
| 4405 | |
| 4406 | /* |
| 4407 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 4408 | * with additional adjustments for plane-specific scaling. |
| 4409 | */ |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 4410 | adjusted_pixel_rate = cstate->pixel_rate; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4411 | downscale_amount = skl_plane_downscale_amount(cstate, pstate); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4412 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4413 | return mul_round_up_u32_fixed16(adjusted_pixel_rate, |
| 4414 | downscale_amount); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4417 | static int skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 4418 | struct intel_crtc_state *cstate, |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4419 | const struct intel_plane_state *intel_pstate, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4420 | int level, |
| 4421 | uint16_t *out_blocks, /* out */ |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4422 | uint8_t *out_lines /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4423 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4424 | struct intel_plane *plane = to_intel_plane(intel_pstate->base.plane); |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4425 | const struct drm_plane_state *pstate = &intel_pstate->base; |
| 4426 | const struct drm_framebuffer *fb = pstate->fb; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4427 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4428 | uint_fixed_16_16_t method1, method2; |
| 4429 | uint_fixed_16_16_t plane_blocks_per_line; |
| 4430 | uint_fixed_16_16_t selected_result; |
| 4431 | uint32_t interm_pbpl; |
| 4432 | uint32_t plane_bytes_per_line; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4433 | uint32_t res_blocks, res_lines; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 4434 | uint8_t cpp; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4435 | uint32_t width = 0, height = 0; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4436 | uint32_t plane_pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4437 | uint_fixed_16_16_t y_tile_minimum; |
| 4438 | uint32_t y_min_scanlines; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4439 | struct intel_atomic_state *state = |
| 4440 | to_intel_atomic_state(cstate->base.state); |
| 4441 | bool apply_memory_bw_wa = skl_needs_memory_bw_wa(state); |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4442 | bool y_tiled, x_tiled; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4443 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4444 | if (latency == 0 || |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4445 | !intel_wm_plane_visible(cstate, intel_pstate)) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4446 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4447 | |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4448 | y_tiled = fb->modifier == I915_FORMAT_MOD_Y_TILED || |
| 4449 | fb->modifier == I915_FORMAT_MOD_Yf_TILED; |
| 4450 | x_tiled = fb->modifier == I915_FORMAT_MOD_X_TILED; |
| 4451 | |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 4452 | /* Display WA #1141: kbl. */ |
| 4453 | if (IS_KABYLAKE(dev_priv) && dev_priv->ipc_enabled) |
| 4454 | latency += 4; |
| 4455 | |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4456 | if (apply_memory_bw_wa && x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4457 | latency += 15; |
| 4458 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4459 | if (plane->id == PLANE_CURSOR) { |
| 4460 | width = intel_pstate->base.crtc_w; |
| 4461 | height = intel_pstate->base.crtc_h; |
| 4462 | } else { |
| 4463 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4464 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
| 4465 | } |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4466 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 4467 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4468 | swap(width, height); |
| 4469 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4470 | cpp = fb->format->cpp[0]; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4471 | plane_pixel_rate = skl_adjusted_plane_pixel_rate(cstate, intel_pstate); |
| 4472 | |
Dave Airlie | 61d0a04 | 2016-10-25 16:35:20 +1000 | [diff] [blame] | 4473 | if (drm_rotation_90_or_270(pstate->rotation)) { |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4474 | int cpp = (fb->format->format == DRM_FORMAT_NV12) ? |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4475 | fb->format->cpp[1] : |
| 4476 | fb->format->cpp[0]; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4477 | |
| 4478 | switch (cpp) { |
| 4479 | case 1: |
| 4480 | y_min_scanlines = 16; |
| 4481 | break; |
| 4482 | case 2: |
| 4483 | y_min_scanlines = 8; |
| 4484 | break; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4485 | case 4: |
| 4486 | y_min_scanlines = 4; |
| 4487 | break; |
Paulo Zanoni | 86a462b | 2016-09-22 18:00:35 -0300 | [diff] [blame] | 4488 | default: |
| 4489 | MISSING_CASE(cpp); |
| 4490 | return -EINVAL; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4491 | } |
| 4492 | } else { |
| 4493 | y_min_scanlines = 4; |
| 4494 | } |
| 4495 | |
Paulo Zanoni | 2ef32de | 2016-11-08 18:22:11 -0200 | [diff] [blame] | 4496 | if (apply_memory_bw_wa) |
| 4497 | y_min_scanlines *= 2; |
| 4498 | |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 4499 | plane_bytes_per_line = width * cpp; |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4500 | if (y_tiled) { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4501 | interm_pbpl = DIV_ROUND_UP(plane_bytes_per_line * |
| 4502 | y_min_scanlines, 512); |
Kumar, Mahesh | afbc95c | 2017-05-17 17:28:20 +0530 | [diff] [blame] | 4503 | plane_blocks_per_line = fixed_16_16_div(interm_pbpl, |
| 4504 | y_min_scanlines); |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4505 | } else if (x_tiled) { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4506 | interm_pbpl = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 4507 | plane_blocks_per_line = u32_to_fixed_16_16(interm_pbpl); |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4508 | } else { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4509 | interm_pbpl = DIV_ROUND_UP(plane_bytes_per_line, 512) + 1; |
| 4510 | plane_blocks_per_line = u32_to_fixed_16_16(interm_pbpl); |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 4511 | } |
| 4512 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4513 | method1 = skl_wm_method1(plane_pixel_rate, cpp, latency); |
| 4514 | method2 = skl_wm_method2(plane_pixel_rate, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4515 | cstate->base.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4516 | latency, |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 4517 | plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4518 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4519 | y_tile_minimum = mul_u32_fixed_16_16(y_min_scanlines, |
| 4520 | plane_blocks_per_line); |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4521 | |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4522 | if (y_tiled) { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4523 | selected_result = max_fixed_16_16(method2, y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4524 | } else { |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4525 | uint32_t linetime_us; |
| 4526 | |
| 4527 | linetime_us = fixed_16_16_to_u32_round_up( |
| 4528 | intel_get_linetime_us(cstate)); |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 4529 | if ((cpp * cstate->base.adjusted_mode.crtc_htotal / 512 < 1) && |
| 4530 | (plane_bytes_per_line / 512 < 1)) |
| 4531 | selected_result = method2; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4532 | else if (latency >= linetime_us) |
| 4533 | selected_result = min_fixed_16_16(method1, method2); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4534 | else |
| 4535 | selected_result = method1; |
| 4536 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4537 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4538 | res_blocks = fixed_16_16_to_u32_round_up(selected_result) + 1; |
Kumar, Mahesh | d273ecc | 2017-05-17 17:28:22 +0530 | [diff] [blame] | 4539 | res_lines = div_round_up_fixed16(selected_result, |
| 4540 | plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4541 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4542 | if (level >= 1 && level <= 7) { |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4543 | if (y_tiled) { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4544 | res_blocks += fixed_16_16_to_u32_round_up(y_tile_minimum); |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4545 | res_lines += y_min_scanlines; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4546 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4547 | res_blocks++; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4548 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4549 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4550 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4551 | if (res_lines >= 31 && level == 0) { |
| 4552 | struct drm_plane *plane = pstate->plane; |
Matt Roper | 6b6bada | 2016-05-12 07:06:10 -0700 | [diff] [blame] | 4553 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4554 | DRM_DEBUG_KMS("Requested display configuration exceeds system watermark limitations\n"); |
| 4555 | DRM_DEBUG_KMS("[PLANE:%d:%s] lines required = %u/31\n", |
| 4556 | plane->base.id, plane->name, res_lines); |
| 4557 | return -EINVAL; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4558 | } |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4559 | |
| 4560 | *out_blocks = res_blocks; |
| 4561 | *out_lines = res_lines; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4562 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4563 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4566 | static int |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4567 | skl_compute_wm_levels(const struct drm_i915_private *dev_priv, |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4568 | struct intel_crtc_state *cstate, |
| 4569 | const struct intel_plane_state *intel_pstate, |
| 4570 | struct skl_plane_wm *wm) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4571 | { |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4572 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4573 | int ret; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4574 | |
Kumar, Mahesh | 7b75119 | 2017-05-17 17:28:24 +0530 | [diff] [blame] | 4575 | if (WARN_ON(!intel_pstate->base.fb)) |
| 4576 | return -EINVAL; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4577 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4578 | for (level = 0; level <= max_level; level++) { |
| 4579 | struct skl_wm_level *result = &wm->wm[level]; |
| 4580 | |
| 4581 | ret = skl_compute_plane_wm(dev_priv, |
| 4582 | cstate, |
| 4583 | intel_pstate, |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4584 | level, |
| 4585 | &result->plane_res_b, |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4586 | &result->plane_res_l); |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4587 | if (ret) |
| 4588 | return ret; |
| 4589 | } |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4590 | |
| 4591 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4592 | } |
| 4593 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4594 | static uint32_t |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4595 | skl_compute_linetime_wm(struct intel_crtc_state *cstate) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4596 | { |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4597 | struct drm_atomic_state *state = cstate->base.state; |
| 4598 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4599 | uint_fixed_16_16_t linetime_us; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4600 | uint32_t linetime_wm; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4601 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4602 | linetime_us = intel_get_linetime_us(cstate); |
| 4603 | |
| 4604 | if (is_fixed16_zero(linetime_us)) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4605 | return 0; |
| 4606 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4607 | linetime_wm = fixed_16_16_to_u32_round_up(mul_u32_fixed_16_16(8, |
| 4608 | linetime_us)); |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4609 | |
| 4610 | /* Display WA #1135: bxt. */ |
| 4611 | if (IS_BROXTON(dev_priv) && dev_priv->ipc_enabled) |
| 4612 | linetime_wm = DIV_ROUND_UP(linetime_wm, 2); |
| 4613 | |
| 4614 | return linetime_wm; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4615 | } |
| 4616 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4617 | static void skl_compute_transition_wm(struct intel_crtc_state *cstate, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4618 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4619 | { |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4620 | if (!cstate->base.active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4621 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4622 | |
| 4623 | /* Until we know more, just disable transition WMs */ |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4624 | trans_wm->plane_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4627 | static int skl_build_pipe_wm(struct intel_crtc_state *cstate, |
| 4628 | struct skl_ddb_allocation *ddb, |
| 4629 | struct skl_pipe_wm *pipe_wm) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4630 | { |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4631 | struct drm_device *dev = cstate->base.crtc->dev; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4632 | struct drm_crtc_state *crtc_state = &cstate->base; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4633 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4634 | struct drm_plane *plane; |
| 4635 | const struct drm_plane_state *pstate; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4636 | struct skl_plane_wm *wm; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4637 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4638 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4639 | /* |
| 4640 | * We'll only calculate watermarks for planes that are actually |
| 4641 | * enabled, so make sure all other planes are set as disabled. |
| 4642 | */ |
| 4643 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 4644 | |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4645 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { |
| 4646 | const struct intel_plane_state *intel_pstate = |
| 4647 | to_intel_plane_state(pstate); |
| 4648 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 4649 | |
| 4650 | wm = &pipe_wm->planes[plane_id]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4651 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4652 | ret = skl_compute_wm_levels(dev_priv, cstate, intel_pstate, wm); |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4653 | if (ret) |
| 4654 | return ret; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4655 | skl_compute_transition_wm(cstate, &wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4656 | } |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4657 | pipe_wm->linetime = skl_compute_linetime_wm(cstate); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4658 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4659 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4662 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 4663 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 4664 | const struct skl_ddb_entry *entry) |
| 4665 | { |
| 4666 | if (entry->end) |
| 4667 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 4668 | else |
| 4669 | I915_WRITE(reg, 0); |
| 4670 | } |
| 4671 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4672 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 4673 | i915_reg_t reg, |
| 4674 | const struct skl_wm_level *level) |
| 4675 | { |
| 4676 | uint32_t val = 0; |
| 4677 | |
| 4678 | if (level->plane_en) { |
| 4679 | val |= PLANE_WM_EN; |
| 4680 | val |= level->plane_res_b; |
| 4681 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
| 4682 | } |
| 4683 | |
| 4684 | I915_WRITE(reg, val); |
| 4685 | } |
| 4686 | |
Ville Syrjälä | d9348de | 2016-11-22 22:21:53 +0200 | [diff] [blame] | 4687 | static void skl_write_plane_wm(struct intel_crtc *intel_crtc, |
| 4688 | const struct skl_plane_wm *wm, |
| 4689 | const struct skl_ddb_allocation *ddb, |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4690 | enum plane_id plane_id) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4691 | { |
| 4692 | struct drm_crtc *crtc = &intel_crtc->base; |
| 4693 | struct drm_device *dev = crtc->dev; |
| 4694 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4695 | int level, max_level = ilk_wm_max_level(dev_priv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4696 | enum pipe pipe = intel_crtc->pipe; |
| 4697 | |
| 4698 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4699 | skl_write_wm_level(dev_priv, PLANE_WM(pipe, plane_id, level), |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4700 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4701 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4702 | skl_write_wm_level(dev_priv, PLANE_WM_TRANS(pipe, plane_id), |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4703 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4704 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4705 | skl_ddb_entry_write(dev_priv, PLANE_BUF_CFG(pipe, plane_id), |
| 4706 | &ddb->plane[pipe][plane_id]); |
| 4707 | skl_ddb_entry_write(dev_priv, PLANE_NV12_BUF_CFG(pipe, plane_id), |
| 4708 | &ddb->y_plane[pipe][plane_id]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4709 | } |
| 4710 | |
Ville Syrjälä | d9348de | 2016-11-22 22:21:53 +0200 | [diff] [blame] | 4711 | static void skl_write_cursor_wm(struct intel_crtc *intel_crtc, |
| 4712 | const struct skl_plane_wm *wm, |
| 4713 | const struct skl_ddb_allocation *ddb) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4714 | { |
| 4715 | struct drm_crtc *crtc = &intel_crtc->base; |
| 4716 | struct drm_device *dev = crtc->dev; |
| 4717 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4718 | int level, max_level = ilk_wm_max_level(dev_priv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4719 | enum pipe pipe = intel_crtc->pipe; |
| 4720 | |
| 4721 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4722 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 4723 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4724 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4725 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4726 | |
| 4727 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4728 | &ddb->plane[pipe][PLANE_CURSOR]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4729 | } |
| 4730 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 4731 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 4732 | const struct skl_wm_level *l2) |
| 4733 | { |
| 4734 | if (l1->plane_en != l2->plane_en) |
| 4735 | return false; |
| 4736 | |
| 4737 | /* If both planes aren't enabled, the rest shouldn't matter */ |
| 4738 | if (!l1->plane_en) |
| 4739 | return true; |
| 4740 | |
| 4741 | return (l1->plane_res_l == l2->plane_res_l && |
| 4742 | l1->plane_res_b == l2->plane_res_b); |
| 4743 | } |
| 4744 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4745 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 4746 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4747 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4748 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4749 | } |
| 4750 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 4751 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry **entries, |
| 4752 | const struct skl_ddb_entry *ddb, |
| 4753 | int ignore) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4754 | { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4755 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4756 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 4757 | for (i = 0; i < I915_MAX_PIPES; i++) |
| 4758 | if (i != ignore && entries[i] && |
| 4759 | skl_ddb_entries_overlap(ddb, entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4760 | return true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4761 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4762 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4763 | } |
| 4764 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4765 | static int |
| 4766 | skl_ddb_add_affected_planes(struct intel_crtc_state *cstate, |
| 4767 | const struct skl_pipe_wm *old_pipe_wm, |
| 4768 | const struct skl_pipe_wm *pipe_wm) |
| 4769 | { |
| 4770 | struct drm_atomic_state *state = cstate->base.state; |
| 4771 | struct drm_device *dev = state->dev; |
| 4772 | struct drm_crtc *crtc = cstate->base.crtc; |
| 4773 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4774 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 4775 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4776 | struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb; |
| 4777 | struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 4778 | struct drm_plane_state *plane_state; |
| 4779 | struct drm_plane *plane; |
| 4780 | enum pipe pipe = intel_crtc->pipe; |
| 4781 | |
| 4782 | WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc)); |
| 4783 | |
| 4784 | drm_for_each_plane_mask(plane, dev, cstate->base.plane_mask) { |
| 4785 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 4786 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 4787 | const struct skl_plane_wm *old_wm = &old_pipe_wm->planes[plane_id]; |
| 4788 | |
| 4789 | if ((skl_ddb_entry_equal(&cur_ddb->plane[pipe][plane_id], |
| 4790 | &new_ddb->plane[pipe][plane_id]) && |
| 4791 | skl_ddb_entry_equal(&cur_ddb->y_plane[pipe][plane_id], |
| 4792 | &new_ddb->y_plane[pipe][plane_id])) && |
| 4793 | !memcmp(wm, old_wm, sizeof(struct skl_plane_wm))) |
| 4794 | continue; |
| 4795 | |
| 4796 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 4797 | if (IS_ERR(plane_state)) |
| 4798 | return PTR_ERR(plane_state); |
| 4799 | } |
| 4800 | |
| 4801 | return 0; |
| 4802 | } |
| 4803 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4804 | static int skl_update_pipe_wm(struct drm_crtc_state *cstate, |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4805 | const struct skl_pipe_wm *old_pipe_wm, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4806 | struct skl_pipe_wm *pipe_wm, /* out */ |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4807 | struct skl_ddb_allocation *ddb, /* out */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4808 | bool *changed /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4809 | { |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4810 | struct intel_crtc_state *intel_cstate = to_intel_crtc_state(cstate); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4811 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4812 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4813 | ret = skl_build_pipe_wm(intel_cstate, ddb, pipe_wm); |
| 4814 | if (ret) |
| 4815 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4816 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4817 | ret = skl_allocate_pipe_ddb(intel_cstate, pipe_wm, ddb); |
| 4818 | if (ret) |
| 4819 | return ret; |
| 4820 | /* |
| 4821 | * TODO: Planes are included in state to arm WM registers. |
| 4822 | * Scope to optimize further, by just rewriting plane surf register. |
| 4823 | */ |
| 4824 | ret = skl_ddb_add_affected_planes(intel_cstate, old_pipe_wm, pipe_wm); |
| 4825 | if (ret) |
| 4826 | return ret; |
| 4827 | |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4828 | if (!memcmp(old_pipe_wm, pipe_wm, sizeof(*pipe_wm))) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4829 | *changed = false; |
| 4830 | else |
| 4831 | *changed = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4832 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4833 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4834 | } |
| 4835 | |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4836 | static uint32_t |
| 4837 | pipes_modified(struct drm_atomic_state *state) |
| 4838 | { |
| 4839 | struct drm_crtc *crtc; |
| 4840 | struct drm_crtc_state *cstate; |
| 4841 | uint32_t i, ret = 0; |
| 4842 | |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 4843 | for_each_new_crtc_in_state(state, crtc, cstate, i) |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4844 | ret |= drm_crtc_mask(crtc); |
| 4845 | |
| 4846 | return ret; |
| 4847 | } |
| 4848 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 4849 | static int |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 4850 | skl_include_affected_crtcs(struct drm_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4851 | { |
| 4852 | struct drm_device *dev = state->dev; |
| 4853 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 4854 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4855 | struct intel_crtc *intel_crtc; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4856 | struct skl_ddb_allocation *ddb = &intel_state->wm_results.ddb; |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4857 | uint32_t realloc_pipes = pipes_modified(state); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4858 | int ret; |
| 4859 | |
| 4860 | /* |
| 4861 | * If this is our first atomic update following hardware readout, |
| 4862 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 4863 | * pretend that all pipes switched active status so that we'll |
| 4864 | * ensure a full DDB recompute. |
| 4865 | */ |
Matt Roper | 1b54a88 | 2016-06-17 13:42:18 -0700 | [diff] [blame] | 4866 | if (dev_priv->wm.distrust_bios_wm) { |
| 4867 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
| 4868 | state->acquire_ctx); |
| 4869 | if (ret) |
| 4870 | return ret; |
| 4871 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4872 | intel_state->active_pipe_changes = ~0; |
| 4873 | |
Matt Roper | 1b54a88 | 2016-06-17 13:42:18 -0700 | [diff] [blame] | 4874 | /* |
| 4875 | * We usually only initialize intel_state->active_crtcs if we |
| 4876 | * we're doing a modeset; make sure this field is always |
| 4877 | * initialized during the sanitization process that happens |
| 4878 | * on the first commit too. |
| 4879 | */ |
| 4880 | if (!intel_state->modeset) |
| 4881 | intel_state->active_crtcs = dev_priv->active_crtcs; |
| 4882 | } |
| 4883 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4884 | /* |
| 4885 | * If the modeset changes which CRTC's are active, we need to |
| 4886 | * recompute the DDB allocation for *all* active pipes, even |
| 4887 | * those that weren't otherwise being modified in any way by this |
| 4888 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 4889 | * when new active CRTC's are added, it's possible for a pipe that |
| 4890 | * we were already using and aren't changing at all here to suddenly |
| 4891 | * become invalid if its DDB needs exceeds its new allocation. |
| 4892 | * |
| 4893 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 4894 | * any other display updates race with this transaction, so we need |
| 4895 | * to grab the lock on *all* CRTC's. |
| 4896 | */ |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4897 | if (intel_state->active_pipe_changes) { |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4898 | realloc_pipes = ~0; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4899 | intel_state->wm_results.dirty_pipes = ~0; |
| 4900 | } |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4901 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4902 | /* |
| 4903 | * We're not recomputing for the pipes not included in the commit, so |
| 4904 | * make sure we start with the current state. |
| 4905 | */ |
| 4906 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 4907 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4908 | for_each_intel_crtc_mask(dev, intel_crtc, realloc_pipes) { |
| 4909 | struct intel_crtc_state *cstate; |
| 4910 | |
| 4911 | cstate = intel_atomic_get_crtc_state(state, intel_crtc); |
| 4912 | if (IS_ERR(cstate)) |
| 4913 | return PTR_ERR(cstate); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | return 0; |
| 4917 | } |
| 4918 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4919 | static void |
| 4920 | skl_copy_wm_for_pipe(struct skl_wm_values *dst, |
| 4921 | struct skl_wm_values *src, |
| 4922 | enum pipe pipe) |
| 4923 | { |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4924 | memcpy(dst->ddb.y_plane[pipe], src->ddb.y_plane[pipe], |
| 4925 | sizeof(dst->ddb.y_plane[pipe])); |
| 4926 | memcpy(dst->ddb.plane[pipe], src->ddb.plane[pipe], |
| 4927 | sizeof(dst->ddb.plane[pipe])); |
| 4928 | } |
| 4929 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4930 | static void |
| 4931 | skl_print_wm_changes(const struct drm_atomic_state *state) |
| 4932 | { |
| 4933 | const struct drm_device *dev = state->dev; |
| 4934 | const struct drm_i915_private *dev_priv = to_i915(dev); |
| 4935 | const struct intel_atomic_state *intel_state = |
| 4936 | to_intel_atomic_state(state); |
| 4937 | const struct drm_crtc *crtc; |
| 4938 | const struct drm_crtc_state *cstate; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4939 | const struct intel_plane *intel_plane; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4940 | const struct skl_ddb_allocation *old_ddb = &dev_priv->wm.skl_hw.ddb; |
| 4941 | const struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4942 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4943 | |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 4944 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4945 | const struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4946 | enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4947 | |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4948 | for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4949 | enum plane_id plane_id = intel_plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4950 | const struct skl_ddb_entry *old, *new; |
| 4951 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4952 | old = &old_ddb->plane[pipe][plane_id]; |
| 4953 | new = &new_ddb->plane[pipe][plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4954 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4955 | if (skl_ddb_entry_equal(old, new)) |
| 4956 | continue; |
| 4957 | |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4958 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] ddb (%d - %d) -> (%d - %d)\n", |
| 4959 | intel_plane->base.base.id, |
| 4960 | intel_plane->base.name, |
| 4961 | old->start, old->end, |
| 4962 | new->start, new->end); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4963 | } |
| 4964 | } |
| 4965 | } |
| 4966 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4967 | static int |
| 4968 | skl_compute_wm(struct drm_atomic_state *state) |
| 4969 | { |
| 4970 | struct drm_crtc *crtc; |
| 4971 | struct drm_crtc_state *cstate; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4972 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4973 | struct skl_wm_values *results = &intel_state->wm_results; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 4974 | struct drm_device *dev = state->dev; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4975 | struct skl_pipe_wm *pipe_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4976 | bool changed = false; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4977 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4978 | |
| 4979 | /* |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 4980 | * When we distrust bios wm we always need to recompute to set the |
| 4981 | * expected DDB allocations for each CRTC. |
| 4982 | */ |
| 4983 | if (to_i915(dev)->wm.distrust_bios_wm) |
| 4984 | changed = true; |
| 4985 | |
| 4986 | /* |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4987 | * If this transaction isn't actually touching any CRTC's, don't |
| 4988 | * bother with watermark calculation. Note that if we pass this |
| 4989 | * test, we're guaranteed to hold at least one CRTC state mutex, |
| 4990 | * which means we can safely use values like dev_priv->active_crtcs |
| 4991 | * since any racing commits that want to update them would need to |
| 4992 | * hold _all_ CRTC state mutexes. |
| 4993 | */ |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 4994 | for_each_new_crtc_in_state(state, crtc, cstate, i) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4995 | changed = true; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 4996 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4997 | if (!changed) |
| 4998 | return 0; |
| 4999 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5000 | /* Clear all dirty flags */ |
| 5001 | results->dirty_pipes = 0; |
| 5002 | |
Kumar, Mahesh | bb9d85f | 2017-06-01 11:29:18 +0530 | [diff] [blame] | 5003 | ret = skl_include_affected_crtcs(state); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5004 | if (ret) |
| 5005 | return ret; |
| 5006 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5007 | /* |
| 5008 | * Calculate WM's for all pipes that are part of this transaction. |
| 5009 | * Note that the DDB allocation above may have added more CRTC's that |
| 5010 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 5011 | * pipe allocations had to change. |
| 5012 | * |
| 5013 | * FIXME: Now that we're doing this in the atomic check phase, we |
| 5014 | * should allow skl_update_pipe_wm() to return failure in cases where |
| 5015 | * no suitable watermark values can be found. |
| 5016 | */ |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 5017 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5018 | struct intel_crtc_state *intel_cstate = |
| 5019 | to_intel_crtc_state(cstate); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5020 | const struct skl_pipe_wm *old_pipe_wm = |
| 5021 | &to_intel_crtc_state(crtc->state)->wm.skl.optimal; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5022 | |
| 5023 | pipe_wm = &intel_cstate->wm.skl.optimal; |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5024 | ret = skl_update_pipe_wm(cstate, old_pipe_wm, pipe_wm, |
| 5025 | &results->ddb, &changed); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5026 | if (ret) |
| 5027 | return ret; |
| 5028 | |
| 5029 | if (changed) |
| 5030 | results->dirty_pipes |= drm_crtc_mask(crtc); |
| 5031 | |
| 5032 | if ((results->dirty_pipes & drm_crtc_mask(crtc)) == 0) |
| 5033 | /* This pipe's WM's did not change */ |
| 5034 | continue; |
| 5035 | |
| 5036 | intel_cstate->update_wm_pre = true; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5037 | } |
| 5038 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5039 | skl_print_wm_changes(state); |
| 5040 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5041 | return 0; |
| 5042 | } |
| 5043 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5044 | static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state, |
| 5045 | struct intel_crtc_state *cstate) |
| 5046 | { |
| 5047 | struct intel_crtc *crtc = to_intel_crtc(cstate->base.crtc); |
| 5048 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5049 | struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5050 | const struct skl_ddb_allocation *ddb = &state->wm_results.ddb; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5051 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5052 | enum plane_id plane_id; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5053 | |
| 5054 | if (!(state->wm_results.dirty_pipes & drm_crtc_mask(&crtc->base))) |
| 5055 | return; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5056 | |
| 5057 | I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5058 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5059 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5060 | if (plane_id != PLANE_CURSOR) |
| 5061 | skl_write_plane_wm(crtc, &pipe_wm->planes[plane_id], |
| 5062 | ddb, plane_id); |
| 5063 | else |
| 5064 | skl_write_cursor_wm(crtc, &pipe_wm->planes[plane_id], |
| 5065 | ddb); |
| 5066 | } |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5067 | } |
| 5068 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5069 | static void skl_initial_wm(struct intel_atomic_state *state, |
| 5070 | struct intel_crtc_state *cstate) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5071 | { |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5072 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5073 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5074 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5075 | struct skl_wm_values *results = &state->wm_results; |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 5076 | struct skl_wm_values *hw_vals = &dev_priv->wm.skl_hw; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5077 | enum pipe pipe = intel_crtc->pipe; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 5078 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5079 | if ((results->dirty_pipes & drm_crtc_mask(&intel_crtc->base)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5080 | return; |
| 5081 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5082 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5083 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5084 | if (cstate->base.active_changed) |
| 5085 | skl_atomic_update_crtc_wm(state, cstate); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5086 | |
| 5087 | skl_copy_wm_for_pipe(hw_vals, results, pipe); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5088 | |
| 5089 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5090 | } |
| 5091 | |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5092 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 5093 | struct intel_wm_config *config) |
| 5094 | { |
| 5095 | struct intel_crtc *crtc; |
| 5096 | |
| 5097 | /* Compute the currently _active_ config */ |
| 5098 | for_each_intel_crtc(dev, crtc) { |
| 5099 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 5100 | |
| 5101 | if (!wm->pipe_enabled) |
| 5102 | continue; |
| 5103 | |
| 5104 | config->sprites_enabled |= wm->sprites_enabled; |
| 5105 | config->sprites_scaled |= wm->sprites_scaled; |
| 5106 | config->num_pipes_active++; |
| 5107 | } |
| 5108 | } |
| 5109 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5110 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 5111 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 5112 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5113 | 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] | 5114 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5115 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5116 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5117 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 5118 | |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5119 | ilk_compute_wm_config(dev, &config); |
| 5120 | |
| 5121 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 5122 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 5123 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5124 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5125 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5126 | config.num_pipes_active == 1 && config.sprites_enabled) { |
| 5127 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 5128 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5129 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5130 | 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] | 5131 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5132 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5133 | } |
| 5134 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5135 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5136 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5137 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5138 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 5139 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5140 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 5141 | } |
| 5142 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5143 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
| 5144 | struct intel_crtc_state *cstate) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5145 | { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5146 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 5147 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5148 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5149 | mutex_lock(&dev_priv->wm.wm_mutex); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5150 | intel_crtc->wm.active.ilk = cstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5151 | ilk_program_watermarks(dev_priv); |
| 5152 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5153 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5154 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5155 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
| 5156 | struct intel_crtc_state *cstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5157 | { |
| 5158 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 5159 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
| 5160 | |
| 5161 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5162 | if (cstate->wm.need_postvbl_update) { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5163 | intel_crtc->wm.active.ilk = cstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5164 | ilk_program_watermarks(dev_priv); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5165 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5166 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5169 | static inline void skl_wm_level_from_reg_val(uint32_t val, |
| 5170 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5171 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5172 | level->plane_en = val & PLANE_WM_EN; |
| 5173 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 5174 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 5175 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5176 | } |
| 5177 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5178 | void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc, |
| 5179 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5180 | { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5181 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5182 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5183 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5184 | int level, max_level; |
| 5185 | enum plane_id plane_id; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5186 | uint32_t val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5187 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5188 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5189 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5190 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 5191 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5192 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5193 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5194 | if (plane_id != PLANE_CURSOR) |
| 5195 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5196 | else |
| 5197 | val = I915_READ(CUR_WM(pipe, level)); |
| 5198 | |
| 5199 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 5200 | } |
| 5201 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5202 | if (plane_id != PLANE_CURSOR) |
| 5203 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5204 | else |
| 5205 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 5206 | |
| 5207 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 5208 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5209 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 5210 | if (!intel_crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5211 | return; |
| 5212 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5213 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 5217 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5218 | struct drm_i915_private *dev_priv = to_i915(dev); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5219 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5220 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5221 | struct drm_crtc *crtc; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5222 | struct intel_crtc *intel_crtc; |
| 5223 | struct intel_crtc_state *cstate; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5224 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5225 | skl_ddb_get_hw_state(dev_priv, ddb); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5226 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 5227 | intel_crtc = to_intel_crtc(crtc); |
| 5228 | cstate = to_intel_crtc_state(crtc->state); |
| 5229 | |
| 5230 | skl_pipe_wm_get_hw_state(crtc, &cstate->wm.skl.optimal); |
| 5231 | |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5232 | if (intel_crtc->active) |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5233 | hw->dirty_pipes |= drm_crtc_mask(crtc); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5234 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5235 | |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5236 | if (dev_priv->active_crtcs) { |
| 5237 | /* Fully recompute DDB on first atomic commit */ |
| 5238 | dev_priv->wm.distrust_bios_wm = true; |
| 5239 | } else { |
| 5240 | /* Easy/common case; just sanitize DDB now if everything off */ |
| 5241 | memset(ddb, 0, sizeof(*ddb)); |
| 5242 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5243 | } |
| 5244 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5245 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 5246 | { |
| 5247 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5248 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5249 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5250 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5251 | struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5252 | struct intel_pipe_wm *active = &cstate->wm.ilk.optimal; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5253 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5254 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5255 | [PIPE_A] = WM0_PIPEA_ILK, |
| 5256 | [PIPE_B] = WM0_PIPEB_ILK, |
| 5257 | [PIPE_C] = WM0_PIPEC_IVB, |
| 5258 | }; |
| 5259 | |
| 5260 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5261 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 5262 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5263 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 5264 | memset(active, 0, sizeof(*active)); |
| 5265 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 5266 | active->pipe_enabled = intel_crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 5267 | |
| 5268 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5269 | u32 tmp = hw->wm_pipe[pipe]; |
| 5270 | |
| 5271 | /* |
| 5272 | * For active pipes LP0 watermark is marked as |
| 5273 | * enabled, and LP1+ watermaks as disabled since |
| 5274 | * we can't really reverse compute them in case |
| 5275 | * multiple pipes are active. |
| 5276 | */ |
| 5277 | active->wm[0].enable = true; |
| 5278 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 5279 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 5280 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 5281 | active->linetime = hw->wm_linetime[pipe]; |
| 5282 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5283 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5284 | |
| 5285 | /* |
| 5286 | * For inactive pipes, all watermark levels |
| 5287 | * should be marked as enabled but zeroed, |
| 5288 | * which is what we'd compute them to. |
| 5289 | */ |
| 5290 | for (level = 0; level <= max_level; level++) |
| 5291 | active->wm[level].enable = true; |
| 5292 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5293 | |
| 5294 | intel_crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5295 | } |
| 5296 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5297 | #define _FW_WM(value, plane) \ |
| 5298 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 5299 | #define _FW_WM_VLV(value, plane) \ |
| 5300 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 5301 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5302 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 5303 | struct g4x_wm_values *wm) |
| 5304 | { |
| 5305 | uint32_t tmp; |
| 5306 | |
| 5307 | tmp = I915_READ(DSPFW1); |
| 5308 | wm->sr.plane = _FW_WM(tmp, SR); |
| 5309 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5310 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 5311 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 5312 | |
| 5313 | tmp = I915_READ(DSPFW2); |
| 5314 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 5315 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 5316 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 5317 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 5318 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5319 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 5320 | |
| 5321 | tmp = I915_READ(DSPFW3); |
| 5322 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 5323 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5324 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 5325 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 5326 | } |
| 5327 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5328 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 5329 | struct vlv_wm_values *wm) |
| 5330 | { |
| 5331 | enum pipe pipe; |
| 5332 | uint32_t tmp; |
| 5333 | |
| 5334 | for_each_pipe(dev_priv, pipe) { |
| 5335 | tmp = I915_READ(VLV_DDL(pipe)); |
| 5336 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5337 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5338 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5339 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5340 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5341 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5342 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5343 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5344 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 5345 | } |
| 5346 | |
| 5347 | tmp = I915_READ(DSPFW1); |
| 5348 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5349 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5350 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 5351 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEA); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5352 | |
| 5353 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5354 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 5355 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5356 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEA); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5357 | |
| 5358 | tmp = I915_READ(DSPFW3); |
| 5359 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5360 | |
| 5361 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5362 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5363 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5364 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5365 | |
| 5366 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5367 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 5368 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEE); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5369 | |
| 5370 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5371 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 5372 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5373 | |
| 5374 | tmp = I915_READ(DSPHOWM); |
| 5375 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5376 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 5377 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 5378 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 5379 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5380 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5381 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5382 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5383 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5384 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEA_HI) << 8; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5385 | } else { |
| 5386 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5387 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5388 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5389 | |
| 5390 | tmp = I915_READ(DSPHOWM); |
| 5391 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5392 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5393 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5394 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5395 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5396 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5397 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEA_HI) << 8; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | #undef _FW_WM |
| 5402 | #undef _FW_WM_VLV |
| 5403 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5404 | void g4x_wm_get_hw_state(struct drm_device *dev) |
| 5405 | { |
| 5406 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5407 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 5408 | struct intel_crtc *crtc; |
| 5409 | |
| 5410 | g4x_read_wm_values(dev_priv, wm); |
| 5411 | |
| 5412 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 5413 | |
| 5414 | for_each_intel_crtc(dev, crtc) { |
| 5415 | struct intel_crtc_state *crtc_state = |
| 5416 | to_intel_crtc_state(crtc->base.state); |
| 5417 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 5418 | struct g4x_pipe_wm *raw; |
| 5419 | enum pipe pipe = crtc->pipe; |
| 5420 | enum plane_id plane_id; |
| 5421 | int level, max_level; |
| 5422 | |
| 5423 | active->cxsr = wm->cxsr; |
| 5424 | active->hpll_en = wm->hpll_en; |
| 5425 | active->fbc_en = wm->fbc_en; |
| 5426 | |
| 5427 | active->sr = wm->sr; |
| 5428 | active->hpll = wm->hpll; |
| 5429 | |
| 5430 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5431 | active->wm.plane[plane_id] = |
| 5432 | wm->pipe[pipe].plane[plane_id]; |
| 5433 | } |
| 5434 | |
| 5435 | if (wm->cxsr && wm->hpll_en) |
| 5436 | max_level = G4X_WM_LEVEL_HPLL; |
| 5437 | else if (wm->cxsr) |
| 5438 | max_level = G4X_WM_LEVEL_SR; |
| 5439 | else |
| 5440 | max_level = G4X_WM_LEVEL_NORMAL; |
| 5441 | |
| 5442 | level = G4X_WM_LEVEL_NORMAL; |
| 5443 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5444 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5445 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 5446 | |
| 5447 | if (++level > max_level) |
| 5448 | goto out; |
| 5449 | |
| 5450 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5451 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 5452 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 5453 | raw->plane[PLANE_SPRITE0] = 0; |
| 5454 | raw->fbc = active->sr.fbc; |
| 5455 | |
| 5456 | if (++level > max_level) |
| 5457 | goto out; |
| 5458 | |
| 5459 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5460 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 5461 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 5462 | raw->plane[PLANE_SPRITE0] = 0; |
| 5463 | raw->fbc = active->hpll.fbc; |
| 5464 | |
| 5465 | out: |
| 5466 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5467 | g4x_raw_plane_wm_set(crtc_state, level, |
| 5468 | plane_id, USHRT_MAX); |
| 5469 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 5470 | |
| 5471 | crtc_state->wm.g4x.optimal = *active; |
| 5472 | crtc_state->wm.g4x.intermediate = *active; |
| 5473 | |
| 5474 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 5475 | pipe_name(pipe), |
| 5476 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 5477 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 5478 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
| 5479 | } |
| 5480 | |
| 5481 | DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 5482 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 5483 | DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 5484 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 5485 | DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", |
| 5486 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
| 5487 | } |
| 5488 | |
| 5489 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 5490 | { |
| 5491 | struct intel_plane *plane; |
| 5492 | struct intel_crtc *crtc; |
| 5493 | |
| 5494 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5495 | |
| 5496 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 5497 | struct intel_crtc *crtc = |
| 5498 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 5499 | struct intel_crtc_state *crtc_state = |
| 5500 | to_intel_crtc_state(crtc->base.state); |
| 5501 | struct intel_plane_state *plane_state = |
| 5502 | to_intel_plane_state(plane->base.state); |
| 5503 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 5504 | enum plane_id plane_id = plane->id; |
| 5505 | int level; |
| 5506 | |
| 5507 | if (plane_state->base.visible) |
| 5508 | continue; |
| 5509 | |
| 5510 | for (level = 0; level < 3; level++) { |
| 5511 | struct g4x_pipe_wm *raw = |
| 5512 | &crtc_state->wm.g4x.raw[level]; |
| 5513 | |
| 5514 | raw->plane[plane_id] = 0; |
| 5515 | wm_state->wm.plane[plane_id] = 0; |
| 5516 | } |
| 5517 | |
| 5518 | if (plane_id == PLANE_PRIMARY) { |
| 5519 | for (level = 0; level < 3; level++) { |
| 5520 | struct g4x_pipe_wm *raw = |
| 5521 | &crtc_state->wm.g4x.raw[level]; |
| 5522 | raw->fbc = 0; |
| 5523 | } |
| 5524 | |
| 5525 | wm_state->sr.fbc = 0; |
| 5526 | wm_state->hpll.fbc = 0; |
| 5527 | wm_state->fbc_en = false; |
| 5528 | } |
| 5529 | } |
| 5530 | |
| 5531 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5532 | struct intel_crtc_state *crtc_state = |
| 5533 | to_intel_crtc_state(crtc->base.state); |
| 5534 | |
| 5535 | crtc_state->wm.g4x.intermediate = |
| 5536 | crtc_state->wm.g4x.optimal; |
| 5537 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 5538 | } |
| 5539 | |
| 5540 | g4x_program_watermarks(dev_priv); |
| 5541 | |
| 5542 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5543 | } |
| 5544 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5545 | void vlv_wm_get_hw_state(struct drm_device *dev) |
| 5546 | { |
| 5547 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5548 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 5549 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5550 | u32 val; |
| 5551 | |
| 5552 | vlv_read_wm_values(dev_priv, wm); |
| 5553 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5554 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 5555 | wm->level = VLV_WM_LEVEL_PM2; |
| 5556 | |
| 5557 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5558 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5559 | |
| 5560 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5561 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 5562 | wm->level = VLV_WM_LEVEL_PM5; |
| 5563 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 5564 | /* |
| 5565 | * If DDR DVFS is disabled in the BIOS, Punit |
| 5566 | * will never ack the request. So if that happens |
| 5567 | * assume we don't have to enable/disable DDR DVFS |
| 5568 | * dynamically. To test that just set the REQ_ACK |
| 5569 | * bit to poke the Punit, but don't change the |
| 5570 | * HIGH/LOW bits so that we don't actually change |
| 5571 | * the current state. |
| 5572 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5573 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 5574 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 5575 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 5576 | |
| 5577 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 5578 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 5579 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 5580 | "assuming DDR DVFS is disabled\n"); |
| 5581 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 5582 | } else { |
| 5583 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 5584 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 5585 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 5586 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5587 | |
| 5588 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5589 | } |
| 5590 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5591 | for_each_intel_crtc(dev, crtc) { |
| 5592 | struct intel_crtc_state *crtc_state = |
| 5593 | to_intel_crtc_state(crtc->base.state); |
| 5594 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 5595 | const struct vlv_fifo_state *fifo_state = |
| 5596 | &crtc_state->wm.vlv.fifo_state; |
| 5597 | enum pipe pipe = crtc->pipe; |
| 5598 | enum plane_id plane_id; |
| 5599 | int level; |
| 5600 | |
| 5601 | vlv_get_fifo_size(crtc_state); |
| 5602 | |
| 5603 | active->num_levels = wm->level + 1; |
| 5604 | active->cxsr = wm->cxsr; |
| 5605 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5606 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 5607 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5608 | &crtc_state->wm.vlv.raw[level]; |
| 5609 | |
| 5610 | active->sr[level].plane = wm->sr.plane; |
| 5611 | active->sr[level].cursor = wm->sr.cursor; |
| 5612 | |
| 5613 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5614 | active->wm[level].plane[plane_id] = |
| 5615 | wm->pipe[pipe].plane[plane_id]; |
| 5616 | |
| 5617 | raw->plane[plane_id] = |
| 5618 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 5619 | fifo_state->plane[plane_id]); |
| 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5624 | vlv_raw_plane_wm_set(crtc_state, level, |
| 5625 | plane_id, USHRT_MAX); |
| 5626 | vlv_invalidate_wms(crtc, active, level); |
| 5627 | |
| 5628 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 5629 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5630 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5631 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n", |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5632 | pipe_name(pipe), |
| 5633 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 5634 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 5635 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 5636 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5637 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5638 | |
| 5639 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 5640 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 5641 | } |
| 5642 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 5643 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 5644 | { |
| 5645 | struct intel_plane *plane; |
| 5646 | struct intel_crtc *crtc; |
| 5647 | |
| 5648 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5649 | |
| 5650 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 5651 | struct intel_crtc *crtc = |
| 5652 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 5653 | struct intel_crtc_state *crtc_state = |
| 5654 | to_intel_crtc_state(crtc->base.state); |
| 5655 | struct intel_plane_state *plane_state = |
| 5656 | to_intel_plane_state(plane->base.state); |
| 5657 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 5658 | const struct vlv_fifo_state *fifo_state = |
| 5659 | &crtc_state->wm.vlv.fifo_state; |
| 5660 | enum plane_id plane_id = plane->id; |
| 5661 | int level; |
| 5662 | |
| 5663 | if (plane_state->base.visible) |
| 5664 | continue; |
| 5665 | |
| 5666 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 5667 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 5668 | &crtc_state->wm.vlv.raw[level]; |
| 5669 | |
| 5670 | raw->plane[plane_id] = 0; |
| 5671 | |
| 5672 | wm_state->wm[level].plane[plane_id] = |
| 5673 | vlv_invert_wm_value(raw->plane[plane_id], |
| 5674 | fifo_state->plane[plane_id]); |
| 5675 | } |
| 5676 | } |
| 5677 | |
| 5678 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5679 | struct intel_crtc_state *crtc_state = |
| 5680 | to_intel_crtc_state(crtc->base.state); |
| 5681 | |
| 5682 | crtc_state->wm.vlv.intermediate = |
| 5683 | crtc_state->wm.vlv.optimal; |
| 5684 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 5685 | } |
| 5686 | |
| 5687 | vlv_program_watermarks(dev_priv); |
| 5688 | |
| 5689 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5690 | } |
| 5691 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5692 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 5693 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5694 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5695 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5696 | struct drm_crtc *crtc; |
| 5697 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 5698 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5699 | ilk_pipe_wm_get_hw_state(crtc); |
| 5700 | |
| 5701 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 5702 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 5703 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 5704 | |
| 5705 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5706 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 5707 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 5708 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 5709 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5710 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5711 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 5712 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 5713 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5714 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 5715 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 5716 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5717 | |
| 5718 | hw->enable_fbc_wm = |
| 5719 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 5720 | } |
| 5721 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5722 | /** |
| 5723 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 5724 | * |
| 5725 | * Calculate watermark values for the various WM regs based on current mode |
| 5726 | * and plane configuration. |
| 5727 | * |
| 5728 | * There are several cases to deal with here: |
| 5729 | * - normal (i.e. non-self-refresh) |
| 5730 | * - self-refresh (SR) mode |
| 5731 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 5732 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 5733 | * lines), so need to account for TLB latency |
| 5734 | * |
| 5735 | * The normal calculation is: |
| 5736 | * watermark = dotclock * bytes per pixel * latency |
| 5737 | * where latency is platform & configuration dependent (we assume pessimal |
| 5738 | * values here). |
| 5739 | * |
| 5740 | * The SR calculation is: |
| 5741 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 5742 | * bytes per pixel |
| 5743 | * where |
| 5744 | * line time = htotal / dotclock |
| 5745 | * surface width = hdisplay for normal plane and 64 for cursor |
| 5746 | * and latency is assumed to be high, as above. |
| 5747 | * |
| 5748 | * The final value programmed to the register should always be rounded up, |
| 5749 | * and include an extra 2 entries to account for clock crossings. |
| 5750 | * |
| 5751 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 5752 | * to set the non-SR watermarks to 8. |
| 5753 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5754 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5755 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5756 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5757 | |
| 5758 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 5759 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5760 | } |
| 5761 | |
Jani Nikula | e282891 | 2016-01-18 09:19:47 +0200 | [diff] [blame] | 5762 | /* |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5763 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5764 | */ |
| 5765 | DEFINE_SPINLOCK(mchdev_lock); |
| 5766 | |
| 5767 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 5768 | * mchdev_lock. */ |
| 5769 | static struct drm_i915_private *i915_mch_dev; |
| 5770 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5771 | bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5772 | { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5773 | u16 rgvswctl; |
| 5774 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 5775 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5776 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5777 | rgvswctl = I915_READ16(MEMSWCTL); |
| 5778 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 5779 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 5780 | return false; /* still busy with another command */ |
| 5781 | } |
| 5782 | |
| 5783 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 5784 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 5785 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 5786 | POSTING_READ16(MEMSWCTL); |
| 5787 | |
| 5788 | rgvswctl |= MEMCTL_CMD_STS; |
| 5789 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 5790 | |
| 5791 | return true; |
| 5792 | } |
| 5793 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5794 | static void ironlake_enable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5795 | { |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 5796 | u32 rgvmodectl; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5797 | u8 fmax, fmin, fstart, vstart; |
| 5798 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5799 | spin_lock_irq(&mchdev_lock); |
| 5800 | |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 5801 | rgvmodectl = I915_READ(MEMMODECTL); |
| 5802 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5803 | /* Enable temp reporting */ |
| 5804 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 5805 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 5806 | |
| 5807 | /* 100ms RC evaluation intervals */ |
| 5808 | I915_WRITE(RCUPEI, 100000); |
| 5809 | I915_WRITE(RCDNEI, 100000); |
| 5810 | |
| 5811 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 5812 | I915_WRITE(RCBMAXAVG, 90000); |
| 5813 | I915_WRITE(RCBMINAVG, 80000); |
| 5814 | |
| 5815 | I915_WRITE(MEMIHYST, 1); |
| 5816 | |
| 5817 | /* Set up min, max, and cur for interrupt handling */ |
| 5818 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 5819 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 5820 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 5821 | MEMMODE_FSTART_SHIFT; |
| 5822 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 5823 | vstart = (I915_READ(PXVFREQ(fstart)) & PXVFREQ_PX_MASK) >> |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5824 | PXVFREQ_PX_SHIFT; |
| 5825 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5826 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 5827 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5828 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5829 | dev_priv->ips.max_delay = fstart; |
| 5830 | dev_priv->ips.min_delay = fmin; |
| 5831 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5832 | |
| 5833 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 5834 | fmax, fmin, fstart); |
| 5835 | |
| 5836 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 5837 | |
| 5838 | /* |
| 5839 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 5840 | */ |
| 5841 | |
| 5842 | I915_WRITE(VIDSTART, vstart); |
| 5843 | POSTING_READ(VIDSTART); |
| 5844 | |
| 5845 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 5846 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 5847 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5848 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5849 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 5850 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5851 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5852 | ironlake_set_drps(dev_priv, fstart); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5853 | |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 5854 | dev_priv->ips.last_count1 = I915_READ(DMIEC) + |
| 5855 | I915_READ(DDREC) + I915_READ(CSIEC); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5856 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 5857 | dev_priv->ips.last_count2 = I915_READ(GFXEC); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5858 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5859 | |
| 5860 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5861 | } |
| 5862 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5863 | static void ironlake_disable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5864 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5865 | u16 rgvswctl; |
| 5866 | |
| 5867 | spin_lock_irq(&mchdev_lock); |
| 5868 | |
| 5869 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5870 | |
| 5871 | /* Ack interrupts, disable EFC interrupt */ |
| 5872 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 5873 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 5874 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 5875 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 5876 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 5877 | |
| 5878 | /* Go back to the starting frequency */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5879 | ironlake_set_drps(dev_priv, dev_priv->ips.fstart); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 5880 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5881 | rgvswctl |= MEMCTL_CMD_STS; |
| 5882 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 5883 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5884 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5885 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5886 | } |
| 5887 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 5888 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 5889 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 5890 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 5891 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 5892 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 5893 | 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] | 5894 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 5895 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5896 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 5897 | /* Only set the down limit when we've reached the lowest level to avoid |
| 5898 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 5899 | * race in the hw when coming out of rc6: There's a tiny window where |
| 5900 | * the hw runs at the minimal clock before selecting the desired |
| 5901 | * frequency, if the down threshold expires in that window we will not |
| 5902 | * receive a down interrupt. */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 5903 | if (IS_GEN9(dev_priv)) { |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 5904 | limits = (dev_priv->rps.max_freq_softlimit) << 23; |
| 5905 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 5906 | limits |= (dev_priv->rps.min_freq_softlimit) << 14; |
| 5907 | } else { |
| 5908 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 5909 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 5910 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
| 5911 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 5912 | |
| 5913 | return limits; |
| 5914 | } |
| 5915 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5916 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 5917 | { |
| 5918 | int new_power; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5919 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 5920 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5921 | |
| 5922 | new_power = dev_priv->rps.power; |
| 5923 | switch (dev_priv->rps.power) { |
| 5924 | case LOW_POWER: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5925 | if (val > dev_priv->rps.efficient_freq + 1 && |
| 5926 | val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5927 | new_power = BETWEEN; |
| 5928 | break; |
| 5929 | |
| 5930 | case BETWEEN: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5931 | if (val <= dev_priv->rps.efficient_freq && |
| 5932 | val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5933 | new_power = LOW_POWER; |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5934 | else if (val >= dev_priv->rps.rp0_freq && |
| 5935 | val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5936 | new_power = HIGH_POWER; |
| 5937 | break; |
| 5938 | |
| 5939 | case HIGH_POWER: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5940 | if (val < (dev_priv->rps.rp1_freq + dev_priv->rps.rp0_freq) >> 1 && |
| 5941 | val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5942 | new_power = BETWEEN; |
| 5943 | break; |
| 5944 | } |
| 5945 | /* Max/min bins are special */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5946 | if (val <= dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5947 | new_power = LOW_POWER; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5948 | if (val >= dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5949 | new_power = HIGH_POWER; |
| 5950 | if (new_power == dev_priv->rps.power) |
| 5951 | return; |
| 5952 | |
| 5953 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 5954 | switch (new_power) { |
| 5955 | case LOW_POWER: |
| 5956 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5957 | ei_up = 16000; |
| 5958 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5959 | |
| 5960 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5961 | ei_down = 32000; |
| 5962 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5963 | break; |
| 5964 | |
| 5965 | case BETWEEN: |
| 5966 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5967 | ei_up = 13000; |
| 5968 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5969 | |
| 5970 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5971 | ei_down = 32000; |
| 5972 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5973 | break; |
| 5974 | |
| 5975 | case HIGH_POWER: |
| 5976 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5977 | ei_up = 10000; |
| 5978 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5979 | |
| 5980 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5981 | ei_down = 32000; |
| 5982 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5983 | break; |
| 5984 | } |
| 5985 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 5986 | /* When byt can survive without system hang with dynamic |
| 5987 | * sw freq adjustments, this restriction can be lifted. |
| 5988 | */ |
| 5989 | if (IS_VALLEYVIEW(dev_priv)) |
| 5990 | goto skip_hw_write; |
| 5991 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5992 | I915_WRITE(GEN6_RP_UP_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5993 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5994 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5995 | GT_INTERVAL_FROM_US(dev_priv, |
| 5996 | ei_up * threshold_up / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5997 | |
| 5998 | I915_WRITE(GEN6_RP_DOWN_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5999 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6000 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6001 | GT_INTERVAL_FROM_US(dev_priv, |
| 6002 | ei_down * threshold_down / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6003 | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6004 | I915_WRITE(GEN6_RP_CONTROL, |
| 6005 | GEN6_RP_MEDIA_TURBO | |
| 6006 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6007 | GEN6_RP_MEDIA_IS_GFX | |
| 6008 | GEN6_RP_ENABLE | |
| 6009 | GEN6_RP_UP_BUSY_AVG | |
| 6010 | GEN6_RP_DOWN_IDLE_AVG); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6011 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6012 | skip_hw_write: |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6013 | dev_priv->rps.power = new_power; |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 6014 | dev_priv->rps.up_threshold = threshold_up; |
| 6015 | dev_priv->rps.down_threshold = threshold_down; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6016 | dev_priv->rps.last_adj = 0; |
| 6017 | } |
| 6018 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6019 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 6020 | { |
| 6021 | u32 mask = 0; |
| 6022 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6023 | /* We use UP_EI_EXPIRED interupts for both up/down in manual mode */ |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6024 | if (val > dev_priv->rps.min_freq_softlimit) |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6025 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6026 | if (val < dev_priv->rps.max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 6027 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6028 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 6029 | mask &= dev_priv->pm_rps_events; |
| 6030 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 6031 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6032 | } |
| 6033 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6034 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 6035 | * called when the range (min_delay and max_delay) is modified so that we can |
| 6036 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6037 | static int gen6_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6038 | { |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6039 | /* min/max delay may still have been modified so be sure to |
| 6040 | * write the limits value. |
| 6041 | */ |
| 6042 | if (val != dev_priv->rps.cur_freq) { |
| 6043 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6044 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6045 | if (IS_GEN9(dev_priv)) |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 6046 | I915_WRITE(GEN6_RPNSWREQ, |
| 6047 | GEN9_FREQUENCY(val)); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6048 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6049 | I915_WRITE(GEN6_RPNSWREQ, |
| 6050 | HSW_FREQUENCY(val)); |
| 6051 | else |
| 6052 | I915_WRITE(GEN6_RPNSWREQ, |
| 6053 | GEN6_FREQUENCY(val) | |
| 6054 | GEN6_OFFSET(0) | |
| 6055 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6056 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6057 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6058 | /* Make sure we continue to get interrupts |
| 6059 | * until we hit the minimum or maximum frequencies. |
| 6060 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6061 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6062 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6063 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 6064 | dev_priv->rps.cur_freq = val; |
Mika Kuoppala | 0f94592 | 2015-11-17 18:14:26 +0200 | [diff] [blame] | 6065 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6066 | |
| 6067 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6068 | } |
| 6069 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6070 | static int valleyview_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6071 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6072 | int err; |
| 6073 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6074 | if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1), |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6075 | "Odd GPU freq value\n")) |
| 6076 | val &= ~1; |
| 6077 | |
Deepak S | cd25dd5 | 2015-07-10 18:31:40 +0530 | [diff] [blame] | 6078 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 6079 | |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 6080 | if (val != dev_priv->rps.cur_freq) { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6081 | err = vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 6082 | if (err) |
| 6083 | return err; |
| 6084 | |
Chris Wilson | db4c5e0 | 2017-02-10 15:03:46 +0000 | [diff] [blame] | 6085 | gen6_set_rps_thresholds(dev_priv, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 6086 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6087 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6088 | dev_priv->rps.cur_freq = val; |
| 6089 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6090 | |
| 6091 | return 0; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6092 | } |
| 6093 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6094 | /* 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] | 6095 | * |
| 6096 | * * If Gfx is Idle, then |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6097 | * 1. Forcewake Media well. |
| 6098 | * 2. Request idle freq. |
| 6099 | * 3. Release Forcewake of Media well. |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6100 | */ |
| 6101 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 6102 | { |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 6103 | u32 val = dev_priv->rps.idle_freq; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6104 | int err; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 6105 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 6106 | if (dev_priv->rps.cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6107 | return; |
| 6108 | |
Chris Wilson | c9efef7 | 2017-01-02 15:28:45 +0000 | [diff] [blame] | 6109 | /* The punit delays the write of the frequency and voltage until it |
| 6110 | * determines the GPU is awake. During normal usage we don't want to |
| 6111 | * waste power changing the frequency if the GPU is sleeping (rc6). |
| 6112 | * However, the GPU and driver is now idle and we do not want to delay |
| 6113 | * switching to minimum voltage (reducing power whilst idle) as we do |
| 6114 | * not expect to be woken in the near future and so must flush the |
| 6115 | * change by waking the device. |
| 6116 | * |
| 6117 | * We choose to take the media powerwell (either would do to trick the |
| 6118 | * punit into committing the voltage change) as that takes a lot less |
| 6119 | * power than the render powerwell. |
| 6120 | */ |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6121 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6122 | err = valleyview_set_rps(dev_priv, val); |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6123 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6124 | |
| 6125 | if (err) |
| 6126 | DRM_ERROR("Failed to set RPS for idle\n"); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6127 | } |
| 6128 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6129 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 6130 | { |
| 6131 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6132 | if (dev_priv->rps.enabled) { |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6133 | u8 freq; |
| 6134 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6135 | if (dev_priv->pm_rps_events & GEN6_PM_RP_UP_EI_EXPIRED) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6136 | gen6_rps_reset_ei(dev_priv); |
| 6137 | I915_WRITE(GEN6_PMINTRMSK, |
| 6138 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 6139 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6140 | gen6_enable_rps_interrupts(dev_priv); |
| 6141 | |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6142 | /* Use the user's desired frequency as a guide, but for better |
| 6143 | * performance, jump directly to RPe as our starting frequency. |
| 6144 | */ |
| 6145 | freq = max(dev_priv->rps.cur_freq, |
| 6146 | dev_priv->rps.efficient_freq); |
| 6147 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6148 | if (intel_set_rps(dev_priv, |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6149 | clamp(freq, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6150 | dev_priv->rps.min_freq_softlimit, |
| 6151 | dev_priv->rps.max_freq_softlimit))) |
| 6152 | DRM_DEBUG_DRIVER("Failed to set idle frequency\n"); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6153 | } |
| 6154 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6155 | } |
| 6156 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6157 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 6158 | { |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6159 | /* Flush our bottom-half so that it does not race with us |
| 6160 | * setting the idle frequency and so that it is bounded by |
| 6161 | * our rpm wakeref. And then disable the interrupts to stop any |
| 6162 | * futher RPS reclocking whilst we are asleep. |
| 6163 | */ |
| 6164 | gen6_disable_rps_interrupts(dev_priv); |
| 6165 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6166 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6167 | if (dev_priv->rps.enabled) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6168 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6169 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6170 | else |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6171 | gen6_set_rps(dev_priv, dev_priv->rps.idle_freq); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6172 | dev_priv->rps.last_adj = 0; |
Ville Syrjälä | 12c100b | 2016-05-23 17:42:48 +0300 | [diff] [blame] | 6173 | I915_WRITE(GEN6_PMINTRMSK, |
| 6174 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6175 | } |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6176 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6177 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6178 | spin_lock(&dev_priv->rps.client_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6179 | while (!list_empty(&dev_priv->rps.clients)) |
| 6180 | list_del_init(dev_priv->rps.clients.next); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6181 | spin_unlock(&dev_priv->rps.client_lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6182 | } |
| 6183 | |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6184 | void gen6_rps_boost(struct drm_i915_private *dev_priv, |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 6185 | struct intel_rps_client *rps, |
| 6186 | unsigned long submitted) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6187 | { |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6188 | /* This is intentionally racy! We peek at the state here, then |
| 6189 | * validate inside the RPS worker. |
| 6190 | */ |
Chris Wilson | 67d97da | 2016-07-04 08:08:31 +0100 | [diff] [blame] | 6191 | if (!(dev_priv->gt.awake && |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6192 | dev_priv->rps.enabled && |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 6193 | dev_priv->rps.cur_freq < dev_priv->rps.boost_freq)) |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6194 | return; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6195 | |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 6196 | /* Force a RPS boost (and don't count it against the client) if |
| 6197 | * the GPU is severely congested. |
| 6198 | */ |
Chris Wilson | d0bc54f | 2015-05-21 21:01:48 +0100 | [diff] [blame] | 6199 | if (rps && time_after(jiffies, submitted + DRM_I915_THROTTLE_JIFFIES)) |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 6200 | rps = NULL; |
| 6201 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6202 | spin_lock(&dev_priv->rps.client_lock); |
| 6203 | if (rps == NULL || list_empty(&rps->link)) { |
| 6204 | spin_lock_irq(&dev_priv->irq_lock); |
| 6205 | if (dev_priv->rps.interrupts_enabled) { |
| 6206 | dev_priv->rps.client_boost = true; |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6207 | schedule_work(&dev_priv->rps.work); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6208 | } |
| 6209 | spin_unlock_irq(&dev_priv->irq_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6210 | |
Chris Wilson | 2e1b873 | 2015-04-27 13:41:22 +0100 | [diff] [blame] | 6211 | if (rps != NULL) { |
| 6212 | list_add(&rps->link, &dev_priv->rps.clients); |
| 6213 | rps->boosts++; |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6214 | } else |
| 6215 | dev_priv->rps.boosts++; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6216 | } |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6217 | spin_unlock(&dev_priv->rps.client_lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6218 | } |
| 6219 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6220 | int intel_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6221 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6222 | int err; |
| 6223 | |
Chris Wilson | cfd1c48 | 2017-02-20 09:47:07 +0000 | [diff] [blame] | 6224 | lockdep_assert_held(&dev_priv->rps.hw_lock); |
| 6225 | GEM_BUG_ON(val > dev_priv->rps.max_freq); |
| 6226 | GEM_BUG_ON(val < dev_priv->rps.min_freq); |
| 6227 | |
Chris Wilson | 76e4e4b | 2017-02-20 09:47:08 +0000 | [diff] [blame] | 6228 | if (!dev_priv->rps.enabled) { |
| 6229 | dev_priv->rps.cur_freq = val; |
| 6230 | return 0; |
| 6231 | } |
| 6232 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6233 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6234 | err = valleyview_set_rps(dev_priv, val); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6235 | else |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6236 | err = gen6_set_rps(dev_priv, val); |
| 6237 | |
| 6238 | return err; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6239 | } |
| 6240 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6241 | static void gen9_disable_rc6(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6242 | { |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6243 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6244 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6247 | static void gen9_disable_rps(struct drm_i915_private *dev_priv) |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6248 | { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6249 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6250 | } |
| 6251 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6252 | static void gen6_disable_rps(struct drm_i915_private *dev_priv) |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6253 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6254 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6255 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6256 | I915_WRITE(GEN6_RP_CONTROL, 0); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6257 | } |
| 6258 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6259 | static void cherryview_disable_rps(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6260 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6261 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6262 | } |
| 6263 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6264 | static void valleyview_disable_rps(struct drm_i915_private *dev_priv) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6265 | { |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6266 | /* we're doing forcewake before Disabling RC6, |
| 6267 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6268 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6269 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6270 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6271 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6272 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6275 | 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] | 6276 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6277 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 6278 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 6279 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 6280 | else |
| 6281 | mode = 0; |
| 6282 | } |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6283 | if (HAS_RC6p(dev_priv)) |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6284 | DRM_DEBUG_DRIVER("Enabling RC6 states: " |
| 6285 | "RC6 %s RC6p %s RC6pp %s\n", |
| 6286 | onoff(mode & GEN6_RC_CTL_RC6_ENABLE), |
| 6287 | onoff(mode & GEN6_RC_CTL_RC6p_ENABLE), |
| 6288 | onoff(mode & GEN6_RC_CTL_RC6pp_ENABLE)); |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 6289 | |
| 6290 | else |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6291 | DRM_DEBUG_DRIVER("Enabling RC6 states: RC6 %s\n", |
| 6292 | onoff(mode & GEN6_RC_CTL_RC6_ENABLE)); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 6293 | } |
| 6294 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6295 | 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] | 6296 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 6297 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6298 | bool enable_rc6 = true; |
| 6299 | unsigned long rc6_ctx_base; |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6300 | u32 rc_ctl; |
| 6301 | int rc_sw_target; |
| 6302 | |
| 6303 | rc_ctl = I915_READ(GEN6_RC_CONTROL); |
| 6304 | rc_sw_target = (I915_READ(GEN6_RC_STATE) & RC_SW_TARGET_STATE_MASK) >> |
| 6305 | RC_SW_TARGET_STATE_SHIFT; |
| 6306 | DRM_DEBUG_DRIVER("BIOS enabled RC states: " |
| 6307 | "HW_CTRL %s HW_RC6 %s SW_TARGET_STATE %x\n", |
| 6308 | onoff(rc_ctl & GEN6_RC_CTL_HW_ENABLE), |
| 6309 | onoff(rc_ctl & GEN6_RC_CTL_RC6_ENABLE), |
| 6310 | rc_sw_target); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6311 | |
| 6312 | if (!(I915_READ(RC6_LOCATION) & RC6_CTX_IN_DRAM)) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6313 | DRM_DEBUG_DRIVER("RC6 Base location not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6314 | enable_rc6 = false; |
| 6315 | } |
| 6316 | |
| 6317 | /* |
| 6318 | * The exact context size is not known for BXT, so assume a page size |
| 6319 | * for this check. |
| 6320 | */ |
| 6321 | rc6_ctx_base = I915_READ(RC6_CTX_BASE) & RC6_CTX_BASE_MASK; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 6322 | if (!((rc6_ctx_base >= ggtt->stolen_reserved_base) && |
| 6323 | (rc6_ctx_base + PAGE_SIZE <= ggtt->stolen_reserved_base + |
| 6324 | ggtt->stolen_reserved_size))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6325 | DRM_DEBUG_DRIVER("RC6 Base address not as expected.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6326 | enable_rc6 = false; |
| 6327 | } |
| 6328 | |
| 6329 | if (!(((I915_READ(PWRCTX_MAXCNT_RCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6330 | ((I915_READ(PWRCTX_MAXCNT_VCSUNIT0) & IDLE_TIME_MASK) > 1) && |
| 6331 | ((I915_READ(PWRCTX_MAXCNT_BCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6332 | ((I915_READ(PWRCTX_MAXCNT_VECSUNIT) & IDLE_TIME_MASK) > 1))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6333 | DRM_DEBUG_DRIVER("Engine Idle wait time not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6334 | enable_rc6 = false; |
| 6335 | } |
| 6336 | |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6337 | if (!I915_READ(GEN8_PUSHBUS_CONTROL) || |
| 6338 | !I915_READ(GEN8_PUSHBUS_ENABLE) || |
| 6339 | !I915_READ(GEN8_PUSHBUS_SHIFT)) { |
| 6340 | DRM_DEBUG_DRIVER("Pushbus not setup properly.\n"); |
| 6341 | enable_rc6 = false; |
| 6342 | } |
| 6343 | |
| 6344 | if (!I915_READ(GEN6_GFXPAUSE)) { |
| 6345 | DRM_DEBUG_DRIVER("GFX pause not setup properly.\n"); |
| 6346 | enable_rc6 = false; |
| 6347 | } |
| 6348 | |
| 6349 | if (!I915_READ(GEN8_MISC_CTRL0)) { |
| 6350 | DRM_DEBUG_DRIVER("GPM control not setup properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6351 | enable_rc6 = false; |
| 6352 | } |
| 6353 | |
| 6354 | return enable_rc6; |
| 6355 | } |
| 6356 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6357 | 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] | 6358 | { |
Daniel Vetter | e7d66d8 | 2015-06-15 23:23:54 +0200 | [diff] [blame] | 6359 | /* No RC6 before Ironlake and code is gone for ilk. */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6360 | if (INTEL_INFO(dev_priv)->gen < 6) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6361 | return 0; |
| 6362 | |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6363 | if (!enable_rc6) |
| 6364 | return 0; |
| 6365 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 6366 | if (IS_GEN9_LP(dev_priv) && !bxt_check_bios_rc6_setup(dev_priv)) { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6367 | DRM_INFO("RC6 disabled by BIOS\n"); |
| 6368 | return 0; |
| 6369 | } |
| 6370 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 6371 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6372 | if (enable_rc6 >= 0) { |
| 6373 | int mask; |
| 6374 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6375 | if (HAS_RC6p(dev_priv)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6376 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 6377 | INTEL_RC6pp_ENABLE; |
| 6378 | else |
| 6379 | mask = INTEL_RC6_ENABLE; |
| 6380 | |
| 6381 | if ((enable_rc6 & mask) != enable_rc6) |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6382 | DRM_DEBUG_DRIVER("Adjusting RC6 mask to %d " |
| 6383 | "(requested %d, valid %d)\n", |
| 6384 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6385 | |
| 6386 | return enable_rc6 & mask; |
| 6387 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6388 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6389 | if (IS_IVYBRIDGE(dev_priv)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 6390 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 6391 | |
| 6392 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6393 | } |
| 6394 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6395 | static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6396 | { |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6397 | /* All of these values are in units of 50MHz */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6398 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6399 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 6400 | if (IS_GEN9_LP(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6401 | u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP); |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 6402 | dev_priv->rps.rp0_freq = (rp_state_cap >> 16) & 0xff; |
| 6403 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 6404 | dev_priv->rps.min_freq = (rp_state_cap >> 0) & 0xff; |
| 6405 | } else { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6406 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 6407 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 6408 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 6409 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 6410 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6411 | /* hw_max = RP0 until we check for overclocking */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6412 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6413 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6414 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6415 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) || |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 6416 | IS_GEN9_BC(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6417 | u32 ddcc_status = 0; |
| 6418 | |
| 6419 | if (sandybridge_pcode_read(dev_priv, |
| 6420 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 6421 | &ddcc_status) == 0) |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6422 | dev_priv->rps.efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 6423 | clamp_t(u8, |
| 6424 | ((ddcc_status >> 8) & 0xff), |
| 6425 | dev_priv->rps.min_freq, |
| 6426 | dev_priv->rps.max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6427 | } |
| 6428 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 6429 | if (IS_GEN9_BC(dev_priv)) { |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 6430 | /* Store the frequency values in 16.66 MHZ units, which is |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6431 | * the natural hardware unit for SKL |
| 6432 | */ |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 6433 | dev_priv->rps.rp0_freq *= GEN9_FREQ_SCALER; |
| 6434 | dev_priv->rps.rp1_freq *= GEN9_FREQ_SCALER; |
| 6435 | dev_priv->rps.min_freq *= GEN9_FREQ_SCALER; |
| 6436 | dev_priv->rps.max_freq *= GEN9_FREQ_SCALER; |
| 6437 | dev_priv->rps.efficient_freq *= GEN9_FREQ_SCALER; |
| 6438 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6439 | } |
| 6440 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6441 | static void reset_rps(struct drm_i915_private *dev_priv, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6442 | int (*set)(struct drm_i915_private *, u8)) |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6443 | { |
| 6444 | u8 freq = dev_priv->rps.cur_freq; |
| 6445 | |
| 6446 | /* force a reset */ |
| 6447 | dev_priv->rps.power = -1; |
| 6448 | dev_priv->rps.cur_freq = -1; |
| 6449 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6450 | if (set(dev_priv, freq)) |
| 6451 | DRM_ERROR("Failed to reset RPS to initial values\n"); |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6452 | } |
| 6453 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6454 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6455 | static void gen9_enable_rps(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6456 | { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6457 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 6458 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6459 | /* Program defaults and thresholds for RPS*/ |
| 6460 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 6461 | GEN9_FREQUENCY(dev_priv->rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6462 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6463 | /* 1 second timeout*/ |
| 6464 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 6465 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 6466 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6467 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6468 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6469 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 6470 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 6471 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6472 | reset_rps(dev_priv, gen6_set_rps); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6473 | |
| 6474 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 6475 | } |
| 6476 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6477 | static void gen9_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6478 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6479 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6480 | enum intel_engine_id id; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6481 | uint32_t rc6_mask = 0; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6482 | |
| 6483 | /* 1a: Software RC state - RC0 */ |
| 6484 | I915_WRITE(GEN6_RC_STATE, 0); |
| 6485 | |
| 6486 | /* 1b: Get forcewake during program sequence. Although the driver |
| 6487 | * 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] | 6488 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6489 | |
| 6490 | /* 2a: Disable RC states. */ |
| 6491 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6492 | |
| 6493 | /* 2b: Program RC6 thresholds.*/ |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 6494 | |
| 6495 | /* WaRsDoubleRc6WrlWithCoarsePowerGating: Doubling WRL only when CPG is enabled */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6496 | if (IS_SKYLAKE(dev_priv)) |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 6497 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 108 << 16); |
| 6498 | else |
| 6499 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6500 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 6501 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6502 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6503 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 6504 | |
Dave Gordon | 1a3d189 | 2016-05-13 15:36:30 +0100 | [diff] [blame] | 6505 | if (HAS_GUC(dev_priv)) |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 6506 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 6507 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6508 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6509 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6510 | /* 2c: Program Coarse Power Gating Policies. */ |
| 6511 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 6512 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 6513 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6514 | /* 3a: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6515 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6516 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 6517 | DRM_INFO("RC6 %s\n", onoff(rc6_mask & GEN6_RC_CTL_RC6_ENABLE)); |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 6518 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
| 6519 | I915_WRITE(GEN6_RC_CONTROL, |
| 6520 | GEN6_RC_CTL_HW_ENABLE | GEN6_RC_CTL_EI_MODE(1) | rc6_mask); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6521 | |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 6522 | /* |
| 6523 | * 3b: Enable Coarse Power Gating only when RC6 is enabled. |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 6524 | * WaRsDisableCoarsePowerGating:skl,bxt - Render/Media PG need to be disabled with RC6. |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 6525 | */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6526 | if (NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 6527 | I915_WRITE(GEN9_PG_ENABLE, 0); |
| 6528 | else |
| 6529 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 6530 | (GEN9_RENDER_PG_ENABLE | GEN9_MEDIA_PG_ENABLE) : 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6531 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6532 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6533 | } |
| 6534 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6535 | static void gen8_enable_rps(struct drm_i915_private *dev_priv) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6536 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6537 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6538 | enum intel_engine_id id; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6539 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6540 | |
| 6541 | /* 1a: Software RC state - RC0 */ |
| 6542 | I915_WRITE(GEN6_RC_STATE, 0); |
| 6543 | |
| 6544 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 6545 | * 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] | 6546 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6547 | |
| 6548 | /* 2a: Disable RC states. */ |
| 6549 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6550 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6551 | /* 2b: Program RC6 thresholds.*/ |
| 6552 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 6553 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 6554 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6555 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6556 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6557 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6558 | if (IS_BROADWELL(dev_priv)) |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 6559 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 6560 | else |
| 6561 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6562 | |
| 6563 | /* 3: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6564 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6565 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6566 | intel_print_rc6_info(dev_priv, rc6_mask); |
| 6567 | if (IS_BROADWELL(dev_priv)) |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 6568 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 6569 | GEN7_RC_CTL_TO_MODE | |
| 6570 | rc6_mask); |
| 6571 | else |
| 6572 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 6573 | GEN6_RC_CTL_EI_MODE(1) | |
| 6574 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6575 | |
| 6576 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 6577 | I915_WRITE(GEN6_RPNSWREQ, |
| 6578 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 6579 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 6580 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6581 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 6582 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6583 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6584 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 6585 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 6586 | dev_priv->rps.max_freq_softlimit << 24 | |
| 6587 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6588 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6589 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 6590 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 6591 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 6592 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6593 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6594 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6595 | |
| 6596 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6597 | I915_WRITE(GEN6_RP_CONTROL, |
| 6598 | GEN6_RP_MEDIA_TURBO | |
| 6599 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6600 | GEN6_RP_MEDIA_IS_GFX | |
| 6601 | GEN6_RP_ENABLE | |
| 6602 | GEN6_RP_UP_BUSY_AVG | |
| 6603 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6604 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6605 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6606 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6607 | reset_rps(dev_priv, gen6_set_rps); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6608 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6609 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6610 | } |
| 6611 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6612 | static void gen6_enable_rps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6613 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6614 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6615 | enum intel_engine_id id; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 6616 | u32 rc6vids, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6617 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6618 | int rc6_mode; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 6619 | int ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6620 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6621 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 6622 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6623 | /* Here begins a magic sequence of register writes to enable |
| 6624 | * auto-downclocking. |
| 6625 | * |
| 6626 | * Perhaps there might be some value in exposing these to |
| 6627 | * userspace... |
| 6628 | */ |
| 6629 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6630 | |
| 6631 | /* Clear the DBG now so we don't confuse earlier errors */ |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 6632 | gtfifodbg = I915_READ(GTFIFODBG); |
| 6633 | if (gtfifodbg) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6634 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 6635 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 6636 | } |
| 6637 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6638 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6639 | |
| 6640 | /* disable the counters and set deterministic thresholds */ |
| 6641 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6642 | |
| 6643 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 6644 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 6645 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 6646 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 6647 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 6648 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6649 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6650 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6651 | |
| 6652 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 6653 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6654 | if (IS_IVYBRIDGE(dev_priv)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 6655 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 6656 | else |
| 6657 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 6658 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6659 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 6660 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6661 | /* Check if we are enabling RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6662 | rc6_mode = intel_enable_rc6(); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6663 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 6664 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 6665 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6666 | /* We don't use those on Haswell */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6667 | if (!IS_HASWELL(dev_priv)) { |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6668 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 6669 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6670 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6671 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 6672 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 6673 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6674 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6675 | intel_print_rc6_info(dev_priv, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6676 | |
| 6677 | I915_WRITE(GEN6_RC_CONTROL, |
| 6678 | rc6_mask | |
| 6679 | GEN6_RC_CTL_EI_MODE(1) | |
| 6680 | GEN6_RC_CTL_HW_ENABLE); |
| 6681 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6682 | /* Power down if completely idle for over 50ms */ |
| 6683 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6684 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6685 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6686 | reset_rps(dev_priv, gen6_set_rps); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6687 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 6688 | rc6vids = 0; |
| 6689 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6690 | if (IS_GEN6(dev_priv) && ret) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 6691 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6692 | } 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] | 6693 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 6694 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 6695 | rc6vids &= 0xffff00; |
| 6696 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 6697 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 6698 | if (ret) |
| 6699 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 6700 | } |
| 6701 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6702 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6703 | } |
| 6704 | |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 6705 | static void gen6_update_ring_freq(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6706 | { |
| 6707 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6708 | unsigned int gpu_freq; |
| 6709 | unsigned int max_ia_freq, min_ring_freq; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6710 | unsigned int max_gpu_freq, min_gpu_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6711 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6712 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6713 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6714 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 6715 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6716 | policy = cpufreq_cpu_get(0); |
| 6717 | if (policy) { |
| 6718 | max_ia_freq = policy->cpuinfo.max_freq; |
| 6719 | cpufreq_cpu_put(policy); |
| 6720 | } else { |
| 6721 | /* |
| 6722 | * Default to measured freq if none found, PCU will ensure we |
| 6723 | * don't go over |
| 6724 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6725 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6726 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6727 | |
| 6728 | /* Convert from kHz to MHz */ |
| 6729 | max_ia_freq /= 1000; |
| 6730 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 6731 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 6732 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 6733 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6734 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 6735 | if (IS_GEN9_BC(dev_priv)) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6736 | /* Convert GT frequency to 50 HZ units */ |
| 6737 | min_gpu_freq = dev_priv->rps.min_freq / GEN9_FREQ_SCALER; |
| 6738 | max_gpu_freq = dev_priv->rps.max_freq / GEN9_FREQ_SCALER; |
| 6739 | } else { |
| 6740 | min_gpu_freq = dev_priv->rps.min_freq; |
| 6741 | max_gpu_freq = dev_priv->rps.max_freq; |
| 6742 | } |
| 6743 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6744 | /* |
| 6745 | * For each potential GPU frequency, load a ring frequency we'd like |
| 6746 | * to use for memory access. We do this by specifying the IA frequency |
| 6747 | * the PCU should use as a reference to determine the ring frequency. |
| 6748 | */ |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6749 | for (gpu_freq = max_gpu_freq; gpu_freq >= min_gpu_freq; gpu_freq--) { |
| 6750 | int diff = max_gpu_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6751 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6752 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 6753 | if (IS_GEN9_BC(dev_priv)) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6754 | /* |
| 6755 | * ring_freq = 2 * GT. ring_freq is in 100MHz units |
| 6756 | * No floor required for ring frequency on SKL. |
| 6757 | */ |
| 6758 | ring_freq = gpu_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6759 | } else if (INTEL_INFO(dev_priv)->gen >= 8) { |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 6760 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 6761 | ring_freq = max(min_ring_freq, gpu_freq); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6762 | } else if (IS_HASWELL(dev_priv)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 6763 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6764 | ring_freq = max(min_ring_freq, ring_freq); |
| 6765 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 6766 | } else { |
| 6767 | /* On older processors, there is no separate ring |
| 6768 | * clock domain, so in order to boost the bandwidth |
| 6769 | * of the ring, we need to upclock the CPU (ia_freq). |
| 6770 | * |
| 6771 | * For GPU frequencies less than 750MHz, |
| 6772 | * just use the lowest ring freq. |
| 6773 | */ |
| 6774 | if (gpu_freq < min_freq) |
| 6775 | ia_freq = 800; |
| 6776 | else |
| 6777 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 6778 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 6779 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6780 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6781 | sandybridge_pcode_write(dev_priv, |
| 6782 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6783 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 6784 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 6785 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6786 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6787 | } |
| 6788 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 6789 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6790 | { |
| 6791 | u32 val, rp0; |
| 6792 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6793 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6794 | |
Imre Deak | 43b6799 | 2016-08-31 19:13:02 +0300 | [diff] [blame] | 6795 | switch (INTEL_INFO(dev_priv)->sseu.eu_total) { |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6796 | case 8: |
| 6797 | /* (2 * 4) config */ |
| 6798 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 6799 | break; |
| 6800 | case 12: |
| 6801 | /* (2 * 6) config */ |
| 6802 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 6803 | break; |
| 6804 | case 16: |
| 6805 | /* (2 * 8) config */ |
| 6806 | default: |
| 6807 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 6808 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 6809 | break; |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 6810 | } |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6811 | |
| 6812 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 6813 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6814 | return rp0; |
| 6815 | } |
| 6816 | |
| 6817 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 6818 | { |
| 6819 | u32 val, rpe; |
| 6820 | |
| 6821 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 6822 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 6823 | |
| 6824 | return rpe; |
| 6825 | } |
| 6826 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 6827 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 6828 | { |
| 6829 | u32 val, rp1; |
| 6830 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6831 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 6832 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 6833 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 6834 | return rp1; |
| 6835 | } |
| 6836 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 6837 | static u32 cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 6838 | { |
| 6839 | u32 val, rpn; |
| 6840 | |
| 6841 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 6842 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 6843 | FB_GFX_FREQ_FUSE_MASK); |
| 6844 | |
| 6845 | return rpn; |
| 6846 | } |
| 6847 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 6848 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 6849 | { |
| 6850 | u32 val, rp1; |
| 6851 | |
| 6852 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 6853 | |
| 6854 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 6855 | |
| 6856 | return rp1; |
| 6857 | } |
| 6858 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 6859 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6860 | { |
| 6861 | u32 val, rp0; |
| 6862 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 6863 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6864 | |
| 6865 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 6866 | /* Clamp to max */ |
| 6867 | rp0 = min_t(u32, rp0, 0xea); |
| 6868 | |
| 6869 | return rp0; |
| 6870 | } |
| 6871 | |
| 6872 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 6873 | { |
| 6874 | u32 val, rpe; |
| 6875 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 6876 | 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] | 6877 | 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] | 6878 | 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] | 6879 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 6880 | |
| 6881 | return rpe; |
| 6882 | } |
| 6883 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 6884 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6885 | { |
Imre Deak | 3614603 | 2014-12-04 18:39:35 +0200 | [diff] [blame] | 6886 | u32 val; |
| 6887 | |
| 6888 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
| 6889 | /* |
| 6890 | * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value |
| 6891 | * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on |
| 6892 | * a BYT-M B0 the above register contains 0xbf. Moreover when setting |
| 6893 | * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0 |
| 6894 | * to make sure it matches what Punit accepts. |
| 6895 | */ |
| 6896 | return max_t(u32, val, 0xc0); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6897 | } |
| 6898 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6899 | /* Check that the pctx buffer wasn't move under us. */ |
| 6900 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 6901 | { |
| 6902 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 6903 | |
| 6904 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 6905 | dev_priv->vlv_pctx->stolen->start); |
| 6906 | } |
| 6907 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6908 | |
| 6909 | /* Check that the pcbr address is not empty. */ |
| 6910 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 6911 | { |
| 6912 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 6913 | |
| 6914 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 6915 | } |
| 6916 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6917 | static void cherryview_setup_pctx(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6918 | { |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 6919 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 6920 | unsigned long pctx_paddr, paddr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6921 | u32 pcbr; |
| 6922 | int pctx_size = 32*1024; |
| 6923 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6924 | pcbr = I915_READ(VLV_PCBR); |
| 6925 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 6926 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6927 | paddr = (dev_priv->mm.stolen_base + |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 6928 | (ggtt->stolen_size - pctx_size)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6929 | |
| 6930 | pctx_paddr = (paddr & (~4095)); |
| 6931 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 6932 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 6933 | |
| 6934 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6935 | } |
| 6936 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6937 | static void valleyview_setup_pctx(struct drm_i915_private *dev_priv) |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6938 | { |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6939 | struct drm_i915_gem_object *pctx; |
| 6940 | unsigned long pctx_paddr; |
| 6941 | u32 pcbr; |
| 6942 | int pctx_size = 24*1024; |
| 6943 | |
| 6944 | pcbr = I915_READ(VLV_PCBR); |
| 6945 | if (pcbr) { |
| 6946 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 6947 | int pcbr_offset; |
| 6948 | |
| 6949 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 6950 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6951 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 6952 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6953 | pctx_size); |
| 6954 | goto out; |
| 6955 | } |
| 6956 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 6957 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 6958 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6959 | /* |
| 6960 | * From the Gunit register HAS: |
| 6961 | * The Gfx driver is expected to program this register and ensure |
| 6962 | * proper allocation within Gfx stolen memory. For example, this |
| 6963 | * register should be programmed such than the PCBR range does not |
| 6964 | * overlap with other ranges, such as the frame buffer, protected |
| 6965 | * memory, or any other relevant ranges. |
| 6966 | */ |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 6967 | pctx = i915_gem_object_create_stolen(dev_priv, pctx_size); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6968 | if (!pctx) { |
| 6969 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
Tvrtko Ursulin | ee50489 | 2016-02-11 10:27:30 +0000 | [diff] [blame] | 6970 | goto out; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 6974 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 6975 | |
| 6976 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 6977 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6978 | dev_priv->vlv_pctx = pctx; |
| 6979 | } |
| 6980 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6981 | static void valleyview_cleanup_pctx(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6982 | { |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6983 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 6984 | return; |
| 6985 | |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 6986 | i915_gem_object_put(dev_priv->vlv_pctx); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6987 | dev_priv->vlv_pctx = NULL; |
| 6988 | } |
| 6989 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 6990 | static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv) |
| 6991 | { |
| 6992 | dev_priv->rps.gpll_ref_freq = |
| 6993 | vlv_get_cck_clock(dev_priv, "GPLL ref", |
| 6994 | CCK_GPLL_CLOCK_CONTROL, |
| 6995 | dev_priv->czclk_freq); |
| 6996 | |
| 6997 | DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n", |
| 6998 | dev_priv->rps.gpll_ref_freq); |
| 6999 | } |
| 7000 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7001 | static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7002 | { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7003 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7004 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7005 | valleyview_setup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7006 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7007 | vlv_init_gpll_ref_freq(dev_priv); |
| 7008 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7009 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7010 | switch ((val >> 6) & 3) { |
| 7011 | case 0: |
| 7012 | case 1: |
| 7013 | dev_priv->mem_freq = 800; |
| 7014 | break; |
| 7015 | case 2: |
| 7016 | dev_priv->mem_freq = 1066; |
| 7017 | break; |
| 7018 | case 3: |
| 7019 | dev_priv->mem_freq = 1333; |
| 7020 | break; |
| 7021 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7022 | 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] | 7023 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7024 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 7025 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 7026 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 7027 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7028 | dev_priv->rps.max_freq); |
| 7029 | |
| 7030 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 7031 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 7032 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7033 | dev_priv->rps.efficient_freq); |
| 7034 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7035 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 7036 | 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] | 7037 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7038 | dev_priv->rps.rp1_freq); |
| 7039 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7040 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 7041 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 7042 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7043 | dev_priv->rps.min_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7044 | } |
| 7045 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7046 | static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7047 | { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7048 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7049 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7050 | cherryview_setup_pctx(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7051 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7052 | vlv_init_gpll_ref_freq(dev_priv); |
| 7053 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7054 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7055 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7056 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7057 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7058 | switch ((val >> 2) & 0x7) { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7059 | case 3: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7060 | dev_priv->mem_freq = 2000; |
| 7061 | break; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 7062 | default: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7063 | dev_priv->mem_freq = 1600; |
| 7064 | break; |
| 7065 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7066 | 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] | 7067 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7068 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 7069 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 7070 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 7071 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7072 | dev_priv->rps.max_freq); |
| 7073 | |
| 7074 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 7075 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 7076 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7077 | dev_priv->rps.efficient_freq); |
| 7078 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7079 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 7080 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 7081 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7082 | dev_priv->rps.rp1_freq); |
| 7083 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 7084 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7085 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 7086 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7087 | dev_priv->rps.min_freq); |
| 7088 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7089 | WARN_ONCE((dev_priv->rps.max_freq | |
| 7090 | dev_priv->rps.efficient_freq | |
| 7091 | dev_priv->rps.rp1_freq | |
| 7092 | dev_priv->rps.min_freq) & 1, |
| 7093 | "Odd GPU freq values\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7094 | } |
| 7095 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7096 | static void valleyview_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7097 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7098 | valleyview_cleanup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7099 | } |
| 7100 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7101 | static void cherryview_enable_rps(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7102 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7103 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7104 | enum intel_engine_id id; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7105 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7106 | |
| 7107 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 7108 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7109 | gtfifodbg = I915_READ(GTFIFODBG) & ~(GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV | |
| 7110 | GT_FIFO_FREE_ENTRIES_CHV); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7111 | if (gtfifodbg) { |
| 7112 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7113 | gtfifodbg); |
| 7114 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7115 | } |
| 7116 | |
| 7117 | cherryview_check_pctx(dev_priv); |
| 7118 | |
| 7119 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 7120 | * 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] | 7121 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7122 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7123 | /* Disable RC states. */ |
| 7124 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7125 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7126 | /* 2a: Program RC6 thresholds.*/ |
| 7127 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 7128 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7129 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 7130 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7131 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7132 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7133 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7134 | |
Deepak S | f4f71c7 | 2015-03-28 15:23:35 +0530 | [diff] [blame] | 7135 | /* TO threshold set to 500 us ( 0x186 * 1.28 us) */ |
| 7136 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x186); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7137 | |
| 7138 | /* allows RC6 residency counter to work */ |
| 7139 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 7140 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7141 | VLV_MEDIA_RC6_COUNT_EN | |
| 7142 | VLV_RENDER_RC6_COUNT_EN)); |
| 7143 | |
| 7144 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 7145 | pcbr = I915_READ(VLV_PCBR); |
| 7146 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7147 | /* 3: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7148 | if ((intel_enable_rc6() & INTEL_RC6_ENABLE) && |
| 7149 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 7150 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7151 | |
| 7152 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 7153 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7154 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 7155 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7156 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7157 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7158 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7159 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7160 | |
| 7161 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7162 | |
| 7163 | /* 5: Enable RPS */ |
| 7164 | I915_WRITE(GEN6_RP_CONTROL, |
| 7165 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 7166 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7167 | GEN6_RP_ENABLE | |
| 7168 | GEN6_RP_UP_BUSY_AVG | |
| 7169 | GEN6_RP_DOWN_IDLE_AVG); |
| 7170 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7171 | /* Setting Fixed Bias */ |
| 7172 | val = VLV_OVERRIDE_EN | |
| 7173 | VLV_SOC_TDP_EN | |
| 7174 | CHV_BIAS_CPU_50_SOC_50; |
| 7175 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7176 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7177 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7178 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7179 | /* RPS code assumes GPLL is used */ |
| 7180 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7181 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7182 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7183 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7184 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7185 | reset_rps(dev_priv, valleyview_set_rps); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7186 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7187 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7188 | } |
| 7189 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7190 | static void valleyview_enable_rps(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7191 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7192 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7193 | enum intel_engine_id id; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 7194 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7195 | |
| 7196 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 7197 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7198 | valleyview_check_pctx(dev_priv); |
| 7199 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7200 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7201 | if (gtfifodbg) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 7202 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7203 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7204 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7205 | } |
| 7206 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 7207 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7208 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7209 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7210 | /* Disable RC states. */ |
| 7211 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7212 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 7213 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7214 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7215 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7216 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7217 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7218 | |
| 7219 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7220 | |
| 7221 | I915_WRITE(GEN6_RP_CONTROL, |
| 7222 | GEN6_RP_MEDIA_TURBO | |
| 7223 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7224 | GEN6_RP_MEDIA_IS_GFX | |
| 7225 | GEN6_RP_ENABLE | |
| 7226 | GEN6_RP_UP_BUSY_AVG | |
| 7227 | GEN6_RP_DOWN_IDLE_CONT); |
| 7228 | |
| 7229 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 7230 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 7231 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 7232 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7233 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7234 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7235 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 7236 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7237 | |
| 7238 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 7239 | I915_WRITE(VLV_COUNTER_CONTROL, |
Mika Kuoppala | 6b7f6aa | 2017-03-15 18:12:59 +0200 | [diff] [blame] | 7240 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7241 | VLV_MEDIA_RC0_COUNT_EN | |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 7242 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 7243 | VLV_MEDIA_RC6_COUNT_EN | |
| 7244 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 7245 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7246 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 7247 | 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] | 7248 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7249 | intel_print_rc6_info(dev_priv, rc6_mode); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 7250 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 7251 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7252 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7253 | /* Setting Fixed Bias */ |
| 7254 | val = VLV_OVERRIDE_EN | |
| 7255 | VLV_SOC_TDP_EN | |
| 7256 | VLV_BIAS_CPU_125_SOC_875; |
| 7257 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7258 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7259 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7260 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7261 | /* RPS code assumes GPLL is used */ |
| 7262 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7263 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7264 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7265 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7266 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7267 | reset_rps(dev_priv, valleyview_set_rps); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7268 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7269 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7270 | } |
| 7271 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7272 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 7273 | { |
| 7274 | unsigned long freq; |
| 7275 | int div = (vidfreq & 0x3f0000) >> 16; |
| 7276 | int post = (vidfreq & 0x3000) >> 12; |
| 7277 | int pre = (vidfreq & 0x7); |
| 7278 | |
| 7279 | if (!pre) |
| 7280 | return 0; |
| 7281 | |
| 7282 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 7283 | |
| 7284 | return freq; |
| 7285 | } |
| 7286 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7287 | static const struct cparams { |
| 7288 | u16 i; |
| 7289 | u16 t; |
| 7290 | u16 m; |
| 7291 | u16 c; |
| 7292 | } cparams[] = { |
| 7293 | { 1, 1333, 301, 28664 }, |
| 7294 | { 1, 1066, 294, 24460 }, |
| 7295 | { 1, 800, 294, 25192 }, |
| 7296 | { 0, 1333, 276, 27605 }, |
| 7297 | { 0, 1066, 276, 27605 }, |
| 7298 | { 0, 800, 231, 23784 }, |
| 7299 | }; |
| 7300 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7301 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7302 | { |
| 7303 | u64 total_count, diff, ret; |
| 7304 | u32 count1, count2, count3, m = 0, c = 0; |
| 7305 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 7306 | int i; |
| 7307 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7308 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7309 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7310 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7311 | |
| 7312 | /* Prevent division-by-zero if we are asking too fast. |
| 7313 | * Also, we don't get interesting results if we are polling |
| 7314 | * faster than once in 10ms, so just return the saved value |
| 7315 | * in such cases. |
| 7316 | */ |
| 7317 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7318 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7319 | |
| 7320 | count1 = I915_READ(DMIEC); |
| 7321 | count2 = I915_READ(DDREC); |
| 7322 | count3 = I915_READ(CSIEC); |
| 7323 | |
| 7324 | total_count = count1 + count2 + count3; |
| 7325 | |
| 7326 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7327 | if (total_count < dev_priv->ips.last_count1) { |
| 7328 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7329 | diff += total_count; |
| 7330 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7331 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7335 | if (cparams[i].i == dev_priv->ips.c_m && |
| 7336 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7337 | m = cparams[i].m; |
| 7338 | c = cparams[i].c; |
| 7339 | break; |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | diff = div_u64(diff, diff1); |
| 7344 | ret = ((m * diff) + c); |
| 7345 | ret = div_u64(ret, 10); |
| 7346 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7347 | dev_priv->ips.last_count1 = total_count; |
| 7348 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7349 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7350 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7351 | |
| 7352 | return ret; |
| 7353 | } |
| 7354 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7355 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 7356 | { |
| 7357 | unsigned long val; |
| 7358 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7359 | if (INTEL_INFO(dev_priv)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7360 | return 0; |
| 7361 | |
| 7362 | spin_lock_irq(&mchdev_lock); |
| 7363 | |
| 7364 | val = __i915_chipset_val(dev_priv); |
| 7365 | |
| 7366 | spin_unlock_irq(&mchdev_lock); |
| 7367 | |
| 7368 | return val; |
| 7369 | } |
| 7370 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7371 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 7372 | { |
| 7373 | unsigned long m, x, b; |
| 7374 | u32 tsfs; |
| 7375 | |
| 7376 | tsfs = I915_READ(TSFS); |
| 7377 | |
| 7378 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 7379 | x = I915_READ8(TR1); |
| 7380 | |
| 7381 | b = tsfs & TSFS_INTR_MASK; |
| 7382 | |
| 7383 | return ((m * x) / 127) - b; |
| 7384 | } |
| 7385 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7386 | static int _pxvid_to_vd(u8 pxvid) |
| 7387 | { |
| 7388 | if (pxvid == 0) |
| 7389 | return 0; |
| 7390 | |
| 7391 | if (pxvid >= 8 && pxvid < 31) |
| 7392 | pxvid = 31; |
| 7393 | |
| 7394 | return (pxvid + 2) * 125; |
| 7395 | } |
| 7396 | |
| 7397 | 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] | 7398 | { |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7399 | const int vd = _pxvid_to_vd(pxvid); |
| 7400 | const int vm = vd - 1125; |
| 7401 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7402 | if (INTEL_INFO(dev_priv)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7403 | return vm > 0 ? vm : 0; |
| 7404 | |
| 7405 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7406 | } |
| 7407 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7408 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7409 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 7410 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7411 | u32 count; |
| 7412 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7413 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7414 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 7415 | now = ktime_get_raw_ns(); |
| 7416 | diffms = now - dev_priv->ips.last_time2; |
| 7417 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7418 | |
| 7419 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7420 | if (!diffms) |
| 7421 | return; |
| 7422 | |
| 7423 | count = I915_READ(GFXEC); |
| 7424 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7425 | if (count < dev_priv->ips.last_count2) { |
| 7426 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7427 | diff += count; |
| 7428 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7429 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7430 | } |
| 7431 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7432 | dev_priv->ips.last_count2 = count; |
| 7433 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7434 | |
| 7435 | /* More magic constants... */ |
| 7436 | diff = diff * 1181; |
| 7437 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7438 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7439 | } |
| 7440 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7441 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 7442 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7443 | if (INTEL_INFO(dev_priv)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7444 | return; |
| 7445 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7446 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7447 | |
| 7448 | __i915_update_gfx_val(dev_priv); |
| 7449 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7450 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7451 | } |
| 7452 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7453 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7454 | { |
| 7455 | unsigned long t, corr, state1, corr2, state2; |
| 7456 | u32 pxvid, ext_v; |
| 7457 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7458 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7459 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7460 | pxvid = I915_READ(PXVFREQ(dev_priv->rps.cur_freq)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7461 | pxvid = (pxvid >> 24) & 0x7f; |
| 7462 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 7463 | |
| 7464 | state1 = ext_v; |
| 7465 | |
| 7466 | t = i915_mch_val(dev_priv); |
| 7467 | |
| 7468 | /* Revel in the empirically derived constants */ |
| 7469 | |
| 7470 | /* Correction factor in 1/100000 units */ |
| 7471 | if (t > 80) |
| 7472 | corr = ((t * 2349) + 135940); |
| 7473 | else if (t >= 50) |
| 7474 | corr = ((t * 964) + 29317); |
| 7475 | else /* < 50 */ |
| 7476 | corr = ((t * 301) + 1004); |
| 7477 | |
| 7478 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 7479 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7480 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7481 | |
| 7482 | state2 = (corr2 * state1) / 10000; |
| 7483 | state2 /= 100; /* convert to mW */ |
| 7484 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7485 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7486 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7487 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7488 | } |
| 7489 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7490 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 7491 | { |
| 7492 | unsigned long val; |
| 7493 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7494 | if (INTEL_INFO(dev_priv)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7495 | return 0; |
| 7496 | |
| 7497 | spin_lock_irq(&mchdev_lock); |
| 7498 | |
| 7499 | val = __i915_gfx_val(dev_priv); |
| 7500 | |
| 7501 | spin_unlock_irq(&mchdev_lock); |
| 7502 | |
| 7503 | return val; |
| 7504 | } |
| 7505 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7506 | /** |
| 7507 | * i915_read_mch_val - return value for IPS use |
| 7508 | * |
| 7509 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 7510 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 7511 | */ |
| 7512 | unsigned long i915_read_mch_val(void) |
| 7513 | { |
| 7514 | struct drm_i915_private *dev_priv; |
| 7515 | unsigned long chipset_val, graphics_val, ret = 0; |
| 7516 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7517 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7518 | if (!i915_mch_dev) |
| 7519 | goto out_unlock; |
| 7520 | dev_priv = i915_mch_dev; |
| 7521 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7522 | chipset_val = __i915_chipset_val(dev_priv); |
| 7523 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7524 | |
| 7525 | ret = chipset_val + graphics_val; |
| 7526 | |
| 7527 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7528 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7529 | |
| 7530 | return ret; |
| 7531 | } |
| 7532 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 7533 | |
| 7534 | /** |
| 7535 | * i915_gpu_raise - raise GPU frequency limit |
| 7536 | * |
| 7537 | * Raise the limit; IPS indicates we have thermal headroom. |
| 7538 | */ |
| 7539 | bool i915_gpu_raise(void) |
| 7540 | { |
| 7541 | struct drm_i915_private *dev_priv; |
| 7542 | bool ret = true; |
| 7543 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7544 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7545 | if (!i915_mch_dev) { |
| 7546 | ret = false; |
| 7547 | goto out_unlock; |
| 7548 | } |
| 7549 | dev_priv = i915_mch_dev; |
| 7550 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7551 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 7552 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7553 | |
| 7554 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7555 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7556 | |
| 7557 | return ret; |
| 7558 | } |
| 7559 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 7560 | |
| 7561 | /** |
| 7562 | * i915_gpu_lower - lower GPU frequency limit |
| 7563 | * |
| 7564 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 7565 | * frequency maximum. |
| 7566 | */ |
| 7567 | bool i915_gpu_lower(void) |
| 7568 | { |
| 7569 | struct drm_i915_private *dev_priv; |
| 7570 | bool ret = true; |
| 7571 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7572 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7573 | if (!i915_mch_dev) { |
| 7574 | ret = false; |
| 7575 | goto out_unlock; |
| 7576 | } |
| 7577 | dev_priv = i915_mch_dev; |
| 7578 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7579 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 7580 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7581 | |
| 7582 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7583 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7584 | |
| 7585 | return ret; |
| 7586 | } |
| 7587 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 7588 | |
| 7589 | /** |
| 7590 | * i915_gpu_busy - indicate GPU business to IPS |
| 7591 | * |
| 7592 | * Tell the IPS driver whether or not the GPU is busy. |
| 7593 | */ |
| 7594 | bool i915_gpu_busy(void) |
| 7595 | { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7596 | bool ret = false; |
| 7597 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7598 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | dcff85c | 2016-08-05 10:14:11 +0100 | [diff] [blame] | 7599 | if (i915_mch_dev) |
| 7600 | ret = i915_mch_dev->gt.awake; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7601 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7602 | |
| 7603 | return ret; |
| 7604 | } |
| 7605 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 7606 | |
| 7607 | /** |
| 7608 | * i915_gpu_turbo_disable - disable graphics turbo |
| 7609 | * |
| 7610 | * Disable graphics turbo by resetting the max frequency and setting the |
| 7611 | * current frequency to the default. |
| 7612 | */ |
| 7613 | bool i915_gpu_turbo_disable(void) |
| 7614 | { |
| 7615 | struct drm_i915_private *dev_priv; |
| 7616 | bool ret = true; |
| 7617 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7618 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7619 | if (!i915_mch_dev) { |
| 7620 | ret = false; |
| 7621 | goto out_unlock; |
| 7622 | } |
| 7623 | dev_priv = i915_mch_dev; |
| 7624 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7625 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7626 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 7627 | if (!ironlake_set_drps(dev_priv, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7628 | ret = false; |
| 7629 | |
| 7630 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7631 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7632 | |
| 7633 | return ret; |
| 7634 | } |
| 7635 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 7636 | |
| 7637 | /** |
| 7638 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 7639 | * IPS got loaded first. |
| 7640 | * |
| 7641 | * This awkward dance is so that neither module has to depend on the |
| 7642 | * other in order for IPS to do the appropriate communication of |
| 7643 | * GPU turbo limits to i915. |
| 7644 | */ |
| 7645 | static void |
| 7646 | ips_ping_for_i915_load(void) |
| 7647 | { |
| 7648 | void (*link)(void); |
| 7649 | |
| 7650 | link = symbol_get(ips_link_to_i915_driver); |
| 7651 | if (link) { |
| 7652 | link(); |
| 7653 | symbol_put(ips_link_to_i915_driver); |
| 7654 | } |
| 7655 | } |
| 7656 | |
| 7657 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 7658 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7659 | /* We only register the i915 ips part with intel-ips once everything is |
| 7660 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7661 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7662 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7663 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7664 | |
| 7665 | ips_ping_for_i915_load(); |
| 7666 | } |
| 7667 | |
| 7668 | void intel_gpu_ips_teardown(void) |
| 7669 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7670 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7671 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7672 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7673 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 7674 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7675 | static void intel_init_emon(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7676 | { |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7677 | u32 lcfuse; |
| 7678 | u8 pxw[16]; |
| 7679 | int i; |
| 7680 | |
| 7681 | /* Disable to program */ |
| 7682 | I915_WRITE(ECR, 0); |
| 7683 | POSTING_READ(ECR); |
| 7684 | |
| 7685 | /* Program energy weights for various events */ |
| 7686 | I915_WRITE(SDEW, 0x15040d00); |
| 7687 | I915_WRITE(CSIEW0, 0x007f0000); |
| 7688 | I915_WRITE(CSIEW1, 0x1e220004); |
| 7689 | I915_WRITE(CSIEW2, 0x04000004); |
| 7690 | |
| 7691 | for (i = 0; i < 5; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7692 | I915_WRITE(PEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7693 | for (i = 0; i < 3; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7694 | I915_WRITE(DEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7695 | |
| 7696 | /* Program P-state weights to account for frequency power adjustment */ |
| 7697 | for (i = 0; i < 16; i++) { |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7698 | u32 pxvidfreq = I915_READ(PXVFREQ(i)); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7699 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 7700 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 7701 | PXVFREQ_PX_SHIFT; |
| 7702 | unsigned long val; |
| 7703 | |
| 7704 | val = vid * vid; |
| 7705 | val *= (freq / 1000); |
| 7706 | val *= 255; |
| 7707 | val /= (127*127*900); |
| 7708 | if (val > 0xff) |
| 7709 | DRM_ERROR("bad pxval: %ld\n", val); |
| 7710 | pxw[i] = val; |
| 7711 | } |
| 7712 | /* Render standby states get 0 weight */ |
| 7713 | pxw[14] = 0; |
| 7714 | pxw[15] = 0; |
| 7715 | |
| 7716 | for (i = 0; i < 4; i++) { |
| 7717 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 7718 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7719 | I915_WRITE(PXW(i), val); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7720 | } |
| 7721 | |
| 7722 | /* Adjust magic regs to magic values (more experimental results) */ |
| 7723 | I915_WRITE(OGW0, 0); |
| 7724 | I915_WRITE(OGW1, 0); |
| 7725 | I915_WRITE(EG0, 0x00007f00); |
| 7726 | I915_WRITE(EG1, 0x0000000e); |
| 7727 | I915_WRITE(EG2, 0x000e0000); |
| 7728 | I915_WRITE(EG3, 0x68000300); |
| 7729 | I915_WRITE(EG4, 0x42000000); |
| 7730 | I915_WRITE(EG5, 0x00140031); |
| 7731 | I915_WRITE(EG6, 0); |
| 7732 | I915_WRITE(EG7, 0); |
| 7733 | |
| 7734 | for (i = 0; i < 8; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7735 | I915_WRITE(PXWL(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7736 | |
| 7737 | /* Enable PMON + select events */ |
| 7738 | I915_WRITE(ECR, 0x80000019); |
| 7739 | |
| 7740 | lcfuse = I915_READ(LCFUSE02); |
| 7741 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7742 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7743 | } |
| 7744 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7745 | void intel_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7746 | { |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 7747 | /* |
| 7748 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 7749 | * requirement. |
| 7750 | */ |
| 7751 | if (!i915.enable_rc6) { |
| 7752 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 7753 | intel_runtime_pm_get(dev_priv); |
| 7754 | } |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7755 | |
Chris Wilson | b5163db | 2016-08-10 13:58:24 +0100 | [diff] [blame] | 7756 | mutex_lock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7757 | mutex_lock(&dev_priv->rps.hw_lock); |
| 7758 | |
| 7759 | /* Initialize RPS limits (for userspace) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7760 | if (IS_CHERRYVIEW(dev_priv)) |
| 7761 | cherryview_init_gt_powersave(dev_priv); |
| 7762 | else if (IS_VALLEYVIEW(dev_priv)) |
| 7763 | valleyview_init_gt_powersave(dev_priv); |
Chris Wilson | 2a13ae7 | 2016-08-02 11:15:27 +0100 | [diff] [blame] | 7764 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7765 | gen6_init_rps_frequencies(dev_priv); |
| 7766 | |
| 7767 | /* Derive initial user preferences/limits from the hardware limits */ |
| 7768 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 7769 | dev_priv->rps.cur_freq = dev_priv->rps.idle_freq; |
| 7770 | |
| 7771 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 7772 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 7773 | |
| 7774 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 7775 | dev_priv->rps.min_freq_softlimit = |
| 7776 | max_t(int, |
| 7777 | dev_priv->rps.efficient_freq, |
| 7778 | intel_freq_opcode(dev_priv, 450)); |
| 7779 | |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7780 | /* After setting max-softlimit, find the overclock max freq */ |
| 7781 | if (IS_GEN6(dev_priv) || |
| 7782 | IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
| 7783 | u32 params = 0; |
| 7784 | |
| 7785 | sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, ¶ms); |
| 7786 | if (params & BIT(31)) { /* OC supported */ |
| 7787 | DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n", |
| 7788 | (dev_priv->rps.max_freq & 0xff) * 50, |
| 7789 | (params & 0xff) * 50); |
| 7790 | dev_priv->rps.max_freq = params & 0xff; |
| 7791 | } |
| 7792 | } |
| 7793 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 7794 | /* Finally allow us to boost to max by default */ |
| 7795 | dev_priv->rps.boost_freq = dev_priv->rps.max_freq; |
| 7796 | |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7797 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | b5163db | 2016-08-10 13:58:24 +0100 | [diff] [blame] | 7798 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7799 | |
| 7800 | intel_autoenable_gt_powersave(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7801 | } |
| 7802 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7803 | void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7804 | { |
Ville Syrjälä | 8dac1e1 | 2016-08-02 14:07:33 +0300 | [diff] [blame] | 7805 | if (IS_VALLEYVIEW(dev_priv)) |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7806 | valleyview_cleanup_gt_powersave(dev_priv); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 7807 | |
| 7808 | if (!i915.enable_rc6) |
| 7809 | intel_runtime_pm_put(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7810 | } |
| 7811 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7812 | /** |
| 7813 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 7814 | * @dev_priv: i915 device |
| 7815 | * |
| 7816 | * We don't want to disable RC6 or other features here, we just want |
| 7817 | * to make sure any work we've queued has finished and won't bother |
| 7818 | * us while we're suspended. |
| 7819 | */ |
| 7820 | void intel_suspend_gt_powersave(struct drm_i915_private *dev_priv) |
| 7821 | { |
| 7822 | if (INTEL_GEN(dev_priv) < 6) |
| 7823 | return; |
| 7824 | |
| 7825 | if (cancel_delayed_work_sync(&dev_priv->rps.autoenable_work)) |
| 7826 | intel_runtime_pm_put(dev_priv); |
| 7827 | |
| 7828 | /* gen6_rps_idle() will be called later to disable interrupts */ |
| 7829 | } |
| 7830 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7831 | void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv) |
| 7832 | { |
| 7833 | dev_priv->rps.enabled = true; /* force disabling */ |
| 7834 | intel_disable_gt_powersave(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7835 | |
| 7836 | gen6_reset_rps_interrupts(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 7837 | } |
| 7838 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7839 | void intel_disable_gt_powersave(struct drm_i915_private *dev_priv) |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 7840 | { |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7841 | if (!READ_ONCE(dev_priv->rps.enabled)) |
| 7842 | return; |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 7843 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7844 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7845 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7846 | if (INTEL_GEN(dev_priv) >= 9) { |
| 7847 | gen9_disable_rc6(dev_priv); |
| 7848 | gen9_disable_rps(dev_priv); |
| 7849 | } else if (IS_CHERRYVIEW(dev_priv)) { |
| 7850 | cherryview_disable_rps(dev_priv); |
| 7851 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 7852 | valleyview_disable_rps(dev_priv); |
| 7853 | } else if (INTEL_GEN(dev_priv) >= 6) { |
| 7854 | gen6_disable_rps(dev_priv); |
| 7855 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 7856 | ironlake_disable_drps(dev_priv); |
| 7857 | } |
| 7858 | |
| 7859 | dev_priv->rps.enabled = false; |
| 7860 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 7861 | } |
| 7862 | |
| 7863 | void intel_enable_gt_powersave(struct drm_i915_private *dev_priv) |
| 7864 | { |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7865 | /* We shouldn't be disabling as we submit, so this should be less |
| 7866 | * racy than it appears! |
| 7867 | */ |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7868 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 7869 | return; |
| 7870 | |
| 7871 | /* Powersaving is controlled by the host when inside a VM */ |
| 7872 | if (intel_vgpu_active(dev_priv)) |
| 7873 | return; |
| 7874 | |
| 7875 | mutex_lock(&dev_priv->rps.hw_lock); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 7876 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7877 | if (IS_CHERRYVIEW(dev_priv)) { |
| 7878 | cherryview_enable_rps(dev_priv); |
| 7879 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 7880 | valleyview_enable_rps(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7881 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7882 | gen9_enable_rc6(dev_priv); |
| 7883 | gen9_enable_rps(dev_priv); |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 7884 | if (IS_GEN9_BC(dev_priv)) |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7885 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7886 | } else if (IS_BROADWELL(dev_priv)) { |
| 7887 | gen8_enable_rps(dev_priv); |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7888 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7889 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7890 | gen6_enable_rps(dev_priv); |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7891 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7892 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 7893 | ironlake_enable_drps(dev_priv); |
| 7894 | intel_init_emon(dev_priv); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7895 | } |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 7896 | |
| 7897 | WARN_ON(dev_priv->rps.max_freq < dev_priv->rps.min_freq); |
| 7898 | WARN_ON(dev_priv->rps.idle_freq > dev_priv->rps.max_freq); |
| 7899 | |
| 7900 | WARN_ON(dev_priv->rps.efficient_freq < dev_priv->rps.min_freq); |
| 7901 | WARN_ON(dev_priv->rps.efficient_freq > dev_priv->rps.max_freq); |
| 7902 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7903 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7904 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7905 | } |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 7906 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7907 | static void __intel_autoenable_gt_powersave(struct work_struct *work) |
| 7908 | { |
| 7909 | struct drm_i915_private *dev_priv = |
| 7910 | container_of(work, typeof(*dev_priv), rps.autoenable_work.work); |
| 7911 | struct intel_engine_cs *rcs; |
| 7912 | struct drm_i915_gem_request *req; |
| 7913 | |
| 7914 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 7915 | goto out; |
| 7916 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7917 | rcs = dev_priv->engine[RCS]; |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 7918 | if (rcs->last_retired_context) |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7919 | goto out; |
| 7920 | |
| 7921 | if (!rcs->init_context) |
| 7922 | goto out; |
| 7923 | |
| 7924 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 7925 | |
| 7926 | req = i915_gem_request_alloc(rcs, dev_priv->kernel_context); |
| 7927 | if (IS_ERR(req)) |
| 7928 | goto unlock; |
| 7929 | |
| 7930 | if (!i915.enable_execlists && i915_switch_context(req) == 0) |
| 7931 | rcs->init_context(req); |
| 7932 | |
| 7933 | /* Mark the device busy, calling intel_enable_gt_powersave() */ |
Chris Wilson | e642c85 | 2017-03-17 11:47:09 +0000 | [diff] [blame] | 7934 | i915_add_request(req); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7935 | |
| 7936 | unlock: |
| 7937 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 7938 | out: |
| 7939 | intel_runtime_pm_put(dev_priv); |
| 7940 | } |
| 7941 | |
| 7942 | void intel_autoenable_gt_powersave(struct drm_i915_private *dev_priv) |
| 7943 | { |
| 7944 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 7945 | return; |
| 7946 | |
| 7947 | if (IS_IRONLAKE_M(dev_priv)) { |
| 7948 | ironlake_enable_drps(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7949 | intel_init_emon(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7950 | } else if (INTEL_INFO(dev_priv)->gen >= 6) { |
| 7951 | /* |
| 7952 | * PCU communication is slow and this doesn't need to be |
| 7953 | * done at any specific time, so do this out of our fast path |
| 7954 | * to make resume and init faster. |
| 7955 | * |
| 7956 | * We depend on the HW RC6 power context save/restore |
| 7957 | * mechanism when entering D3 through runtime PM suspend. So |
| 7958 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 7959 | * get here via the driver load/system resume/runtime resume |
| 7960 | * paths, so the _noresume version is enough (and in case of |
| 7961 | * runtime resume it's necessary). |
| 7962 | */ |
| 7963 | if (queue_delayed_work(dev_priv->wq, |
| 7964 | &dev_priv->rps.autoenable_work, |
| 7965 | round_jiffies_up_relative(HZ))) |
| 7966 | intel_runtime_pm_get_noresume(dev_priv); |
| 7967 | } |
| 7968 | } |
| 7969 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7970 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7971 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7972 | /* |
| 7973 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7974 | * gating for the panel power sequencer or it will fail to |
| 7975 | * start up when no ports are active. |
| 7976 | */ |
| 7977 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 7978 | } |
| 7979 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7980 | static void g4x_disable_trickle_feed(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7981 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7982 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7983 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7984 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7985 | I915_WRITE(DSPCNTR(pipe), |
| 7986 | I915_READ(DSPCNTR(pipe)) | |
| 7987 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7988 | |
| 7989 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 7990 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7991 | } |
| 7992 | } |
| 7993 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7994 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7995 | { |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7996 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 7997 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 7998 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 7999 | |
| 8000 | /* |
| 8001 | * Don't touch WM1S_LP_EN here. |
| 8002 | * Doing so could cause underruns. |
| 8003 | */ |
| 8004 | } |
| 8005 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8006 | static void ironlake_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8007 | { |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8008 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8009 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 8010 | /* |
| 8011 | * Required for FBC |
| 8012 | * WaFbcDisableDpfcClockGating:ilk |
| 8013 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8014 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 8015 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 8016 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8017 | |
| 8018 | I915_WRITE(PCH_3DCGDIS0, |
| 8019 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 8020 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 8021 | I915_WRITE(PCH_3DCGDIS1, |
| 8022 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 8023 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8024 | /* |
| 8025 | * According to the spec the following bits should be set in |
| 8026 | * order to enable memory self-refresh |
| 8027 | * The bit 22/21 of 0x42004 |
| 8028 | * The bit 5 of 0x42020 |
| 8029 | * The bit 15 of 0x45000 |
| 8030 | */ |
| 8031 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8032 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8033 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8034 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8035 | I915_WRITE(DISP_ARB_CTL, |
| 8036 | (I915_READ(DISP_ARB_CTL) | |
| 8037 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 8038 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8039 | ilk_init_lp_watermarks(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8040 | |
| 8041 | /* |
| 8042 | * Based on the document from hardware guys the following bits |
| 8043 | * should be set unconditionally in order to enable FBC. |
| 8044 | * The bit 22 of 0x42000 |
| 8045 | * The bit 22 of 0x42004 |
| 8046 | * The bit 7,8,9 of 0x42020. |
| 8047 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8048 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8049 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8050 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8051 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8052 | ILK_FBCQ_DIS); |
| 8053 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8054 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8055 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8056 | } |
| 8057 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8058 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 8059 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8060 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8061 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8062 | ILK_ELPIN_409_SELECT); |
| 8063 | I915_WRITE(_3D_CHICKEN2, |
| 8064 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 8065 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8066 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8067 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8068 | I915_WRITE(CACHE_MODE_0, |
| 8069 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8070 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8071 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 8072 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8073 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8074 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 8075 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8076 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8077 | } |
| 8078 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8079 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8080 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8081 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8082 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8083 | |
| 8084 | /* |
| 8085 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8086 | * gating for the panel power sequencer or it will fail to |
| 8087 | * start up when no ports are active. |
| 8088 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 8089 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 8090 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 8091 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8092 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 8093 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 8094 | /* The below fixes the weird display corruption, a few pixels shifted |
| 8095 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 8096 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8097 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8098 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 8099 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 8100 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8101 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8102 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8103 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 8104 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 8105 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8106 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 8107 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8108 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8109 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8110 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 8111 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 8112 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8113 | } |
| 8114 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8115 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8116 | { |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8117 | uint32_t tmp; |
| 8118 | |
| 8119 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 8120 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 8121 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 8122 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8123 | } |
| 8124 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8125 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8126 | { |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8127 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8128 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8129 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8130 | |
| 8131 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8132 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8133 | ILK_ELPIN_409_SELECT); |
| 8134 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8135 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 8136 | I915_WRITE(_3D_CHICKEN, |
| 8137 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 8138 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8139 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 8140 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8141 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8142 | /* |
| 8143 | * BSpec recoomends 8x4 when MSAA is used, |
| 8144 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8145 | * |
| 8146 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8147 | * disable bit, which we don't touch here, but it's good |
| 8148 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8149 | */ |
| 8150 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8151 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8152 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8153 | ilk_init_lp_watermarks(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8154 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8155 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 8156 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8157 | |
| 8158 | I915_WRITE(GEN6_UCGCTL1, |
| 8159 | I915_READ(GEN6_UCGCTL1) | |
| 8160 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 8161 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 8162 | |
| 8163 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 8164 | * gating disable must be set. Failure to set it results in |
| 8165 | * flickering pixels due to Z write ordering failures after |
| 8166 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 8167 | * Sanctuary and Tropics, and apparently anything else with |
| 8168 | * alpha test or pixel discard. |
| 8169 | * |
| 8170 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 8171 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8172 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 8173 | * WaDisableRCCUnitClockGating:snb |
| 8174 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8175 | */ |
| 8176 | I915_WRITE(GEN6_UCGCTL2, |
| 8177 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 8178 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 8179 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 8180 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 8181 | I915_WRITE(_3D_CHICKEN3, |
| 8182 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8183 | |
| 8184 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 8185 | * Bspec says: |
| 8186 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 8187 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 8188 | */ |
| 8189 | I915_WRITE(_3D_CHICKEN3, |
| 8190 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 8191 | |
| 8192 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8193 | * According to the spec the following bits should be |
| 8194 | * set in order to enable memory self-refresh and fbc: |
| 8195 | * The bit21 and bit22 of 0x42000 |
| 8196 | * The bit21 and bit22 of 0x42004 |
| 8197 | * The bit5 and bit7 of 0x42020 |
| 8198 | * The bit14 of 0x70180 |
| 8199 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8200 | * |
| 8201 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8202 | */ |
| 8203 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8204 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8205 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 8206 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8207 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8208 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8209 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 8210 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 8211 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 8212 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8213 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8214 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 8215 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8216 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8217 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8218 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8219 | } |
| 8220 | |
| 8221 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 8222 | { |
| 8223 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 8224 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8225 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8226 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8227 | * |
| 8228 | * This actually overrides the dispatch |
| 8229 | * mode for all thread types. |
| 8230 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8231 | reg &= ~GEN7_FF_SCHED_MASK; |
| 8232 | reg |= GEN7_FF_TS_SCHED_HW; |
| 8233 | reg |= GEN7_FF_VS_SCHED_HW; |
| 8234 | reg |= GEN7_FF_DS_SCHED_HW; |
| 8235 | |
| 8236 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 8237 | } |
| 8238 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8239 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8240 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8241 | /* |
| 8242 | * TODO: this bit should only be enabled when really needed, then |
| 8243 | * disabled when not needed anymore in order to save power. |
| 8244 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8245 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8246 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 8247 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 8248 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8249 | |
| 8250 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 8251 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 8252 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8253 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8254 | } |
| 8255 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8256 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8257 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8258 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8259 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8260 | |
| 8261 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8262 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8263 | } |
| 8264 | } |
| 8265 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8266 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 8267 | int general_prio_credits, |
| 8268 | int high_prio_credits) |
| 8269 | { |
| 8270 | u32 misccpctl; |
| 8271 | |
| 8272 | /* WaTempDisableDOPClkGating:bdw */ |
| 8273 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 8274 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 8275 | |
| 8276 | I915_WRITE(GEN8_L3SQCREG1, |
| 8277 | L3_GENERAL_PRIO_CREDITS(general_prio_credits) | |
| 8278 | L3_HIGH_PRIO_CREDITS(high_prio_credits)); |
| 8279 | |
| 8280 | /* |
| 8281 | * Wait at least 100 clocks before re-enabling clock gating. |
| 8282 | * See the definition of L3SQCREG1 in BSpec. |
| 8283 | */ |
| 8284 | POSTING_READ(GEN8_L3SQCREG1); |
| 8285 | udelay(1); |
| 8286 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 8287 | } |
| 8288 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8289 | static void kabylake_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8290 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8291 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8292 | |
| 8293 | /* WaDisableSDEUnitClockGating:kbl */ |
| 8294 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 8295 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8296 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 8297 | |
| 8298 | /* WaDisableGamClockGating:kbl */ |
| 8299 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 8300 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 8301 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8302 | |
| 8303 | /* WaFbcNukeOnHostModify:kbl */ |
| 8304 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8305 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8306 | } |
| 8307 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8308 | static void skylake_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8309 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8310 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 8311 | |
| 8312 | /* WAC6entrylatency:skl */ |
| 8313 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 8314 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8315 | |
| 8316 | /* WaFbcNukeOnHostModify:skl */ |
| 8317 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8318 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8319 | } |
| 8320 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8321 | static void broadwell_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8322 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 8323 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8324 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8325 | ilk_init_lp_watermarks(dev_priv); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 8326 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8327 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 8328 | 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] | 8329 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8330 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 8331 | I915_WRITE(CHICKEN_PAR1_1, |
| 8332 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 8333 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8334 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8335 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 8336 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 8337 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 8338 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 8339 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 8340 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8341 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 8342 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 8343 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8344 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 8345 | ~(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] | 8346 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 8347 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 8348 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 8349 | |
| 8350 | /* WaDisableSDEUnitClockGating:bdw */ |
| 8351 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8352 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 8353 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8354 | /* WaProgramL3SqcReg1Default:bdw */ |
| 8355 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 8356 | |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8357 | /* |
| 8358 | * WaGttCachingOffByDefault:bdw |
| 8359 | * GTT cache may not work with big pages, so if those |
| 8360 | * are ever enabled GTT cache may need to be disabled. |
| 8361 | */ |
| 8362 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
| 8363 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 8364 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 8365 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 8366 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 8367 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8368 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 8369 | |
| 8370 | /* WaDisableDopClockGating:bdw |
| 8371 | * |
| 8372 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 8373 | * clock gating. |
| 8374 | */ |
| 8375 | I915_WRITE(GEN6_UCGCTL1, |
| 8376 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8377 | } |
| 8378 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8379 | static void haswell_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8380 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8381 | ilk_init_lp_watermarks(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8382 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 8383 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 8384 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 8385 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 8386 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 8387 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8388 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8389 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8390 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8391 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8392 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 8393 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 8394 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8395 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8396 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8397 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 8398 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8399 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 8400 | /* enable HiZ Raw Stall Optimization */ |
| 8401 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 8402 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 8403 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8404 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8405 | I915_WRITE(CACHE_MODE_1, |
| 8406 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 8407 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8408 | /* |
| 8409 | * BSpec recommends 8x4 when MSAA is used, |
| 8410 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8411 | * |
| 8412 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8413 | * disable bit, which we don't touch here, but it's good |
| 8414 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8415 | */ |
| 8416 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8417 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8418 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 8419 | /* WaSampleCChickenBitEnable:hsw */ |
| 8420 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 8421 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 8422 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8423 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 8424 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 8425 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 8426 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 8427 | I915_WRITE(CHICKEN_PAR1_1, |
| 8428 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 8429 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8430 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8431 | } |
| 8432 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8433 | static void ivybridge_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8434 | { |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8435 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8436 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8437 | ilk_init_lp_watermarks(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8438 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8439 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8440 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8441 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 8442 | I915_WRITE(_3D_CHICKEN3, |
| 8443 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 8444 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8445 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8446 | I915_WRITE(IVB_CHICKEN3, |
| 8447 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 8448 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 8449 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8450 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8451 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8452 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 8453 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8454 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8455 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 8456 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8457 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8458 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8459 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 8460 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 8461 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8462 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8463 | I915_WRITE(GEN7_L3CNTLREG1, |
| 8464 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 8465 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8466 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8467 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8468 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8469 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 8470 | else { |
| 8471 | /* must write both registers */ |
| 8472 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8473 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8474 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 8475 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 8476 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8477 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8478 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 8479 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 8480 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 8481 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 8482 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8483 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8484 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8485 | */ |
| 8486 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 8487 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8488 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8489 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8490 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8491 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8492 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8493 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8494 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8495 | |
| 8496 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 8497 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 8498 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 8499 | /* enable HiZ Raw Stall Optimization */ |
| 8500 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 8501 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 8502 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 8503 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8504 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 8505 | I915_WRITE(CACHE_MODE_1, |
| 8506 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8507 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8508 | /* |
| 8509 | * BSpec recommends 8x4 when MSAA is used, |
| 8510 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8511 | * |
| 8512 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8513 | * disable bit, which we don't touch here, but it's good |
| 8514 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8515 | */ |
| 8516 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8517 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8518 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8519 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 8520 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 8521 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 8522 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8523 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8524 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8525 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8526 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8527 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8528 | } |
| 8529 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8530 | static void valleyview_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8531 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8532 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 8533 | I915_WRITE(_3D_CHICKEN3, |
| 8534 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 8535 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8536 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8537 | I915_WRITE(IVB_CHICKEN3, |
| 8538 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 8539 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 8540 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 8541 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8542 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8543 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 8544 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 8545 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8546 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8547 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 8548 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8549 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8550 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 8551 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 8552 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 8553 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8554 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8555 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8556 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 8557 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8558 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8559 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8560 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8561 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8562 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8563 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 8564 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 8565 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8566 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8567 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8568 | */ |
| 8569 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 8570 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8571 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 8572 | /* WaDisableL3Bank2xClockGate:vlv |
| 8573 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 8574 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 8575 | I915_WRITE(GEN7_UCGCTL4, |
| 8576 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 8577 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 8578 | /* |
| 8579 | * BSpec says this must be set, even though |
| 8580 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 8581 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 8582 | I915_WRITE(CACHE_MODE_1, |
| 8583 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 8584 | |
| 8585 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 8586 | * BSpec recommends 8x4 when MSAA is used, |
| 8587 | * however in practice 16x4 seems fastest. |
| 8588 | * |
| 8589 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8590 | * disable bit, which we don't touch here, but it's good |
| 8591 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 8592 | */ |
| 8593 | I915_WRITE(GEN7_GT_MODE, |
| 8594 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 8595 | |
| 8596 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 8597 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 8598 | * This is the hardware default actually. |
| 8599 | */ |
| 8600 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 8601 | |
| 8602 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8603 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 8604 | * Disable clock gating on th GCFG unit to prevent a delay |
| 8605 | * in the reporting of vblank events. |
| 8606 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 8607 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8608 | } |
| 8609 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8610 | static void cherryview_init_clock_gating(struct drm_i915_private *dev_priv) |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 8611 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 8612 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 8613 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 8614 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8615 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 8616 | ~(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] | 8617 | |
| 8618 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 8619 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 8620 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 8621 | |
| 8622 | /* WaDisableCSUnitClockGating:chv */ |
| 8623 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 8624 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 8625 | |
| 8626 | /* WaDisableSDEUnitClockGating:chv */ |
| 8627 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8628 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8629 | |
| 8630 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8631 | * WaProgramL3SqcReg1Default:chv |
| 8632 | * See gfxspecs/Related Documents/Performance Guide/ |
| 8633 | * LSQC Setting Recommendations. |
| 8634 | */ |
| 8635 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
| 8636 | |
| 8637 | /* |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8638 | * GTT cache may not work with big pages, so if those |
| 8639 | * are ever enabled GTT cache may need to be disabled. |
| 8640 | */ |
| 8641 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 8642 | } |
| 8643 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8644 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8645 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8646 | uint32_t dspclk_gate; |
| 8647 | |
| 8648 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 8649 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 8650 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 8651 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 8652 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 8653 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 8654 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 8655 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8656 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8657 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 8658 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8659 | |
| 8660 | /* WaDisableRenderCachePipelinedFlush */ |
| 8661 | I915_WRITE(CACHE_MODE_0, |
| 8662 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 8663 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8664 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 8665 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8666 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8667 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8668 | } |
| 8669 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8670 | static void crestline_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8671 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8672 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 8673 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 8674 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 8675 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 8676 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 8677 | I915_WRITE(MI_ARB_STATE, |
| 8678 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8679 | |
| 8680 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 8681 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8682 | } |
| 8683 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8684 | static void broadwater_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8685 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8686 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 8687 | I965_RCC_CLOCK_GATE_DISABLE | |
| 8688 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 8689 | I965_ISC_CLOCK_GATE_DISABLE | |
| 8690 | I965_FBC_CLOCK_GATE_DISABLE); |
| 8691 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 8692 | I915_WRITE(MI_ARB_STATE, |
| 8693 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8694 | |
| 8695 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 8696 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8697 | } |
| 8698 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8699 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8700 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8701 | u32 dstate = I915_READ(D_STATE); |
| 8702 | |
| 8703 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 8704 | DSTATE_DOT_CLOCK_GATING; |
| 8705 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 8706 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8707 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 8708 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 8709 | |
| 8710 | /* IIR "flip pending" means done if this bit is set */ |
| 8711 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 8712 | |
| 8713 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 8714 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 8715 | |
| 8716 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 8717 | 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] | 8718 | |
| 8719 | I915_WRITE(MI_ARB_STATE, |
| 8720 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8721 | } |
| 8722 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8723 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8724 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8725 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 8726 | |
| 8727 | /* interrupts should cause a wake up from C3 */ |
| 8728 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 8729 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 8730 | |
| 8731 | I915_WRITE(MEM_MODE, |
| 8732 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8733 | } |
| 8734 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8735 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8736 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 8737 | I915_WRITE(MEM_MODE, |
| 8738 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 8739 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8740 | } |
| 8741 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8742 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8743 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8744 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8745 | } |
| 8746 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8747 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8748 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8749 | if (HAS_PCH_LPT(dev_priv)) |
| 8750 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8751 | } |
| 8752 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8753 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8754 | { |
| 8755 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 8756 | } |
| 8757 | |
| 8758 | /** |
| 8759 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 8760 | * @dev_priv: device private |
| 8761 | * |
| 8762 | * Setup the hooks that configure which clocks of a given platform can be |
| 8763 | * gated and also apply various GT and display specific workarounds for these |
| 8764 | * platforms. Note that some GT specific workarounds are applied separately |
| 8765 | * when GPU contexts or batchbuffers start their execution. |
| 8766 | */ |
| 8767 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 8768 | { |
| 8769 | if (IS_SKYLAKE(dev_priv)) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8770 | dev_priv->display.init_clock_gating = skylake_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8771 | else if (IS_KABYLAKE(dev_priv)) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8772 | dev_priv->display.init_clock_gating = kabylake_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 8773 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8774 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 8775 | else if (IS_GEMINILAKE(dev_priv)) |
| 8776 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8777 | else if (IS_BROADWELL(dev_priv)) |
| 8778 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
| 8779 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8780 | dev_priv->display.init_clock_gating = cherryview_init_clock_gating; |
| 8781 | else if (IS_HASWELL(dev_priv)) |
| 8782 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
| 8783 | else if (IS_IVYBRIDGE(dev_priv)) |
| 8784 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
| 8785 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8786 | dev_priv->display.init_clock_gating = valleyview_init_clock_gating; |
| 8787 | else if (IS_GEN6(dev_priv)) |
| 8788 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
| 8789 | else if (IS_GEN5(dev_priv)) |
| 8790 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
| 8791 | else if (IS_G4X(dev_priv)) |
| 8792 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 8793 | else if (IS_I965GM(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8794 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 8795 | else if (IS_I965G(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8796 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 8797 | else if (IS_GEN3(dev_priv)) |
| 8798 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 8799 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 8800 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 8801 | else if (IS_GEN2(dev_priv)) |
| 8802 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 8803 | else { |
| 8804 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 8805 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 8806 | } |
| 8807 | } |
| 8808 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8809 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8810 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8811 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 8812 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8813 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8814 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8815 | if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 8816 | i915_pineview_get_mem_freq(dev_priv); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8817 | else if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 8818 | i915_ironlake_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8819 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8820 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8821 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8822 | skl_setup_wm_latency(dev_priv); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 8823 | dev_priv->display.initial_watermarks = skl_initial_wm; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 8824 | dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 8825 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8826 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8827 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 8828 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8829 | if ((IS_GEN5(dev_priv) && dev_priv->wm.pri_latency[1] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8830 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8831 | (!IS_GEN5(dev_priv) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8832 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 8833 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 8834 | dev_priv->display.compute_intermediate_wm = |
| 8835 | ilk_compute_intermediate_wm; |
| 8836 | dev_priv->display.initial_watermarks = |
| 8837 | ilk_initial_watermarks; |
| 8838 | dev_priv->display.optimize_watermarks = |
| 8839 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8840 | } else { |
| 8841 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 8842 | "Disable CxSR\n"); |
| 8843 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 8844 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8845 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8846 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 8847 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8848 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 8849 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8850 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 8851 | } else if (IS_G4X(dev_priv)) { |
| 8852 | g4x_setup_wm_latency(dev_priv); |
| 8853 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 8854 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 8855 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 8856 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8857 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8858 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8859 | dev_priv->is_ddr3, |
| 8860 | dev_priv->fsb_freq, |
| 8861 | dev_priv->mem_freq)) { |
| 8862 | DRM_INFO("failed to find known CxSR latency " |
| 8863 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 8864 | "disabling CxSR\n", |
| 8865 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 8866 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 8867 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 8868 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8869 | dev_priv->display.update_wm = NULL; |
| 8870 | } else |
| 8871 | dev_priv->display.update_wm = pineview_update_wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8872 | } else if (IS_GEN4(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8873 | dev_priv->display.update_wm = i965_update_wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8874 | } else if (IS_GEN3(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8875 | dev_priv->display.update_wm = i9xx_update_wm; |
| 8876 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8877 | } else if (IS_GEN2(dev_priv)) { |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8878 | if (INTEL_INFO(dev_priv)->num_pipes == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8879 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8880 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8881 | } else { |
| 8882 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8883 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8884 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8885 | } else { |
| 8886 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8887 | } |
| 8888 | } |
| 8889 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8890 | static inline int gen6_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 8891 | { |
| 8892 | uint32_t flags = |
| 8893 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 8894 | |
| 8895 | switch (flags) { |
| 8896 | case GEN6_PCODE_SUCCESS: |
| 8897 | return 0; |
| 8898 | case GEN6_PCODE_UNIMPLEMENTED_CMD: |
| 8899 | case GEN6_PCODE_ILLEGAL_CMD: |
| 8900 | return -ENXIO; |
| 8901 | case GEN6_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Chris Wilson | 7850d1c | 2016-08-26 11:59:26 +0100 | [diff] [blame] | 8902 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8903 | return -EOVERFLOW; |
| 8904 | case GEN6_PCODE_TIMEOUT: |
| 8905 | return -ETIMEDOUT; |
| 8906 | default: |
Michal Wajdeczko | f0d6615 | 2017-03-28 08:45:12 +0000 | [diff] [blame] | 8907 | MISSING_CASE(flags); |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8908 | return 0; |
| 8909 | } |
| 8910 | } |
| 8911 | |
| 8912 | static inline int gen7_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 8913 | { |
| 8914 | uint32_t flags = |
| 8915 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 8916 | |
| 8917 | switch (flags) { |
| 8918 | case GEN6_PCODE_SUCCESS: |
| 8919 | return 0; |
| 8920 | case GEN6_PCODE_ILLEGAL_CMD: |
| 8921 | return -ENXIO; |
| 8922 | case GEN7_PCODE_TIMEOUT: |
| 8923 | return -ETIMEDOUT; |
| 8924 | case GEN7_PCODE_ILLEGAL_DATA: |
| 8925 | return -EINVAL; |
| 8926 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
| 8927 | return -EOVERFLOW; |
| 8928 | default: |
| 8929 | MISSING_CASE(flags); |
| 8930 | return 0; |
| 8931 | } |
| 8932 | } |
| 8933 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 8934 | 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] | 8935 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8936 | int status; |
| 8937 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 8938 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8939 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8940 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 8941 | * use te fw I915_READ variants to reduce the amount of work |
| 8942 | * required when reading/writing. |
| 8943 | */ |
| 8944 | |
| 8945 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8946 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 8947 | return -EAGAIN; |
| 8948 | } |
| 8949 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8950 | I915_WRITE_FW(GEN6_PCODE_DATA, *val); |
| 8951 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
| 8952 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8953 | |
Chris Wilson | e09a303 | 2017-04-11 11:13:39 +0100 | [diff] [blame] | 8954 | if (__intel_wait_for_register_fw(dev_priv, |
| 8955 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 8956 | 500, 0, NULL)) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8957 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 8958 | return -ETIMEDOUT; |
| 8959 | } |
| 8960 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8961 | *val = I915_READ_FW(GEN6_PCODE_DATA); |
| 8962 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8963 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8964 | if (INTEL_GEN(dev_priv) > 6) |
| 8965 | status = gen7_check_mailbox_status(dev_priv); |
| 8966 | else |
| 8967 | status = gen6_check_mailbox_status(dev_priv); |
| 8968 | |
| 8969 | if (status) { |
| 8970 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed: %d\n", |
| 8971 | status); |
| 8972 | return status; |
| 8973 | } |
| 8974 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8975 | return 0; |
| 8976 | } |
| 8977 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8978 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8979 | u32 mbox, u32 val) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8980 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8981 | int status; |
| 8982 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 8983 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8984 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8985 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 8986 | * use te fw I915_READ variants to reduce the amount of work |
| 8987 | * required when reading/writing. |
| 8988 | */ |
| 8989 | |
| 8990 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8991 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 8992 | return -EAGAIN; |
| 8993 | } |
| 8994 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8995 | I915_WRITE_FW(GEN6_PCODE_DATA, val); |
Imre Deak | 8bf41b7 | 2016-11-28 17:29:27 +0200 | [diff] [blame] | 8996 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8997 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8998 | |
Chris Wilson | e09a303 | 2017-04-11 11:13:39 +0100 | [diff] [blame] | 8999 | if (__intel_wait_for_register_fw(dev_priv, |
| 9000 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 9001 | 500, 0, NULL)) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9002 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 9003 | return -ETIMEDOUT; |
| 9004 | } |
| 9005 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9006 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9007 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9008 | if (INTEL_GEN(dev_priv) > 6) |
| 9009 | status = gen7_check_mailbox_status(dev_priv); |
| 9010 | else |
| 9011 | status = gen6_check_mailbox_status(dev_priv); |
| 9012 | |
| 9013 | if (status) { |
| 9014 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed: %d\n", |
| 9015 | status); |
| 9016 | return status; |
| 9017 | } |
| 9018 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9019 | return 0; |
| 9020 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 9021 | |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9022 | static bool skl_pcode_try_request(struct drm_i915_private *dev_priv, u32 mbox, |
| 9023 | u32 request, u32 reply_mask, u32 reply, |
| 9024 | u32 *status) |
| 9025 | { |
| 9026 | u32 val = request; |
| 9027 | |
| 9028 | *status = sandybridge_pcode_read(dev_priv, mbox, &val); |
| 9029 | |
| 9030 | return *status || ((val & reply_mask) == reply); |
| 9031 | } |
| 9032 | |
| 9033 | /** |
| 9034 | * skl_pcode_request - send PCODE request until acknowledgment |
| 9035 | * @dev_priv: device private |
| 9036 | * @mbox: PCODE mailbox ID the request is targeted for |
| 9037 | * @request: request ID |
| 9038 | * @reply_mask: mask used to check for request acknowledgment |
| 9039 | * @reply: value used to check for request acknowledgment |
| 9040 | * @timeout_base_ms: timeout for polling with preemption enabled |
| 9041 | * |
| 9042 | * Keep resending the @request to @mbox until PCODE acknowledges it, PCODE |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9043 | * reports an error or an overall timeout of @timeout_base_ms+50 ms expires. |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9044 | * The request is acknowledged once the PCODE reply dword equals @reply after |
| 9045 | * applying @reply_mask. Polling is first attempted with preemption enabled |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9046 | * for @timeout_base_ms and if this times out for another 50 ms with |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9047 | * preemption disabled. |
| 9048 | * |
| 9049 | * Returns 0 on success, %-ETIMEDOUT in case of a timeout, <0 in case of some |
| 9050 | * other error as reported by PCODE. |
| 9051 | */ |
| 9052 | int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request, |
| 9053 | u32 reply_mask, u32 reply, int timeout_base_ms) |
| 9054 | { |
| 9055 | u32 status; |
| 9056 | int ret; |
| 9057 | |
| 9058 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 9059 | |
| 9060 | #define COND skl_pcode_try_request(dev_priv, mbox, request, reply_mask, reply, \ |
| 9061 | &status) |
| 9062 | |
| 9063 | /* |
| 9064 | * Prime the PCODE by doing a request first. Normally it guarantees |
| 9065 | * that a subsequent request, at most @timeout_base_ms later, succeeds. |
| 9066 | * _wait_for() doesn't guarantee when its passed condition is evaluated |
| 9067 | * first, so send the first request explicitly. |
| 9068 | */ |
| 9069 | if (COND) { |
| 9070 | ret = 0; |
| 9071 | goto out; |
| 9072 | } |
| 9073 | ret = _wait_for(COND, timeout_base_ms * 1000, 10); |
| 9074 | if (!ret) |
| 9075 | goto out; |
| 9076 | |
| 9077 | /* |
| 9078 | * The above can time out if the number of requests was low (2 in the |
| 9079 | * worst case) _and_ PCODE was busy for some reason even after a |
| 9080 | * (queued) request and @timeout_base_ms delay. As a workaround retry |
| 9081 | * the poll with preemption disabled to maximize the number of |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9082 | * requests. Increase the timeout from @timeout_base_ms to 50ms to |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9083 | * account for interrupts that could reduce the number of these |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9084 | * requests, and for any quirks of the PCODE firmware that delays |
| 9085 | * the request completion. |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9086 | */ |
| 9087 | DRM_DEBUG_KMS("PCODE timeout, retrying with preemption disabled\n"); |
| 9088 | WARN_ON_ONCE(timeout_base_ms > 3); |
| 9089 | preempt_disable(); |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9090 | ret = wait_for_atomic(COND, 50); |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9091 | preempt_enable(); |
| 9092 | |
| 9093 | out: |
| 9094 | return ret ? ret : status; |
| 9095 | #undef COND |
| 9096 | } |
| 9097 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 9098 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9099 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9100 | /* |
| 9101 | * N = val - 0xb7 |
| 9102 | * Slow = Fast = GPLL ref * N |
| 9103 | */ |
| 9104 | 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] | 9105 | } |
| 9106 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9107 | 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] | 9108 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9109 | 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] | 9110 | } |
| 9111 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9112 | 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] | 9113 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9114 | /* |
| 9115 | * N = val / 2 |
| 9116 | * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2 |
| 9117 | */ |
| 9118 | 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] | 9119 | } |
| 9120 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9121 | 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] | 9122 | { |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 9123 | /* CHV needs even values */ |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9124 | 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] | 9125 | } |
| 9126 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9127 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9128 | { |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9129 | if (IS_GEN9(dev_priv)) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9130 | return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, |
| 9131 | GEN9_FREQ_SCALER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9132 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9133 | return chv_gpu_freq(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9134 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9135 | return byt_gpu_freq(dev_priv, val); |
| 9136 | else |
| 9137 | return val * GT_FREQUENCY_MULTIPLIER; |
| 9138 | } |
| 9139 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9140 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 9141 | { |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9142 | if (IS_GEN9(dev_priv)) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9143 | return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, |
| 9144 | GT_FREQUENCY_MULTIPLIER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9145 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9146 | return chv_freq_opcode(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9147 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9148 | return byt_freq_opcode(dev_priv, val); |
| 9149 | else |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9150 | return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9151 | } |
| 9152 | |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9153 | struct request_boost { |
| 9154 | struct work_struct work; |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 9155 | struct drm_i915_gem_request *req; |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9156 | }; |
| 9157 | |
| 9158 | static void __intel_rps_boost_work(struct work_struct *work) |
| 9159 | { |
| 9160 | struct request_boost *boost = container_of(work, struct request_boost, work); |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 9161 | struct drm_i915_gem_request *req = boost->req; |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9162 | |
Chris Wilson | f69a02c | 2016-07-01 17:23:16 +0100 | [diff] [blame] | 9163 | if (!i915_gem_request_completed(req)) |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 9164 | gen6_rps_boost(req->i915, NULL, req->emitted_jiffies); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9165 | |
Chris Wilson | e8a261e | 2016-07-20 13:31:49 +0100 | [diff] [blame] | 9166 | i915_gem_request_put(req); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9167 | kfree(boost); |
| 9168 | } |
| 9169 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 9170 | 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] | 9171 | { |
| 9172 | struct request_boost *boost; |
| 9173 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 9174 | if (req == NULL || INTEL_GEN(req->i915) < 6) |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9175 | return; |
| 9176 | |
Chris Wilson | f69a02c | 2016-07-01 17:23:16 +0100 | [diff] [blame] | 9177 | if (i915_gem_request_completed(req)) |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 9178 | return; |
| 9179 | |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9180 | boost = kmalloc(sizeof(*boost), GFP_ATOMIC); |
| 9181 | if (boost == NULL) |
| 9182 | return; |
| 9183 | |
Chris Wilson | e8a261e | 2016-07-20 13:31:49 +0100 | [diff] [blame] | 9184 | boost->req = i915_gem_request_get(req); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9185 | |
| 9186 | INIT_WORK(&boost->work, __intel_rps_boost_work); |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 9187 | queue_work(req->i915->wq, &boost->work); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9188 | } |
| 9189 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 9190 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9191 | { |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9192 | mutex_init(&dev_priv->rps.hw_lock); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 9193 | spin_lock_init(&dev_priv->rps.client_lock); |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9194 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 9195 | INIT_DELAYED_WORK(&dev_priv->rps.autoenable_work, |
| 9196 | __intel_autoenable_gt_powersave); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 9197 | INIT_LIST_HEAD(&dev_priv->rps.clients); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 9198 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 9199 | dev_priv->pm.suspended = false; |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 9200 | atomic_set(&dev_priv->pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9201 | } |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9202 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9203 | static u64 vlv_residency_raw(struct drm_i915_private *dev_priv, |
| 9204 | const i915_reg_t reg) |
| 9205 | { |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9206 | u32 lower, upper, tmp; |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9207 | int loop = 2; |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9208 | |
| 9209 | /* The register accessed do not need forcewake. We borrow |
| 9210 | * uncore lock to prevent concurrent access to range reg. |
| 9211 | */ |
| 9212 | spin_lock_irq(&dev_priv->uncore.lock); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9213 | |
| 9214 | /* vlv and chv residency counters are 40 bits in width. |
| 9215 | * With a control bit, we can choose between upper or lower |
| 9216 | * 32bit window into this counter. |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9217 | * |
| 9218 | * Although we always use the counter in high-range mode elsewhere, |
| 9219 | * userspace may attempt to read the value before rc6 is initialised, |
| 9220 | * before we have set the default VLV_COUNTER_CONTROL value. So always |
| 9221 | * set the high bit to be safe. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9222 | */ |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9223 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9224 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9225 | upper = I915_READ_FW(reg); |
| 9226 | do { |
| 9227 | tmp = upper; |
| 9228 | |
| 9229 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9230 | _MASKED_BIT_DISABLE(VLV_COUNT_RANGE_HIGH)); |
| 9231 | lower = I915_READ_FW(reg); |
| 9232 | |
| 9233 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9234 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
| 9235 | upper = I915_READ_FW(reg); |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9236 | } while (upper != tmp && --loop); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9237 | |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9238 | /* Everywhere else we always use VLV_COUNTER_CONTROL with the |
| 9239 | * VLV_COUNT_RANGE_HIGH bit set - so it is safe to leave it set |
| 9240 | * now. |
| 9241 | */ |
| 9242 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9243 | spin_unlock_irq(&dev_priv->uncore.lock); |
| 9244 | |
| 9245 | return lower | (u64)upper << 8; |
| 9246 | } |
| 9247 | |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9248 | u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv, |
| 9249 | const i915_reg_t reg) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9250 | { |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9251 | u64 time_hw, units, div; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9252 | |
| 9253 | if (!intel_enable_rc6()) |
| 9254 | return 0; |
| 9255 | |
| 9256 | intel_runtime_pm_get(dev_priv); |
| 9257 | |
| 9258 | /* On VLV and CHV, residency time is in CZ units rather than 1.28us */ |
| 9259 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9260 | units = 1000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9261 | div = dev_priv->czclk_freq; |
| 9262 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9263 | time_hw = vlv_residency_raw(dev_priv, reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9264 | } else if (IS_GEN9_LP(dev_priv)) { |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9265 | units = 1000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9266 | div = 1200; /* 833.33ns */ |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9267 | |
| 9268 | time_hw = I915_READ(reg); |
| 9269 | } else { |
| 9270 | units = 128000; /* 1.28us */ |
| 9271 | div = 100000; |
| 9272 | |
| 9273 | time_hw = I915_READ(reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9274 | } |
| 9275 | |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9276 | intel_runtime_pm_put(dev_priv); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9277 | return DIV_ROUND_UP_ULL(time_hw * units, div); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9278 | } |