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 | |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 28 | #include <linux/module.h> |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 29 | #include <linux/pm_runtime.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 30 | |
| 31 | #include <drm/drm_atomic_helper.h> |
| 32 | #include <drm/drm_fourcc.h> |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 33 | #include <drm/drm_plane_helper.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 34 | |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 35 | #include "display/intel_atomic.h" |
Jani Nikula | 1d455f8 | 2019-08-06 14:39:33 +0300 | [diff] [blame] | 36 | #include "display/intel_display_types.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 37 | #include "display/intel_fbc.h" |
| 38 | #include "display/intel_sprite.h" |
| 39 | |
Andi Shyti | 0dc3c56 | 2019-10-20 19:41:39 +0100 | [diff] [blame] | 40 | #include "gt/intel_llc.h" |
| 41 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 42 | #include "i915_drv.h" |
Jani Nikula | 440e2b3 | 2019-04-29 15:29:27 +0300 | [diff] [blame] | 43 | #include "i915_irq.h" |
Jani Nikula | a09d9a8 | 2019-08-06 13:07:28 +0300 | [diff] [blame] | 44 | #include "i915_trace.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 45 | #include "intel_pm.h" |
Chris Wilson | 56c5098 | 2019-04-26 09:17:22 +0100 | [diff] [blame] | 46 | #include "intel_sideband.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 47 | #include "../../../platform/x86/intel_ips.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 48 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 49 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 50 | { |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 51 | if (HAS_LLC(dev_priv)) { |
| 52 | /* |
| 53 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
Lucas De Marchi | e0403cb | 2017-12-05 11:01:17 -0800 | [diff] [blame] | 54 | * Display WA #0390: skl,kbl |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 55 | * |
| 56 | * Must match Sampler, Pixel Back End, and Media. See |
| 57 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 58 | */ |
| 59 | I915_WRITE(CHICKEN_PAR1_1, |
| 60 | I915_READ(CHICKEN_PAR1_1) | |
| 61 | SKL_DE_COMPRESSED_HASH_MODE); |
| 62 | } |
| 63 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 64 | /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl,cfl */ |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 65 | I915_WRITE(CHICKEN_PAR1_1, |
| 66 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 67 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 68 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
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 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 72 | /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl,cfl */ |
| 73 | /* WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl */ |
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 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 78 | /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl,cfl */ |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 79 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 80 | ILK_DPFC_DISABLE_DUMMY0); |
Praveen Paneri | 32087d1 | 2017-08-03 23:02:10 +0530 | [diff] [blame] | 81 | |
| 82 | if (IS_SKYLAKE(dev_priv)) { |
| 83 | /* WaDisableDopClockGating */ |
| 84 | I915_WRITE(GEN7_MISCCPCTL, I915_READ(GEN7_MISCCPCTL) |
| 85 | & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 86 | } |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 87 | } |
| 88 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 89 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 90 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 91 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 92 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 93 | /* WaDisableSDEUnitClockGating:bxt */ |
| 94 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 95 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 96 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 97 | /* |
| 98 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 99 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 100 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 101 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 102 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 106 | * to stay fully on. |
| 107 | */ |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 108 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 109 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 112 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 113 | { |
| 114 | gen9_init_clock_gating(dev_priv); |
| 115 | |
| 116 | /* |
| 117 | * WaDisablePWMClockGating:glk |
| 118 | * Backlight PWM may stop in the asserted state, causing backlight |
| 119 | * to stay fully on. |
| 120 | */ |
| 121 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 122 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Ander Conselvan de Oliveira | f4f4b59 | 2017-02-22 08:34:29 +0200 | [diff] [blame] | 123 | |
| 124 | /* WaDDIIOTimeout:glk */ |
| 125 | if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1)) { |
| 126 | u32 val = I915_READ(CHICKEN_MISC_2); |
| 127 | val &= ~(GLK_CL0_PWR_DOWN | |
| 128 | GLK_CL1_PWR_DOWN | |
| 129 | GLK_CL2_PWR_DOWN); |
| 130 | I915_WRITE(CHICKEN_MISC_2, val); |
| 131 | } |
| 132 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 135 | 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] | 136 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 137 | u32 tmp; |
| 138 | |
| 139 | tmp = I915_READ(CLKCFG); |
| 140 | |
| 141 | switch (tmp & CLKCFG_FSB_MASK) { |
| 142 | case CLKCFG_FSB_533: |
| 143 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 144 | break; |
| 145 | case CLKCFG_FSB_800: |
| 146 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 147 | break; |
| 148 | case CLKCFG_FSB_667: |
| 149 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 150 | break; |
| 151 | case CLKCFG_FSB_400: |
| 152 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | switch (tmp & CLKCFG_MEM_MASK) { |
| 157 | case CLKCFG_MEM_533: |
| 158 | dev_priv->mem_freq = 533; |
| 159 | break; |
| 160 | case CLKCFG_MEM_667: |
| 161 | dev_priv->mem_freq = 667; |
| 162 | break; |
| 163 | case CLKCFG_MEM_800: |
| 164 | dev_priv->mem_freq = 800; |
| 165 | break; |
| 166 | } |
| 167 | |
| 168 | /* detect pineview DDR3 setting */ |
| 169 | tmp = I915_READ(CSHRDDR3CTL); |
| 170 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 171 | } |
| 172 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 173 | 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] | 174 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 175 | u16 ddrpll, csipll; |
| 176 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 177 | ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1); |
| 178 | csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 179 | |
| 180 | switch (ddrpll & 0xff) { |
| 181 | case 0xc: |
| 182 | dev_priv->mem_freq = 800; |
| 183 | break; |
| 184 | case 0x10: |
| 185 | dev_priv->mem_freq = 1066; |
| 186 | break; |
| 187 | case 0x14: |
| 188 | dev_priv->mem_freq = 1333; |
| 189 | break; |
| 190 | case 0x18: |
| 191 | dev_priv->mem_freq = 1600; |
| 192 | break; |
| 193 | default: |
| 194 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 195 | ddrpll & 0xff); |
| 196 | dev_priv->mem_freq = 0; |
| 197 | break; |
| 198 | } |
| 199 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 200 | switch (csipll & 0x3ff) { |
| 201 | case 0x00c: |
| 202 | dev_priv->fsb_freq = 3200; |
| 203 | break; |
| 204 | case 0x00e: |
| 205 | dev_priv->fsb_freq = 3733; |
| 206 | break; |
| 207 | case 0x010: |
| 208 | dev_priv->fsb_freq = 4266; |
| 209 | break; |
| 210 | case 0x012: |
| 211 | dev_priv->fsb_freq = 4800; |
| 212 | break; |
| 213 | case 0x014: |
| 214 | dev_priv->fsb_freq = 5333; |
| 215 | break; |
| 216 | case 0x016: |
| 217 | dev_priv->fsb_freq = 5866; |
| 218 | break; |
| 219 | case 0x018: |
| 220 | dev_priv->fsb_freq = 6400; |
| 221 | break; |
| 222 | default: |
| 223 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 224 | csipll & 0x3ff); |
| 225 | dev_priv->fsb_freq = 0; |
| 226 | break; |
| 227 | } |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 228 | } |
| 229 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 230 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 231 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 232 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 233 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 234 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 235 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 236 | |
| 237 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 238 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 239 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 240 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 241 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 242 | |
| 243 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 244 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 245 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 246 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 247 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 248 | |
| 249 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 250 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 251 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 252 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 253 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 254 | |
| 255 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 256 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 257 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 258 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 259 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 260 | |
| 261 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 262 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 263 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 264 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 265 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 266 | }; |
| 267 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 268 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 269 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 270 | int fsb, |
| 271 | int mem) |
| 272 | { |
| 273 | const struct cxsr_latency *latency; |
| 274 | int i; |
| 275 | |
| 276 | if (fsb == 0 || mem == 0) |
| 277 | return NULL; |
| 278 | |
| 279 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 280 | latency = &cxsr_latency_table[i]; |
| 281 | if (is_desktop == latency->is_desktop && |
| 282 | is_ddr3 == latency->is_ddr3 && |
| 283 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 284 | return latency; |
| 285 | } |
| 286 | |
| 287 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 288 | |
| 289 | return NULL; |
| 290 | } |
| 291 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 292 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 293 | { |
| 294 | u32 val; |
| 295 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 296 | vlv_punit_get(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 297 | |
| 298 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 299 | if (enable) |
| 300 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 301 | else |
| 302 | val |= FORCE_DDR_HIGH_FREQ; |
| 303 | val &= ~FORCE_DDR_LOW_FREQ; |
| 304 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 305 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 306 | |
| 307 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 308 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 309 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 310 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 311 | vlv_punit_put(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 314 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 315 | { |
| 316 | u32 val; |
| 317 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 318 | vlv_punit_get(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 319 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 320 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 321 | if (enable) |
| 322 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 323 | else |
| 324 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 325 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 326 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 327 | vlv_punit_put(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 328 | } |
| 329 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 330 | #define FW_WM(value, plane) \ |
| 331 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 332 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 333 | 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] | 334 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 335 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 336 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 337 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 338 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 339 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 340 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 341 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 342 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 343 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 344 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 345 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 346 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 347 | val = I915_READ(DSPFW3); |
| 348 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 349 | if (enable) |
| 350 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 351 | else |
| 352 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 353 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 354 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 355 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 356 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 357 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 358 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 359 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 360 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 361 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 362 | /* |
| 363 | * FIXME can't find a bit like this for 915G, and |
| 364 | * and yet it does have the related watermark in |
| 365 | * FW_BLC_SELF. What's going on? |
| 366 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 367 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 368 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 369 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 370 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 371 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 372 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 373 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 374 | } |
| 375 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 376 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 377 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 378 | DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", |
| 379 | enableddisabled(enable), |
| 380 | enableddisabled(was_enabled)); |
| 381 | |
| 382 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 383 | } |
| 384 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 385 | /** |
| 386 | * intel_set_memory_cxsr - Configure CxSR state |
| 387 | * @dev_priv: i915 device |
| 388 | * @enable: Allow vs. disallow CxSR |
| 389 | * |
| 390 | * Allow or disallow the system to enter a special CxSR |
| 391 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 392 | * is that several display FIFOs may get combined into a single larger |
| 393 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 394 | * system to defer memory fetches longer, and the memory will enter |
| 395 | * self refresh. |
| 396 | * |
| 397 | * Note that enabling CxSR does not guarantee that the system enter |
| 398 | * this special mode, nor does it guarantee that the system stays |
| 399 | * in that mode once entered. So this just allows/disallows the system |
| 400 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 401 | * C-states will affect when/if the system actually enters/exits the |
| 402 | * CxSR mode. |
| 403 | * |
| 404 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 405 | * and the system is free to enter/exit memory self refresh at any time |
| 406 | * even when the use of CxSR has been disallowed. |
| 407 | * |
| 408 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 409 | * control registers will not get latched on vblank. Thus in order to |
| 410 | * guarantee the system will respond to changes in the plane registers |
| 411 | * we must always disallow CxSR prior to making changes to those registers. |
| 412 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 413 | * frame start which happens after vblank start (which is when the plane |
| 414 | * registers would get latched), so we can't proceed with the plane update |
| 415 | * during the same frame where we disallowed CxSR. |
| 416 | * |
| 417 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 418 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 419 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 420 | * Disallowing just CxSR is sufficient. |
| 421 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 422 | 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] | 423 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 424 | bool ret; |
| 425 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 426 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 427 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 428 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 429 | dev_priv->wm.vlv.cxsr = enable; |
| 430 | else if (IS_G4X(dev_priv)) |
| 431 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 432 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 433 | |
| 434 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 435 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 436 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 437 | /* |
| 438 | * Latency for FIFO fetches is dependent on several factors: |
| 439 | * - memory configuration (speed, channels) |
| 440 | * - chipset |
| 441 | * - current MCH state |
| 442 | * It can be fairly high in some situations, so here we assume a fairly |
| 443 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 444 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 445 | * and power consumption (set it too low to save power and we might see |
| 446 | * FIFO underruns and display "flicker"). |
| 447 | * |
| 448 | * A value of 5us seems to be a good balance; safe for very low end |
| 449 | * platforms but not overly aggressive on lower latency configs. |
| 450 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 451 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 452 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 453 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 454 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 455 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 456 | 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] | 457 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 458 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 459 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 460 | 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] | 461 | enum pipe pipe = crtc->pipe; |
| 462 | int sprite0_start, sprite1_start; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 463 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 464 | switch (pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 465 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 466 | case PIPE_A: |
| 467 | dsparb = I915_READ(DSPARB); |
| 468 | dsparb2 = I915_READ(DSPARB2); |
| 469 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 470 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 471 | break; |
| 472 | case PIPE_B: |
| 473 | dsparb = I915_READ(DSPARB); |
| 474 | dsparb2 = I915_READ(DSPARB2); |
| 475 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 476 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 477 | break; |
| 478 | case PIPE_C: |
| 479 | dsparb2 = I915_READ(DSPARB2); |
| 480 | dsparb3 = I915_READ(DSPARB3); |
| 481 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 482 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 483 | break; |
| 484 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 485 | MISSING_CASE(pipe); |
| 486 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 487 | } |
| 488 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 489 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 490 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 491 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 492 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 495 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 496 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 497 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 498 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 499 | int size; |
| 500 | |
| 501 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 502 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 503 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 504 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 505 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 506 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 507 | |
| 508 | return size; |
| 509 | } |
| 510 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 511 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 512 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 513 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 514 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 515 | int size; |
| 516 | |
| 517 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 518 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 519 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 520 | size >>= 1; /* Convert to cachelines */ |
| 521 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 522 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 523 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 524 | |
| 525 | return size; |
| 526 | } |
| 527 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 528 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 529 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 530 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 531 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 532 | int size; |
| 533 | |
| 534 | size = dsparb & 0x7f; |
| 535 | size >>= 2; /* Convert to cachelines */ |
| 536 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 537 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 538 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 539 | |
| 540 | return size; |
| 541 | } |
| 542 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 543 | /* Pineview has different values for various configs */ |
| 544 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 545 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 546 | .max_wm = PINEVIEW_MAX_WM, |
| 547 | .default_wm = PINEVIEW_DFT_WM, |
| 548 | .guard_size = PINEVIEW_GUARD_WM, |
| 549 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 550 | }; |
| 551 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 552 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 553 | .max_wm = PINEVIEW_MAX_WM, |
| 554 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 555 | .guard_size = PINEVIEW_GUARD_WM, |
| 556 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 557 | }; |
| 558 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 559 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 560 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 561 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 562 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 563 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 564 | }; |
| 565 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 566 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 567 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 568 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 569 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 570 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 571 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 572 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 573 | .fifo_size = I965_CURSOR_FIFO, |
| 574 | .max_wm = I965_CURSOR_MAX_WM, |
| 575 | .default_wm = I965_CURSOR_DFT_WM, |
| 576 | .guard_size = 2, |
| 577 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 578 | }; |
| 579 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 580 | .fifo_size = I945_FIFO_SIZE, |
| 581 | .max_wm = I915_MAX_WM, |
| 582 | .default_wm = 1, |
| 583 | .guard_size = 2, |
| 584 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 585 | }; |
| 586 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 587 | .fifo_size = I915_FIFO_SIZE, |
| 588 | .max_wm = I915_MAX_WM, |
| 589 | .default_wm = 1, |
| 590 | .guard_size = 2, |
| 591 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 592 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 593 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 594 | .fifo_size = I855GM_FIFO_SIZE, |
| 595 | .max_wm = I915_MAX_WM, |
| 596 | .default_wm = 1, |
| 597 | .guard_size = 2, |
| 598 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 599 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 600 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 601 | .fifo_size = I855GM_FIFO_SIZE, |
| 602 | .max_wm = I915_MAX_WM/2, |
| 603 | .default_wm = 1, |
| 604 | .guard_size = 2, |
| 605 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 606 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 607 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 608 | .fifo_size = I830_FIFO_SIZE, |
| 609 | .max_wm = I915_MAX_WM, |
| 610 | .default_wm = 1, |
| 611 | .guard_size = 2, |
| 612 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 613 | }; |
| 614 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 615 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 616 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 617 | * @pixel_rate: Pipe pixel rate in kHz |
| 618 | * @cpp: Plane bytes per pixel |
| 619 | * @latency: Memory wakeup latency in 0.1us units |
| 620 | * |
| 621 | * Compute the watermark using the method 1 or "small buffer" |
| 622 | * formula. The caller may additonally add extra cachelines |
| 623 | * to account for TLB misses and clock crossings. |
| 624 | * |
| 625 | * This method is concerned with the short term drain rate |
| 626 | * of the FIFO, ie. it does not account for blanking periods |
| 627 | * which would effectively reduce the average drain rate across |
| 628 | * a longer period. The name "small" refers to the fact the |
| 629 | * FIFO is relatively small compared to the amount of data |
| 630 | * fetched. |
| 631 | * |
| 632 | * The FIFO level vs. time graph might look something like: |
| 633 | * |
| 634 | * |\ |\ |
| 635 | * | \ | \ |
| 636 | * __---__---__ (- plane active, _ blanking) |
| 637 | * -> time |
| 638 | * |
| 639 | * or perhaps like this: |
| 640 | * |
| 641 | * |\|\ |\|\ |
| 642 | * __----__----__ (- plane active, _ blanking) |
| 643 | * -> time |
| 644 | * |
| 645 | * Returns: |
| 646 | * The watermark in bytes |
| 647 | */ |
| 648 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 649 | unsigned int cpp, |
| 650 | unsigned int latency) |
| 651 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 652 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 653 | |
Ville Syrjälä | d492a29 | 2019-04-08 18:27:01 +0300 | [diff] [blame] | 654 | ret = mul_u32_u32(pixel_rate, cpp * latency); |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 655 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 656 | |
| 657 | return ret; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 662 | * @pixel_rate: Pipe pixel rate in kHz |
| 663 | * @htotal: Pipe horizontal total |
| 664 | * @width: Plane width in pixels |
| 665 | * @cpp: Plane bytes per pixel |
| 666 | * @latency: Memory wakeup latency in 0.1us units |
| 667 | * |
| 668 | * Compute the watermark using the method 2 or "large buffer" |
| 669 | * formula. The caller may additonally add extra cachelines |
| 670 | * to account for TLB misses and clock crossings. |
| 671 | * |
| 672 | * This method is concerned with the long term drain rate |
| 673 | * of the FIFO, ie. it does account for blanking periods |
| 674 | * which effectively reduce the average drain rate across |
| 675 | * a longer period. The name "large" refers to the fact the |
| 676 | * FIFO is relatively large compared to the amount of data |
| 677 | * fetched. |
| 678 | * |
| 679 | * The FIFO level vs. time graph might look something like: |
| 680 | * |
| 681 | * |\___ |\___ |
| 682 | * | \___ | \___ |
| 683 | * | \ | \ |
| 684 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 685 | * -> time |
| 686 | * |
| 687 | * Returns: |
| 688 | * The watermark in bytes |
| 689 | */ |
| 690 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 691 | unsigned int htotal, |
| 692 | unsigned int width, |
| 693 | unsigned int cpp, |
| 694 | unsigned int latency) |
| 695 | { |
| 696 | unsigned int ret; |
| 697 | |
| 698 | /* |
| 699 | * FIXME remove once all users are computing |
| 700 | * watermarks in the correct place. |
| 701 | */ |
| 702 | if (WARN_ON_ONCE(htotal == 0)) |
| 703 | htotal = 1; |
| 704 | |
| 705 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 706 | ret = (ret + 1) * width * cpp; |
| 707 | |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 712 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 713 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 714 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 715 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 716 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 717 | * @latency_ns: memory latency for the platform |
| 718 | * |
| 719 | * Calculate the watermark level (the level at which the display plane will |
| 720 | * start fetching from memory again). Each chip has a different display |
| 721 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 722 | * in the correct intel_watermark_params structure. |
| 723 | * |
| 724 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 725 | * on the pixel size. When it reaches the watermark level, it'll start |
| 726 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 727 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 728 | * will occur, and a display engine hang could result. |
| 729 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 730 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 731 | const struct intel_watermark_params *wm, |
| 732 | int fifo_size, int cpp, |
| 733 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 734 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 735 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 736 | |
| 737 | /* |
| 738 | * Note: we need to make sure we don't overflow for various clock & |
| 739 | * latency values. |
| 740 | * clocks go from a few thousand to several hundred thousand. |
| 741 | * latency is usually a few thousand |
| 742 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 743 | entries = intel_wm_method1(pixel_rate, cpp, |
| 744 | latency_ns / 100); |
| 745 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 746 | wm->guard_size; |
| 747 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 748 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 749 | wm_size = fifo_size - entries; |
| 750 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 751 | |
| 752 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 753 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 754 | wm_size = wm->max_wm; |
| 755 | if (wm_size <= 0) |
| 756 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 757 | |
| 758 | /* |
| 759 | * Bspec seems to indicate that the value shouldn't be lower than |
| 760 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 761 | * Lets go for 8 which is the burst size since certain platforms |
| 762 | * already use a hardcoded 8 (which is what the spec says should be |
| 763 | * done). |
| 764 | */ |
| 765 | if (wm_size <= 8) |
| 766 | wm_size = 8; |
| 767 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 768 | return wm_size; |
| 769 | } |
| 770 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 771 | static bool is_disabling(int old, int new, int threshold) |
| 772 | { |
| 773 | return old >= threshold && new < threshold; |
| 774 | } |
| 775 | |
| 776 | static bool is_enabling(int old, int new, int threshold) |
| 777 | { |
| 778 | return old < threshold && new >= threshold; |
| 779 | } |
| 780 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 781 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 782 | { |
| 783 | return dev_priv->wm.max_level + 1; |
| 784 | } |
| 785 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 786 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 787 | const struct intel_plane_state *plane_state) |
| 788 | { |
| 789 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 790 | |
| 791 | /* FIXME check the 'enable' instead */ |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 792 | if (!crtc_state->hw.active) |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 793 | return false; |
| 794 | |
| 795 | /* |
| 796 | * Treat cursor with fb as always visible since cursor updates |
| 797 | * can happen faster than the vrefresh rate, and the current |
| 798 | * watermark code doesn't handle that correctly. Cursor updates |
| 799 | * which set/clear the fb or change the cursor size are going |
| 800 | * to get throttled by intel_legacy_cursor_update() to work |
| 801 | * around this problem with the watermark code. |
| 802 | */ |
| 803 | if (plane->id == PLANE_CURSOR) |
| 804 | return plane_state->base.fb != NULL; |
| 805 | else |
| 806 | return plane_state->base.visible; |
| 807 | } |
| 808 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 809 | 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] | 810 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 811 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 812 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 813 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 814 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 815 | if (enabled) |
| 816 | return NULL; |
| 817 | enabled = crtc; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | return enabled; |
| 822 | } |
| 823 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 824 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 825 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 826 | 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] | 827 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 828 | const struct cxsr_latency *latency; |
| 829 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 830 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 831 | |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 832 | latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 833 | dev_priv->is_ddr3, |
| 834 | dev_priv->fsb_freq, |
| 835 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 836 | if (!latency) { |
| 837 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 838 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 839 | return; |
| 840 | } |
| 841 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 842 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 843 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 844 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 845 | &crtc->config->hw.adjusted_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 846 | const struct drm_framebuffer *fb = |
| 847 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 848 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 849 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 850 | |
| 851 | /* Display SR */ |
| 852 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 853 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 854 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 855 | reg = I915_READ(DSPFW1); |
| 856 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 857 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 858 | I915_WRITE(DSPFW1, reg); |
| 859 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 860 | |
| 861 | /* cursor SR */ |
| 862 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 863 | pineview_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 864 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 865 | reg = I915_READ(DSPFW3); |
| 866 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 867 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 868 | I915_WRITE(DSPFW3, reg); |
| 869 | |
| 870 | /* Display HPLL off SR */ |
| 871 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 872 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 873 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 874 | reg = I915_READ(DSPFW3); |
| 875 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 876 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 877 | I915_WRITE(DSPFW3, reg); |
| 878 | |
| 879 | /* cursor HPLL off SR */ |
| 880 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 881 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 882 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 883 | reg = I915_READ(DSPFW3); |
| 884 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 885 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 886 | I915_WRITE(DSPFW3, reg); |
| 887 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 888 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 889 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 890 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 891 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 895 | /* |
| 896 | * Documentation says: |
| 897 | * "If the line size is small, the TLB fetches can get in the way of the |
| 898 | * data fetches, causing some lag in the pixel data return which is not |
| 899 | * accounted for in the above formulas. The following adjustment only |
| 900 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 901 | * The WM is adjusted upwards by the difference between the FIFO size |
| 902 | * and the size of 8 whole lines. This adjustment is always performed |
| 903 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 904 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 905 | static unsigned int g4x_tlb_miss_wa(int fifo_size, int width, int cpp) |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 906 | { |
| 907 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 908 | |
| 909 | return max(0, tlb_miss); |
| 910 | } |
| 911 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 912 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 913 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 914 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 915 | enum pipe pipe; |
| 916 | |
| 917 | for_each_pipe(dev_priv, pipe) |
| 918 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 919 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 920 | I915_WRITE(DSPFW1, |
| 921 | FW_WM(wm->sr.plane, SR) | |
| 922 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 923 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 924 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 925 | I915_WRITE(DSPFW2, |
| 926 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 927 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 928 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 929 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 930 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 931 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 932 | I915_WRITE(DSPFW3, |
| 933 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 934 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 935 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 936 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 937 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 938 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 939 | } |
| 940 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 941 | #define FW_WM_VLV(value, plane) \ |
| 942 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 943 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 944 | 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] | 945 | const struct vlv_wm_values *wm) |
| 946 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 947 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 948 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 949 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 950 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 951 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 952 | I915_WRITE(VLV_DDL(pipe), |
| 953 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 954 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 955 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 956 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 957 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 958 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 959 | /* |
| 960 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 961 | * high order bits so that there are no out of bounds values |
| 962 | * present in the registers during the reprogramming. |
| 963 | */ |
| 964 | I915_WRITE(DSPHOWM, 0); |
| 965 | I915_WRITE(DSPHOWM1, 0); |
| 966 | I915_WRITE(DSPFW4, 0); |
| 967 | I915_WRITE(DSPFW5, 0); |
| 968 | I915_WRITE(DSPFW6, 0); |
| 969 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 970 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 971 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 972 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 973 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 974 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 975 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 976 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 977 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 978 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 979 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 980 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 981 | |
| 982 | if (IS_CHERRYVIEW(dev_priv)) { |
| 983 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 984 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 985 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 986 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 987 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 988 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 989 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 990 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 991 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 992 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 993 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 994 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 995 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 996 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 997 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 998 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 999 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1000 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1001 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1002 | 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] | 1003 | } else { |
| 1004 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1005 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1006 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1007 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1008 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1009 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1010 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1011 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1012 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1013 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1014 | 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] | 1015 | } |
| 1016 | |
| 1017 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1018 | } |
| 1019 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1020 | #undef FW_WM_VLV |
| 1021 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1022 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1023 | { |
| 1024 | /* all latencies in usec */ |
| 1025 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1026 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1027 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1028 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1029 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1033 | { |
| 1034 | /* |
| 1035 | * DSPCNTR[13] supposedly controls whether the |
| 1036 | * primary plane can use the FIFO space otherwise |
| 1037 | * reserved for the sprite plane. It's not 100% clear |
| 1038 | * what the actual FIFO size is, but it looks like we |
| 1039 | * can happily set both primary and sprite watermarks |
| 1040 | * up to 127 cachelines. So that would seem to mean |
| 1041 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1042 | * the total FIFO is >= 256 cachelines in size. Either |
| 1043 | * way, we don't seem to have to worry about this |
| 1044 | * repartitioning as the maximum watermark value the |
| 1045 | * register can hold for each plane is lower than the |
| 1046 | * minimum FIFO size. |
| 1047 | */ |
| 1048 | switch (plane_id) { |
| 1049 | case PLANE_CURSOR: |
| 1050 | return 63; |
| 1051 | case PLANE_PRIMARY: |
| 1052 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1053 | case PLANE_SPRITE0: |
| 1054 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1055 | default: |
| 1056 | MISSING_CASE(plane_id); |
| 1057 | return 0; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | static int g4x_fbc_fifo_size(int level) |
| 1062 | { |
| 1063 | switch (level) { |
| 1064 | case G4X_WM_LEVEL_SR: |
| 1065 | return 7; |
| 1066 | case G4X_WM_LEVEL_HPLL: |
| 1067 | return 15; |
| 1068 | default: |
| 1069 | MISSING_CASE(level); |
| 1070 | return 0; |
| 1071 | } |
| 1072 | } |
| 1073 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1074 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1075 | const struct intel_plane_state *plane_state, |
| 1076 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1077 | { |
| 1078 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1079 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 1080 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 1081 | &crtc_state->hw.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1082 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1083 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1084 | |
| 1085 | if (latency == 0) |
| 1086 | return USHRT_MAX; |
| 1087 | |
| 1088 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1089 | return 0; |
| 1090 | |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1091 | cpp = plane_state->base.fb->format->cpp[0]; |
| 1092 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1093 | /* |
| 1094 | * Not 100% sure which way ELK should go here as the |
| 1095 | * spec only says CL/CTG should assume 32bpp and BW |
| 1096 | * doesn't need to. But as these things followed the |
| 1097 | * mobile vs. desktop lines on gen3 as well, let's |
| 1098 | * assume ELK doesn't need this. |
| 1099 | * |
| 1100 | * The spec also fails to list such a restriction for |
| 1101 | * the HPLL watermark, which seems a little strange. |
| 1102 | * Let's use 32bpp for the HPLL watermark as well. |
| 1103 | */ |
| 1104 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1105 | level != G4X_WM_LEVEL_NORMAL) |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1106 | cpp = max(cpp, 4u); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1107 | |
| 1108 | clock = adjusted_mode->crtc_clock; |
| 1109 | htotal = adjusted_mode->crtc_htotal; |
| 1110 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 1111 | width = drm_rect_width(&plane_state->base.dst); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1112 | |
| 1113 | if (plane->id == PLANE_CURSOR) { |
| 1114 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1115 | } else if (plane->id == PLANE_PRIMARY && |
| 1116 | level == G4X_WM_LEVEL_NORMAL) { |
| 1117 | wm = intel_wm_method1(clock, cpp, latency); |
| 1118 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1119 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1120 | |
| 1121 | small = intel_wm_method1(clock, cpp, latency); |
| 1122 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1123 | |
| 1124 | wm = min(small, large); |
| 1125 | } |
| 1126 | |
| 1127 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1128 | width, cpp); |
| 1129 | |
| 1130 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1131 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1132 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1136 | int level, enum plane_id plane_id, u16 value) |
| 1137 | { |
| 1138 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1139 | bool dirty = false; |
| 1140 | |
| 1141 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1142 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1143 | |
| 1144 | dirty |= raw->plane[plane_id] != value; |
| 1145 | raw->plane[plane_id] = value; |
| 1146 | } |
| 1147 | |
| 1148 | return dirty; |
| 1149 | } |
| 1150 | |
| 1151 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1152 | int level, u16 value) |
| 1153 | { |
| 1154 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1155 | bool dirty = false; |
| 1156 | |
| 1157 | /* NORMAL level doesn't have an FBC watermark */ |
| 1158 | level = max(level, G4X_WM_LEVEL_SR); |
| 1159 | |
| 1160 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1161 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1162 | |
| 1163 | dirty |= raw->fbc != value; |
| 1164 | raw->fbc = value; |
| 1165 | } |
| 1166 | |
| 1167 | return dirty; |
| 1168 | } |
| 1169 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 1170 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 1171 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1172 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1173 | |
| 1174 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1175 | const struct intel_plane_state *plane_state) |
| 1176 | { |
| 1177 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1178 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1179 | enum plane_id plane_id = plane->id; |
| 1180 | bool dirty = false; |
| 1181 | int level; |
| 1182 | |
| 1183 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1184 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1185 | if (plane_id == PLANE_PRIMARY) |
| 1186 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1187 | goto out; |
| 1188 | } |
| 1189 | |
| 1190 | for (level = 0; level < num_levels; level++) { |
| 1191 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1192 | int wm, max_wm; |
| 1193 | |
| 1194 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1195 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1196 | |
| 1197 | if (wm > max_wm) |
| 1198 | break; |
| 1199 | |
| 1200 | dirty |= raw->plane[plane_id] != wm; |
| 1201 | raw->plane[plane_id] = wm; |
| 1202 | |
| 1203 | if (plane_id != PLANE_PRIMARY || |
| 1204 | level == G4X_WM_LEVEL_NORMAL) |
| 1205 | continue; |
| 1206 | |
| 1207 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1208 | raw->plane[plane_id]); |
| 1209 | max_wm = g4x_fbc_fifo_size(level); |
| 1210 | |
| 1211 | /* |
| 1212 | * FBC wm is not mandatory as we |
| 1213 | * can always just disable its use. |
| 1214 | */ |
| 1215 | if (wm > max_wm) |
| 1216 | wm = USHRT_MAX; |
| 1217 | |
| 1218 | dirty |= raw->fbc != wm; |
| 1219 | raw->fbc = wm; |
| 1220 | } |
| 1221 | |
| 1222 | /* mark watermarks as invalid */ |
| 1223 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1224 | |
| 1225 | if (plane_id == PLANE_PRIMARY) |
| 1226 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1227 | |
| 1228 | out: |
| 1229 | if (dirty) { |
| 1230 | DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1231 | plane->base.name, |
| 1232 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1233 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1234 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
| 1235 | |
| 1236 | if (plane_id == PLANE_PRIMARY) |
| 1237 | DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", |
| 1238 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1239 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
| 1240 | } |
| 1241 | |
| 1242 | return dirty; |
| 1243 | } |
| 1244 | |
| 1245 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1246 | enum plane_id plane_id, int level) |
| 1247 | { |
| 1248 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1249 | |
| 1250 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1251 | } |
| 1252 | |
| 1253 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1254 | int level) |
| 1255 | { |
| 1256 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1257 | |
| 1258 | if (level > dev_priv->wm.max_level) |
| 1259 | return false; |
| 1260 | |
| 1261 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1262 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1263 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1264 | } |
| 1265 | |
| 1266 | /* mark all levels starting from 'level' as invalid */ |
| 1267 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1268 | struct g4x_wm_state *wm_state, int level) |
| 1269 | { |
| 1270 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1271 | enum plane_id plane_id; |
| 1272 | |
| 1273 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1274 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1275 | } |
| 1276 | |
| 1277 | if (level <= G4X_WM_LEVEL_SR) { |
| 1278 | wm_state->cxsr = false; |
| 1279 | wm_state->sr.cursor = USHRT_MAX; |
| 1280 | wm_state->sr.plane = USHRT_MAX; |
| 1281 | wm_state->sr.fbc = USHRT_MAX; |
| 1282 | } |
| 1283 | |
| 1284 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1285 | wm_state->hpll_en = false; |
| 1286 | wm_state->hpll.cursor = USHRT_MAX; |
| 1287 | wm_state->hpll.plane = USHRT_MAX; |
| 1288 | wm_state->hpll.fbc = USHRT_MAX; |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1293 | { |
| 1294 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1295 | struct intel_atomic_state *state = |
| 1296 | to_intel_atomic_state(crtc_state->base.state); |
| 1297 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1298 | int num_active_planes = hweight8(crtc_state->active_planes & |
| 1299 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1300 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1301 | const struct intel_plane_state *old_plane_state; |
| 1302 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1303 | struct intel_plane *plane; |
| 1304 | enum plane_id plane_id; |
| 1305 | int i, level; |
| 1306 | unsigned int dirty = 0; |
| 1307 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1308 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1309 | old_plane_state, |
| 1310 | new_plane_state, i) { |
| 1311 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1312 | old_plane_state->base.crtc != &crtc->base) |
| 1313 | continue; |
| 1314 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1315 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1316 | dirty |= BIT(plane->id); |
| 1317 | } |
| 1318 | |
| 1319 | if (!dirty) |
| 1320 | return 0; |
| 1321 | |
| 1322 | level = G4X_WM_LEVEL_NORMAL; |
| 1323 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1324 | goto out; |
| 1325 | |
| 1326 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1327 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1328 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1329 | |
| 1330 | level = G4X_WM_LEVEL_SR; |
| 1331 | |
| 1332 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1333 | goto out; |
| 1334 | |
| 1335 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1336 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1337 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1338 | wm_state->sr.fbc = raw->fbc; |
| 1339 | |
| 1340 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1341 | |
| 1342 | level = G4X_WM_LEVEL_HPLL; |
| 1343 | |
| 1344 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1345 | goto out; |
| 1346 | |
| 1347 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1348 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1349 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1350 | wm_state->hpll.fbc = raw->fbc; |
| 1351 | |
| 1352 | wm_state->hpll_en = wm_state->cxsr; |
| 1353 | |
| 1354 | level++; |
| 1355 | |
| 1356 | out: |
| 1357 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1358 | return -EINVAL; |
| 1359 | |
| 1360 | /* invalidate the higher levels */ |
| 1361 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1362 | |
| 1363 | /* |
| 1364 | * Determine if the FBC watermark(s) can be used. IF |
| 1365 | * this isn't the case we prefer to disable the FBC |
| 1366 | ( watermark(s) rather than disable the SR/HPLL |
| 1367 | * level(s) entirely. |
| 1368 | */ |
| 1369 | wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL; |
| 1370 | |
| 1371 | if (level >= G4X_WM_LEVEL_SR && |
| 1372 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1373 | wm_state->fbc_en = false; |
| 1374 | else if (level >= G4X_WM_LEVEL_HPLL && |
| 1375 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1376 | wm_state->fbc_en = false; |
| 1377 | |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1381 | static int g4x_compute_intermediate_wm(struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1382 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1383 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1384 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1385 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
| 1386 | struct intel_atomic_state *intel_state = |
| 1387 | to_intel_atomic_state(new_crtc_state->base.state); |
| 1388 | const struct intel_crtc_state *old_crtc_state = |
| 1389 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 1390 | const struct g4x_wm_state *active = &old_crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1391 | enum plane_id plane_id; |
| 1392 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 1393 | if (!new_crtc_state->hw.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1394 | *intermediate = *optimal; |
| 1395 | |
| 1396 | intermediate->cxsr = false; |
| 1397 | intermediate->hpll_en = false; |
| 1398 | goto out; |
| 1399 | } |
| 1400 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1401 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1402 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1403 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1404 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1405 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1406 | |
| 1407 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1408 | intermediate->wm.plane[plane_id] = |
| 1409 | max(optimal->wm.plane[plane_id], |
| 1410 | active->wm.plane[plane_id]); |
| 1411 | |
| 1412 | WARN_ON(intermediate->wm.plane[plane_id] > |
| 1413 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
| 1414 | } |
| 1415 | |
| 1416 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1417 | active->sr.plane); |
| 1418 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1419 | active->sr.cursor); |
| 1420 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1421 | active->sr.fbc); |
| 1422 | |
| 1423 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1424 | active->hpll.plane); |
| 1425 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1426 | active->hpll.cursor); |
| 1427 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1428 | active->hpll.fbc); |
| 1429 | |
| 1430 | WARN_ON((intermediate->sr.plane > |
| 1431 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1432 | intermediate->sr.cursor > |
| 1433 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1434 | intermediate->cxsr); |
| 1435 | WARN_ON((intermediate->sr.plane > |
| 1436 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1437 | intermediate->sr.cursor > |
| 1438 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1439 | intermediate->hpll_en); |
| 1440 | |
| 1441 | WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1442 | intermediate->fbc_en && intermediate->cxsr); |
| 1443 | WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1444 | intermediate->fbc_en && intermediate->hpll_en); |
| 1445 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1446 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1447 | /* |
| 1448 | * If our intermediate WM are identical to the final WM, then we can |
| 1449 | * omit the post-vblank programming; only update if it's different. |
| 1450 | */ |
| 1451 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1452 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1453 | |
| 1454 | return 0; |
| 1455 | } |
| 1456 | |
| 1457 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1458 | struct g4x_wm_values *wm) |
| 1459 | { |
| 1460 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1461 | int num_active_pipes = 0; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1462 | |
| 1463 | wm->cxsr = true; |
| 1464 | wm->hpll_en = true; |
| 1465 | wm->fbc_en = true; |
| 1466 | |
| 1467 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1468 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1469 | |
| 1470 | if (!crtc->active) |
| 1471 | continue; |
| 1472 | |
| 1473 | if (!wm_state->cxsr) |
| 1474 | wm->cxsr = false; |
| 1475 | if (!wm_state->hpll_en) |
| 1476 | wm->hpll_en = false; |
| 1477 | if (!wm_state->fbc_en) |
| 1478 | wm->fbc_en = false; |
| 1479 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1480 | num_active_pipes++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1481 | } |
| 1482 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1483 | if (num_active_pipes != 1) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1484 | wm->cxsr = false; |
| 1485 | wm->hpll_en = false; |
| 1486 | wm->fbc_en = false; |
| 1487 | } |
| 1488 | |
| 1489 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1490 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1491 | enum pipe pipe = crtc->pipe; |
| 1492 | |
| 1493 | wm->pipe[pipe] = wm_state->wm; |
| 1494 | if (crtc->active && wm->cxsr) |
| 1495 | wm->sr = wm_state->sr; |
| 1496 | if (crtc->active && wm->hpll_en) |
| 1497 | wm->hpll = wm_state->hpll; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1502 | { |
| 1503 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1504 | struct g4x_wm_values new_wm = {}; |
| 1505 | |
| 1506 | g4x_merge_wm(dev_priv, &new_wm); |
| 1507 | |
| 1508 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1509 | return; |
| 1510 | |
| 1511 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1512 | _intel_set_memory_cxsr(dev_priv, false); |
| 1513 | |
| 1514 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1515 | |
| 1516 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1517 | _intel_set_memory_cxsr(dev_priv, true); |
| 1518 | |
| 1519 | *old_wm = new_wm; |
| 1520 | } |
| 1521 | |
| 1522 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
| 1523 | struct intel_crtc_state *crtc_state) |
| 1524 | { |
| 1525 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1526 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1527 | |
| 1528 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1529 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1530 | g4x_program_watermarks(dev_priv); |
| 1531 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1532 | } |
| 1533 | |
| 1534 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
| 1535 | struct intel_crtc_state *crtc_state) |
| 1536 | { |
| 1537 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 1538 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1539 | |
| 1540 | if (!crtc_state->wm.need_postvbl_update) |
| 1541 | return; |
| 1542 | |
| 1543 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 1544 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1545 | g4x_program_watermarks(dev_priv); |
| 1546 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1547 | } |
| 1548 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1549 | /* latency must be in 0.1us units. */ |
| 1550 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1551 | unsigned int htotal, |
| 1552 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1553 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1554 | unsigned int latency) |
| 1555 | { |
| 1556 | unsigned int ret; |
| 1557 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1558 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1559 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1560 | ret = DIV_ROUND_UP(ret, 64); |
| 1561 | |
| 1562 | return ret; |
| 1563 | } |
| 1564 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1565 | 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] | 1566 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1567 | /* all latencies in usec */ |
| 1568 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1569 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1570 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1571 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1572 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1573 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1574 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1575 | |
| 1576 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1577 | } |
| 1578 | } |
| 1579 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1580 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1581 | const struct intel_plane_state *plane_state, |
| 1582 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1583 | { |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1584 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1585 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1586 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 1587 | &crtc_state->hw.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1588 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1589 | |
| 1590 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1591 | return USHRT_MAX; |
| 1592 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1593 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1594 | return 0; |
| 1595 | |
Daniel Vetter | ef426c1 | 2017-01-04 11:41:10 +0100 | [diff] [blame] | 1596 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1597 | clock = adjusted_mode->crtc_clock; |
| 1598 | htotal = adjusted_mode->crtc_htotal; |
| 1599 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1600 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1601 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1602 | /* |
| 1603 | * FIXME the formula gives values that are |
| 1604 | * too big for the cursor FIFO, and hence we |
| 1605 | * would never be able to use cursors. For |
| 1606 | * now just hardcode the watermark. |
| 1607 | */ |
| 1608 | wm = 63; |
| 1609 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1610 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1611 | dev_priv->wm.pri_latency[level] * 10); |
| 1612 | } |
| 1613 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1614 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1615 | } |
| 1616 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1617 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1618 | { |
| 1619 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1620 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1621 | } |
| 1622 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1623 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1624 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1625 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1626 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1627 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1628 | 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] | 1629 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1630 | int num_active_planes = hweight8(active_planes); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1631 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1632 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1633 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1634 | unsigned int total_rate; |
| 1635 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1636 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1637 | /* |
| 1638 | * When enabling sprite0 after sprite1 has already been enabled |
| 1639 | * we tend to get an underrun unless sprite0 already has some |
| 1640 | * FIFO space allcoated. Hence we always allocate at least one |
| 1641 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1642 | * |
| 1643 | * All other plane enable sequences appear immune to this problem. |
| 1644 | */ |
| 1645 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1646 | sprite0_fifo_extra = 1; |
| 1647 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1648 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1649 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1650 | raw->plane[PLANE_SPRITE1] + |
| 1651 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1652 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1653 | if (total_rate > fifo_size) |
| 1654 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1655 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1656 | if (total_rate == 0) |
| 1657 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1658 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1659 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1660 | unsigned int rate; |
| 1661 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1662 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1663 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1664 | continue; |
| 1665 | } |
| 1666 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1667 | rate = raw->plane[plane_id]; |
| 1668 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1669 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1670 | } |
| 1671 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1672 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1673 | fifo_left -= sprite0_fifo_extra; |
| 1674 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1675 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1676 | |
| 1677 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1678 | |
| 1679 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1680 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1681 | int plane_extra; |
| 1682 | |
| 1683 | if (fifo_left == 0) |
| 1684 | break; |
| 1685 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1686 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1687 | continue; |
| 1688 | |
| 1689 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1690 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1691 | fifo_left -= plane_extra; |
| 1692 | } |
| 1693 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1694 | WARN_ON(active_planes != 0 && fifo_left != 0); |
| 1695 | |
| 1696 | /* give it all to the first plane if none are active */ |
| 1697 | if (active_planes == 0) { |
| 1698 | WARN_ON(fifo_left != fifo_size); |
| 1699 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1700 | } |
| 1701 | |
| 1702 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1703 | } |
| 1704 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1705 | /* mark all levels starting from 'level' as invalid */ |
| 1706 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1707 | struct vlv_wm_state *wm_state, int level) |
| 1708 | { |
| 1709 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1710 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1711 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1712 | enum plane_id plane_id; |
| 1713 | |
| 1714 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1715 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1716 | |
| 1717 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1718 | wm_state->sr[level].plane = USHRT_MAX; |
| 1719 | } |
| 1720 | } |
| 1721 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1722 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1723 | { |
| 1724 | if (wm > fifo_size) |
| 1725 | return USHRT_MAX; |
| 1726 | else |
| 1727 | return fifo_size - wm; |
| 1728 | } |
| 1729 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1730 | /* |
| 1731 | * Starting from 'level' set all higher |
| 1732 | * levels to 'value' in the "raw" watermarks. |
| 1733 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1734 | 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] | 1735 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1736 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1737 | 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] | 1738 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1739 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1740 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1741 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1742 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1743 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1744 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1745 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1746 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1747 | |
| 1748 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1749 | } |
| 1750 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1751 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1752 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1753 | { |
| 1754 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1755 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1756 | 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] | 1757 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1758 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1759 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1760 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1761 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1762 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1766 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1767 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1768 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1769 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1770 | if (wm > max_wm) |
| 1771 | break; |
| 1772 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1773 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1774 | raw->plane[plane_id] = wm; |
| 1775 | } |
| 1776 | |
| 1777 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1778 | 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] | 1779 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1780 | out: |
| 1781 | if (dirty) |
Ville Syrjälä | 57a6528 | 2017-04-21 21:14:22 +0300 | [diff] [blame] | 1782 | 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] | 1783 | plane->base.name, |
| 1784 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1785 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1786 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
| 1787 | |
| 1788 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1789 | } |
| 1790 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1791 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1792 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1793 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1794 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1795 | &crtc_state->wm.vlv.raw[level]; |
| 1796 | const struct vlv_fifo_state *fifo_state = |
| 1797 | &crtc_state->wm.vlv.fifo_state; |
| 1798 | |
| 1799 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1800 | } |
| 1801 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1802 | 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] | 1803 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1804 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1805 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1806 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1807 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | 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] | 1811 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1812 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1813 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1814 | struct intel_atomic_state *state = |
| 1815 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1816 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1817 | const struct vlv_fifo_state *fifo_state = |
| 1818 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1819 | int num_active_planes = hweight8(crtc_state->active_planes & |
| 1820 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1821 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->base); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1822 | const struct intel_plane_state *old_plane_state; |
| 1823 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1824 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1825 | enum plane_id plane_id; |
| 1826 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1827 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1828 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1829 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1830 | old_plane_state, |
| 1831 | new_plane_state, i) { |
| 1832 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1833 | old_plane_state->base.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1834 | continue; |
| 1835 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1836 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1837 | dirty |= BIT(plane->id); |
| 1838 | } |
| 1839 | |
| 1840 | /* |
| 1841 | * DSPARB registers may have been reset due to the |
| 1842 | * power well being turned off. Make sure we restore |
| 1843 | * them to a consistent state even if no primary/sprite |
| 1844 | * planes are initially active. |
| 1845 | */ |
| 1846 | if (needs_modeset) |
| 1847 | crtc_state->fifo_changed = true; |
| 1848 | |
| 1849 | if (!dirty) |
| 1850 | return 0; |
| 1851 | |
| 1852 | /* cursor changes don't warrant a FIFO recompute */ |
| 1853 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1854 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1855 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1856 | const struct vlv_fifo_state *old_fifo_state = |
| 1857 | &old_crtc_state->wm.vlv.fifo_state; |
| 1858 | |
| 1859 | ret = vlv_compute_fifo(crtc_state); |
| 1860 | if (ret) |
| 1861 | return ret; |
| 1862 | |
| 1863 | if (needs_modeset || |
| 1864 | memcmp(old_fifo_state, fifo_state, |
| 1865 | sizeof(*fifo_state)) != 0) |
| 1866 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1867 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1868 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1869 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1870 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1871 | /* |
| 1872 | * Note that enabling cxsr with no primary/sprite planes |
| 1873 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1874 | * with exactly one enabled primary/sprite plane. |
| 1875 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1876 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1877 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1878 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1879 | const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 1880 | const int sr_fifo_size = INTEL_NUM_PIPES(dev_priv) * 512 - 1; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1881 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1882 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1883 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1884 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1885 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1886 | wm_state->wm[level].plane[plane_id] = |
| 1887 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1888 | fifo_state->plane[plane_id]); |
| 1889 | } |
| 1890 | |
| 1891 | wm_state->sr[level].plane = |
| 1892 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1893 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1894 | raw->plane[PLANE_SPRITE1]), |
| 1895 | sr_fifo_size); |
| 1896 | |
| 1897 | wm_state->sr[level].cursor = |
| 1898 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1899 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1900 | } |
| 1901 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1902 | if (level == 0) |
| 1903 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1904 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1905 | /* limit to only levels we can actually handle */ |
| 1906 | wm_state->num_levels = level; |
| 1907 | |
| 1908 | /* invalidate the higher levels */ |
| 1909 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1910 | |
| 1911 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1912 | } |
| 1913 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1914 | #define VLV_FIFO(plane, value) \ |
| 1915 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1916 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1917 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
| 1918 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1919 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1920 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1921 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1922 | struct intel_uncore *uncore = &dev_priv->uncore; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1923 | const struct vlv_fifo_state *fifo_state = |
| 1924 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1925 | int sprite0_start, sprite1_start, fifo_size; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1926 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1927 | if (!crtc_state->fifo_changed) |
| 1928 | return; |
| 1929 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1930 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 1931 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 1932 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1933 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1934 | WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63); |
| 1935 | WARN_ON(fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1936 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1937 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 1938 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1939 | /* |
| 1940 | * uncore.lock serves a double purpose here. It allows us to |
| 1941 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 1942 | * it protects the DSPARB registers from getting clobbered by |
| 1943 | * parallel updates from multiple pipes. |
| 1944 | * |
| 1945 | * intel_pipe_update_start() has already disabled interrupts |
| 1946 | * for us, so a plain spin_lock() is sufficient here. |
| 1947 | */ |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1948 | spin_lock(&uncore->lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1949 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1950 | switch (crtc->pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1951 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1952 | case PIPE_A: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1953 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 1954 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1955 | |
| 1956 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1957 | VLV_FIFO(SPRITEB, 0xff)); |
| 1958 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1959 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1960 | |
| 1961 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1962 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1963 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1964 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1965 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1966 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 1967 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1968 | break; |
| 1969 | case PIPE_B: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1970 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 1971 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1972 | |
| 1973 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 1974 | VLV_FIFO(SPRITED, 0xff)); |
| 1975 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 1976 | VLV_FIFO(SPRITED, sprite1_start)); |
| 1977 | |
| 1978 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 1979 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 1980 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 1981 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 1982 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1983 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 1984 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1985 | break; |
| 1986 | case PIPE_C: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1987 | dsparb3 = intel_uncore_read_fw(uncore, DSPARB3); |
| 1988 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1989 | |
| 1990 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 1991 | VLV_FIFO(SPRITEF, 0xff)); |
| 1992 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 1993 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 1994 | |
| 1995 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 1996 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 1997 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 1998 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 1999 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2000 | intel_uncore_write_fw(uncore, DSPARB3, dsparb3); |
| 2001 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2002 | break; |
| 2003 | default: |
| 2004 | break; |
| 2005 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2006 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2007 | intel_uncore_posting_read_fw(uncore, DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2008 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2009 | spin_unlock(&uncore->lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | #undef VLV_FIFO |
| 2013 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2014 | static int vlv_compute_intermediate_wm(struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2015 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2016 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2017 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2018 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
| 2019 | struct intel_atomic_state *intel_state = |
| 2020 | to_intel_atomic_state(new_crtc_state->base.state); |
| 2021 | const struct intel_crtc_state *old_crtc_state = |
| 2022 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 2023 | const struct vlv_wm_state *active = &old_crtc_state->wm.vlv.optimal; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2024 | int level; |
| 2025 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2026 | if (!new_crtc_state->hw.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2027 | *intermediate = *optimal; |
| 2028 | |
| 2029 | intermediate->cxsr = false; |
| 2030 | goto out; |
| 2031 | } |
| 2032 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2033 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2034 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2035 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2036 | |
| 2037 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2038 | enum plane_id plane_id; |
| 2039 | |
| 2040 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2041 | intermediate->wm[level].plane[plane_id] = |
| 2042 | min(optimal->wm[level].plane[plane_id], |
| 2043 | active->wm[level].plane[plane_id]); |
| 2044 | } |
| 2045 | |
| 2046 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2047 | active->sr[level].plane); |
| 2048 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2049 | active->sr[level].cursor); |
| 2050 | } |
| 2051 | |
| 2052 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2053 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2054 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2055 | /* |
| 2056 | * If our intermediate WM are identical to the final WM, then we can |
| 2057 | * omit the post-vblank programming; only update if it's different. |
| 2058 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2059 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2060 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2061 | |
| 2062 | return 0; |
| 2063 | } |
| 2064 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2065 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2066 | struct vlv_wm_values *wm) |
| 2067 | { |
| 2068 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2069 | int num_active_pipes = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2070 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2071 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2072 | wm->cxsr = true; |
| 2073 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2074 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2075 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2076 | |
| 2077 | if (!crtc->active) |
| 2078 | continue; |
| 2079 | |
| 2080 | if (!wm_state->cxsr) |
| 2081 | wm->cxsr = false; |
| 2082 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2083 | num_active_pipes++; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2084 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2085 | } |
| 2086 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2087 | if (num_active_pipes != 1) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2088 | wm->cxsr = false; |
| 2089 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2090 | if (num_active_pipes > 1) |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2091 | wm->level = VLV_WM_LEVEL_PM2; |
| 2092 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2093 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2094 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2095 | enum pipe pipe = crtc->pipe; |
| 2096 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2097 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2098 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2099 | wm->sr = wm_state->sr[wm->level]; |
| 2100 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2101 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2102 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2103 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2104 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2105 | } |
| 2106 | } |
| 2107 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2108 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2109 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2110 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2111 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2112 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2113 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2114 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2115 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2116 | return; |
| 2117 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2118 | 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] | 2119 | chv_set_memory_dvfs(dev_priv, false); |
| 2120 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2121 | 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] | 2122 | chv_set_memory_pm5(dev_priv, false); |
| 2123 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2124 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2125 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2126 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2127 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2128 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2129 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2130 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2131 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2132 | 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] | 2133 | chv_set_memory_pm5(dev_priv, true); |
| 2134 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2135 | 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] | 2136 | chv_set_memory_dvfs(dev_priv, true); |
| 2137 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2138 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2139 | } |
| 2140 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2141 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
| 2142 | struct intel_crtc_state *crtc_state) |
| 2143 | { |
| 2144 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2145 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2146 | |
| 2147 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2148 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2149 | vlv_program_watermarks(dev_priv); |
| 2150 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2151 | } |
| 2152 | |
| 2153 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
| 2154 | struct intel_crtc_state *crtc_state) |
| 2155 | { |
| 2156 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 2157 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2158 | |
| 2159 | if (!crtc_state->wm.need_postvbl_update) |
| 2160 | return; |
| 2161 | |
| 2162 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 2163 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2164 | vlv_program_watermarks(dev_priv); |
| 2165 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2166 | } |
| 2167 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2168 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2169 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2170 | 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] | 2171 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2172 | int srwm = 1; |
| 2173 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2174 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2175 | |
| 2176 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2177 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2178 | if (crtc) { |
| 2179 | /* self-refresh has much higher latency */ |
| 2180 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2181 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2182 | &crtc->config->hw.adjusted_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2183 | const struct drm_framebuffer *fb = |
| 2184 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2185 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2186 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2187 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2188 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2189 | int entries; |
| 2190 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2191 | entries = intel_wm_method2(clock, htotal, |
| 2192 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2193 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2194 | srwm = I965_FIFO_SIZE - entries; |
| 2195 | if (srwm < 0) |
| 2196 | srwm = 1; |
| 2197 | srwm &= 0x1ff; |
| 2198 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 2199 | entries, srwm); |
| 2200 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2201 | entries = intel_wm_method2(clock, htotal, |
| 2202 | crtc->base.cursor->state->crtc_w, 4, |
| 2203 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2204 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2205 | i965_cursor_wm_info.cacheline_size) + |
| 2206 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2207 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2208 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2209 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2210 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2211 | |
| 2212 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 2213 | "cursor %d\n", srwm, cursor_sr); |
| 2214 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2215 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2216 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2217 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2218 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2219 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2223 | srwm); |
| 2224 | |
| 2225 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2226 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2227 | FW_WM(8, CURSORB) | |
| 2228 | FW_WM(8, PLANEB) | |
| 2229 | FW_WM(8, PLANEA)); |
| 2230 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2231 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2232 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2233 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2234 | |
| 2235 | if (cxsr_enabled) |
| 2236 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2237 | } |
| 2238 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2239 | #undef FW_WM |
| 2240 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2241 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2242 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2243 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2244 | const struct intel_watermark_params *wm_info; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2245 | u32 fwater_lo; |
| 2246 | u32 fwater_hi; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2247 | int cwm, srwm = 1; |
| 2248 | int fifo_size; |
| 2249 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2250 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2251 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2252 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2253 | wm_info = &i945_wm_info; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2254 | else if (!IS_GEN(dev_priv, 2)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2255 | wm_info = &i915_wm_info; |
| 2256 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2257 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2258 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2259 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_A); |
| 2260 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2261 | if (intel_crtc_active(crtc)) { |
| 2262 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2263 | &crtc->config->hw.adjusted_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2264 | const struct drm_framebuffer *fb = |
| 2265 | crtc->base.primary->state->fb; |
| 2266 | int cpp; |
| 2267 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2268 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2269 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2270 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2271 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2272 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2273 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2274 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2275 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2276 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2277 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2278 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2279 | if (planea_wm > (long)wm_info->max_wm) |
| 2280 | planea_wm = wm_info->max_wm; |
| 2281 | } |
| 2282 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2283 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2284 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2285 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2286 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_B); |
| 2287 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2288 | if (intel_crtc_active(crtc)) { |
| 2289 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2290 | &crtc->config->hw.adjusted_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2291 | const struct drm_framebuffer *fb = |
| 2292 | crtc->base.primary->state->fb; |
| 2293 | int cpp; |
| 2294 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2295 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2296 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2297 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2298 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2299 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2300 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2301 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2302 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2303 | if (enabled == NULL) |
| 2304 | enabled = crtc; |
| 2305 | else |
| 2306 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2307 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2308 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2309 | if (planeb_wm > (long)wm_info->max_wm) |
| 2310 | planeb_wm = wm_info->max_wm; |
| 2311 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2312 | |
| 2313 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2314 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2315 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2316 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2317 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2318 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2319 | |
| 2320 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2321 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2322 | enabled = NULL; |
| 2323 | } |
| 2324 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2325 | /* |
| 2326 | * Overlay gets an aggressive default since video jitter is bad. |
| 2327 | */ |
| 2328 | cwm = 2; |
| 2329 | |
| 2330 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2331 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2332 | |
| 2333 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2334 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2335 | /* self-refresh has much higher latency */ |
| 2336 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2337 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2338 | &enabled->config->hw.adjusted_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2339 | const struct drm_framebuffer *fb = |
| 2340 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2341 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2342 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2343 | int hdisplay = enabled->config->pipe_src_w; |
| 2344 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2345 | int entries; |
| 2346 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2347 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2348 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2349 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2350 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2351 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2352 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2353 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2354 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 2355 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 2356 | srwm = wm_info->fifo_size - entries; |
| 2357 | if (srwm < 0) |
| 2358 | srwm = 1; |
| 2359 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2360 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2361 | I915_WRITE(FW_BLC_SELF, |
| 2362 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2363 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2364 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2365 | } |
| 2366 | |
| 2367 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2368 | planea_wm, planeb_wm, cwm, srwm); |
| 2369 | |
| 2370 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2371 | fwater_hi = (cwm & 0x1f); |
| 2372 | |
| 2373 | /* Set request length to 8 cachelines per fetch */ |
| 2374 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2375 | fwater_hi = fwater_hi | (1 << 8); |
| 2376 | |
| 2377 | I915_WRITE(FW_BLC, fwater_lo); |
| 2378 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2379 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2380 | if (enabled) |
| 2381 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2382 | } |
| 2383 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2384 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2385 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2386 | 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] | 2387 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2388 | const struct drm_display_mode *adjusted_mode; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2389 | u32 fwater_lo; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2390 | int planea_wm; |
| 2391 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2392 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2393 | if (crtc == NULL) |
| 2394 | return; |
| 2395 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2396 | adjusted_mode = &crtc->config->hw.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2397 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2398 | &i845_wm_info, |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2399 | dev_priv->display.get_fifo_size(dev_priv, PLANE_A), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2400 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2401 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2402 | fwater_lo |= (3<<8) | planea_wm; |
| 2403 | |
| 2404 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 2405 | |
| 2406 | I915_WRITE(FW_BLC, fwater_lo); |
| 2407 | } |
| 2408 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2409 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2410 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2411 | unsigned int cpp, |
| 2412 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2413 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2414 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2415 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2416 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2417 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2418 | |
| 2419 | return ret; |
| 2420 | } |
| 2421 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2422 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2423 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2424 | unsigned int htotal, |
| 2425 | unsigned int width, |
| 2426 | unsigned int cpp, |
| 2427 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2428 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2429 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2430 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2431 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2432 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2433 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2434 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2435 | return ret; |
| 2436 | } |
| 2437 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2438 | static u32 ilk_wm_fbc(u32 pri_val, u32 horiz_pixels, u8 cpp) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2439 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2440 | /* |
| 2441 | * Neither of these should be possible since this function shouldn't be |
| 2442 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2443 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2444 | * elsewhere in the driver. |
| 2445 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2446 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2447 | return 0; |
| 2448 | if (WARN_ON(!horiz_pixels)) |
| 2449 | return 0; |
| 2450 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2451 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2452 | } |
| 2453 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2454 | struct ilk_wm_maximums { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2455 | u16 pri; |
| 2456 | u16 spr; |
| 2457 | u16 cur; |
| 2458 | u16 fbc; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2459 | }; |
| 2460 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2461 | /* |
| 2462 | * For both WM_PIPE and WM_LP. |
| 2463 | * mem_value must be in 0.1us units. |
| 2464 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2465 | static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state, |
| 2466 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2467 | u32 mem_value, bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2468 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2469 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2470 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2471 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2472 | if (mem_value == 0) |
| 2473 | return U32_MAX; |
| 2474 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2475 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2476 | return 0; |
| 2477 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2478 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2479 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2480 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2481 | |
| 2482 | if (!is_lp) |
| 2483 | return method1; |
| 2484 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2485 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2486 | crtc_state->hw.adjusted_mode.crtc_htotal, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2487 | drm_rect_width(&plane_state->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2488 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2489 | |
| 2490 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2491 | } |
| 2492 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2493 | /* |
| 2494 | * For both WM_PIPE and WM_LP. |
| 2495 | * mem_value must be in 0.1us units. |
| 2496 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2497 | static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state, |
| 2498 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2499 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2500 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2501 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2502 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2503 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2504 | if (mem_value == 0) |
| 2505 | return U32_MAX; |
| 2506 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2507 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2508 | return 0; |
| 2509 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2510 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2511 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2512 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
| 2513 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2514 | crtc_state->hw.adjusted_mode.crtc_htotal, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2515 | drm_rect_width(&plane_state->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2516 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2517 | return min(method1, method2); |
| 2518 | } |
| 2519 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2520 | /* |
| 2521 | * For both WM_PIPE and WM_LP. |
| 2522 | * mem_value must be in 0.1us units. |
| 2523 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2524 | static u32 ilk_compute_cur_wm(const struct intel_crtc_state *crtc_state, |
| 2525 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2526 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2527 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2528 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2529 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2530 | if (mem_value == 0) |
| 2531 | return U32_MAX; |
| 2532 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2533 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2534 | return 0; |
| 2535 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2536 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2537 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2538 | return ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2539 | crtc_state->hw.adjusted_mode.crtc_htotal, |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 2540 | drm_rect_width(&plane_state->base.dst), |
| 2541 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2542 | } |
| 2543 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2544 | /* Only for WM_LP. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2545 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 2546 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2547 | u32 pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2548 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2549 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2550 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2551 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2552 | return 0; |
| 2553 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2554 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2555 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2556 | return ilk_wm_fbc(pri_val, drm_rect_width(&plane_state->base.dst), cpp); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2557 | } |
| 2558 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2559 | static unsigned int |
| 2560 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2561 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2562 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2563 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2564 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2565 | return 768; |
| 2566 | else |
| 2567 | return 512; |
| 2568 | } |
| 2569 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2570 | static unsigned int |
| 2571 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2572 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2573 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2574 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2575 | /* BDW primary/sprite plane watermarks */ |
| 2576 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2577 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2578 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2579 | return level == 0 ? 127 : 1023; |
| 2580 | else if (!is_sprite) |
| 2581 | /* ILK/SNB primary plane watermarks */ |
| 2582 | return level == 0 ? 127 : 511; |
| 2583 | else |
| 2584 | /* ILK/SNB sprite plane watermarks */ |
| 2585 | return level == 0 ? 63 : 255; |
| 2586 | } |
| 2587 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2588 | static unsigned int |
| 2589 | 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] | 2590 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2591 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2592 | return level == 0 ? 63 : 255; |
| 2593 | else |
| 2594 | return level == 0 ? 31 : 63; |
| 2595 | } |
| 2596 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2597 | 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] | 2598 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2599 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2600 | return 31; |
| 2601 | else |
| 2602 | return 15; |
| 2603 | } |
| 2604 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2605 | /* Calculate the maximum primary/sprite plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2606 | static unsigned int ilk_plane_wm_max(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2607 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2608 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2609 | enum intel_ddb_partitioning ddb_partitioning, |
| 2610 | bool is_sprite) |
| 2611 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2612 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2613 | |
| 2614 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2615 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2616 | return 0; |
| 2617 | |
| 2618 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2619 | if (level == 0 || config->num_pipes_active > 1) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 2620 | fifo_size /= INTEL_NUM_PIPES(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2621 | |
| 2622 | /* |
| 2623 | * For some reason the non self refresh |
| 2624 | * FIFO size is only half of the self |
| 2625 | * refresh FIFO size on ILK/SNB. |
| 2626 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2627 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2628 | fifo_size /= 2; |
| 2629 | } |
| 2630 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2631 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2632 | /* level 0 is always calculated with 1:1 split */ |
| 2633 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2634 | if (is_sprite) |
| 2635 | fifo_size *= 5; |
| 2636 | fifo_size /= 6; |
| 2637 | } else { |
| 2638 | fifo_size /= 2; |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2643 | 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] | 2644 | } |
| 2645 | |
| 2646 | /* Calculate the maximum cursor plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2647 | static unsigned int ilk_cursor_wm_max(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2648 | int level, |
| 2649 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2650 | { |
| 2651 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2652 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2653 | return 64; |
| 2654 | |
| 2655 | /* otherwise just report max that registers can hold */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2656 | return ilk_cursor_wm_reg_max(dev_priv, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2657 | } |
| 2658 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2659 | static void ilk_compute_wm_maximums(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2660 | int level, |
| 2661 | const struct intel_wm_config *config, |
| 2662 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2663 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2664 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2665 | max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false); |
| 2666 | max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true); |
| 2667 | max->cur = ilk_cursor_wm_max(dev_priv, level, config); |
| 2668 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2669 | } |
| 2670 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2671 | 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] | 2672 | int level, |
| 2673 | struct ilk_wm_maximums *max) |
| 2674 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2675 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2676 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2677 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2678 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2679 | } |
| 2680 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2681 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2682 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2683 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2684 | { |
| 2685 | bool ret; |
| 2686 | |
| 2687 | /* already determined to be invalid? */ |
| 2688 | if (!result->enable) |
| 2689 | return false; |
| 2690 | |
| 2691 | result->enable = result->pri_val <= max->pri && |
| 2692 | result->spr_val <= max->spr && |
| 2693 | result->cur_val <= max->cur; |
| 2694 | |
| 2695 | ret = result->enable; |
| 2696 | |
| 2697 | /* |
| 2698 | * HACK until we can pre-compute everything, |
| 2699 | * and thus fail gracefully if LP0 watermarks |
| 2700 | * are exceeded... |
| 2701 | */ |
| 2702 | if (level == 0 && !result->enable) { |
| 2703 | if (result->pri_val > max->pri) |
| 2704 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2705 | level, result->pri_val, max->pri); |
| 2706 | if (result->spr_val > max->spr) |
| 2707 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2708 | level, result->spr_val, max->spr); |
| 2709 | if (result->cur_val > max->cur) |
| 2710 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2711 | level, result->cur_val, max->cur); |
| 2712 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2713 | result->pri_val = min_t(u32, result->pri_val, max->pri); |
| 2714 | result->spr_val = min_t(u32, result->spr_val, max->spr); |
| 2715 | result->cur_val = min_t(u32, result->cur_val, max->cur); |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2716 | result->enable = true; |
| 2717 | } |
| 2718 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2719 | return ret; |
| 2720 | } |
| 2721 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2722 | 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] | 2723 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2724 | int level, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2725 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2726 | const struct intel_plane_state *pristate, |
| 2727 | const struct intel_plane_state *sprstate, |
| 2728 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2729 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2730 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2731 | u16 pri_latency = dev_priv->wm.pri_latency[level]; |
| 2732 | u16 spr_latency = dev_priv->wm.spr_latency[level]; |
| 2733 | u16 cur_latency = dev_priv->wm.cur_latency[level]; |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2734 | |
| 2735 | /* WM1+ latency values stored in 0.5us units */ |
| 2736 | if (level > 0) { |
| 2737 | pri_latency *= 5; |
| 2738 | spr_latency *= 5; |
| 2739 | cur_latency *= 5; |
| 2740 | } |
| 2741 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2742 | if (pristate) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2743 | result->pri_val = ilk_compute_pri_wm(crtc_state, pristate, |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2744 | pri_latency, level); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2745 | result->fbc_val = ilk_compute_fbc_wm(crtc_state, pristate, result->pri_val); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | if (sprstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2749 | result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2750 | |
| 2751 | if (curstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2752 | result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2753 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2754 | result->enable = true; |
| 2755 | } |
| 2756 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2757 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2758 | hsw_compute_linetime_wm(const struct intel_crtc_state *crtc_state) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2759 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2760 | const struct intel_atomic_state *intel_state = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2761 | to_intel_atomic_state(crtc_state->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2762 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2763 | &crtc_state->hw.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2764 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2765 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 2766 | if (!crtc_state->hw.active) |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2767 | return 0; |
| 2768 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2769 | return 0; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2770 | if (WARN_ON(intel_state->cdclk.logical.cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2771 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2772 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2773 | /* The WM are computed with base on how long it takes to fill a single |
| 2774 | * row at the given clock rate, multiplied by 8. |
| 2775 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2776 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2777 | adjusted_mode->crtc_clock); |
| 2778 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2779 | intel_state->cdclk.logical.cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2780 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2781 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2782 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2783 | } |
| 2784 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2785 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2786 | u16 wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2787 | { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2788 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 2789 | |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2790 | if (INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2791 | u32 val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2792 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2793 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2794 | |
| 2795 | /* read the first set of memory latencies[0:3] */ |
| 2796 | val = 0; /* data0 to be programmed to 0 for first set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2797 | ret = sandybridge_pcode_read(dev_priv, |
| 2798 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2799 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2800 | |
| 2801 | if (ret) { |
| 2802 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2803 | return; |
| 2804 | } |
| 2805 | |
| 2806 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2807 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2808 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2809 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2810 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2811 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2812 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2813 | |
| 2814 | /* read the second set of memory latencies[4:7] */ |
| 2815 | val = 1; /* data0 to be programmed to 1 for second set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2816 | ret = sandybridge_pcode_read(dev_priv, |
| 2817 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2818 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2819 | if (ret) { |
| 2820 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2821 | return; |
| 2822 | } |
| 2823 | |
| 2824 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2825 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2826 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2827 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2828 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2829 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2830 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2831 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2832 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2833 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2834 | * need to be disabled. We make sure to sanitize the values out |
| 2835 | * of the punit to satisfy this requirement. |
| 2836 | */ |
| 2837 | for (level = 1; level <= max_level; level++) { |
| 2838 | if (wm[level] == 0) { |
| 2839 | for (i = level + 1; i <= max_level; i++) |
| 2840 | wm[i] = 0; |
| 2841 | break; |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | /* |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2846 | * WaWmMemoryReadLatency:skl+,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2847 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2848 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2849 | * to add 2us to the various latency levels we retrieve from the |
| 2850 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2851 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2852 | if (wm[0] == 0) { |
| 2853 | wm[0] += 2; |
| 2854 | for (level = 1; level <= max_level; level++) { |
| 2855 | if (wm[level] == 0) |
| 2856 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2857 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2858 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2859 | } |
| 2860 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2861 | /* |
| 2862 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2863 | * If we could not get dimm info enable this WA to prevent from |
| 2864 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2865 | * to avoid any underrun. |
| 2866 | */ |
Ville Syrjälä | 5d6f36b | 2018-10-23 21:21:02 +0300 | [diff] [blame] | 2867 | if (dev_priv->dram_info.is_16gb_dimm) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2868 | wm[0] += 1; |
| 2869 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2870 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2871 | u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2872 | |
| 2873 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2874 | if (wm[0] == 0) |
| 2875 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2876 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2877 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2878 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2879 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2880 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2881 | u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2882 | |
| 2883 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2884 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2885 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2886 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2887 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2888 | u32 mltr = intel_uncore_read(uncore, MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2889 | |
| 2890 | /* ILK primary LP0 latency is 700 ns */ |
| 2891 | wm[0] = 7; |
| 2892 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2893 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2894 | } else { |
| 2895 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2899 | static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2900 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2901 | { |
| 2902 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2903 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2904 | wm[0] = 13; |
| 2905 | } |
| 2906 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2907 | static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2908 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2909 | { |
| 2910 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2911 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2912 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2913 | } |
| 2914 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2915 | 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] | 2916 | { |
| 2917 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2918 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2919 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2920 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2921 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2922 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2923 | return 3; |
| 2924 | else |
| 2925 | return 2; |
| 2926 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2927 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2928 | 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] | 2929 | const char *name, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2930 | const u16 wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2931 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2932 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2933 | |
| 2934 | for (level = 0; level <= max_level; level++) { |
| 2935 | unsigned int latency = wm[level]; |
| 2936 | |
| 2937 | if (latency == 0) { |
Chris Wilson | 86c1c87 | 2018-07-26 17:15:27 +0100 | [diff] [blame] | 2938 | DRM_DEBUG_KMS("%s WM%d latency not provided\n", |
| 2939 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2940 | continue; |
| 2941 | } |
| 2942 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2943 | /* |
| 2944 | * - latencies are in us on gen9. |
| 2945 | * - before then, WM1+ latency values are in 0.5us units |
| 2946 | */ |
Paulo Zanoni | dfc267a | 2017-08-09 13:52:46 -0700 | [diff] [blame] | 2947 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2948 | latency *= 10; |
| 2949 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2950 | latency *= 5; |
| 2951 | |
| 2952 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2953 | name, level, wm[level], |
| 2954 | latency / 10, latency % 10); |
| 2955 | } |
| 2956 | } |
| 2957 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2958 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2959 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2960 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2961 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2962 | |
| 2963 | if (wm[0] >= min) |
| 2964 | return false; |
| 2965 | |
| 2966 | wm[0] = max(wm[0], min); |
| 2967 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2968 | wm[level] = max_t(u16, wm[level], DIV_ROUND_UP(min, 5)); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2969 | |
| 2970 | return true; |
| 2971 | } |
| 2972 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2973 | 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] | 2974 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2975 | bool changed; |
| 2976 | |
| 2977 | /* |
| 2978 | * The BIOS provided WM memory latency values are often |
| 2979 | * inadequate for high resolution displays. Adjust them. |
| 2980 | */ |
| 2981 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2982 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2983 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2984 | |
| 2985 | if (!changed) |
| 2986 | return; |
| 2987 | |
| 2988 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2989 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 2990 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 2991 | 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] | 2992 | } |
| 2993 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2994 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 2995 | { |
| 2996 | /* |
| 2997 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 2998 | * LP3 usage can cause vblank interrupts to be lost. |
| 2999 | * The DEIIR bit will go high but it looks like the CPU |
| 3000 | * never gets interrupted. |
| 3001 | * |
| 3002 | * It's not clear whether other interrupt source could |
| 3003 | * be affected or if this is somehow limited to vblank |
| 3004 | * interrupts only. To play it safe we disable LP3 |
| 3005 | * watermarks entirely. |
| 3006 | */ |
| 3007 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3008 | dev_priv->wm.spr_latency[3] == 0 && |
| 3009 | dev_priv->wm.cur_latency[3] == 0) |
| 3010 | return; |
| 3011 | |
| 3012 | dev_priv->wm.pri_latency[3] = 0; |
| 3013 | dev_priv->wm.spr_latency[3] = 0; |
| 3014 | dev_priv->wm.cur_latency[3] = 0; |
| 3015 | |
| 3016 | DRM_DEBUG_KMS("LP3 watermarks disabled due to potential for lost interrupts\n"); |
| 3017 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3018 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3019 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3020 | } |
| 3021 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3022 | 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] | 3023 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3024 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3025 | |
| 3026 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3027 | sizeof(dev_priv->wm.pri_latency)); |
| 3028 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3029 | sizeof(dev_priv->wm.pri_latency)); |
| 3030 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3031 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3032 | 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] | 3033 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3034 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3035 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3036 | 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] | 3037 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3038 | if (IS_GEN(dev_priv, 6)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3039 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3040 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3041 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3042 | } |
| 3043 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3044 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3045 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3046 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3047 | 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] | 3048 | } |
| 3049 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3050 | static bool ilk_validate_pipe_wm(const struct drm_i915_private *dev_priv, |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3051 | struct intel_pipe_wm *pipe_wm) |
| 3052 | { |
| 3053 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3054 | const struct intel_wm_config config = { |
| 3055 | .num_pipes_active = 1, |
| 3056 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3057 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3058 | }; |
| 3059 | struct ilk_wm_maximums max; |
| 3060 | |
| 3061 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3062 | ilk_compute_wm_maximums(dev_priv, 0, &config, INTEL_DDB_PART_1_2, &max); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3063 | |
| 3064 | /* At least LP0 must be valid */ |
| 3065 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 3066 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 3067 | return false; |
| 3068 | } |
| 3069 | |
| 3070 | return true; |
| 3071 | } |
| 3072 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3073 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3074 | static int ilk_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3075 | { |
Maarten Lankhorst | 3558caf | 2019-10-31 12:25:59 +0100 | [diff] [blame] | 3076 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3077 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3078 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3079 | struct intel_plane *plane; |
| 3080 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3081 | const struct intel_plane_state *pristate = NULL; |
| 3082 | const struct intel_plane_state *sprstate = NULL; |
| 3083 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3084 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3085 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3086 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3087 | pipe_wm = &crtc_state->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3088 | |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3089 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 3090 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 3091 | pristate = plane_state; |
| 3092 | else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
| 3093 | sprstate = plane_state; |
| 3094 | else if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 3095 | curstate = plane_state; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 3098 | pipe_wm->pipe_enabled = crtc_state->hw.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3099 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3100 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 3101 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 3102 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 3103 | 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] | 3104 | } |
| 3105 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3106 | usable_level = max_level; |
| 3107 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3108 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3109 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3110 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3111 | |
| 3112 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3113 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3114 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3115 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3116 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3117 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3118 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3119 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3120 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3121 | pipe_wm->linetime = hsw_compute_linetime_wm(crtc_state); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3122 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3123 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3124 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3125 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3126 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3127 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3128 | for (level = 1; level <= usable_level; level++) { |
| 3129 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3130 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3131 | ilk_compute_wm_level(dev_priv, intel_crtc, level, crtc_state, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3132 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3133 | |
| 3134 | /* |
| 3135 | * Disable any watermark level that exceeds the |
| 3136 | * register maximums since such watermarks are |
| 3137 | * always invalid. |
| 3138 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3139 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3140 | memset(wm, 0, sizeof(*wm)); |
| 3141 | break; |
| 3142 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3143 | } |
| 3144 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3145 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3149 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3150 | * state and the new state. These can be programmed to the hardware |
| 3151 | * immediately. |
| 3152 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3153 | static int ilk_compute_intermediate_wm(struct intel_crtc_state *newstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3154 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3155 | struct intel_crtc *intel_crtc = to_intel_crtc(newstate->base.crtc); |
| 3156 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3157 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3158 | struct intel_atomic_state *intel_state = |
| 3159 | to_intel_atomic_state(newstate->base.state); |
| 3160 | const struct intel_crtc_state *oldstate = |
| 3161 | intel_atomic_get_old_crtc_state(intel_state, intel_crtc); |
| 3162 | const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3163 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3164 | |
| 3165 | /* |
| 3166 | * Start with the final, target watermarks, then combine with the |
| 3167 | * currently active watermarks to get values that are safe both before |
| 3168 | * and after the vblank. |
| 3169 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3170 | *a = newstate->wm.ilk.optimal; |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 3171 | if (!newstate->hw.active || drm_atomic_crtc_needs_modeset(&newstate->base) || |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 3172 | intel_state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3173 | return 0; |
| 3174 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3175 | a->pipe_enabled |= b->pipe_enabled; |
| 3176 | a->sprites_enabled |= b->sprites_enabled; |
| 3177 | a->sprites_scaled |= b->sprites_scaled; |
| 3178 | |
| 3179 | for (level = 0; level <= max_level; level++) { |
| 3180 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3181 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3182 | |
| 3183 | a_wm->enable &= b_wm->enable; |
| 3184 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3185 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3186 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3187 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3188 | } |
| 3189 | |
| 3190 | /* |
| 3191 | * We need to make sure that these merged watermark values are |
| 3192 | * actually a valid configuration themselves. If they're not, |
| 3193 | * there's no safe way to transition from the old state to |
| 3194 | * the new state, so we need to fail the atomic transaction. |
| 3195 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3196 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3197 | return -EINVAL; |
| 3198 | |
| 3199 | /* |
| 3200 | * If our intermediate WM are identical to the final WM, then we can |
| 3201 | * omit the post-vblank programming; only update if it's different. |
| 3202 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3203 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3204 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3205 | |
| 3206 | return 0; |
| 3207 | } |
| 3208 | |
| 3209 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3210 | * Merge the watermarks from all active pipes for a specific level. |
| 3211 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3212 | static void ilk_merge_wm_level(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3213 | int level, |
| 3214 | struct intel_wm_level *ret_wm) |
| 3215 | { |
| 3216 | const struct intel_crtc *intel_crtc; |
| 3217 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3218 | ret_wm->enable = true; |
| 3219 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3220 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3221 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3222 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3223 | |
| 3224 | if (!active->pipe_enabled) |
| 3225 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3226 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3227 | /* |
| 3228 | * The watermark values may have been used in the past, |
| 3229 | * so we must maintain them in the registers for some |
| 3230 | * time even if the level is now disabled. |
| 3231 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3232 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3233 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3234 | |
| 3235 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3236 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3237 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3238 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3239 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | /* |
| 3243 | * Merge all low power watermarks for all active pipes. |
| 3244 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3245 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3246 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3247 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3248 | struct intel_pipe_wm *merged) |
| 3249 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3250 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3251 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3252 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3253 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3254 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3255 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3256 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3257 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3258 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3259 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3260 | |
| 3261 | /* merge each WM1+ level */ |
| 3262 | for (level = 1; level <= max_level; level++) { |
| 3263 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3264 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3265 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3266 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3267 | if (level > last_enabled_level) |
| 3268 | wm->enable = false; |
| 3269 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3270 | /* make sure all following levels get disabled */ |
| 3271 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3272 | |
| 3273 | /* |
| 3274 | * The spec says it is preferred to disable |
| 3275 | * FBC WMs instead of disabling a WM level. |
| 3276 | */ |
| 3277 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3278 | if (wm->enable) |
| 3279 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3280 | wm->fbc_val = 0; |
| 3281 | } |
| 3282 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3283 | |
| 3284 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3285 | /* |
| 3286 | * FIXME this is racy. FBC might get enabled later. |
| 3287 | * What we should check here is whether FBC can be |
| 3288 | * enabled sometime later. |
| 3289 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3290 | if (IS_GEN(dev_priv, 5) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3291 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3292 | for (level = 2; level <= max_level; level++) { |
| 3293 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3294 | |
| 3295 | wm->enable = false; |
| 3296 | } |
| 3297 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3298 | } |
| 3299 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3300 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3301 | { |
| 3302 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3303 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3304 | } |
| 3305 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3306 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3307 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3308 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3309 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3310 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3311 | return 2 * level; |
| 3312 | else |
| 3313 | return dev_priv->wm.pri_latency[level]; |
| 3314 | } |
| 3315 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3316 | static void ilk_compute_wm_results(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3317 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3318 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3319 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3320 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3321 | struct intel_crtc *intel_crtc; |
| 3322 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3323 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3324 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3325 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3326 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3327 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3328 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3329 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3330 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3331 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3332 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3333 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3334 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3335 | /* |
| 3336 | * Maintain the watermark values even if the level is |
| 3337 | * disabled. Doing otherwise could cause underruns. |
| 3338 | */ |
| 3339 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3340 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3341 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3342 | r->cur_val; |
| 3343 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3344 | if (r->enable) |
| 3345 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3346 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3347 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3348 | results->wm_lp[wm_lp - 1] |= |
| 3349 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3350 | else |
| 3351 | results->wm_lp[wm_lp - 1] |= |
| 3352 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3353 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3354 | /* |
| 3355 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3356 | * level is disabled. Doing otherwise could cause underruns. |
| 3357 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3358 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3359 | WARN_ON(wm_lp != 1); |
| 3360 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3361 | } else |
| 3362 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3363 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3364 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3365 | /* LP0 register values */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3366 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3367 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3368 | const struct intel_wm_level *r = |
| 3369 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3370 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3371 | if (WARN_ON(!r->enable)) |
| 3372 | continue; |
| 3373 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3374 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3375 | |
| 3376 | results->wm_pipe[pipe] = |
| 3377 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3378 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3379 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3380 | } |
| 3381 | } |
| 3382 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3383 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3384 | * case both are at the same level. Prefer r1 in case they're the same. */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3385 | static struct intel_pipe_wm * |
| 3386 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3387 | struct intel_pipe_wm *r1, |
| 3388 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3389 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3390 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3391 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3392 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3393 | for (level = 1; level <= max_level; level++) { |
| 3394 | if (r1->wm[level].enable) |
| 3395 | level1 = level; |
| 3396 | if (r2->wm[level].enable) |
| 3397 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3398 | } |
| 3399 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3400 | if (level1 == level2) { |
| 3401 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3402 | return r2; |
| 3403 | else |
| 3404 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3405 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3406 | return r1; |
| 3407 | } else { |
| 3408 | return r2; |
| 3409 | } |
| 3410 | } |
| 3411 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3412 | /* dirty bits used to track which watermarks need changes */ |
| 3413 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 3414 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 3415 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3416 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3417 | #define WM_DIRTY_FBC (1 << 24) |
| 3418 | #define WM_DIRTY_DDB (1 << 25) |
| 3419 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3420 | 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] | 3421 | const struct ilk_wm_values *old, |
| 3422 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3423 | { |
| 3424 | unsigned int dirty = 0; |
| 3425 | enum pipe pipe; |
| 3426 | int wm_lp; |
| 3427 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3428 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3429 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 3430 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 3431 | /* Must disable LP1+ watermarks too */ |
| 3432 | dirty |= WM_DIRTY_LP_ALL; |
| 3433 | } |
| 3434 | |
| 3435 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3436 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3437 | /* Must disable LP1+ watermarks too */ |
| 3438 | dirty |= WM_DIRTY_LP_ALL; |
| 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3443 | dirty |= WM_DIRTY_FBC; |
| 3444 | /* Must disable LP1+ watermarks too */ |
| 3445 | dirty |= WM_DIRTY_LP_ALL; |
| 3446 | } |
| 3447 | |
| 3448 | if (old->partitioning != new->partitioning) { |
| 3449 | dirty |= WM_DIRTY_DDB; |
| 3450 | /* Must disable LP1+ watermarks too */ |
| 3451 | dirty |= WM_DIRTY_LP_ALL; |
| 3452 | } |
| 3453 | |
| 3454 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3455 | if (dirty & WM_DIRTY_LP_ALL) |
| 3456 | return dirty; |
| 3457 | |
| 3458 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3459 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3460 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3461 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3462 | break; |
| 3463 | } |
| 3464 | |
| 3465 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3466 | for (; wm_lp <= 3; wm_lp++) |
| 3467 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3468 | |
| 3469 | return dirty; |
| 3470 | } |
| 3471 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3472 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3473 | unsigned int dirty) |
| 3474 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3475 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3476 | bool changed = false; |
| 3477 | |
| 3478 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3479 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3480 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3481 | changed = true; |
| 3482 | } |
| 3483 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3484 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3485 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3486 | changed = true; |
| 3487 | } |
| 3488 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3489 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3490 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3491 | changed = true; |
| 3492 | } |
| 3493 | |
| 3494 | /* |
| 3495 | * Don't touch WM1S_LP_EN here. |
| 3496 | * Doing so could cause underruns. |
| 3497 | */ |
| 3498 | |
| 3499 | return changed; |
| 3500 | } |
| 3501 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3502 | /* |
| 3503 | * The spec says we shouldn't write when we don't need, because every write |
| 3504 | * causes WMs to be re-evaluated, expending some power. |
| 3505 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3506 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3507 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3508 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3509 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3510 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3511 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3512 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3513 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3514 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3515 | return; |
| 3516 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3517 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3518 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3519 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3520 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3521 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3522 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3523 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3524 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 3525 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3526 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3527 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3528 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3529 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3530 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3531 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 3532 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3533 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3534 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3535 | val = I915_READ(WM_MISC); |
| 3536 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3537 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3538 | else |
| 3539 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3540 | I915_WRITE(WM_MISC, val); |
| 3541 | } else { |
| 3542 | val = I915_READ(DISP_ARB_CTL2); |
| 3543 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3544 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3545 | else |
| 3546 | val |= DISP_DATA_PARTITION_5_6; |
| 3547 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3548 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3549 | } |
| 3550 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3551 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3552 | val = I915_READ(DISP_ARB_CTL); |
| 3553 | if (results->enable_fbc_wm) |
| 3554 | val &= ~DISP_FBC_WM_DIS; |
| 3555 | else |
| 3556 | val |= DISP_FBC_WM_DIS; |
| 3557 | I915_WRITE(DISP_ARB_CTL, val); |
| 3558 | } |
| 3559 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3560 | if (dirty & WM_DIRTY_LP(1) && |
| 3561 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3562 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3563 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3564 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3565 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3566 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3567 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3568 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3569 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3570 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3571 | 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] | 3572 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3573 | 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] | 3574 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3575 | 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] | 3576 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3577 | |
| 3578 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3579 | } |
| 3580 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3581 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3582 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3583 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3584 | |
| 3585 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3586 | } |
| 3587 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3588 | static u8 intel_enabled_dbuf_slices_num(struct drm_i915_private *dev_priv) |
| 3589 | { |
| 3590 | u8 enabled_slices; |
| 3591 | |
| 3592 | /* Slice 1 will always be enabled */ |
| 3593 | enabled_slices = 1; |
| 3594 | |
| 3595 | /* Gen prior to GEN11 have only one DBuf slice */ |
| 3596 | if (INTEL_GEN(dev_priv) < 11) |
| 3597 | return enabled_slices; |
| 3598 | |
Imre Deak | 209d735 | 2019-03-07 12:32:35 +0200 | [diff] [blame] | 3599 | /* |
| 3600 | * FIXME: for now we'll only ever use 1 slice; pretend that we have |
| 3601 | * only that 1 slice enabled until we have a proper way for on-demand |
| 3602 | * toggling of the second slice. |
| 3603 | */ |
| 3604 | if (0 && I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3605 | enabled_slices++; |
| 3606 | |
| 3607 | return enabled_slices; |
| 3608 | } |
| 3609 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3610 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3611 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3612 | * so assume we'll always need it in order to avoid underruns. |
| 3613 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3614 | static bool skl_needs_memory_bw_wa(struct drm_i915_private *dev_priv) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3615 | { |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3616 | return IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3617 | } |
| 3618 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3619 | static bool |
| 3620 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3621 | { |
Lucas De Marchi | 8ffa439 | 2019-09-04 14:34:18 -0700 | [diff] [blame] | 3622 | /* HACK! */ |
| 3623 | if (IS_GEN(dev_priv, 12)) |
| 3624 | return false; |
| 3625 | |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3626 | return (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) && |
| 3627 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3628 | } |
| 3629 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3630 | static void |
| 3631 | skl_setup_sagv_block_time(struct drm_i915_private *dev_priv) |
| 3632 | { |
James Ausmus | da80f04 | 2019-10-09 10:23:15 -0700 | [diff] [blame] | 3633 | if (INTEL_GEN(dev_priv) >= 12) { |
| 3634 | u32 val = 0; |
| 3635 | int ret; |
| 3636 | |
| 3637 | ret = sandybridge_pcode_read(dev_priv, |
| 3638 | GEN12_PCODE_READ_SAGV_BLOCK_TIME_US, |
| 3639 | &val, NULL); |
| 3640 | if (!ret) { |
| 3641 | dev_priv->sagv_block_time_us = val; |
| 3642 | return; |
| 3643 | } |
| 3644 | |
| 3645 | DRM_DEBUG_DRIVER("Couldn't read SAGV block time!\n"); |
| 3646 | } else if (IS_GEN(dev_priv, 11)) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3647 | dev_priv->sagv_block_time_us = 10; |
| 3648 | return; |
| 3649 | } else if (IS_GEN(dev_priv, 10)) { |
| 3650 | dev_priv->sagv_block_time_us = 20; |
| 3651 | return; |
| 3652 | } else if (IS_GEN(dev_priv, 9)) { |
| 3653 | dev_priv->sagv_block_time_us = 30; |
| 3654 | return; |
| 3655 | } else { |
| 3656 | MISSING_CASE(INTEL_GEN(dev_priv)); |
| 3657 | } |
| 3658 | |
| 3659 | /* Default to an unusable block time */ |
| 3660 | dev_priv->sagv_block_time_us = -1; |
| 3661 | } |
| 3662 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3663 | /* |
| 3664 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3665 | * depending on power and performance requirements. The display engine access |
| 3666 | * to system memory is blocked during the adjustment time. Because of the |
| 3667 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3668 | * underruns if we don't meet all of the following requirements: |
| 3669 | * |
| 3670 | * - <= 1 pipe enabled |
| 3671 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3672 | * - We're not using an interlaced display configuration |
| 3673 | */ |
| 3674 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3675 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3676 | { |
| 3677 | int ret; |
| 3678 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3679 | if (!intel_has_sagv(dev_priv)) |
| 3680 | return 0; |
| 3681 | |
| 3682 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3683 | return 0; |
| 3684 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3685 | DRM_DEBUG_KMS("Enabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3686 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3687 | GEN9_SAGV_ENABLE); |
| 3688 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3689 | /* We don't need to wait for SAGV when enabling */ |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3690 | |
| 3691 | /* |
| 3692 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3693 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3694 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3695 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3696 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3697 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3698 | return 0; |
| 3699 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3700 | DRM_ERROR("Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3701 | return ret; |
| 3702 | } |
| 3703 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3704 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3705 | return 0; |
| 3706 | } |
| 3707 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3708 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3709 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3710 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3711 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3712 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3713 | if (!intel_has_sagv(dev_priv)) |
| 3714 | return 0; |
| 3715 | |
| 3716 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3717 | return 0; |
| 3718 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3719 | DRM_DEBUG_KMS("Disabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3720 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3721 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3722 | GEN9_SAGV_DISABLE, |
| 3723 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3724 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3725 | /* |
| 3726 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3727 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3728 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3729 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3730 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3731 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3732 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3733 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3734 | DRM_ERROR("Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3735 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3736 | } |
| 3737 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3738 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3739 | return 0; |
| 3740 | } |
| 3741 | |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3742 | bool intel_can_enable_sagv(struct intel_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3743 | { |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3744 | struct drm_device *dev = state->base.dev; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3745 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3746 | struct intel_crtc *crtc; |
| 3747 | struct intel_plane *plane; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3748 | struct intel_crtc_state *crtc_state; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3749 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3750 | int level, latency; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3751 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3752 | if (!intel_has_sagv(dev_priv)) |
| 3753 | return false; |
| 3754 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3755 | /* |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3756 | * If there are no active CRTCs, no additional checks need be performed |
| 3757 | */ |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3758 | if (hweight8(state->active_pipes) == 0) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3759 | return true; |
Lucas De Marchi | da17223 | 2019-04-04 16:04:26 -0700 | [diff] [blame] | 3760 | |
| 3761 | /* |
| 3762 | * SKL+ workaround: bspec recommends we disable SAGV when we have |
| 3763 | * more then one pipe enabled |
| 3764 | */ |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3765 | if (hweight8(state->active_pipes) > 1) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3766 | return false; |
| 3767 | |
| 3768 | /* Since we're now guaranteed to only have one active CRTC... */ |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 3769 | pipe = ffs(state->active_pipes) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 3770 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3771 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3772 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 3773 | if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3774 | return false; |
| 3775 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3776 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3777 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3778 | &crtc_state->wm.skl.optimal.planes[plane->id]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3779 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3780 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3781 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3782 | continue; |
| 3783 | |
| 3784 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3785 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3786 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3787 | { } |
| 3788 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3789 | latency = dev_priv->wm.skl_latency[level]; |
| 3790 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3791 | if (skl_needs_memory_bw_wa(dev_priv) && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3792 | plane->base.state->fb->modifier == |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3793 | I915_FORMAT_MOD_X_TILED) |
| 3794 | latency += 15; |
| 3795 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3796 | /* |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3797 | * If any of the planes on this pipe don't enable wm levels that |
| 3798 | * incur memory latencies higher than sagv_block_time_us we |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3799 | * can't enable SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3800 | */ |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3801 | if (latency < dev_priv->sagv_block_time_us) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3802 | return false; |
| 3803 | } |
| 3804 | |
| 3805 | return true; |
| 3806 | } |
| 3807 | |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3808 | static u16 intel_get_ddb_size(struct drm_i915_private *dev_priv, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3809 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3810 | const u64 total_data_rate, |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3811 | const int num_active, |
| 3812 | struct skl_ddb_allocation *ddb) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3813 | { |
| 3814 | const struct drm_display_mode *adjusted_mode; |
| 3815 | u64 total_data_bw; |
| 3816 | u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3817 | |
| 3818 | WARN_ON(ddb_size == 0); |
| 3819 | |
| 3820 | if (INTEL_GEN(dev_priv) < 11) |
| 3821 | return ddb_size - 4; /* 4 blocks for bypass path allocation */ |
| 3822 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 3823 | adjusted_mode = &crtc_state->hw.adjusted_mode; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3824 | total_data_bw = total_data_rate * drm_mode_vrefresh(adjusted_mode); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3825 | |
| 3826 | /* |
| 3827 | * 12GB/s is maximum BW supported by single DBuf slice. |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3828 | * |
| 3829 | * FIXME dbuf slice code is broken: |
| 3830 | * - must wait for planes to stop using the slice before powering it off |
| 3831 | * - plane straddling both slices is illegal in multi-pipe scenarios |
| 3832 | * - should validate we stay within the hw bandwidth limits |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3833 | */ |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3834 | if (0 && (num_active > 1 || total_data_bw >= GBps(12))) { |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3835 | ddb->enabled_slices = 2; |
| 3836 | } else { |
| 3837 | ddb->enabled_slices = 1; |
| 3838 | ddb_size /= 2; |
| 3839 | } |
| 3840 | |
| 3841 | return ddb_size; |
| 3842 | } |
| 3843 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3844 | static void |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 3845 | skl_ddb_get_pipe_allocation_limits(struct drm_i915_private *dev_priv, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3846 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3847 | const u64 total_data_rate, |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3848 | struct skl_ddb_allocation *ddb, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3849 | struct skl_ddb_entry *alloc, /* out */ |
| 3850 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3851 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3852 | struct drm_atomic_state *state = crtc_state->base.state; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3853 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3854 | struct drm_crtc *for_crtc = crtc_state->base.crtc; |
| 3855 | const struct intel_crtc *crtc; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3856 | u32 pipe_width = 0, total_width = 0, width_before_pipe = 0; |
| 3857 | enum pipe for_pipe = to_intel_crtc(for_crtc)->pipe; |
| 3858 | u16 ddb_size; |
| 3859 | u32 i; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3860 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 3861 | if (WARN_ON(!state) || !crtc_state->hw.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3862 | alloc->start = 0; |
| 3863 | alloc->end = 0; |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3864 | *num_active = hweight8(dev_priv->active_pipes); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3865 | return; |
| 3866 | } |
| 3867 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3868 | if (intel_state->active_pipe_changes) |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3869 | *num_active = hweight8(intel_state->active_pipes); |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3870 | else |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3871 | *num_active = hweight8(dev_priv->active_pipes); |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3872 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3873 | ddb_size = intel_get_ddb_size(dev_priv, crtc_state, total_data_rate, |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3874 | *num_active, ddb); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3875 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3876 | /* |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3877 | * If the state doesn't change the active CRTC's or there is no |
| 3878 | * modeset request, then there's no need to recalculate; |
| 3879 | * the existing pipe allocation limits should remain unchanged. |
| 3880 | * Note that we're safe from racing commits since any racing commit |
| 3881 | * that changes the active CRTC list or do modeset would need to |
| 3882 | * grab _all_ crtc locks, including the one we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3883 | */ |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3884 | if (!intel_state->active_pipe_changes && !intel_state->modeset) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 3885 | /* |
| 3886 | * alloc may be cleared by clear_intel_crtc_state, |
| 3887 | * copy from old state to be sure |
| 3888 | */ |
| 3889 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3890 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3891 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3892 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3893 | /* |
| 3894 | * Watermark/ddb requirement highly depends upon width of the |
| 3895 | * framebuffer, So instead of allocating DDB equally among pipes |
| 3896 | * distribute DDB based on resolution/width of the display. |
| 3897 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3898 | for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) { |
| 3899 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 3900 | &crtc_state->hw.adjusted_mode; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3901 | enum pipe pipe = crtc->pipe; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3902 | int hdisplay, vdisplay; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3903 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 3904 | if (!crtc_state->hw.enable) |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3905 | continue; |
| 3906 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3907 | drm_mode_get_hv_timing(adjusted_mode, &hdisplay, &vdisplay); |
| 3908 | total_width += hdisplay; |
| 3909 | |
| 3910 | if (pipe < for_pipe) |
| 3911 | width_before_pipe += hdisplay; |
| 3912 | else if (pipe == for_pipe) |
| 3913 | pipe_width = hdisplay; |
| 3914 | } |
| 3915 | |
| 3916 | alloc->start = ddb_size * width_before_pipe / total_width; |
| 3917 | alloc->end = ddb_size * (width_before_pipe + pipe_width) / total_width; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3918 | } |
| 3919 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3920 | static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 3921 | int width, const struct drm_format_info *format, |
| 3922 | u64 modifier, unsigned int rotation, |
| 3923 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 3924 | int color_plane); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3925 | static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state, |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3926 | int level, |
| 3927 | const struct skl_wm_params *wp, |
| 3928 | const struct skl_wm_level *result_prev, |
| 3929 | struct skl_wm_level *result /* out */); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3930 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3931 | static unsigned int |
| 3932 | skl_cursor_allocation(const struct intel_crtc_state *crtc_state, |
| 3933 | int num_active) |
| 3934 | { |
| 3935 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 3936 | int level, max_level = ilk_wm_max_level(dev_priv); |
| 3937 | struct skl_wm_level wm = {}; |
| 3938 | int ret, min_ddb_alloc = 0; |
| 3939 | struct skl_wm_params wp; |
| 3940 | |
| 3941 | ret = skl_compute_wm_params(crtc_state, 256, |
| 3942 | drm_format_info(DRM_FORMAT_ARGB8888), |
| 3943 | DRM_FORMAT_MOD_LINEAR, |
| 3944 | DRM_MODE_ROTATE_0, |
| 3945 | crtc_state->pixel_rate, &wp, 0); |
| 3946 | WARN_ON(ret); |
| 3947 | |
| 3948 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | 6086e47 | 2019-03-21 19:51:28 +0200 | [diff] [blame] | 3949 | skl_compute_plane_wm(crtc_state, level, &wp, &wm, &wm); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3950 | if (wm.min_ddb_alloc == U16_MAX) |
| 3951 | break; |
| 3952 | |
| 3953 | min_ddb_alloc = wm.min_ddb_alloc; |
| 3954 | } |
| 3955 | |
| 3956 | return max(num_active == 1 ? 32 : 8, min_ddb_alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3957 | } |
| 3958 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3959 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 3960 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3961 | { |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3962 | |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 3963 | entry->start = reg & DDB_ENTRY_MASK; |
| 3964 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3965 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3966 | if (entry->end) |
| 3967 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3970 | static void |
| 3971 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 3972 | const enum pipe pipe, |
| 3973 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3974 | struct skl_ddb_entry *ddb_y, |
| 3975 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3976 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3977 | u32 val, val2; |
| 3978 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3979 | |
| 3980 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 3981 | if (plane_id == PLANE_CURSOR) { |
| 3982 | val = I915_READ(CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3983 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3984 | return; |
| 3985 | } |
| 3986 | |
| 3987 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
| 3988 | |
| 3989 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3990 | if (val & PLANE_CTL_ENABLE) |
| 3991 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 3992 | val & PLANE_CTL_ORDER_RGBX, |
| 3993 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3994 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3995 | if (INTEL_GEN(dev_priv) >= 11) { |
| 3996 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 3997 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 3998 | } else { |
| 3999 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
Paulo Zanoni | 12a6c93 | 2018-07-31 17:46:14 -0700 | [diff] [blame] | 4000 | val2 = I915_READ(PLANE_NV12_BUF_CFG(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4001 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4002 | if (fourcc && |
| 4003 | drm_format_info_is_yuv_semiplanar(drm_format_info(fourcc))) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4004 | swap(val, val2); |
| 4005 | |
| 4006 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4007 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4008 | } |
| 4009 | } |
| 4010 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4011 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 4012 | struct skl_ddb_entry *ddb_y, |
| 4013 | struct skl_ddb_entry *ddb_uv) |
| 4014 | { |
| 4015 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4016 | enum intel_display_power_domain power_domain; |
| 4017 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4018 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4019 | enum plane_id plane_id; |
| 4020 | |
| 4021 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4022 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 4023 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4024 | return; |
| 4025 | |
| 4026 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4027 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4028 | plane_id, |
| 4029 | &ddb_y[plane_id], |
| 4030 | &ddb_uv[plane_id]); |
| 4031 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4032 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4033 | } |
| 4034 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 4035 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 4036 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4037 | { |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 4038 | ddb->enabled_slices = intel_enabled_dbuf_slices_num(dev_priv); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4039 | } |
| 4040 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4041 | /* |
| 4042 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4043 | * The bspec defines downscale amount as: |
| 4044 | * |
| 4045 | * """ |
| 4046 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4047 | * Horizontal destination size] |
| 4048 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4049 | * Vertical destination size] |
| 4050 | * Total down scale amount = Horizontal down scale amount * |
| 4051 | * Vertical down scale amount |
| 4052 | * """ |
| 4053 | * |
| 4054 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4055 | * Caller should take care of dividing & rounding off the value. |
| 4056 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4057 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4058 | skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state, |
| 4059 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4060 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4061 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4062 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4063 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4064 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4065 | if (WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4066 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4067 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 4068 | /* |
| 4069 | * Src coordinates are already rotated by 270 degrees for |
| 4070 | * the 90/270 degree plane rotation cases (to match the |
| 4071 | * GTT mapping), hence no need to account for rotation here. |
| 4072 | * |
| 4073 | * n.b., src is 16.16 fixed point, dst is whole integer. |
| 4074 | */ |
| 4075 | src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 4076 | src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 4077 | dst_w = drm_rect_width(&plane_state->base.dst); |
| 4078 | dst_h = drm_rect_height(&plane_state->base.dst); |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4079 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4080 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4081 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4082 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4083 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4084 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4085 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4088 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4089 | skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state, |
| 4090 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4091 | int color_plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4092 | { |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4093 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 4094 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4095 | u32 data_rate; |
| 4096 | u32 width = 0, height = 0; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4097 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4098 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4099 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4100 | if (!plane_state->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4101 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4102 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4103 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4104 | return 0; |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4105 | |
| 4106 | if (color_plane == 1 && |
| 4107 | !drm_format_info_is_yuv_semiplanar(fb->format)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4108 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4109 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4110 | /* |
| 4111 | * Src coordinates are already rotated by 270 degrees for |
| 4112 | * the 90/270 degree plane rotation cases (to match the |
| 4113 | * GTT mapping), hence no need to account for rotation here. |
| 4114 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4115 | width = drm_rect_width(&plane_state->base.src) >> 16; |
| 4116 | height = drm_rect_height(&plane_state->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4117 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4118 | /* UV plane does 1/2 pixel sub-sampling */ |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4119 | if (color_plane == 1) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4120 | width /= 2; |
| 4121 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4122 | } |
| 4123 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4124 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4125 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4126 | down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4127 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4128 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4129 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4130 | rate *= fb->format->cpp[color_plane]; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4131 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4134 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4135 | skl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4136 | u64 *plane_data_rate, |
| 4137 | u64 *uv_plane_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4138 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4139 | struct drm_atomic_state *state = crtc_state->base.state; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4140 | struct intel_plane *plane; |
| 4141 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4142 | u64 total_data_rate = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4143 | |
| 4144 | if (WARN_ON(!state)) |
| 4145 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4146 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4147 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4148 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 4149 | enum plane_id plane_id = plane->id; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4150 | u64 rate; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4151 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4152 | /* packed/y */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4153 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4154 | plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4155 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4156 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4157 | /* uv-plane */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4158 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4159 | uv_plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4160 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | return total_data_rate; |
| 4164 | } |
| 4165 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4166 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4167 | icl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4168 | u64 *plane_data_rate) |
| 4169 | { |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4170 | struct intel_plane *plane; |
| 4171 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4172 | u64 total_data_rate = 0; |
| 4173 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4174 | if (WARN_ON(!crtc_state->base.state)) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4175 | return 0; |
| 4176 | |
| 4177 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4178 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 4179 | enum plane_id plane_id = plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4180 | u64 rate; |
| 4181 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4182 | if (!plane_state->planar_linked_plane) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4183 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4184 | plane_data_rate[plane_id] = rate; |
| 4185 | total_data_rate += rate; |
| 4186 | } else { |
| 4187 | enum plane_id y_plane_id; |
| 4188 | |
| 4189 | /* |
| 4190 | * The slave plane might not iterate in |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4191 | * intel_atomic_crtc_state_for_each_plane_state(), |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4192 | * and needs the master plane state which may be |
| 4193 | * NULL if we try get_new_plane_state(), so we |
| 4194 | * always calculate from the master. |
| 4195 | */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4196 | if (plane_state->planar_slave) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4197 | continue; |
| 4198 | |
| 4199 | /* Y plane rate is calculated on the slave */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4200 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4201 | y_plane_id = plane_state->planar_linked_plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4202 | plane_data_rate[y_plane_id] = rate; |
| 4203 | total_data_rate += rate; |
| 4204 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4205 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4206 | plane_data_rate[plane_id] = rate; |
| 4207 | total_data_rate += rate; |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | return total_data_rate; |
| 4212 | } |
| 4213 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4214 | static int |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4215 | skl_allocate_pipe_ddb(struct intel_crtc_state *crtc_state, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4216 | struct skl_ddb_allocation *ddb /* out */) |
| 4217 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4218 | struct drm_atomic_state *state = crtc_state->base.state; |
| 4219 | struct drm_crtc *crtc = crtc_state->base.crtc; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4220 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4221 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4222 | struct skl_ddb_entry *alloc = &crtc_state->wm.skl.ddb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4223 | u16 alloc_size, start = 0; |
| 4224 | u16 total[I915_MAX_PLANES] = {}; |
| 4225 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4226 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4227 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4228 | int num_active; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4229 | u64 plane_data_rate[I915_MAX_PLANES] = {}; |
| 4230 | u64 uv_plane_data_rate[I915_MAX_PLANES] = {}; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4231 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4232 | int level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4233 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4234 | /* Clear the partitioning for disabled planes. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4235 | memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y)); |
| 4236 | memset(crtc_state->wm.skl.plane_ddb_uv, 0, sizeof(crtc_state->wm.skl.plane_ddb_uv)); |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4237 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4238 | if (WARN_ON(!state)) |
| 4239 | return 0; |
| 4240 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 4241 | if (!crtc_state->hw.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4242 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4243 | return 0; |
| 4244 | } |
| 4245 | |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4246 | if (INTEL_GEN(dev_priv) >= 11) |
| 4247 | total_data_rate = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4248 | icl_get_total_relative_data_rate(crtc_state, |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4249 | plane_data_rate); |
| 4250 | else |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4251 | total_data_rate = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4252 | skl_get_total_relative_data_rate(crtc_state, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4253 | plane_data_rate, |
| 4254 | uv_plane_data_rate); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4255 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4256 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4257 | skl_ddb_get_pipe_allocation_limits(dev_priv, crtc_state, total_data_rate, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4258 | ddb, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4259 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 4260 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4261 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4262 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4263 | /* Allocate fixed number of blocks for cursor. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4264 | total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4265 | alloc_size -= total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4266 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4267 | alloc->end - total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4268 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4269 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4270 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4271 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4272 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4273 | /* |
| 4274 | * Find the highest watermark level for which we can satisfy the block |
| 4275 | * requirement of active planes. |
| 4276 | */ |
| 4277 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 4278 | blocks = 0; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4279 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4280 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4281 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 4282 | |
| 4283 | if (plane_id == PLANE_CURSOR) { |
| 4284 | if (WARN_ON(wm->wm[level].min_ddb_alloc > |
| 4285 | total[PLANE_CURSOR])) { |
| 4286 | blocks = U32_MAX; |
| 4287 | break; |
| 4288 | } |
| 4289 | continue; |
| 4290 | } |
| 4291 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4292 | blocks += wm->wm[level].min_ddb_alloc; |
| 4293 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4294 | } |
| 4295 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame] | 4296 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4297 | alloc_size -= blocks; |
| 4298 | break; |
| 4299 | } |
| 4300 | } |
| 4301 | |
| 4302 | if (level < 0) { |
| 4303 | DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); |
| 4304 | DRM_DEBUG_KMS("minimum required %d/%d\n", blocks, |
| 4305 | alloc_size); |
| 4306 | return -EINVAL; |
| 4307 | } |
| 4308 | |
| 4309 | /* |
| 4310 | * Grant each plane the blocks it requires at the highest achievable |
| 4311 | * watermark level, plus an extra share of the leftover blocks |
| 4312 | * proportional to its relative data rate. |
| 4313 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4314 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4315 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4316 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4317 | u64 rate; |
| 4318 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4319 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4320 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4321 | continue; |
| 4322 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4323 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4324 | * We've accounted for all active planes; remaining planes are |
| 4325 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4326 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4327 | if (total_data_rate == 0) |
| 4328 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4329 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4330 | rate = plane_data_rate[plane_id]; |
| 4331 | extra = min_t(u16, alloc_size, |
| 4332 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4333 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4334 | total[plane_id] = wm->wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4335 | alloc_size -= extra; |
| 4336 | total_data_rate -= rate; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4337 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4338 | if (total_data_rate == 0) |
| 4339 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4340 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4341 | rate = uv_plane_data_rate[plane_id]; |
| 4342 | extra = min_t(u16, alloc_size, |
| 4343 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4344 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4345 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4346 | alloc_size -= extra; |
| 4347 | total_data_rate -= rate; |
| 4348 | } |
| 4349 | WARN_ON(alloc_size != 0 || total_data_rate != 0); |
| 4350 | |
| 4351 | /* Set the actual DDB start/end points for each plane */ |
| 4352 | start = alloc->start; |
| 4353 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4354 | struct skl_ddb_entry *plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4355 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4356 | struct skl_ddb_entry *uv_plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4357 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4358 | |
| 4359 | if (plane_id == PLANE_CURSOR) |
| 4360 | continue; |
| 4361 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4362 | /* Gen11+ uses a separate plane for UV watermarks */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4363 | WARN_ON(INTEL_GEN(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4364 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4365 | /* Leave disabled planes at (0,0) */ |
| 4366 | if (total[plane_id]) { |
| 4367 | plane_alloc->start = start; |
| 4368 | start += total[plane_id]; |
| 4369 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4370 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4371 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4372 | if (uv_total[plane_id]) { |
| 4373 | uv_plane_alloc->start = start; |
| 4374 | start += uv_total[plane_id]; |
| 4375 | uv_plane_alloc->end = start; |
| 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | /* |
| 4380 | * When we calculated watermark values we didn't know how high |
| 4381 | * of a level we'd actually be able to hit, so we just marked |
| 4382 | * all levels as "enabled." Go back now and disable the ones |
| 4383 | * that aren't actually possible. |
| 4384 | */ |
| 4385 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
| 4386 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4387 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4388 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | a301cb0 | 2019-03-12 22:58:41 +0200 | [diff] [blame] | 4389 | |
| 4390 | /* |
| 4391 | * We only disable the watermarks for each plane if |
| 4392 | * they exceed the ddb allocation of said plane. This |
| 4393 | * is done so that we don't end up touching cursor |
| 4394 | * watermarks needlessly when some other plane reduces |
| 4395 | * our max possible watermark level. |
| 4396 | * |
| 4397 | * Bspec has this to say about the PLANE_WM enable bit: |
| 4398 | * "All the watermarks at this level for all enabled |
| 4399 | * planes must be enabled before the level will be used." |
| 4400 | * So this is actually safe to do. |
| 4401 | */ |
| 4402 | if (wm->wm[level].min_ddb_alloc > total[plane_id] || |
| 4403 | wm->uv_wm[level].min_ddb_alloc > uv_total[plane_id]) |
| 4404 | memset(&wm->wm[level], 0, sizeof(wm->wm[level])); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4405 | |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4406 | /* |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 4407 | * Wa_1408961008:icl, ehl |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4408 | * Underruns with WM1+ disabled |
| 4409 | */ |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 4410 | if (IS_GEN(dev_priv, 11) && |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4411 | level == 1 && wm->wm[0].plane_en) { |
| 4412 | wm->wm[level].plane_res_b = wm->wm[0].plane_res_b; |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4413 | wm->wm[level].plane_res_l = wm->wm[0].plane_res_l; |
| 4414 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4415 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | /* |
| 4420 | * Go back and disable the transition watermark if it turns out we |
| 4421 | * don't have enough DDB blocks for it. |
| 4422 | */ |
| 4423 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4424 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4425 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4426 | |
Ville Syrjälä | b19c9bc | 2018-12-21 19:14:31 +0200 | [diff] [blame] | 4427 | if (wm->trans_wm.plane_res_b >= total[plane_id]) |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4428 | memset(&wm->trans_wm, 0, sizeof(wm->trans_wm)); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4431 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4432 | } |
| 4433 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4434 | /* |
| 4435 | * 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] | 4436 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4437 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 4438 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 4439 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4440 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4441 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 4442 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4443 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4444 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4445 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4446 | |
| 4447 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4448 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4449 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4450 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4451 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4452 | |
| 4453 | if (INTEL_GEN(dev_priv) >= 10) |
| 4454 | ret = add_fixed16_u32(ret, 1); |
| 4455 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4456 | return ret; |
| 4457 | } |
| 4458 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4459 | static uint_fixed_16_16_t |
| 4460 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 4461 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4462 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4463 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4464 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4465 | |
| 4466 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4467 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4468 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4469 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4470 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 4471 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4472 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4473 | return ret; |
| 4474 | } |
| 4475 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4476 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4477 | intel_get_linetime_us(const struct intel_crtc_state *crtc_state) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4478 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4479 | u32 pixel_rate; |
| 4480 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4481 | uint_fixed_16_16_t linetime_us; |
| 4482 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 4483 | if (!crtc_state->hw.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4484 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4485 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4486 | pixel_rate = crtc_state->pixel_rate; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4487 | |
| 4488 | if (WARN_ON(pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4489 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4490 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 4491 | crtc_htotal = crtc_state->hw.adjusted_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4492 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4493 | |
| 4494 | return linetime_us; |
| 4495 | } |
| 4496 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4497 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4498 | skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *crtc_state, |
| 4499 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4500 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4501 | u64 adjusted_pixel_rate; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4502 | uint_fixed_16_16_t downscale_amount; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4503 | |
| 4504 | /* Shouldn't reach here on disabled planes... */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4505 | if (WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4506 | return 0; |
| 4507 | |
| 4508 | /* |
| 4509 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 4510 | * with additional adjustments for plane-specific scaling. |
| 4511 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4512 | adjusted_pixel_rate = crtc_state->pixel_rate; |
| 4513 | downscale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4514 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4515 | return mul_round_up_u32_fixed16(adjusted_pixel_rate, |
| 4516 | downscale_amount); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4519 | static int |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4520 | skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 4521 | int width, const struct drm_format_info *format, |
| 4522 | u64 modifier, unsigned int rotation, |
| 4523 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 4524 | int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4525 | { |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4526 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4527 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4528 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4529 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4530 | /* only planar format has two planes */ |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4531 | if (color_plane == 1 && !drm_format_info_is_yuv_semiplanar(format)) { |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4532 | DRM_DEBUG_KMS("Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4533 | return -EINVAL; |
| 4534 | } |
| 4535 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4536 | wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED || |
| 4537 | modifier == I915_FORMAT_MOD_Yf_TILED || |
| 4538 | modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4539 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4540 | wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED; |
| 4541 | wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4542 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4543 | wp->is_planar = drm_format_info_is_yuv_semiplanar(format); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4544 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4545 | wp->width = width; |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 4546 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4547 | wp->width /= 2; |
| 4548 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4549 | wp->cpp = format->cpp[color_plane]; |
| 4550 | wp->plane_pixel_rate = plane_pixel_rate; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4551 | |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4552 | if (INTEL_GEN(dev_priv) >= 11 && |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4553 | modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4554 | wp->dbuf_block_size = 256; |
| 4555 | else |
| 4556 | wp->dbuf_block_size = 512; |
| 4557 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4558 | if (drm_rotation_90_or_270(rotation)) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4559 | switch (wp->cpp) { |
| 4560 | case 1: |
| 4561 | wp->y_min_scanlines = 16; |
| 4562 | break; |
| 4563 | case 2: |
| 4564 | wp->y_min_scanlines = 8; |
| 4565 | break; |
| 4566 | case 4: |
| 4567 | wp->y_min_scanlines = 4; |
| 4568 | break; |
| 4569 | default: |
| 4570 | MISSING_CASE(wp->cpp); |
| 4571 | return -EINVAL; |
| 4572 | } |
| 4573 | } else { |
| 4574 | wp->y_min_scanlines = 4; |
| 4575 | } |
| 4576 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4577 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4578 | wp->y_min_scanlines *= 2; |
| 4579 | |
| 4580 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 4581 | if (wp->y_tiled) { |
| 4582 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4583 | wp->y_min_scanlines, |
| 4584 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4585 | |
| 4586 | if (INTEL_GEN(dev_priv) >= 10) |
| 4587 | interm_pbpl++; |
| 4588 | |
| 4589 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 4590 | wp->y_min_scanlines); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4591 | } else if (wp->x_tiled && IS_GEN(dev_priv, 9)) { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4592 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4593 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4594 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4595 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4596 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4597 | wp->dbuf_block_size) + 1; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4598 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4599 | } |
| 4600 | |
| 4601 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 4602 | wp->plane_blocks_per_line); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4603 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4604 | wp->linetime_us = fixed16_to_u32_round_up( |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4605 | intel_get_linetime_us(crtc_state)); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4606 | |
| 4607 | return 0; |
| 4608 | } |
| 4609 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4610 | static int |
| 4611 | skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state, |
| 4612 | const struct intel_plane_state *plane_state, |
| 4613 | struct skl_wm_params *wp, int color_plane) |
| 4614 | { |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4615 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 4616 | int width; |
| 4617 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 4618 | /* |
| 4619 | * Src coordinates are already rotated by 270 degrees for |
| 4620 | * the 90/270 degree plane rotation cases (to match the |
| 4621 | * GTT mapping), hence no need to account for rotation here. |
| 4622 | */ |
| 4623 | width = drm_rect_width(&plane_state->base.src) >> 16; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4624 | |
| 4625 | return skl_compute_wm_params(crtc_state, width, |
| 4626 | fb->format, fb->modifier, |
| 4627 | plane_state->base.rotation, |
| 4628 | skl_adjusted_plane_pixel_rate(crtc_state, plane_state), |
| 4629 | wp, color_plane); |
| 4630 | } |
| 4631 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4632 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 4633 | { |
| 4634 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 4635 | return true; |
| 4636 | |
| 4637 | /* The number of lines are ignored for the level 0 watermark. */ |
| 4638 | return level > 0; |
| 4639 | } |
| 4640 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4641 | static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4642 | int level, |
| 4643 | const struct skl_wm_params *wp, |
| 4644 | const struct skl_wm_level *result_prev, |
| 4645 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4646 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4647 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4648 | u32 latency = dev_priv->wm.skl_latency[level]; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4649 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4650 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4651 | u32 res_blocks, res_lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 4652 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4653 | if (latency == 0) { |
| 4654 | /* reject it */ |
| 4655 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4656 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4657 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4658 | |
Ville Syrjälä | 25312ef | 2019-05-03 20:38:05 +0300 | [diff] [blame] | 4659 | /* |
| 4660 | * WaIncreaseLatencyIPCEnabled: kbl,cfl |
| 4661 | * Display WA #1141: kbl,cfl |
| 4662 | */ |
Ville Syrjälä | 5a7d202 | 2019-05-03 20:38:06 +0300 | [diff] [blame] | 4663 | if ((IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) || |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4664 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 4665 | latency += 4; |
| 4666 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4667 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4668 | latency += 15; |
| 4669 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4670 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4671 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4672 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 4673 | crtc_state->hw.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4674 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4675 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4676 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4677 | if (wp->y_tiled) { |
| 4678 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4679 | } else { |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame^] | 4680 | if ((wp->cpp * crtc_state->hw.adjusted_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4681 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4682 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 4683 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4684 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4685 | if (IS_GEN(dev_priv, 9) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4686 | !IS_GEMINILAKE(dev_priv)) |
| 4687 | selected_result = min_fixed16(method1, method2); |
| 4688 | else |
| 4689 | selected_result = method2; |
| 4690 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4691 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4692 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4693 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4694 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4695 | res_blocks = fixed16_to_u32_round_up(selected_result) + 1; |
Kumar, Mahesh | d273ecc | 2017-05-17 17:28:22 +0530 | [diff] [blame] | 4696 | res_lines = div_round_up_fixed16(selected_result, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4697 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4698 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4699 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) { |
| 4700 | /* Display WA #1125: skl,bxt,kbl */ |
| 4701 | if (level == 0 && wp->rc_surface) |
| 4702 | res_blocks += |
| 4703 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 4704 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4705 | /* Display WA #1126: skl,bxt,kbl */ |
| 4706 | if (level >= 1 && level <= 7) { |
| 4707 | if (wp->y_tiled) { |
| 4708 | res_blocks += |
| 4709 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 4710 | res_lines += wp->y_min_scanlines; |
| 4711 | } else { |
| 4712 | res_blocks++; |
| 4713 | } |
| 4714 | |
| 4715 | /* |
| 4716 | * Make sure result blocks for higher latency levels are |
| 4717 | * atleast as high as level below the current level. |
| 4718 | * Assumption in DDB algorithm optimization for special |
| 4719 | * cases. Also covers Display WA #1125 for RC. |
| 4720 | */ |
| 4721 | if (result_prev->plane_res_b > res_blocks) |
| 4722 | res_blocks = result_prev->plane_res_b; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4723 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4724 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4725 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4726 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4727 | if (wp->y_tiled) { |
| 4728 | int extra_lines; |
| 4729 | |
| 4730 | if (res_lines % wp->y_min_scanlines == 0) |
| 4731 | extra_lines = wp->y_min_scanlines; |
| 4732 | else |
| 4733 | extra_lines = wp->y_min_scanlines * 2 - |
| 4734 | res_lines % wp->y_min_scanlines; |
| 4735 | |
| 4736 | min_ddb_alloc = mul_round_up_u32_fixed16(res_lines + extra_lines, |
| 4737 | wp->plane_blocks_per_line); |
| 4738 | } else { |
| 4739 | min_ddb_alloc = res_blocks + |
| 4740 | DIV_ROUND_UP(res_blocks, 10); |
| 4741 | } |
| 4742 | } |
| 4743 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4744 | if (!skl_wm_has_lines(dev_priv, level)) |
| 4745 | res_lines = 0; |
| 4746 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4747 | if (res_lines > 31) { |
| 4748 | /* reject it */ |
| 4749 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4750 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4751 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4752 | |
| 4753 | /* |
| 4754 | * If res_lines is valid, assume we can use this watermark level |
| 4755 | * for now. We'll come back and disable it after we calculate the |
| 4756 | * DDB allocation if it turns out we don't actually have enough |
| 4757 | * blocks to satisfy it. |
| 4758 | */ |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4759 | result->plane_res_b = res_blocks; |
| 4760 | result->plane_res_l = res_lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4761 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
| 4762 | result->min_ddb_alloc = max(min_ddb_alloc, res_blocks) + 1; |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4763 | result->plane_en = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4764 | } |
| 4765 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4766 | static void |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4767 | skl_compute_wm_levels(const struct intel_crtc_state *crtc_state, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4768 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4769 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4770 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4771 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4772 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4773 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4774 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4775 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4776 | struct skl_wm_level *result = &levels[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4777 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4778 | skl_compute_plane_wm(crtc_state, level, wm_params, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4779 | result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4780 | |
| 4781 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4782 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4785 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4786 | skl_compute_linetime_wm(const struct intel_crtc_state *crtc_state) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4787 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4788 | struct drm_atomic_state *state = crtc_state->base.state; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4789 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4790 | uint_fixed_16_16_t linetime_us; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4791 | u32 linetime_wm; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4792 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4793 | linetime_us = intel_get_linetime_us(crtc_state); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4794 | linetime_wm = fixed16_to_u32_round_up(mul_u32_fixed16(8, linetime_us)); |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4795 | |
Ville Syrjälä | 717671c | 2018-12-21 19:14:36 +0200 | [diff] [blame] | 4796 | /* Display WA #1135: BXT:ALL GLK:ALL */ |
| 4797 | if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled) |
Kumar, Mahesh | 446e850 | 2017-08-17 19:15:25 +0530 | [diff] [blame] | 4798 | linetime_wm /= 2; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4799 | |
| 4800 | return linetime_wm; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4801 | } |
| 4802 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4803 | static void skl_compute_transition_wm(const struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 4804 | const struct skl_wm_params *wp, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4805 | struct skl_plane_wm *wm) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4806 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4807 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4808 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4809 | u16 trans_min, trans_y_tile_min; |
| 4810 | const u16 trans_amount = 10; /* This is configurable amount */ |
| 4811 | u16 wm0_sel_res_b, trans_offset_b, res_blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4812 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4813 | /* Transition WM are not recommended by HW team for GEN9 */ |
| 4814 | if (INTEL_GEN(dev_priv) <= 9) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4815 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4816 | |
| 4817 | /* Transition WM don't make any sense if ipc is disabled */ |
| 4818 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4819 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4820 | |
Paulo Zanoni | 91961a8 | 2018-10-04 16:15:56 -0700 | [diff] [blame] | 4821 | trans_min = 14; |
| 4822 | if (INTEL_GEN(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4823 | trans_min = 4; |
| 4824 | |
| 4825 | trans_offset_b = trans_min + trans_amount; |
| 4826 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4827 | /* |
| 4828 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 4829 | * not Result Blocks (the integer value). Pay attention to the capital |
| 4830 | * letters. The value wm_l0->plane_res_b is actually Result Blocks, but |
| 4831 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 4832 | * and since we later will have to get the ceiling of the sum in the |
| 4833 | * transition watermarks calculation, we can just pretend Selected |
| 4834 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 4835 | * current platforms. |
| 4836 | */ |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 4837 | wm0_sel_res_b = wm->wm[0].plane_res_b - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4838 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4839 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4840 | trans_y_tile_min = |
| 4841 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4842 | res_blocks = max(wm0_sel_res_b, trans_y_tile_min) + |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4843 | trans_offset_b; |
| 4844 | } else { |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4845 | res_blocks = wm0_sel_res_b + trans_offset_b; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4846 | |
| 4847 | /* WA BUG:1938466 add one block for non y-tile planes */ |
| 4848 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_A0)) |
| 4849 | res_blocks += 1; |
| 4850 | |
| 4851 | } |
| 4852 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4853 | /* |
| 4854 | * Just assume we can enable the transition watermark. After |
| 4855 | * computing the DDB we'll come back and disable it if that |
| 4856 | * assumption turns out to be false. |
| 4857 | */ |
| 4858 | wm->trans_wm.plane_res_b = res_blocks + 1; |
| 4859 | wm->trans_wm.plane_en = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4860 | } |
| 4861 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4862 | static int skl_build_plane_wm_single(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4863 | const struct intel_plane_state *plane_state, |
| 4864 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4865 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4866 | struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id]; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4867 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4868 | int ret; |
| 4869 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4870 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4871 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4872 | if (ret) |
| 4873 | return ret; |
| 4874 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4875 | skl_compute_wm_levels(crtc_state, &wm_params, wm->wm); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4876 | skl_compute_transition_wm(crtc_state, &wm_params, wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4877 | |
| 4878 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4879 | } |
| 4880 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4881 | static int skl_build_plane_wm_uv(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4882 | const struct intel_plane_state *plane_state, |
| 4883 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4884 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4885 | struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 4886 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4887 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4888 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4889 | wm->is_planar = true; |
| 4890 | |
| 4891 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4892 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4893 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4894 | if (ret) |
| 4895 | return ret; |
| 4896 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4897 | skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4898 | |
| 4899 | return 0; |
| 4900 | } |
| 4901 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 4902 | static int skl_build_plane_wm(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4903 | const struct intel_plane_state *plane_state) |
| 4904 | { |
| 4905 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 4906 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 4907 | enum plane_id plane_id = plane->id; |
| 4908 | int ret; |
| 4909 | |
| 4910 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 4911 | return 0; |
| 4912 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4913 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4914 | plane_id, 0); |
| 4915 | if (ret) |
| 4916 | return ret; |
| 4917 | |
| 4918 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4919 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4920 | plane_id); |
| 4921 | if (ret) |
| 4922 | return ret; |
| 4923 | } |
| 4924 | |
| 4925 | return 0; |
| 4926 | } |
| 4927 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 4928 | static int icl_build_plane_wm(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4929 | const struct intel_plane_state *plane_state) |
| 4930 | { |
| 4931 | enum plane_id plane_id = to_intel_plane(plane_state->base.plane)->id; |
| 4932 | int ret; |
| 4933 | |
| 4934 | /* Watermarks calculated in master */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4935 | if (plane_state->planar_slave) |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4936 | return 0; |
| 4937 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4938 | if (plane_state->planar_linked_plane) { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4939 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4940 | enum plane_id y_plane_id = plane_state->planar_linked_plane->id; |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4941 | |
| 4942 | WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state)); |
| 4943 | WARN_ON(!fb->format->is_yuv || |
| 4944 | fb->format->num_planes == 1); |
| 4945 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4946 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4947 | y_plane_id, 0); |
| 4948 | if (ret) |
| 4949 | return ret; |
| 4950 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4951 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4952 | plane_id, 1); |
| 4953 | if (ret) |
| 4954 | return ret; |
| 4955 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4956 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4957 | plane_id, 0); |
| 4958 | if (ret) |
| 4959 | return ret; |
| 4960 | } |
| 4961 | |
| 4962 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4963 | } |
| 4964 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4965 | static int skl_build_pipe_wm(struct intel_crtc_state *crtc_state) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4966 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4967 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 4968 | struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4969 | struct intel_plane *plane; |
| 4970 | const struct intel_plane_state *plane_state; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4971 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4972 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4973 | /* |
| 4974 | * We'll only calculate watermarks for planes that are actually |
| 4975 | * enabled, so make sure all other planes are set as disabled. |
| 4976 | */ |
| 4977 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 4978 | |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4979 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, |
| 4980 | crtc_state) { |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4981 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4982 | if (INTEL_GEN(dev_priv) >= 11) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4983 | ret = icl_build_plane_wm(crtc_state, plane_state); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4984 | else |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4985 | ret = skl_build_plane_wm(crtc_state, plane_state); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4986 | if (ret) |
| 4987 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4988 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4989 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4990 | pipe_wm->linetime = skl_compute_linetime_wm(crtc_state); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4991 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4992 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4993 | } |
| 4994 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4995 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 4996 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 4997 | const struct skl_ddb_entry *entry) |
| 4998 | { |
| 4999 | if (entry->end) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5000 | I915_WRITE_FW(reg, (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5001 | else |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5002 | I915_WRITE_FW(reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5005 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5006 | i915_reg_t reg, |
| 5007 | const struct skl_wm_level *level) |
| 5008 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5009 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5010 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5011 | if (level->plane_en) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5012 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5013 | if (level->ignore_lines) |
| 5014 | val |= PLANE_WM_IGNORE_LINES; |
| 5015 | val |= level->plane_res_b; |
| 5016 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5017 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5018 | I915_WRITE_FW(reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5019 | } |
| 5020 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5021 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5022 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5023 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5024 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5025 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5026 | enum plane_id plane_id = plane->id; |
| 5027 | enum pipe pipe = plane->pipe; |
| 5028 | const struct skl_plane_wm *wm = |
| 5029 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5030 | const struct skl_ddb_entry *ddb_y = |
| 5031 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5032 | const struct skl_ddb_entry *ddb_uv = |
| 5033 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5034 | |
| 5035 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5036 | 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] | 5037 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5038 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5039 | 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] | 5040 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5041 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5042 | if (INTEL_GEN(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5043 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5044 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5045 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5046 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5047 | |
| 5048 | if (wm->is_planar) |
| 5049 | swap(ddb_y, ddb_uv); |
| 5050 | |
| 5051 | skl_ddb_entry_write(dev_priv, |
| 5052 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5053 | skl_ddb_entry_write(dev_priv, |
| 5054 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5055 | } |
| 5056 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5057 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5058 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5059 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5060 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5061 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5062 | enum plane_id plane_id = plane->id; |
| 5063 | enum pipe pipe = plane->pipe; |
| 5064 | const struct skl_plane_wm *wm = |
| 5065 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5066 | const struct skl_ddb_entry *ddb = |
| 5067 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5068 | |
| 5069 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5070 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 5071 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5072 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5073 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5074 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5075 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5076 | } |
| 5077 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5078 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5079 | const struct skl_wm_level *l2) |
| 5080 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5081 | return l1->plane_en == l2->plane_en && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5082 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5083 | l1->plane_res_l == l2->plane_res_l && |
| 5084 | l1->plane_res_b == l2->plane_res_b; |
| 5085 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5086 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5087 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5088 | const struct skl_plane_wm *wm1, |
| 5089 | const struct skl_plane_wm *wm2) |
| 5090 | { |
| 5091 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5092 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5093 | for (level = 0; level <= max_level; level++) { |
| 5094 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level]) || |
| 5095 | !skl_wm_level_equals(&wm1->uv_wm[level], &wm2->uv_wm[level])) |
| 5096 | return false; |
| 5097 | } |
| 5098 | |
| 5099 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5100 | } |
| 5101 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5102 | static bool skl_pipe_wm_equals(struct intel_crtc *crtc, |
| 5103 | const struct skl_pipe_wm *wm1, |
| 5104 | const struct skl_pipe_wm *wm2) |
| 5105 | { |
| 5106 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5107 | enum plane_id plane_id; |
| 5108 | |
| 5109 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5110 | if (!skl_plane_wm_equals(dev_priv, |
| 5111 | &wm1->planes[plane_id], |
| 5112 | &wm2->planes[plane_id])) |
| 5113 | return false; |
| 5114 | } |
| 5115 | |
| 5116 | return wm1->linetime == wm2->linetime; |
| 5117 | } |
| 5118 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5119 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 5120 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5121 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5122 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5123 | } |
| 5124 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5125 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 5126 | const struct skl_ddb_entry *entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5127 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5128 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5129 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5130 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5131 | for (i = 0; i < num_entries; i++) { |
| 5132 | if (i != ignore_idx && |
| 5133 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5134 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 5135 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5136 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5137 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5138 | } |
| 5139 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 5140 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5141 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 5142 | struct intel_crtc_state *new_crtc_state) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5143 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5144 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->base.state); |
| 5145 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5146 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5147 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5148 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5149 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5150 | struct intel_plane_state *plane_state; |
| 5151 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5152 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5153 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 5154 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 5155 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 5156 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5157 | continue; |
| 5158 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5159 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5160 | if (IS_ERR(plane_state)) |
| 5161 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 5162 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5163 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | return 0; |
| 5167 | } |
| 5168 | |
| 5169 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5170 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5171 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5172 | const struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5173 | struct skl_ddb_allocation *ddb = &state->wm_results.ddb; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5174 | struct intel_crtc_state *old_crtc_state; |
| 5175 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5176 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5177 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5178 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 5179 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 5180 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5181 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5182 | new_crtc_state, i) { |
| 5183 | ret = skl_allocate_pipe_ddb(new_crtc_state, ddb); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5184 | if (ret) |
| 5185 | return ret; |
| 5186 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5187 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 5188 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5189 | if (ret) |
| 5190 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
| 5193 | return 0; |
| 5194 | } |
| 5195 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5196 | static char enast(bool enable) |
| 5197 | { |
| 5198 | return enable ? '*' : ' '; |
| 5199 | } |
| 5200 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 5201 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5202 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5203 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5204 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5205 | const struct intel_crtc_state *old_crtc_state; |
| 5206 | const struct intel_crtc_state *new_crtc_state; |
| 5207 | struct intel_plane *plane; |
| 5208 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5209 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5210 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5211 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 5212 | return; |
| 5213 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5214 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 5215 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5216 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 5217 | |
| 5218 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 5219 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 5220 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5221 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5222 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5223 | const struct skl_ddb_entry *old, *new; |
| 5224 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5225 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5226 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5227 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5228 | if (skl_ddb_entry_equal(old, new)) |
| 5229 | continue; |
| 5230 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5231 | DRM_DEBUG_KMS("[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n", |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5232 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5233 | old->start, old->end, new->start, new->end, |
| 5234 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
| 5235 | } |
| 5236 | |
| 5237 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5238 | enum plane_id plane_id = plane->id; |
| 5239 | const struct skl_plane_wm *old_wm, *new_wm; |
| 5240 | |
| 5241 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 5242 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 5243 | |
| 5244 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 5245 | continue; |
| 5246 | |
| 5247 | DRM_DEBUG_KMS("[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm" |
| 5248 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm\n", |
| 5249 | plane->base.base.id, plane->base.name, |
| 5250 | enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en), |
| 5251 | enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en), |
| 5252 | enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en), |
| 5253 | enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en), |
| 5254 | enast(old_wm->trans_wm.plane_en), |
| 5255 | enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en), |
| 5256 | enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en), |
| 5257 | enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en), |
| 5258 | enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en), |
| 5259 | enast(new_wm->trans_wm.plane_en)); |
| 5260 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5261 | DRM_DEBUG_KMS("[PLANE:%d:%s] lines %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d" |
| 5262 | " -> %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d\n", |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5263 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5264 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l, |
| 5265 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l, |
| 5266 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l, |
| 5267 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l, |
| 5268 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l, |
| 5269 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l, |
| 5270 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l, |
| 5271 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l, |
| 5272 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l, |
| 5273 | |
| 5274 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l, |
| 5275 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l, |
| 5276 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l, |
| 5277 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l, |
| 5278 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l, |
| 5279 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l, |
| 5280 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l, |
| 5281 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l, |
| 5282 | enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.plane_res_l); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5283 | |
| 5284 | DRM_DEBUG_KMS("[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5285 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5286 | plane->base.base.id, plane->base.name, |
| 5287 | old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b, |
| 5288 | old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b, |
| 5289 | old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b, |
| 5290 | old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b, |
| 5291 | old_wm->trans_wm.plane_res_b, |
| 5292 | new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b, |
| 5293 | new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b, |
| 5294 | new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b, |
| 5295 | new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b, |
| 5296 | new_wm->trans_wm.plane_res_b); |
| 5297 | |
| 5298 | DRM_DEBUG_KMS("[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5299 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5300 | plane->base.base.id, plane->base.name, |
| 5301 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 5302 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 5303 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 5304 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 5305 | old_wm->trans_wm.min_ddb_alloc, |
| 5306 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 5307 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 5308 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 5309 | new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc, |
| 5310 | new_wm->trans_wm.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5311 | } |
| 5312 | } |
| 5313 | } |
| 5314 | |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5315 | static int intel_add_all_pipes(struct intel_atomic_state *state) |
| 5316 | { |
| 5317 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5318 | struct intel_crtc *crtc; |
| 5319 | |
| 5320 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5321 | struct intel_crtc_state *crtc_state; |
| 5322 | |
| 5323 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 5324 | if (IS_ERR(crtc_state)) |
| 5325 | return PTR_ERR(crtc_state); |
| 5326 | } |
| 5327 | |
| 5328 | return 0; |
| 5329 | } |
| 5330 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5331 | static int |
Ville Syrjälä | d7a1458 | 2019-10-11 23:09:42 +0300 | [diff] [blame] | 5332 | skl_ddb_add_affected_pipes(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5333 | { |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5334 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Ville Syrjälä | d7a1458 | 2019-10-11 23:09:42 +0300 | [diff] [blame] | 5335 | int ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5336 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5337 | /* |
| 5338 | * If this is our first atomic update following hardware readout, |
| 5339 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 5340 | * pretend that all pipes switched active status so that we'll |
| 5341 | * ensure a full DDB recompute. |
| 5342 | */ |
| 5343 | if (dev_priv->wm.distrust_bios_wm) { |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5344 | ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5345 | state->base.acquire_ctx); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5346 | if (ret) |
| 5347 | return ret; |
| 5348 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5349 | state->active_pipe_changes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5350 | |
| 5351 | /* |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 5352 | * We usually only initialize state->active_pipes if we |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5353 | * we're doing a modeset; make sure this field is always |
| 5354 | * initialized during the sanitization process that happens |
| 5355 | * on the first commit too. |
| 5356 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5357 | if (!state->modeset) |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 5358 | state->active_pipes = dev_priv->active_pipes; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | /* |
| 5362 | * If the modeset changes which CRTC's are active, we need to |
| 5363 | * recompute the DDB allocation for *all* active pipes, even |
| 5364 | * those that weren't otherwise being modified in any way by this |
| 5365 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 5366 | * when new active CRTC's are added, it's possible for a pipe that |
| 5367 | * we were already using and aren't changing at all here to suddenly |
| 5368 | * become invalid if its DDB needs exceeds its new allocation. |
| 5369 | * |
| 5370 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 5371 | * any other display updates race with this transaction, so we need |
| 5372 | * to grab the lock on *all* CRTC's. |
| 5373 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5374 | if (state->active_pipe_changes || state->modeset) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5375 | state->wm_results.dirty_pipes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5376 | |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5377 | ret = intel_add_all_pipes(state); |
| 5378 | if (ret) |
| 5379 | return ret; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | return 0; |
| 5383 | } |
| 5384 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5385 | /* |
| 5386 | * To make sure the cursor watermark registers are always consistent |
| 5387 | * with our computed state the following scenario needs special |
| 5388 | * treatment: |
| 5389 | * |
| 5390 | * 1. enable cursor |
| 5391 | * 2. move cursor entirely offscreen |
| 5392 | * 3. disable cursor |
| 5393 | * |
| 5394 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 5395 | * (since we consider an offscreen cursor still active for the purposes |
| 5396 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 5397 | * because the actual plane visibility isn't changing, and we don't |
| 5398 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 5399 | * force step 3. to call .disable_plane() to update the watermark |
| 5400 | * registers properly. |
| 5401 | * |
| 5402 | * Other planes do not suffer from this issues as their watermarks are |
| 5403 | * calculated based on the actual plane visibility. The only time this |
| 5404 | * can trigger for the other planes is during the initial readout as the |
| 5405 | * default value of the watermarks registers is not zero. |
| 5406 | */ |
| 5407 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 5408 | struct intel_crtc *crtc) |
| 5409 | { |
| 5410 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5411 | const struct intel_crtc_state *old_crtc_state = |
| 5412 | intel_atomic_get_old_crtc_state(state, crtc); |
| 5413 | struct intel_crtc_state *new_crtc_state = |
| 5414 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5415 | struct intel_plane *plane; |
| 5416 | |
| 5417 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5418 | struct intel_plane_state *plane_state; |
| 5419 | enum plane_id plane_id = plane->id; |
| 5420 | |
| 5421 | /* |
| 5422 | * Force a full wm update for every plane on modeset. |
| 5423 | * Required because the reset value of the wm registers |
| 5424 | * is non-zero, whereas we want all disabled planes to |
| 5425 | * have zero watermarks. So if we turn off the relevant |
| 5426 | * power well the hardware state will go out of sync |
| 5427 | * with the software state. |
| 5428 | */ |
| 5429 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->base) && |
| 5430 | skl_plane_wm_equals(dev_priv, |
| 5431 | &old_crtc_state->wm.skl.optimal.planes[plane_id], |
| 5432 | &new_crtc_state->wm.skl.optimal.planes[plane_id])) |
| 5433 | continue; |
| 5434 | |
| 5435 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 5436 | if (IS_ERR(plane_state)) |
| 5437 | return PTR_ERR(plane_state); |
| 5438 | |
| 5439 | new_crtc_state->update_planes |= BIT(plane_id); |
| 5440 | } |
| 5441 | |
| 5442 | return 0; |
| 5443 | } |
| 5444 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5445 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5446 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5447 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5448 | struct intel_crtc *crtc; |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5449 | struct intel_crtc_state *new_crtc_state; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5450 | struct intel_crtc_state *old_crtc_state; |
| 5451 | struct skl_ddb_values *results = &state->wm_results; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5452 | int ret, i; |
| 5453 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5454 | /* Clear all dirty flags */ |
| 5455 | results->dirty_pipes = 0; |
| 5456 | |
Ville Syrjälä | d7a1458 | 2019-10-11 23:09:42 +0300 | [diff] [blame] | 5457 | ret = skl_ddb_add_affected_pipes(state); |
| 5458 | if (ret) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5459 | return ret; |
| 5460 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5461 | /* |
| 5462 | * Calculate WM's for all pipes that are part of this transaction. |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5463 | * Note that skl_ddb_add_affected_pipes may have added more CRTC's that |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5464 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 5465 | * pipe allocations had to change. |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5466 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5467 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5468 | new_crtc_state, i) { |
| 5469 | ret = skl_build_pipe_wm(new_crtc_state); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5470 | if (ret) |
| 5471 | return ret; |
| 5472 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5473 | ret = skl_wm_add_affected_planes(state, crtc); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5474 | if (ret) |
| 5475 | return ret; |
| 5476 | |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5477 | if (!skl_pipe_wm_equals(crtc, |
| 5478 | &old_crtc_state->wm.skl.optimal, |
| 5479 | &new_crtc_state->wm.skl.optimal)) |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5480 | results->dirty_pipes |= BIT(crtc->pipe); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5481 | } |
| 5482 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5483 | ret = skl_compute_ddb(state); |
| 5484 | if (ret) |
| 5485 | return ret; |
| 5486 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5487 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5488 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5489 | return 0; |
| 5490 | } |
| 5491 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5492 | static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5493 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5494 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5495 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5496 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5497 | struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5498 | enum pipe pipe = crtc->pipe; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5499 | |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5500 | if ((state->wm_results.dirty_pipes & BIT(crtc->pipe)) == 0) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5501 | return; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5502 | |
| 5503 | I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime); |
| 5504 | } |
| 5505 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5506 | static void skl_initial_wm(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5507 | struct intel_crtc_state *crtc_state) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5508 | { |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5509 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5510 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5511 | struct skl_ddb_values *results = &state->wm_results; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 5512 | |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5513 | if ((results->dirty_pipes & BIT(crtc->pipe)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5514 | return; |
| 5515 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5516 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5517 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5518 | if (crtc_state->base.active_changed) |
| 5519 | skl_atomic_update_crtc_wm(state, crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5520 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5521 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5522 | } |
| 5523 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5524 | static void ilk_compute_wm_config(struct drm_i915_private *dev_priv, |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5525 | struct intel_wm_config *config) |
| 5526 | { |
| 5527 | struct intel_crtc *crtc; |
| 5528 | |
| 5529 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5530 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5531 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 5532 | |
| 5533 | if (!wm->pipe_enabled) |
| 5534 | continue; |
| 5535 | |
| 5536 | config->sprites_enabled |= wm->sprites_enabled; |
| 5537 | config->sprites_scaled |= wm->sprites_scaled; |
| 5538 | config->num_pipes_active++; |
| 5539 | } |
| 5540 | } |
| 5541 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5542 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 5543 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5544 | 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] | 5545 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5546 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5547 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5548 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 5549 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5550 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5551 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5552 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 5553 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 5554 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5555 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5556 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5557 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5558 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 5559 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5560 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5561 | best_lp_wm = ilk_find_best_result(dev_priv, &lp_wm_1_2, &lp_wm_5_6); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5562 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5563 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5564 | } |
| 5565 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5566 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5567 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5568 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5569 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 5570 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5571 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 5572 | } |
| 5573 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5574 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5575 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5576 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5577 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 5578 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5579 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5580 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 5581 | crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5582 | ilk_program_watermarks(dev_priv); |
| 5583 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5584 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5585 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5586 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5587 | struct intel_crtc_state *crtc_state) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5588 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5589 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 5590 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5591 | |
| 5592 | if (!crtc_state->wm.need_postvbl_update) |
| 5593 | return; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5594 | |
| 5595 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 5596 | crtc->wm.active.ilk = crtc_state->wm.ilk.optimal; |
| 5597 | ilk_program_watermarks(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5598 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5599 | } |
| 5600 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5601 | static inline void skl_wm_level_from_reg_val(u32 val, |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5602 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5603 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5604 | level->plane_en = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5605 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5606 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 5607 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 5608 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5609 | } |
| 5610 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5611 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5612 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5613 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5614 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5615 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5616 | int level, max_level; |
| 5617 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5618 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5619 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5620 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5621 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5622 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5623 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5624 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5625 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5626 | if (plane_id != PLANE_CURSOR) |
| 5627 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5628 | else |
| 5629 | val = I915_READ(CUR_WM(pipe, level)); |
| 5630 | |
| 5631 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 5632 | } |
| 5633 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5634 | if (plane_id != PLANE_CURSOR) |
| 5635 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5636 | else |
| 5637 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 5638 | |
| 5639 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 5640 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5641 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5642 | if (!crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5643 | return; |
| 5644 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5645 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5646 | } |
| 5647 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5648 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5649 | { |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5650 | struct skl_ddb_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5651 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5652 | struct intel_crtc *crtc; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5653 | struct intel_crtc_state *crtc_state; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5654 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5655 | skl_ddb_get_hw_state(dev_priv, ddb); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5656 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5657 | crtc_state = to_intel_crtc_state(crtc->base.state); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5658 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5659 | skl_pipe_wm_get_hw_state(crtc, &crtc_state->wm.skl.optimal); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5660 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5661 | if (crtc->active) |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5662 | hw->dirty_pipes |= BIT(crtc->pipe); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5663 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5664 | |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 5665 | if (dev_priv->active_pipes) { |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5666 | /* Fully recompute DDB on first atomic commit */ |
| 5667 | dev_priv->wm.distrust_bios_wm = true; |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5668 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5671 | static void ilk_pipe_wm_get_hw_state(struct intel_crtc *crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5672 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5673 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5674 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5675 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5676 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 5677 | struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5678 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5679 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5680 | [PIPE_A] = WM0_PIPEA_ILK, |
| 5681 | [PIPE_B] = WM0_PIPEB_ILK, |
| 5682 | [PIPE_C] = WM0_PIPEC_IVB, |
| 5683 | }; |
| 5684 | |
| 5685 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5686 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 5687 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5688 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 5689 | memset(active, 0, sizeof(*active)); |
| 5690 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5691 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 5692 | |
| 5693 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5694 | u32 tmp = hw->wm_pipe[pipe]; |
| 5695 | |
| 5696 | /* |
| 5697 | * For active pipes LP0 watermark is marked as |
| 5698 | * enabled, and LP1+ watermaks as disabled since |
| 5699 | * we can't really reverse compute them in case |
| 5700 | * multiple pipes are active. |
| 5701 | */ |
| 5702 | active->wm[0].enable = true; |
| 5703 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 5704 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 5705 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 5706 | active->linetime = hw->wm_linetime[pipe]; |
| 5707 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5708 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5709 | |
| 5710 | /* |
| 5711 | * For inactive pipes, all watermark levels |
| 5712 | * should be marked as enabled but zeroed, |
| 5713 | * which is what we'd compute them to. |
| 5714 | */ |
| 5715 | for (level = 0; level <= max_level; level++) |
| 5716 | active->wm[level].enable = true; |
| 5717 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5718 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5719 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5720 | } |
| 5721 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5722 | #define _FW_WM(value, plane) \ |
| 5723 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 5724 | #define _FW_WM_VLV(value, plane) \ |
| 5725 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 5726 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5727 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 5728 | struct g4x_wm_values *wm) |
| 5729 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5730 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5731 | |
| 5732 | tmp = I915_READ(DSPFW1); |
| 5733 | wm->sr.plane = _FW_WM(tmp, SR); |
| 5734 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5735 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 5736 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 5737 | |
| 5738 | tmp = I915_READ(DSPFW2); |
| 5739 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 5740 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 5741 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 5742 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 5743 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5744 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 5745 | |
| 5746 | tmp = I915_READ(DSPFW3); |
| 5747 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 5748 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5749 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 5750 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 5751 | } |
| 5752 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5753 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 5754 | struct vlv_wm_values *wm) |
| 5755 | { |
| 5756 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5757 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5758 | |
| 5759 | for_each_pipe(dev_priv, pipe) { |
| 5760 | tmp = I915_READ(VLV_DDL(pipe)); |
| 5761 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5762 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5763 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5764 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5765 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5766 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5767 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5768 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5769 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 5770 | } |
| 5771 | |
| 5772 | tmp = I915_READ(DSPFW1); |
| 5773 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5774 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5775 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 5776 | 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] | 5777 | |
| 5778 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5779 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 5780 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5781 | 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] | 5782 | |
| 5783 | tmp = I915_READ(DSPFW3); |
| 5784 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5785 | |
| 5786 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5787 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5788 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5789 | 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] | 5790 | |
| 5791 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5792 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 5793 | 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] | 5794 | |
| 5795 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5796 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 5797 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5798 | |
| 5799 | tmp = I915_READ(DSPHOWM); |
| 5800 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5801 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 5802 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 5803 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 5804 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5805 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5806 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5807 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5808 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5809 | 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] | 5810 | } else { |
| 5811 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5812 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5813 | 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] | 5814 | |
| 5815 | tmp = I915_READ(DSPHOWM); |
| 5816 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5817 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5818 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5819 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5820 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5821 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5822 | 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] | 5823 | } |
| 5824 | } |
| 5825 | |
| 5826 | #undef _FW_WM |
| 5827 | #undef _FW_WM_VLV |
| 5828 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5829 | void g4x_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5830 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5831 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 5832 | struct intel_crtc *crtc; |
| 5833 | |
| 5834 | g4x_read_wm_values(dev_priv, wm); |
| 5835 | |
| 5836 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 5837 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5838 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5839 | struct intel_crtc_state *crtc_state = |
| 5840 | to_intel_crtc_state(crtc->base.state); |
| 5841 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 5842 | struct g4x_pipe_wm *raw; |
| 5843 | enum pipe pipe = crtc->pipe; |
| 5844 | enum plane_id plane_id; |
| 5845 | int level, max_level; |
| 5846 | |
| 5847 | active->cxsr = wm->cxsr; |
| 5848 | active->hpll_en = wm->hpll_en; |
| 5849 | active->fbc_en = wm->fbc_en; |
| 5850 | |
| 5851 | active->sr = wm->sr; |
| 5852 | active->hpll = wm->hpll; |
| 5853 | |
| 5854 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5855 | active->wm.plane[plane_id] = |
| 5856 | wm->pipe[pipe].plane[plane_id]; |
| 5857 | } |
| 5858 | |
| 5859 | if (wm->cxsr && wm->hpll_en) |
| 5860 | max_level = G4X_WM_LEVEL_HPLL; |
| 5861 | else if (wm->cxsr) |
| 5862 | max_level = G4X_WM_LEVEL_SR; |
| 5863 | else |
| 5864 | max_level = G4X_WM_LEVEL_NORMAL; |
| 5865 | |
| 5866 | level = G4X_WM_LEVEL_NORMAL; |
| 5867 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5868 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5869 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 5870 | |
| 5871 | if (++level > max_level) |
| 5872 | goto out; |
| 5873 | |
| 5874 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5875 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 5876 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 5877 | raw->plane[PLANE_SPRITE0] = 0; |
| 5878 | raw->fbc = active->sr.fbc; |
| 5879 | |
| 5880 | if (++level > max_level) |
| 5881 | goto out; |
| 5882 | |
| 5883 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5884 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 5885 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 5886 | raw->plane[PLANE_SPRITE0] = 0; |
| 5887 | raw->fbc = active->hpll.fbc; |
| 5888 | |
| 5889 | out: |
| 5890 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5891 | g4x_raw_plane_wm_set(crtc_state, level, |
| 5892 | plane_id, USHRT_MAX); |
| 5893 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 5894 | |
| 5895 | crtc_state->wm.g4x.optimal = *active; |
| 5896 | crtc_state->wm.g4x.intermediate = *active; |
| 5897 | |
| 5898 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 5899 | pipe_name(pipe), |
| 5900 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 5901 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 5902 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
| 5903 | } |
| 5904 | |
| 5905 | DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 5906 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 5907 | DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 5908 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 5909 | DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", |
| 5910 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
| 5911 | } |
| 5912 | |
| 5913 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 5914 | { |
| 5915 | struct intel_plane *plane; |
| 5916 | struct intel_crtc *crtc; |
| 5917 | |
| 5918 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5919 | |
| 5920 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 5921 | struct intel_crtc *crtc = |
| 5922 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 5923 | struct intel_crtc_state *crtc_state = |
| 5924 | to_intel_crtc_state(crtc->base.state); |
| 5925 | struct intel_plane_state *plane_state = |
| 5926 | to_intel_plane_state(plane->base.state); |
| 5927 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 5928 | enum plane_id plane_id = plane->id; |
| 5929 | int level; |
| 5930 | |
| 5931 | if (plane_state->base.visible) |
| 5932 | continue; |
| 5933 | |
| 5934 | for (level = 0; level < 3; level++) { |
| 5935 | struct g4x_pipe_wm *raw = |
| 5936 | &crtc_state->wm.g4x.raw[level]; |
| 5937 | |
| 5938 | raw->plane[plane_id] = 0; |
| 5939 | wm_state->wm.plane[plane_id] = 0; |
| 5940 | } |
| 5941 | |
| 5942 | if (plane_id == PLANE_PRIMARY) { |
| 5943 | for (level = 0; level < 3; level++) { |
| 5944 | struct g4x_pipe_wm *raw = |
| 5945 | &crtc_state->wm.g4x.raw[level]; |
| 5946 | raw->fbc = 0; |
| 5947 | } |
| 5948 | |
| 5949 | wm_state->sr.fbc = 0; |
| 5950 | wm_state->hpll.fbc = 0; |
| 5951 | wm_state->fbc_en = false; |
| 5952 | } |
| 5953 | } |
| 5954 | |
| 5955 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5956 | struct intel_crtc_state *crtc_state = |
| 5957 | to_intel_crtc_state(crtc->base.state); |
| 5958 | |
| 5959 | crtc_state->wm.g4x.intermediate = |
| 5960 | crtc_state->wm.g4x.optimal; |
| 5961 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 5962 | } |
| 5963 | |
| 5964 | g4x_program_watermarks(dev_priv); |
| 5965 | |
| 5966 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5967 | } |
| 5968 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5969 | void vlv_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5970 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5971 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 5972 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5973 | u32 val; |
| 5974 | |
| 5975 | vlv_read_wm_values(dev_priv, wm); |
| 5976 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5977 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 5978 | wm->level = VLV_WM_LEVEL_PM2; |
| 5979 | |
| 5980 | if (IS_CHERRYVIEW(dev_priv)) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 5981 | vlv_punit_get(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5982 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 5983 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5984 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 5985 | wm->level = VLV_WM_LEVEL_PM5; |
| 5986 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 5987 | /* |
| 5988 | * If DDR DVFS is disabled in the BIOS, Punit |
| 5989 | * will never ack the request. So if that happens |
| 5990 | * assume we don't have to enable/disable DDR DVFS |
| 5991 | * dynamically. To test that just set the REQ_ACK |
| 5992 | * bit to poke the Punit, but don't change the |
| 5993 | * HIGH/LOW bits so that we don't actually change |
| 5994 | * the current state. |
| 5995 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5996 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 5997 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 5998 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 5999 | |
| 6000 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 6001 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 6002 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 6003 | "assuming DDR DVFS is disabled\n"); |
| 6004 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 6005 | } else { |
| 6006 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 6007 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 6008 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 6009 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6010 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6011 | vlv_punit_put(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6012 | } |
| 6013 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6014 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6015 | struct intel_crtc_state *crtc_state = |
| 6016 | to_intel_crtc_state(crtc->base.state); |
| 6017 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 6018 | const struct vlv_fifo_state *fifo_state = |
| 6019 | &crtc_state->wm.vlv.fifo_state; |
| 6020 | enum pipe pipe = crtc->pipe; |
| 6021 | enum plane_id plane_id; |
| 6022 | int level; |
| 6023 | |
| 6024 | vlv_get_fifo_size(crtc_state); |
| 6025 | |
| 6026 | active->num_levels = wm->level + 1; |
| 6027 | active->cxsr = wm->cxsr; |
| 6028 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6029 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6030 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6031 | &crtc_state->wm.vlv.raw[level]; |
| 6032 | |
| 6033 | active->sr[level].plane = wm->sr.plane; |
| 6034 | active->sr[level].cursor = wm->sr.cursor; |
| 6035 | |
| 6036 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6037 | active->wm[level].plane[plane_id] = |
| 6038 | wm->pipe[pipe].plane[plane_id]; |
| 6039 | |
| 6040 | raw->plane[plane_id] = |
| 6041 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 6042 | fifo_state->plane[plane_id]); |
| 6043 | } |
| 6044 | } |
| 6045 | |
| 6046 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6047 | vlv_raw_plane_wm_set(crtc_state, level, |
| 6048 | plane_id, USHRT_MAX); |
| 6049 | vlv_invalidate_wms(crtc, active, level); |
| 6050 | |
| 6051 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 6052 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6053 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6054 | 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] | 6055 | pipe_name(pipe), |
| 6056 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6057 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6058 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 6059 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6060 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6061 | |
| 6062 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 6063 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 6064 | } |
| 6065 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6066 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6067 | { |
| 6068 | struct intel_plane *plane; |
| 6069 | struct intel_crtc *crtc; |
| 6070 | |
| 6071 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6072 | |
| 6073 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6074 | struct intel_crtc *crtc = |
| 6075 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6076 | struct intel_crtc_state *crtc_state = |
| 6077 | to_intel_crtc_state(crtc->base.state); |
| 6078 | struct intel_plane_state *plane_state = |
| 6079 | to_intel_plane_state(plane->base.state); |
| 6080 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 6081 | const struct vlv_fifo_state *fifo_state = |
| 6082 | &crtc_state->wm.vlv.fifo_state; |
| 6083 | enum plane_id plane_id = plane->id; |
| 6084 | int level; |
| 6085 | |
| 6086 | if (plane_state->base.visible) |
| 6087 | continue; |
| 6088 | |
| 6089 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6090 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6091 | &crtc_state->wm.vlv.raw[level]; |
| 6092 | |
| 6093 | raw->plane[plane_id] = 0; |
| 6094 | |
| 6095 | wm_state->wm[level].plane[plane_id] = |
| 6096 | vlv_invert_wm_value(raw->plane[plane_id], |
| 6097 | fifo_state->plane[plane_id]); |
| 6098 | } |
| 6099 | } |
| 6100 | |
| 6101 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6102 | struct intel_crtc_state *crtc_state = |
| 6103 | to_intel_crtc_state(crtc->base.state); |
| 6104 | |
| 6105 | crtc_state->wm.vlv.intermediate = |
| 6106 | crtc_state->wm.vlv.optimal; |
| 6107 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 6108 | } |
| 6109 | |
| 6110 | vlv_program_watermarks(dev_priv); |
| 6111 | |
| 6112 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6113 | } |
| 6114 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6115 | /* |
| 6116 | * FIXME should probably kill this and improve |
| 6117 | * the real watermark readout/sanitation instead |
| 6118 | */ |
| 6119 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 6120 | { |
| 6121 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 6122 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 6123 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 6124 | |
| 6125 | /* |
| 6126 | * Don't touch WM1S_LP_EN here. |
| 6127 | * Doing so could cause underruns. |
| 6128 | */ |
| 6129 | } |
| 6130 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6131 | void ilk_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6132 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6133 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6134 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6135 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6136 | ilk_init_lp_watermarks(dev_priv); |
| 6137 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6138 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6139 | ilk_pipe_wm_get_hw_state(crtc); |
| 6140 | |
| 6141 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 6142 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 6143 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 6144 | |
| 6145 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 6146 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 6147 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 6148 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 6149 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6150 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6151 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6152 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 6153 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 6154 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6155 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 6156 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6157 | |
| 6158 | hw->enable_fbc_wm = |
| 6159 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 6160 | } |
| 6161 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6162 | /** |
| 6163 | * intel_update_watermarks - update FIFO watermark values based on current modes |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 6164 | * @crtc: the #intel_crtc on which to compute the WM |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6165 | * |
| 6166 | * Calculate watermark values for the various WM regs based on current mode |
| 6167 | * and plane configuration. |
| 6168 | * |
| 6169 | * There are several cases to deal with here: |
| 6170 | * - normal (i.e. non-self-refresh) |
| 6171 | * - self-refresh (SR) mode |
| 6172 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 6173 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 6174 | * lines), so need to account for TLB latency |
| 6175 | * |
| 6176 | * The normal calculation is: |
| 6177 | * watermark = dotclock * bytes per pixel * latency |
| 6178 | * where latency is platform & configuration dependent (we assume pessimal |
| 6179 | * values here). |
| 6180 | * |
| 6181 | * The SR calculation is: |
| 6182 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 6183 | * bytes per pixel |
| 6184 | * where |
| 6185 | * line time = htotal / dotclock |
| 6186 | * surface width = hdisplay for normal plane and 64 for cursor |
| 6187 | * and latency is assumed to be high, as above. |
| 6188 | * |
| 6189 | * The final value programmed to the register should always be rounded up, |
| 6190 | * and include an extra 2 entries to account for clock crossings. |
| 6191 | * |
| 6192 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 6193 | * to set the non-SR watermarks to 8. |
| 6194 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6195 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6196 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6197 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6198 | |
| 6199 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 6200 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6201 | } |
| 6202 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6203 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 6204 | { |
| 6205 | u32 val; |
| 6206 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 6207 | if (!HAS_IPC(dev_priv)) |
| 6208 | return; |
| 6209 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6210 | val = I915_READ(DISP_ARB_CTL2); |
| 6211 | |
| 6212 | if (dev_priv->ipc_enabled) |
| 6213 | val |= DISP_IPC_ENABLE; |
| 6214 | else |
| 6215 | val &= ~DISP_IPC_ENABLE; |
| 6216 | |
| 6217 | I915_WRITE(DISP_ARB_CTL2, val); |
| 6218 | } |
| 6219 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6220 | static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv) |
| 6221 | { |
| 6222 | /* Display WA #0477 WaDisableIPC: skl */ |
| 6223 | if (IS_SKYLAKE(dev_priv)) |
| 6224 | return false; |
| 6225 | |
| 6226 | /* Display WA #1141: SKL:all KBL:all CFL */ |
| 6227 | if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) |
| 6228 | return dev_priv->dram_info.symmetric_memory; |
| 6229 | |
| 6230 | return true; |
| 6231 | } |
| 6232 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6233 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 6234 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6235 | if (!HAS_IPC(dev_priv)) |
| 6236 | return; |
| 6237 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6238 | dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv); |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 6239 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6240 | intel_enable_ipc(dev_priv); |
| 6241 | } |
| 6242 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6243 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6244 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6245 | /* |
| 6246 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6247 | * gating for the panel power sequencer or it will fail to |
| 6248 | * start up when no ports are active. |
| 6249 | */ |
| 6250 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 6251 | } |
| 6252 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6253 | 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] | 6254 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 6255 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6256 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6257 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6258 | I915_WRITE(DSPCNTR(pipe), |
| 6259 | I915_READ(DSPCNTR(pipe)) | |
| 6260 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 6261 | |
| 6262 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 6263 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6264 | } |
| 6265 | } |
| 6266 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6267 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6268 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6269 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6270 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 6271 | /* |
| 6272 | * Required for FBC |
| 6273 | * WaFbcDisableDpfcClockGating:ilk |
| 6274 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6275 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 6276 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 6277 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6278 | |
| 6279 | I915_WRITE(PCH_3DCGDIS0, |
| 6280 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 6281 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 6282 | I915_WRITE(PCH_3DCGDIS1, |
| 6283 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 6284 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6285 | /* |
| 6286 | * According to the spec the following bits should be set in |
| 6287 | * order to enable memory self-refresh |
| 6288 | * The bit 22/21 of 0x42004 |
| 6289 | * The bit 5 of 0x42020 |
| 6290 | * The bit 15 of 0x45000 |
| 6291 | */ |
| 6292 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6293 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6294 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6295 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6296 | I915_WRITE(DISP_ARB_CTL, |
| 6297 | (I915_READ(DISP_ARB_CTL) | |
| 6298 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6299 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6300 | /* |
| 6301 | * Based on the document from hardware guys the following bits |
| 6302 | * should be set unconditionally in order to enable FBC. |
| 6303 | * The bit 22 of 0x42000 |
| 6304 | * The bit 22 of 0x42004 |
| 6305 | * The bit 7,8,9 of 0x42020. |
| 6306 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6307 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6308 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6309 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6310 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6311 | ILK_FBCQ_DIS); |
| 6312 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6313 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6314 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6315 | } |
| 6316 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6317 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 6318 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6319 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6320 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6321 | ILK_ELPIN_409_SELECT); |
| 6322 | I915_WRITE(_3D_CHICKEN2, |
| 6323 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 6324 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6325 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6326 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6327 | I915_WRITE(CACHE_MODE_0, |
| 6328 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6329 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6330 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 6331 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6332 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6333 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 6334 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6335 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6336 | } |
| 6337 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6338 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6339 | { |
Ville Syrjälä | d048a26 | 2019-08-21 20:30:31 +0300 | [diff] [blame] | 6340 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6341 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6342 | |
| 6343 | /* |
| 6344 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6345 | * gating for the panel power sequencer or it will fail to |
| 6346 | * start up when no ports are active. |
| 6347 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 6348 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 6349 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 6350 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6351 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 6352 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 6353 | /* The below fixes the weird display corruption, a few pixels shifted |
| 6354 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 6355 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6356 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 6357 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 6358 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 6359 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6360 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 6361 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 6362 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 6363 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 6364 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 6365 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 6366 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6367 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6368 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6369 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 6370 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 6371 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6372 | } |
| 6373 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6374 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6375 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6376 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6377 | |
| 6378 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 6379 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 6380 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 6381 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6382 | } |
| 6383 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6384 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6385 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6386 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6387 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6388 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6389 | |
| 6390 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6391 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6392 | ILK_ELPIN_409_SELECT); |
| 6393 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6394 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 6395 | I915_WRITE(_3D_CHICKEN, |
| 6396 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 6397 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6398 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 6399 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6400 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 6401 | /* |
| 6402 | * BSpec recoomends 8x4 when MSAA is used, |
| 6403 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6404 | * |
| 6405 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6406 | * disable bit, which we don't touch here, but it's good |
| 6407 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 6408 | */ |
| 6409 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6410 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 6411 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6412 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 6413 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6414 | |
| 6415 | I915_WRITE(GEN6_UCGCTL1, |
| 6416 | I915_READ(GEN6_UCGCTL1) | |
| 6417 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 6418 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 6419 | |
| 6420 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 6421 | * gating disable must be set. Failure to set it results in |
| 6422 | * flickering pixels due to Z write ordering failures after |
| 6423 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 6424 | * Sanctuary and Tropics, and apparently anything else with |
| 6425 | * alpha test or pixel discard. |
| 6426 | * |
| 6427 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 6428 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6429 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 6430 | * WaDisableRCCUnitClockGating:snb |
| 6431 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6432 | */ |
| 6433 | I915_WRITE(GEN6_UCGCTL2, |
| 6434 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 6435 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 6436 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 6437 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 6438 | I915_WRITE(_3D_CHICKEN3, |
| 6439 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6440 | |
| 6441 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 6442 | * Bspec says: |
| 6443 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 6444 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 6445 | */ |
| 6446 | I915_WRITE(_3D_CHICKEN3, |
| 6447 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 6448 | |
| 6449 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6450 | * According to the spec the following bits should be |
| 6451 | * set in order to enable memory self-refresh and fbc: |
| 6452 | * The bit21 and bit22 of 0x42000 |
| 6453 | * The bit21 and bit22 of 0x42004 |
| 6454 | * The bit5 and bit7 of 0x42020 |
| 6455 | * The bit14 of 0x70180 |
| 6456 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6457 | * |
| 6458 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6459 | */ |
| 6460 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6461 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6462 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 6463 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6464 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6465 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6466 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 6467 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 6468 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 6469 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6470 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6471 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 6472 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6473 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6474 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6475 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6476 | } |
| 6477 | |
| 6478 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 6479 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6480 | u32 reg = I915_READ(GEN7_FF_THREAD_MODE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6481 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6482 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6483 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6484 | * |
| 6485 | * This actually overrides the dispatch |
| 6486 | * mode for all thread types. |
| 6487 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6488 | reg &= ~GEN7_FF_SCHED_MASK; |
| 6489 | reg |= GEN7_FF_TS_SCHED_HW; |
| 6490 | reg |= GEN7_FF_VS_SCHED_HW; |
| 6491 | reg |= GEN7_FF_DS_SCHED_HW; |
| 6492 | |
| 6493 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 6494 | } |
| 6495 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6496 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6497 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6498 | /* |
| 6499 | * TODO: this bit should only be enabled when really needed, then |
| 6500 | * disabled when not needed anymore in order to save power. |
| 6501 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6502 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6503 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 6504 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 6505 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 6506 | |
| 6507 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 6508 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 6509 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 6510 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6511 | } |
| 6512 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 6513 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6514 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 6515 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6516 | u32 val = I915_READ(SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6517 | |
| 6518 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 6519 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 6520 | } |
| 6521 | } |
| 6522 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 6523 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 6524 | int general_prio_credits, |
| 6525 | int high_prio_credits) |
| 6526 | { |
| 6527 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 6528 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 6529 | |
| 6530 | /* WaTempDisableDOPClkGating:bdw */ |
| 6531 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 6532 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 6533 | |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 6534 | val = I915_READ(GEN8_L3SQCREG1); |
| 6535 | val &= ~L3_PRIO_CREDITS_MASK; |
| 6536 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 6537 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
| 6538 | I915_WRITE(GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 6539 | |
| 6540 | /* |
| 6541 | * Wait at least 100 clocks before re-enabling clock gating. |
| 6542 | * See the definition of L3SQCREG1 in BSpec. |
| 6543 | */ |
| 6544 | POSTING_READ(GEN8_L3SQCREG1); |
| 6545 | udelay(1); |
| 6546 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 6547 | } |
| 6548 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 6549 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 6550 | { |
| 6551 | /* This is not an Wa. Enable to reduce Sampler power */ |
| 6552 | I915_WRITE(GEN10_DFR_RATIO_EN_AND_CHICKEN, |
| 6553 | I915_READ(GEN10_DFR_RATIO_EN_AND_CHICKEN) & ~DFR_DISABLE); |
Radhakrishna Sripada | 622b3f6 | 2018-10-30 01:45:01 -0700 | [diff] [blame] | 6554 | |
| 6555 | /* WaEnable32PlaneMode:icl */ |
| 6556 | I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, |
| 6557 | _MASKED_BIT_ENABLE(GEN11_ENABLE_32_PLANE_MODE)); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 6558 | } |
| 6559 | |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 6560 | static void tgl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 6561 | { |
| 6562 | u32 vd_pg_enable = 0; |
| 6563 | unsigned int i; |
| 6564 | |
| 6565 | /* This is not a WA. Enable VD HCP & MFX_ENC powergate */ |
| 6566 | for (i = 0; i < I915_MAX_VCS; i++) { |
| 6567 | if (HAS_ENGINE(dev_priv, _VCS(i))) |
| 6568 | vd_pg_enable |= VDN_HCP_POWERGATE_ENABLE(i) | |
| 6569 | VDN_MFX_POWERGATE_ENABLE(i); |
| 6570 | } |
| 6571 | |
| 6572 | I915_WRITE(POWERGATE_ENABLE, |
| 6573 | I915_READ(POWERGATE_ENABLE) | vd_pg_enable); |
| 6574 | } |
| 6575 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 6576 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 6577 | { |
| 6578 | if (!HAS_PCH_CNP(dev_priv)) |
| 6579 | return; |
| 6580 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 6581 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Rodrigo Vivi | 4cc6feb | 2017-09-08 16:45:33 -0700 | [diff] [blame] | 6582 | I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 6583 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 6584 | } |
| 6585 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6586 | static void cnl_init_clock_gating(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 6587 | { |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 6588 | u32 val; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 6589 | cnp_init_clock_gating(dev_priv); |
| 6590 | |
Rodrigo Vivi | 1a25db6 | 2017-08-15 16:16:51 -0700 | [diff] [blame] | 6591 | /* This is not an Wa. Enable for better image quality */ |
| 6592 | I915_WRITE(_3D_CHICKEN3, |
| 6593 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE)); |
| 6594 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 6595 | /* WaEnableChickenDCPR:cnl */ |
| 6596 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 6597 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
| 6598 | |
| 6599 | /* WaFbcWakeMemOn:cnl */ |
| 6600 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 6601 | DISP_FBC_MEMORY_WAKE); |
| 6602 | |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 6603 | val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE); |
| 6604 | /* ReadHitWriteOnlyDisable:cnl */ |
| 6605 | val |= RCCUNIT_CLKGATE_DIS; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 6606 | /* WaSarbUnitClockGatingDisable:cnl (pre-prod) */ |
| 6607 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 6608 | val |= SARBUNIT_CLKGATE_DIS; |
| 6609 | I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val); |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 6610 | |
Rodrigo Vivi | a4713c5 | 2018-03-07 14:09:12 -0800 | [diff] [blame] | 6611 | /* Wa_2201832410:cnl */ |
| 6612 | val = I915_READ(SUBSLICE_UNIT_LEVEL_CLKGATE); |
| 6613 | val |= GWUNIT_CLKGATE_DIS; |
| 6614 | I915_WRITE(SUBSLICE_UNIT_LEVEL_CLKGATE, val); |
| 6615 | |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 6616 | /* WaDisableVFclkgate:cnl */ |
Rodrigo Vivi | 14941b6 | 2018-03-05 17:20:00 -0800 | [diff] [blame] | 6617 | /* WaVFUnitClockGatingDisable:cnl */ |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 6618 | val = I915_READ(UNSLICE_UNIT_LEVEL_CLKGATE); |
| 6619 | val |= VFUNIT_CLKGATE_DIS; |
| 6620 | I915_WRITE(UNSLICE_UNIT_LEVEL_CLKGATE, val); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 6623 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 6624 | { |
| 6625 | cnp_init_clock_gating(dev_priv); |
| 6626 | gen9_init_clock_gating(dev_priv); |
| 6627 | |
| 6628 | /* WaFbcNukeOnHostModify:cfl */ |
| 6629 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 6630 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 6631 | } |
| 6632 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6633 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 6634 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6635 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 6636 | |
| 6637 | /* WaDisableSDEUnitClockGating:kbl */ |
| 6638 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 6639 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6640 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 6641 | |
| 6642 | /* WaDisableGamClockGating:kbl */ |
| 6643 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 6644 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6645 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 6646 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 6647 | /* WaFbcNukeOnHostModify:kbl */ |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 6648 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 6649 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 6650 | } |
| 6651 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6652 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 6653 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6654 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 6655 | |
| 6656 | /* WAC6entrylatency:skl */ |
| 6657 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 6658 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 6659 | |
| 6660 | /* WaFbcNukeOnHostModify:skl */ |
| 6661 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 6662 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 6663 | } |
| 6664 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6665 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6666 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6667 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6668 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6669 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6670 | 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] | 6671 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6672 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6673 | I915_WRITE(CHICKEN_PAR1_1, |
| 6674 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 6675 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6676 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6677 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6678 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 6679 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 6680 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6681 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 6682 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6683 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 6684 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 6685 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6686 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6687 | ~(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] | 6688 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 6689 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6690 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 6691 | |
| 6692 | /* WaDisableSDEUnitClockGating:bdw */ |
| 6693 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6694 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 6695 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 6696 | /* WaProgramL3SqcReg1Default:bdw */ |
| 6697 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 6698 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 6699 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 6700 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 6701 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 6702 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6703 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 6704 | |
| 6705 | /* WaDisableDopClockGating:bdw |
| 6706 | * |
| 6707 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 6708 | * clock gating. |
| 6709 | */ |
| 6710 | I915_WRITE(GEN6_UCGCTL1, |
| 6711 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6712 | } |
| 6713 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6714 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6715 | { |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 6716 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 6717 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 6718 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 6719 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 6720 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6721 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6722 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6723 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6724 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6725 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 6726 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 6727 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6728 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6729 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6730 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 6731 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6732 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 6733 | /* enable HiZ Raw Stall Optimization */ |
| 6734 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6735 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6736 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6737 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6738 | I915_WRITE(CACHE_MODE_1, |
| 6739 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6740 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6741 | /* |
| 6742 | * BSpec recommends 8x4 when MSAA is used, |
| 6743 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6744 | * |
| 6745 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6746 | * disable bit, which we don't touch here, but it's good |
| 6747 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6748 | */ |
| 6749 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6750 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6751 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 6752 | /* WaSampleCChickenBitEnable:hsw */ |
| 6753 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 6754 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 6755 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6756 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 6757 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 6758 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6759 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6760 | } |
| 6761 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6762 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6763 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6764 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6765 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6766 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6767 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6768 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6769 | I915_WRITE(_3D_CHICKEN3, |
| 6770 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6771 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6772 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6773 | I915_WRITE(IVB_CHICKEN3, |
| 6774 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6775 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6776 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6777 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6778 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6779 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 6780 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6781 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6782 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 6783 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6784 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6785 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6786 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 6787 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 6788 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6789 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6790 | I915_WRITE(GEN7_L3CNTLREG1, |
| 6791 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 6792 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6793 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6794 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6795 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6796 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6797 | else { |
| 6798 | /* must write both registers */ |
| 6799 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6800 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6801 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 6802 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6803 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6804 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6805 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6806 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6807 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6808 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 6809 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6810 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6811 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6812 | */ |
| 6813 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 6814 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6815 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6816 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6817 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6818 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6819 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6820 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6821 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6822 | |
| 6823 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6824 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 6825 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 6826 | /* enable HiZ Raw Stall Optimization */ |
| 6827 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6828 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6829 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 6830 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6831 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6832 | I915_WRITE(CACHE_MODE_1, |
| 6833 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6834 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6835 | /* |
| 6836 | * BSpec recommends 8x4 when MSAA is used, |
| 6837 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6838 | * |
| 6839 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6840 | * disable bit, which we don't touch here, but it's good |
| 6841 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6842 | */ |
| 6843 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6844 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6845 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6846 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 6847 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 6848 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 6849 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6850 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 6851 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6852 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6853 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6854 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6855 | } |
| 6856 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6857 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6858 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6859 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6860 | I915_WRITE(_3D_CHICKEN3, |
| 6861 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6862 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6863 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6864 | I915_WRITE(IVB_CHICKEN3, |
| 6865 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6866 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6867 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 6868 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6869 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6870 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 6871 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 6872 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6873 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6874 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 6875 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6876 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6877 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6878 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6879 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6880 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6881 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6882 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6883 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 6884 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6885 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6886 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6887 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6888 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6889 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6890 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 6891 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6892 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6893 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6894 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6895 | */ |
| 6896 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6897 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6898 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6899 | /* WaDisableL3Bank2xClockGate:vlv |
| 6900 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6901 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6902 | I915_WRITE(GEN7_UCGCTL4, |
| 6903 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6904 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6905 | /* |
| 6906 | * BSpec says this must be set, even though |
| 6907 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6908 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6909 | I915_WRITE(CACHE_MODE_1, |
| 6910 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6911 | |
| 6912 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 6913 | * BSpec recommends 8x4 when MSAA is used, |
| 6914 | * however in practice 16x4 seems fastest. |
| 6915 | * |
| 6916 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6917 | * disable bit, which we don't touch here, but it's good |
| 6918 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 6919 | */ |
| 6920 | I915_WRITE(GEN7_GT_MODE, |
| 6921 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 6922 | |
| 6923 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6924 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6925 | * This is the hardware default actually. |
| 6926 | */ |
| 6927 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6928 | |
| 6929 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6930 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6931 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6932 | * in the reporting of vblank events. |
| 6933 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6934 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6935 | } |
| 6936 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6937 | static void chv_init_clock_gating(struct drm_i915_private *dev_priv) |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6938 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6939 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6940 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6941 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6942 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6943 | ~(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] | 6944 | |
| 6945 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6946 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6947 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6948 | |
| 6949 | /* WaDisableCSUnitClockGating:chv */ |
| 6950 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6951 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6952 | |
| 6953 | /* WaDisableSDEUnitClockGating:chv */ |
| 6954 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6955 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 6956 | |
| 6957 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 6958 | * WaProgramL3SqcReg1Default:chv |
| 6959 | * See gfxspecs/Related Documents/Performance Guide/ |
| 6960 | * LSQC Setting Recommendations. |
| 6961 | */ |
| 6962 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6963 | } |
| 6964 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6965 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6966 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6967 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6968 | |
| 6969 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6970 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6971 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6972 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6973 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6974 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6975 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6976 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6977 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6978 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6979 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6980 | |
| 6981 | /* WaDisableRenderCachePipelinedFlush */ |
| 6982 | I915_WRITE(CACHE_MODE_0, |
| 6983 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6984 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6985 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6986 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6987 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6988 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6989 | } |
| 6990 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6991 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6992 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6993 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 6994 | |
| 6995 | intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6996 | intel_uncore_write(uncore, RENCLK_GATE_D2, 0); |
| 6997 | intel_uncore_write(uncore, DSPCLK_GATE_D, 0); |
| 6998 | intel_uncore_write(uncore, RAMCLK_GATE_D, 0); |
| 6999 | intel_uncore_write16(uncore, DEUC, 0); |
| 7000 | intel_uncore_write(uncore, |
| 7001 | MI_ARB_STATE, |
| 7002 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7003 | |
| 7004 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 7005 | intel_uncore_write(uncore, |
| 7006 | CACHE_MODE_0, |
| 7007 | _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7008 | } |
| 7009 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7010 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7011 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7012 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 7013 | I965_RCC_CLOCK_GATE_DISABLE | |
| 7014 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 7015 | I965_ISC_CLOCK_GATE_DISABLE | |
| 7016 | I965_FBC_CLOCK_GATE_DISABLE); |
| 7017 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 7018 | I915_WRITE(MI_ARB_STATE, |
| 7019 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7020 | |
| 7021 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 7022 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7023 | } |
| 7024 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7025 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7026 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7027 | u32 dstate = I915_READ(D_STATE); |
| 7028 | |
| 7029 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 7030 | DSTATE_DOT_CLOCK_GATING; |
| 7031 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 7032 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7033 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 7034 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 7035 | |
| 7036 | /* IIR "flip pending" means done if this bit is set */ |
| 7037 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 7038 | |
| 7039 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 7040 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 7041 | |
| 7042 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 7043 | 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] | 7044 | |
| 7045 | I915_WRITE(MI_ARB_STATE, |
| 7046 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7047 | } |
| 7048 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7049 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7050 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7051 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 7052 | |
| 7053 | /* interrupts should cause a wake up from C3 */ |
| 7054 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 7055 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7056 | |
| 7057 | I915_WRITE(MEM_MODE, |
| 7058 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7059 | } |
| 7060 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7061 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7062 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7063 | I915_WRITE(MEM_MODE, |
| 7064 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 7065 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7066 | } |
| 7067 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7068 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7069 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7070 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7071 | } |
| 7072 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7073 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7074 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7075 | if (HAS_PCH_LPT(dev_priv)) |
| 7076 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7077 | } |
| 7078 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7079 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7080 | { |
| 7081 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 7082 | } |
| 7083 | |
| 7084 | /** |
| 7085 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 7086 | * @dev_priv: device private |
| 7087 | * |
| 7088 | * Setup the hooks that configure which clocks of a given platform can be |
| 7089 | * gated and also apply various GT and display specific workarounds for these |
| 7090 | * platforms. Note that some GT specific workarounds are applied separately |
| 7091 | * when GPU contexts or batchbuffers start their execution. |
| 7092 | */ |
| 7093 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 7094 | { |
Lucas De Marchi | 13e53c5 | 2019-08-17 02:38:42 -0700 | [diff] [blame] | 7095 | if (IS_GEN(dev_priv, 12)) |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7096 | dev_priv->display.init_clock_gating = tgl_init_clock_gating; |
Lucas De Marchi | 13e53c5 | 2019-08-17 02:38:42 -0700 | [diff] [blame] | 7097 | else if (IS_GEN(dev_priv, 11)) |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7098 | dev_priv->display.init_clock_gating = icl_init_clock_gating; |
Oscar Mateo | cc38cae | 2018-05-08 14:29:23 -0700 | [diff] [blame] | 7099 | else if (IS_CANNONLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7100 | dev_priv->display.init_clock_gating = cnl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7101 | else if (IS_COFFEELAKE(dev_priv)) |
| 7102 | dev_priv->display.init_clock_gating = cfl_init_clock_gating; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7103 | else if (IS_SKYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7104 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7105 | else if (IS_KABYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7106 | dev_priv->display.init_clock_gating = kbl_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7107 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7108 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7109 | else if (IS_GEMINILAKE(dev_priv)) |
| 7110 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7111 | else if (IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7112 | dev_priv->display.init_clock_gating = bdw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7113 | else if (IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7114 | dev_priv->display.init_clock_gating = chv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7115 | else if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7116 | dev_priv->display.init_clock_gating = hsw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7117 | else if (IS_IVYBRIDGE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7118 | dev_priv->display.init_clock_gating = ivb_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7119 | else if (IS_VALLEYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7120 | dev_priv->display.init_clock_gating = vlv_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7121 | else if (IS_GEN(dev_priv, 6)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7122 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7123 | else if (IS_GEN(dev_priv, 5)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7124 | dev_priv->display.init_clock_gating = ilk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7125 | else if (IS_G4X(dev_priv)) |
| 7126 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7127 | else if (IS_I965GM(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7128 | dev_priv->display.init_clock_gating = i965gm_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7129 | else if (IS_I965G(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7130 | dev_priv->display.init_clock_gating = i965g_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7131 | else if (IS_GEN(dev_priv, 3)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7132 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 7133 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 7134 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7135 | else if (IS_GEN(dev_priv, 2)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7136 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 7137 | else { |
| 7138 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 7139 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 7140 | } |
| 7141 | } |
| 7142 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7143 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 7144 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7145 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7146 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7147 | if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 7148 | i915_pineview_get_mem_freq(dev_priv); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7149 | else if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 7150 | i915_ironlake_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7151 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 7152 | if (intel_has_sagv(dev_priv)) |
| 7153 | skl_setup_sagv_block_time(dev_priv); |
| 7154 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7155 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 7156 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 7157 | skl_setup_wm_latency(dev_priv); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 7158 | dev_priv->display.initial_watermarks = skl_initial_wm; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 7159 | dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 7160 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7161 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 7162 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 7163 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7164 | if ((IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[1] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7165 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7166 | (!IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7167 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 7168 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 7169 | dev_priv->display.compute_intermediate_wm = |
| 7170 | ilk_compute_intermediate_wm; |
| 7171 | dev_priv->display.initial_watermarks = |
| 7172 | ilk_initial_watermarks; |
| 7173 | dev_priv->display.optimize_watermarks = |
| 7174 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7175 | } else { |
| 7176 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 7177 | "Disable CxSR\n"); |
| 7178 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 7179 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 7180 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7181 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 7182 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7183 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 7184 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7185 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 7186 | } else if (IS_G4X(dev_priv)) { |
| 7187 | g4x_setup_wm_latency(dev_priv); |
| 7188 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 7189 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 7190 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 7191 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7192 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 7193 | if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7194 | dev_priv->is_ddr3, |
| 7195 | dev_priv->fsb_freq, |
| 7196 | dev_priv->mem_freq)) { |
| 7197 | DRM_INFO("failed to find known CxSR latency " |
| 7198 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 7199 | "disabling CxSR\n", |
| 7200 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 7201 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 7202 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 7203 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7204 | dev_priv->display.update_wm = NULL; |
| 7205 | } else |
| 7206 | dev_priv->display.update_wm = pineview_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7207 | } else if (IS_GEN(dev_priv, 4)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7208 | dev_priv->display.update_wm = i965_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7209 | } else if (IS_GEN(dev_priv, 3)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7210 | dev_priv->display.update_wm = i9xx_update_wm; |
| 7211 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7212 | } else if (IS_GEN(dev_priv, 2)) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 7213 | if (INTEL_NUM_PIPES(dev_priv) == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7214 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7215 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7216 | } else { |
| 7217 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7218 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7219 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7220 | } else { |
| 7221 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7222 | } |
| 7223 | } |
| 7224 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 7225 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7226 | { |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 7227 | dev_priv->runtime_pm.suspended = false; |
| 7228 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7229 | } |