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 | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 200 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 201 | |
| 202 | switch (csipll & 0x3ff) { |
| 203 | case 0x00c: |
| 204 | dev_priv->fsb_freq = 3200; |
| 205 | break; |
| 206 | case 0x00e: |
| 207 | dev_priv->fsb_freq = 3733; |
| 208 | break; |
| 209 | case 0x010: |
| 210 | dev_priv->fsb_freq = 4266; |
| 211 | break; |
| 212 | case 0x012: |
| 213 | dev_priv->fsb_freq = 4800; |
| 214 | break; |
| 215 | case 0x014: |
| 216 | dev_priv->fsb_freq = 5333; |
| 217 | break; |
| 218 | case 0x016: |
| 219 | dev_priv->fsb_freq = 5866; |
| 220 | break; |
| 221 | case 0x018: |
| 222 | dev_priv->fsb_freq = 6400; |
| 223 | break; |
| 224 | default: |
| 225 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 226 | csipll & 0x3ff); |
| 227 | dev_priv->fsb_freq = 0; |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 232 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 233 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 234 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 235 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 236 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 240 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 241 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 242 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 243 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 244 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 245 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 246 | |
| 247 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 248 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 249 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 250 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 251 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 252 | |
| 253 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 254 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 255 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 256 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 257 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 258 | |
| 259 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 260 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 261 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 262 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 263 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 264 | |
| 265 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 266 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 267 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 268 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 269 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 270 | |
| 271 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 272 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 273 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 274 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 275 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 276 | }; |
| 277 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 278 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 279 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 280 | int fsb, |
| 281 | int mem) |
| 282 | { |
| 283 | const struct cxsr_latency *latency; |
| 284 | int i; |
| 285 | |
| 286 | if (fsb == 0 || mem == 0) |
| 287 | return NULL; |
| 288 | |
| 289 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 290 | latency = &cxsr_latency_table[i]; |
| 291 | if (is_desktop == latency->is_desktop && |
| 292 | is_ddr3 == latency->is_ddr3 && |
| 293 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 294 | return latency; |
| 295 | } |
| 296 | |
| 297 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 298 | |
| 299 | return NULL; |
| 300 | } |
| 301 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 302 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 303 | { |
| 304 | u32 val; |
| 305 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 306 | vlv_punit_get(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 307 | |
| 308 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 309 | if (enable) |
| 310 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 311 | else |
| 312 | val |= FORCE_DDR_HIGH_FREQ; |
| 313 | val &= ~FORCE_DDR_LOW_FREQ; |
| 314 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 315 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 316 | |
| 317 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 318 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 319 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 320 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 321 | vlv_punit_put(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 324 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 325 | { |
| 326 | u32 val; |
| 327 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 328 | vlv_punit_get(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 329 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 330 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 331 | if (enable) |
| 332 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 333 | else |
| 334 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 335 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 336 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 337 | vlv_punit_put(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 340 | #define FW_WM(value, plane) \ |
| 341 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 342 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 343 | 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] | 344 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 345 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 346 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 347 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 348 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 349 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 350 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 351 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 352 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 353 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 354 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 355 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 356 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 357 | val = I915_READ(DSPFW3); |
| 358 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 359 | if (enable) |
| 360 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 361 | else |
| 362 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 363 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 364 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 365 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 366 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 367 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 368 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 369 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 370 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 371 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 372 | /* |
| 373 | * FIXME can't find a bit like this for 915G, and |
| 374 | * and yet it does have the related watermark in |
| 375 | * FW_BLC_SELF. What's going on? |
| 376 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 377 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 378 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 379 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 380 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 381 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 382 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 383 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 384 | } |
| 385 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 386 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 387 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 388 | DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", |
| 389 | enableddisabled(enable), |
| 390 | enableddisabled(was_enabled)); |
| 391 | |
| 392 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 393 | } |
| 394 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 395 | /** |
| 396 | * intel_set_memory_cxsr - Configure CxSR state |
| 397 | * @dev_priv: i915 device |
| 398 | * @enable: Allow vs. disallow CxSR |
| 399 | * |
| 400 | * Allow or disallow the system to enter a special CxSR |
| 401 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 402 | * is that several display FIFOs may get combined into a single larger |
| 403 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 404 | * system to defer memory fetches longer, and the memory will enter |
| 405 | * self refresh. |
| 406 | * |
| 407 | * Note that enabling CxSR does not guarantee that the system enter |
| 408 | * this special mode, nor does it guarantee that the system stays |
| 409 | * in that mode once entered. So this just allows/disallows the system |
| 410 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 411 | * C-states will affect when/if the system actually enters/exits the |
| 412 | * CxSR mode. |
| 413 | * |
| 414 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 415 | * and the system is free to enter/exit memory self refresh at any time |
| 416 | * even when the use of CxSR has been disallowed. |
| 417 | * |
| 418 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 419 | * control registers will not get latched on vblank. Thus in order to |
| 420 | * guarantee the system will respond to changes in the plane registers |
| 421 | * we must always disallow CxSR prior to making changes to those registers. |
| 422 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 423 | * frame start which happens after vblank start (which is when the plane |
| 424 | * registers would get latched), so we can't proceed with the plane update |
| 425 | * during the same frame where we disallowed CxSR. |
| 426 | * |
| 427 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 428 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 429 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 430 | * Disallowing just CxSR is sufficient. |
| 431 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 432 | 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] | 433 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 434 | bool ret; |
| 435 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 436 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 437 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 438 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 439 | dev_priv->wm.vlv.cxsr = enable; |
| 440 | else if (IS_G4X(dev_priv)) |
| 441 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 442 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 443 | |
| 444 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 445 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 446 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 447 | /* |
| 448 | * Latency for FIFO fetches is dependent on several factors: |
| 449 | * - memory configuration (speed, channels) |
| 450 | * - chipset |
| 451 | * - current MCH state |
| 452 | * It can be fairly high in some situations, so here we assume a fairly |
| 453 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 454 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 455 | * and power consumption (set it too low to save power and we might see |
| 456 | * FIFO underruns and display "flicker"). |
| 457 | * |
| 458 | * A value of 5us seems to be a good balance; safe for very low end |
| 459 | * platforms but not overly aggressive on lower latency configs. |
| 460 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 461 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 462 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 463 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 464 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 465 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 466 | 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] | 467 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 468 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 469 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 470 | 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] | 471 | enum pipe pipe = crtc->pipe; |
| 472 | int sprite0_start, sprite1_start; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 473 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 474 | switch (pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 475 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 476 | case PIPE_A: |
| 477 | dsparb = I915_READ(DSPARB); |
| 478 | dsparb2 = I915_READ(DSPARB2); |
| 479 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 480 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 481 | break; |
| 482 | case PIPE_B: |
| 483 | dsparb = I915_READ(DSPARB); |
| 484 | dsparb2 = I915_READ(DSPARB2); |
| 485 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 486 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 487 | break; |
| 488 | case PIPE_C: |
| 489 | dsparb2 = I915_READ(DSPARB2); |
| 490 | dsparb3 = I915_READ(DSPARB3); |
| 491 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 492 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 493 | break; |
| 494 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 495 | MISSING_CASE(pipe); |
| 496 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 497 | } |
| 498 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 499 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 500 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 501 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 502 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 503 | } |
| 504 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 505 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 506 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 507 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 508 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 509 | int size; |
| 510 | |
| 511 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 512 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 513 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 514 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 515 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 516 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 517 | |
| 518 | return size; |
| 519 | } |
| 520 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 521 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 522 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 523 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 524 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 525 | int size; |
| 526 | |
| 527 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 528 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 529 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 530 | size >>= 1; /* Convert to cachelines */ |
| 531 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 532 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 533 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 534 | |
| 535 | return size; |
| 536 | } |
| 537 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 538 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 539 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 540 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 541 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 542 | int size; |
| 543 | |
| 544 | size = dsparb & 0x7f; |
| 545 | size >>= 2; /* Convert to cachelines */ |
| 546 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 547 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 548 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 549 | |
| 550 | return size; |
| 551 | } |
| 552 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 553 | /* Pineview has different values for various configs */ |
| 554 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 555 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 556 | .max_wm = PINEVIEW_MAX_WM, |
| 557 | .default_wm = PINEVIEW_DFT_WM, |
| 558 | .guard_size = PINEVIEW_GUARD_WM, |
| 559 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 560 | }; |
| 561 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 562 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 563 | .max_wm = PINEVIEW_MAX_WM, |
| 564 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 565 | .guard_size = PINEVIEW_GUARD_WM, |
| 566 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 567 | }; |
| 568 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 569 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 570 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 571 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 572 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 573 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 574 | }; |
| 575 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 576 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 577 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 578 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 579 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 580 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 581 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 582 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 583 | .fifo_size = I965_CURSOR_FIFO, |
| 584 | .max_wm = I965_CURSOR_MAX_WM, |
| 585 | .default_wm = I965_CURSOR_DFT_WM, |
| 586 | .guard_size = 2, |
| 587 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 588 | }; |
| 589 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 590 | .fifo_size = I945_FIFO_SIZE, |
| 591 | .max_wm = I915_MAX_WM, |
| 592 | .default_wm = 1, |
| 593 | .guard_size = 2, |
| 594 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 595 | }; |
| 596 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 597 | .fifo_size = I915_FIFO_SIZE, |
| 598 | .max_wm = I915_MAX_WM, |
| 599 | .default_wm = 1, |
| 600 | .guard_size = 2, |
| 601 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 602 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 603 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 604 | .fifo_size = I855GM_FIFO_SIZE, |
| 605 | .max_wm = I915_MAX_WM, |
| 606 | .default_wm = 1, |
| 607 | .guard_size = 2, |
| 608 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 609 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 610 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 611 | .fifo_size = I855GM_FIFO_SIZE, |
| 612 | .max_wm = I915_MAX_WM/2, |
| 613 | .default_wm = 1, |
| 614 | .guard_size = 2, |
| 615 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 616 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 617 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 618 | .fifo_size = I830_FIFO_SIZE, |
| 619 | .max_wm = I915_MAX_WM, |
| 620 | .default_wm = 1, |
| 621 | .guard_size = 2, |
| 622 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 623 | }; |
| 624 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 625 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 626 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 627 | * @pixel_rate: Pipe pixel rate in kHz |
| 628 | * @cpp: Plane bytes per pixel |
| 629 | * @latency: Memory wakeup latency in 0.1us units |
| 630 | * |
| 631 | * Compute the watermark using the method 1 or "small buffer" |
| 632 | * formula. The caller may additonally add extra cachelines |
| 633 | * to account for TLB misses and clock crossings. |
| 634 | * |
| 635 | * This method is concerned with the short term drain rate |
| 636 | * of the FIFO, ie. it does not account for blanking periods |
| 637 | * which would effectively reduce the average drain rate across |
| 638 | * a longer period. The name "small" refers to the fact the |
| 639 | * FIFO is relatively small compared to the amount of data |
| 640 | * fetched. |
| 641 | * |
| 642 | * The FIFO level vs. time graph might look something like: |
| 643 | * |
| 644 | * |\ |\ |
| 645 | * | \ | \ |
| 646 | * __---__---__ (- plane active, _ blanking) |
| 647 | * -> time |
| 648 | * |
| 649 | * or perhaps like this: |
| 650 | * |
| 651 | * |\|\ |\|\ |
| 652 | * __----__----__ (- plane active, _ blanking) |
| 653 | * -> time |
| 654 | * |
| 655 | * Returns: |
| 656 | * The watermark in bytes |
| 657 | */ |
| 658 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 659 | unsigned int cpp, |
| 660 | unsigned int latency) |
| 661 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 662 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 663 | |
Ville Syrjälä | d492a29 | 2019-04-08 18:27:01 +0300 | [diff] [blame] | 664 | ret = mul_u32_u32(pixel_rate, cpp * latency); |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 665 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 666 | |
| 667 | return ret; |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 672 | * @pixel_rate: Pipe pixel rate in kHz |
| 673 | * @htotal: Pipe horizontal total |
| 674 | * @width: Plane width in pixels |
| 675 | * @cpp: Plane bytes per pixel |
| 676 | * @latency: Memory wakeup latency in 0.1us units |
| 677 | * |
| 678 | * Compute the watermark using the method 2 or "large buffer" |
| 679 | * formula. The caller may additonally add extra cachelines |
| 680 | * to account for TLB misses and clock crossings. |
| 681 | * |
| 682 | * This method is concerned with the long term drain rate |
| 683 | * of the FIFO, ie. it does account for blanking periods |
| 684 | * which effectively reduce the average drain rate across |
| 685 | * a longer period. The name "large" refers to the fact the |
| 686 | * FIFO is relatively large compared to the amount of data |
| 687 | * fetched. |
| 688 | * |
| 689 | * The FIFO level vs. time graph might look something like: |
| 690 | * |
| 691 | * |\___ |\___ |
| 692 | * | \___ | \___ |
| 693 | * | \ | \ |
| 694 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 695 | * -> time |
| 696 | * |
| 697 | * Returns: |
| 698 | * The watermark in bytes |
| 699 | */ |
| 700 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 701 | unsigned int htotal, |
| 702 | unsigned int width, |
| 703 | unsigned int cpp, |
| 704 | unsigned int latency) |
| 705 | { |
| 706 | unsigned int ret; |
| 707 | |
| 708 | /* |
| 709 | * FIXME remove once all users are computing |
| 710 | * watermarks in the correct place. |
| 711 | */ |
| 712 | if (WARN_ON_ONCE(htotal == 0)) |
| 713 | htotal = 1; |
| 714 | |
| 715 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 716 | ret = (ret + 1) * width * cpp; |
| 717 | |
| 718 | return ret; |
| 719 | } |
| 720 | |
| 721 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 722 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 723 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 724 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 725 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 726 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 727 | * @latency_ns: memory latency for the platform |
| 728 | * |
| 729 | * Calculate the watermark level (the level at which the display plane will |
| 730 | * start fetching from memory again). Each chip has a different display |
| 731 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 732 | * in the correct intel_watermark_params structure. |
| 733 | * |
| 734 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 735 | * on the pixel size. When it reaches the watermark level, it'll start |
| 736 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 737 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 738 | * will occur, and a display engine hang could result. |
| 739 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 740 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 741 | const struct intel_watermark_params *wm, |
| 742 | int fifo_size, int cpp, |
| 743 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 744 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 745 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 746 | |
| 747 | /* |
| 748 | * Note: we need to make sure we don't overflow for various clock & |
| 749 | * latency values. |
| 750 | * clocks go from a few thousand to several hundred thousand. |
| 751 | * latency is usually a few thousand |
| 752 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 753 | entries = intel_wm_method1(pixel_rate, cpp, |
| 754 | latency_ns / 100); |
| 755 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 756 | wm->guard_size; |
| 757 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 758 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 759 | wm_size = fifo_size - entries; |
| 760 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 761 | |
| 762 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 763 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 764 | wm_size = wm->max_wm; |
| 765 | if (wm_size <= 0) |
| 766 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 767 | |
| 768 | /* |
| 769 | * Bspec seems to indicate that the value shouldn't be lower than |
| 770 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 771 | * Lets go for 8 which is the burst size since certain platforms |
| 772 | * already use a hardcoded 8 (which is what the spec says should be |
| 773 | * done). |
| 774 | */ |
| 775 | if (wm_size <= 8) |
| 776 | wm_size = 8; |
| 777 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 778 | return wm_size; |
| 779 | } |
| 780 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 781 | static bool is_disabling(int old, int new, int threshold) |
| 782 | { |
| 783 | return old >= threshold && new < threshold; |
| 784 | } |
| 785 | |
| 786 | static bool is_enabling(int old, int new, int threshold) |
| 787 | { |
| 788 | return old < threshold && new >= threshold; |
| 789 | } |
| 790 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 791 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 792 | { |
| 793 | return dev_priv->wm.max_level + 1; |
| 794 | } |
| 795 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 796 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 797 | const struct intel_plane_state *plane_state) |
| 798 | { |
| 799 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 800 | |
| 801 | /* FIXME check the 'enable' instead */ |
| 802 | if (!crtc_state->base.active) |
| 803 | return false; |
| 804 | |
| 805 | /* |
| 806 | * Treat cursor with fb as always visible since cursor updates |
| 807 | * can happen faster than the vrefresh rate, and the current |
| 808 | * watermark code doesn't handle that correctly. Cursor updates |
| 809 | * which set/clear the fb or change the cursor size are going |
| 810 | * to get throttled by intel_legacy_cursor_update() to work |
| 811 | * around this problem with the watermark code. |
| 812 | */ |
| 813 | if (plane->id == PLANE_CURSOR) |
| 814 | return plane_state->base.fb != NULL; |
| 815 | else |
| 816 | return plane_state->base.visible; |
| 817 | } |
| 818 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 819 | 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] | 820 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 821 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 822 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 823 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 824 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 825 | if (enabled) |
| 826 | return NULL; |
| 827 | enabled = crtc; |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | return enabled; |
| 832 | } |
| 833 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 834 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 835 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 836 | 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] | 837 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 838 | const struct cxsr_latency *latency; |
| 839 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 840 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 841 | |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 842 | latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 843 | dev_priv->is_ddr3, |
| 844 | dev_priv->fsb_freq, |
| 845 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 846 | if (!latency) { |
| 847 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 848 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 849 | return; |
| 850 | } |
| 851 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 852 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 853 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 854 | const struct drm_display_mode *adjusted_mode = |
| 855 | &crtc->config->base.adjusted_mode; |
| 856 | const struct drm_framebuffer *fb = |
| 857 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 858 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 859 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 860 | |
| 861 | /* Display SR */ |
| 862 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 863 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 864 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 865 | reg = I915_READ(DSPFW1); |
| 866 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 867 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 868 | I915_WRITE(DSPFW1, reg); |
| 869 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 870 | |
| 871 | /* cursor SR */ |
| 872 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 873 | pineview_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 874 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 875 | reg = I915_READ(DSPFW3); |
| 876 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 877 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 878 | I915_WRITE(DSPFW3, reg); |
| 879 | |
| 880 | /* Display HPLL off SR */ |
| 881 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 882 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 883 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 884 | reg = I915_READ(DSPFW3); |
| 885 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 886 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 887 | I915_WRITE(DSPFW3, reg); |
| 888 | |
| 889 | /* cursor HPLL off SR */ |
| 890 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 891 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 892 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 893 | reg = I915_READ(DSPFW3); |
| 894 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 895 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 896 | I915_WRITE(DSPFW3, reg); |
| 897 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 898 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 899 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 900 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 901 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 905 | /* |
| 906 | * Documentation says: |
| 907 | * "If the line size is small, the TLB fetches can get in the way of the |
| 908 | * data fetches, causing some lag in the pixel data return which is not |
| 909 | * accounted for in the above formulas. The following adjustment only |
| 910 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 911 | * The WM is adjusted upwards by the difference between the FIFO size |
| 912 | * and the size of 8 whole lines. This adjustment is always performed |
| 913 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 914 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 915 | 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] | 916 | { |
| 917 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 918 | |
| 919 | return max(0, tlb_miss); |
| 920 | } |
| 921 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 922 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 923 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 924 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 925 | enum pipe pipe; |
| 926 | |
| 927 | for_each_pipe(dev_priv, pipe) |
| 928 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 929 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 930 | I915_WRITE(DSPFW1, |
| 931 | FW_WM(wm->sr.plane, SR) | |
| 932 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 933 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 934 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 935 | I915_WRITE(DSPFW2, |
| 936 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 937 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 938 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 939 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 940 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 941 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 942 | I915_WRITE(DSPFW3, |
| 943 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 944 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 945 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 946 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 947 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 948 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 949 | } |
| 950 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 951 | #define FW_WM_VLV(value, plane) \ |
| 952 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 953 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 954 | 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] | 955 | const struct vlv_wm_values *wm) |
| 956 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 957 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 958 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 959 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 960 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 961 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 962 | I915_WRITE(VLV_DDL(pipe), |
| 963 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 964 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 965 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 966 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 967 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 968 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 969 | /* |
| 970 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 971 | * high order bits so that there are no out of bounds values |
| 972 | * present in the registers during the reprogramming. |
| 973 | */ |
| 974 | I915_WRITE(DSPHOWM, 0); |
| 975 | I915_WRITE(DSPHOWM1, 0); |
| 976 | I915_WRITE(DSPFW4, 0); |
| 977 | I915_WRITE(DSPFW5, 0); |
| 978 | I915_WRITE(DSPFW6, 0); |
| 979 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 980 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 981 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 982 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 983 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 984 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 985 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 986 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 987 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 988 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 989 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 990 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 991 | |
| 992 | if (IS_CHERRYVIEW(dev_priv)) { |
| 993 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 994 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 995 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 996 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 997 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 998 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 999 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1000 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1001 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1002 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1003 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1004 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1005 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1006 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 1007 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1008 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1009 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1010 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1011 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1012 | 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] | 1013 | } else { |
| 1014 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1015 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1016 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1017 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1018 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1019 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1020 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1021 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1022 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1023 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1024 | 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] | 1025 | } |
| 1026 | |
| 1027 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1028 | } |
| 1029 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1030 | #undef FW_WM_VLV |
| 1031 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1032 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1033 | { |
| 1034 | /* all latencies in usec */ |
| 1035 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1036 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1037 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1038 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1039 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1043 | { |
| 1044 | /* |
| 1045 | * DSPCNTR[13] supposedly controls whether the |
| 1046 | * primary plane can use the FIFO space otherwise |
| 1047 | * reserved for the sprite plane. It's not 100% clear |
| 1048 | * what the actual FIFO size is, but it looks like we |
| 1049 | * can happily set both primary and sprite watermarks |
| 1050 | * up to 127 cachelines. So that would seem to mean |
| 1051 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1052 | * the total FIFO is >= 256 cachelines in size. Either |
| 1053 | * way, we don't seem to have to worry about this |
| 1054 | * repartitioning as the maximum watermark value the |
| 1055 | * register can hold for each plane is lower than the |
| 1056 | * minimum FIFO size. |
| 1057 | */ |
| 1058 | switch (plane_id) { |
| 1059 | case PLANE_CURSOR: |
| 1060 | return 63; |
| 1061 | case PLANE_PRIMARY: |
| 1062 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1063 | case PLANE_SPRITE0: |
| 1064 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1065 | default: |
| 1066 | MISSING_CASE(plane_id); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | static int g4x_fbc_fifo_size(int level) |
| 1072 | { |
| 1073 | switch (level) { |
| 1074 | case G4X_WM_LEVEL_SR: |
| 1075 | return 7; |
| 1076 | case G4X_WM_LEVEL_HPLL: |
| 1077 | return 15; |
| 1078 | default: |
| 1079 | MISSING_CASE(level); |
| 1080 | return 0; |
| 1081 | } |
| 1082 | } |
| 1083 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1084 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1085 | const struct intel_plane_state *plane_state, |
| 1086 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1087 | { |
| 1088 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1089 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 1090 | const struct drm_display_mode *adjusted_mode = |
| 1091 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1092 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1093 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1094 | |
| 1095 | if (latency == 0) |
| 1096 | return USHRT_MAX; |
| 1097 | |
| 1098 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1099 | return 0; |
| 1100 | |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1101 | cpp = plane_state->base.fb->format->cpp[0]; |
| 1102 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1103 | /* |
| 1104 | * Not 100% sure which way ELK should go here as the |
| 1105 | * spec only says CL/CTG should assume 32bpp and BW |
| 1106 | * doesn't need to. But as these things followed the |
| 1107 | * mobile vs. desktop lines on gen3 as well, let's |
| 1108 | * assume ELK doesn't need this. |
| 1109 | * |
| 1110 | * The spec also fails to list such a restriction for |
| 1111 | * the HPLL watermark, which seems a little strange. |
| 1112 | * Let's use 32bpp for the HPLL watermark as well. |
| 1113 | */ |
| 1114 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1115 | level != G4X_WM_LEVEL_NORMAL) |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1116 | cpp = max(cpp, 4u); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1117 | |
| 1118 | clock = adjusted_mode->crtc_clock; |
| 1119 | htotal = adjusted_mode->crtc_htotal; |
| 1120 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 1121 | width = drm_rect_width(&plane_state->base.dst); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1122 | |
| 1123 | if (plane->id == PLANE_CURSOR) { |
| 1124 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1125 | } else if (plane->id == PLANE_PRIMARY && |
| 1126 | level == G4X_WM_LEVEL_NORMAL) { |
| 1127 | wm = intel_wm_method1(clock, cpp, latency); |
| 1128 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1129 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1130 | |
| 1131 | small = intel_wm_method1(clock, cpp, latency); |
| 1132 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1133 | |
| 1134 | wm = min(small, large); |
| 1135 | } |
| 1136 | |
| 1137 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1138 | width, cpp); |
| 1139 | |
| 1140 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1141 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1142 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1146 | int level, enum plane_id plane_id, u16 value) |
| 1147 | { |
| 1148 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1149 | bool dirty = false; |
| 1150 | |
| 1151 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1152 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1153 | |
| 1154 | dirty |= raw->plane[plane_id] != value; |
| 1155 | raw->plane[plane_id] = value; |
| 1156 | } |
| 1157 | |
| 1158 | return dirty; |
| 1159 | } |
| 1160 | |
| 1161 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1162 | int level, u16 value) |
| 1163 | { |
| 1164 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1165 | bool dirty = false; |
| 1166 | |
| 1167 | /* NORMAL level doesn't have an FBC watermark */ |
| 1168 | level = max(level, G4X_WM_LEVEL_SR); |
| 1169 | |
| 1170 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1171 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1172 | |
| 1173 | dirty |= raw->fbc != value; |
| 1174 | raw->fbc = value; |
| 1175 | } |
| 1176 | |
| 1177 | return dirty; |
| 1178 | } |
| 1179 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 1180 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 1181 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1182 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1183 | |
| 1184 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1185 | const struct intel_plane_state *plane_state) |
| 1186 | { |
| 1187 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1188 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1189 | enum plane_id plane_id = plane->id; |
| 1190 | bool dirty = false; |
| 1191 | int level; |
| 1192 | |
| 1193 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1194 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1195 | if (plane_id == PLANE_PRIMARY) |
| 1196 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1197 | goto out; |
| 1198 | } |
| 1199 | |
| 1200 | for (level = 0; level < num_levels; level++) { |
| 1201 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1202 | int wm, max_wm; |
| 1203 | |
| 1204 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1205 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1206 | |
| 1207 | if (wm > max_wm) |
| 1208 | break; |
| 1209 | |
| 1210 | dirty |= raw->plane[plane_id] != wm; |
| 1211 | raw->plane[plane_id] = wm; |
| 1212 | |
| 1213 | if (plane_id != PLANE_PRIMARY || |
| 1214 | level == G4X_WM_LEVEL_NORMAL) |
| 1215 | continue; |
| 1216 | |
| 1217 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1218 | raw->plane[plane_id]); |
| 1219 | max_wm = g4x_fbc_fifo_size(level); |
| 1220 | |
| 1221 | /* |
| 1222 | * FBC wm is not mandatory as we |
| 1223 | * can always just disable its use. |
| 1224 | */ |
| 1225 | if (wm > max_wm) |
| 1226 | wm = USHRT_MAX; |
| 1227 | |
| 1228 | dirty |= raw->fbc != wm; |
| 1229 | raw->fbc = wm; |
| 1230 | } |
| 1231 | |
| 1232 | /* mark watermarks as invalid */ |
| 1233 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1234 | |
| 1235 | if (plane_id == PLANE_PRIMARY) |
| 1236 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1237 | |
| 1238 | out: |
| 1239 | if (dirty) { |
| 1240 | DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1241 | plane->base.name, |
| 1242 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1243 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1244 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
| 1245 | |
| 1246 | if (plane_id == PLANE_PRIMARY) |
| 1247 | DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", |
| 1248 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1249 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
| 1250 | } |
| 1251 | |
| 1252 | return dirty; |
| 1253 | } |
| 1254 | |
| 1255 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1256 | enum plane_id plane_id, int level) |
| 1257 | { |
| 1258 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1259 | |
| 1260 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1261 | } |
| 1262 | |
| 1263 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1264 | int level) |
| 1265 | { |
| 1266 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1267 | |
| 1268 | if (level > dev_priv->wm.max_level) |
| 1269 | return false; |
| 1270 | |
| 1271 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1272 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1273 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1274 | } |
| 1275 | |
| 1276 | /* mark all levels starting from 'level' as invalid */ |
| 1277 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1278 | struct g4x_wm_state *wm_state, int level) |
| 1279 | { |
| 1280 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1281 | enum plane_id plane_id; |
| 1282 | |
| 1283 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1284 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1285 | } |
| 1286 | |
| 1287 | if (level <= G4X_WM_LEVEL_SR) { |
| 1288 | wm_state->cxsr = false; |
| 1289 | wm_state->sr.cursor = USHRT_MAX; |
| 1290 | wm_state->sr.plane = USHRT_MAX; |
| 1291 | wm_state->sr.fbc = USHRT_MAX; |
| 1292 | } |
| 1293 | |
| 1294 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1295 | wm_state->hpll_en = false; |
| 1296 | wm_state->hpll.cursor = USHRT_MAX; |
| 1297 | wm_state->hpll.plane = USHRT_MAX; |
| 1298 | wm_state->hpll.fbc = USHRT_MAX; |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1303 | { |
| 1304 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1305 | struct intel_atomic_state *state = |
| 1306 | to_intel_atomic_state(crtc_state->base.state); |
| 1307 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1308 | int num_active_planes = hweight8(crtc_state->active_planes & |
| 1309 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1310 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1311 | const struct intel_plane_state *old_plane_state; |
| 1312 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1313 | struct intel_plane *plane; |
| 1314 | enum plane_id plane_id; |
| 1315 | int i, level; |
| 1316 | unsigned int dirty = 0; |
| 1317 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1318 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1319 | old_plane_state, |
| 1320 | new_plane_state, i) { |
| 1321 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1322 | old_plane_state->base.crtc != &crtc->base) |
| 1323 | continue; |
| 1324 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1325 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1326 | dirty |= BIT(plane->id); |
| 1327 | } |
| 1328 | |
| 1329 | if (!dirty) |
| 1330 | return 0; |
| 1331 | |
| 1332 | level = G4X_WM_LEVEL_NORMAL; |
| 1333 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1334 | goto out; |
| 1335 | |
| 1336 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1337 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1338 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1339 | |
| 1340 | level = G4X_WM_LEVEL_SR; |
| 1341 | |
| 1342 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1343 | goto out; |
| 1344 | |
| 1345 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1346 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1347 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1348 | wm_state->sr.fbc = raw->fbc; |
| 1349 | |
| 1350 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1351 | |
| 1352 | level = G4X_WM_LEVEL_HPLL; |
| 1353 | |
| 1354 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1355 | goto out; |
| 1356 | |
| 1357 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1358 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1359 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1360 | wm_state->hpll.fbc = raw->fbc; |
| 1361 | |
| 1362 | wm_state->hpll_en = wm_state->cxsr; |
| 1363 | |
| 1364 | level++; |
| 1365 | |
| 1366 | out: |
| 1367 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1368 | return -EINVAL; |
| 1369 | |
| 1370 | /* invalidate the higher levels */ |
| 1371 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1372 | |
| 1373 | /* |
| 1374 | * Determine if the FBC watermark(s) can be used. IF |
| 1375 | * this isn't the case we prefer to disable the FBC |
| 1376 | ( watermark(s) rather than disable the SR/HPLL |
| 1377 | * level(s) entirely. |
| 1378 | */ |
| 1379 | wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL; |
| 1380 | |
| 1381 | if (level >= G4X_WM_LEVEL_SR && |
| 1382 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1383 | wm_state->fbc_en = false; |
| 1384 | else if (level >= G4X_WM_LEVEL_HPLL && |
| 1385 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1386 | wm_state->fbc_en = false; |
| 1387 | |
| 1388 | return 0; |
| 1389 | } |
| 1390 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1391 | 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] | 1392 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1393 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1394 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1395 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
| 1396 | struct intel_atomic_state *intel_state = |
| 1397 | to_intel_atomic_state(new_crtc_state->base.state); |
| 1398 | const struct intel_crtc_state *old_crtc_state = |
| 1399 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 1400 | 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] | 1401 | enum plane_id plane_id; |
| 1402 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1403 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 1404 | *intermediate = *optimal; |
| 1405 | |
| 1406 | intermediate->cxsr = false; |
| 1407 | intermediate->hpll_en = false; |
| 1408 | goto out; |
| 1409 | } |
| 1410 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1411 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1412 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1413 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1414 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1415 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1416 | |
| 1417 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1418 | intermediate->wm.plane[plane_id] = |
| 1419 | max(optimal->wm.plane[plane_id], |
| 1420 | active->wm.plane[plane_id]); |
| 1421 | |
| 1422 | WARN_ON(intermediate->wm.plane[plane_id] > |
| 1423 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
| 1424 | } |
| 1425 | |
| 1426 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1427 | active->sr.plane); |
| 1428 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1429 | active->sr.cursor); |
| 1430 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1431 | active->sr.fbc); |
| 1432 | |
| 1433 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1434 | active->hpll.plane); |
| 1435 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1436 | active->hpll.cursor); |
| 1437 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1438 | active->hpll.fbc); |
| 1439 | |
| 1440 | WARN_ON((intermediate->sr.plane > |
| 1441 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1442 | intermediate->sr.cursor > |
| 1443 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1444 | intermediate->cxsr); |
| 1445 | WARN_ON((intermediate->sr.plane > |
| 1446 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1447 | intermediate->sr.cursor > |
| 1448 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1449 | intermediate->hpll_en); |
| 1450 | |
| 1451 | WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1452 | intermediate->fbc_en && intermediate->cxsr); |
| 1453 | WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1454 | intermediate->fbc_en && intermediate->hpll_en); |
| 1455 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1456 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1457 | /* |
| 1458 | * If our intermediate WM are identical to the final WM, then we can |
| 1459 | * omit the post-vblank programming; only update if it's different. |
| 1460 | */ |
| 1461 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1462 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1463 | |
| 1464 | return 0; |
| 1465 | } |
| 1466 | |
| 1467 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1468 | struct g4x_wm_values *wm) |
| 1469 | { |
| 1470 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1471 | int num_active_pipes = 0; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1472 | |
| 1473 | wm->cxsr = true; |
| 1474 | wm->hpll_en = true; |
| 1475 | wm->fbc_en = true; |
| 1476 | |
| 1477 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1478 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1479 | |
| 1480 | if (!crtc->active) |
| 1481 | continue; |
| 1482 | |
| 1483 | if (!wm_state->cxsr) |
| 1484 | wm->cxsr = false; |
| 1485 | if (!wm_state->hpll_en) |
| 1486 | wm->hpll_en = false; |
| 1487 | if (!wm_state->fbc_en) |
| 1488 | wm->fbc_en = false; |
| 1489 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1490 | num_active_pipes++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1491 | } |
| 1492 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1493 | if (num_active_pipes != 1) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1494 | wm->cxsr = false; |
| 1495 | wm->hpll_en = false; |
| 1496 | wm->fbc_en = false; |
| 1497 | } |
| 1498 | |
| 1499 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1500 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1501 | enum pipe pipe = crtc->pipe; |
| 1502 | |
| 1503 | wm->pipe[pipe] = wm_state->wm; |
| 1504 | if (crtc->active && wm->cxsr) |
| 1505 | wm->sr = wm_state->sr; |
| 1506 | if (crtc->active && wm->hpll_en) |
| 1507 | wm->hpll = wm_state->hpll; |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1512 | { |
| 1513 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1514 | struct g4x_wm_values new_wm = {}; |
| 1515 | |
| 1516 | g4x_merge_wm(dev_priv, &new_wm); |
| 1517 | |
| 1518 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1519 | return; |
| 1520 | |
| 1521 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1522 | _intel_set_memory_cxsr(dev_priv, false); |
| 1523 | |
| 1524 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1525 | |
| 1526 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1527 | _intel_set_memory_cxsr(dev_priv, true); |
| 1528 | |
| 1529 | *old_wm = new_wm; |
| 1530 | } |
| 1531 | |
| 1532 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
| 1533 | struct intel_crtc_state *crtc_state) |
| 1534 | { |
| 1535 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1536 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1537 | |
| 1538 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1539 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1540 | g4x_program_watermarks(dev_priv); |
| 1541 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1542 | } |
| 1543 | |
| 1544 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
| 1545 | struct intel_crtc_state *crtc_state) |
| 1546 | { |
| 1547 | 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] | 1548 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1549 | |
| 1550 | if (!crtc_state->wm.need_postvbl_update) |
| 1551 | return; |
| 1552 | |
| 1553 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 1554 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1555 | g4x_program_watermarks(dev_priv); |
| 1556 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1557 | } |
| 1558 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1559 | /* latency must be in 0.1us units. */ |
| 1560 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1561 | unsigned int htotal, |
| 1562 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1563 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1564 | unsigned int latency) |
| 1565 | { |
| 1566 | unsigned int ret; |
| 1567 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1568 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1569 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1570 | ret = DIV_ROUND_UP(ret, 64); |
| 1571 | |
| 1572 | return ret; |
| 1573 | } |
| 1574 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1575 | 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] | 1576 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1577 | /* all latencies in usec */ |
| 1578 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1579 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1580 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1581 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1582 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1583 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1584 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1585 | |
| 1586 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1590 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1591 | const struct intel_plane_state *plane_state, |
| 1592 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1593 | { |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1594 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1595 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1596 | const struct drm_display_mode *adjusted_mode = |
| 1597 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1598 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1599 | |
| 1600 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1601 | return USHRT_MAX; |
| 1602 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1603 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1604 | return 0; |
| 1605 | |
Daniel Vetter | ef426c1 | 2017-01-04 11:41:10 +0100 | [diff] [blame] | 1606 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1607 | clock = adjusted_mode->crtc_clock; |
| 1608 | htotal = adjusted_mode->crtc_htotal; |
| 1609 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1610 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1611 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1612 | /* |
| 1613 | * FIXME the formula gives values that are |
| 1614 | * too big for the cursor FIFO, and hence we |
| 1615 | * would never be able to use cursors. For |
| 1616 | * now just hardcode the watermark. |
| 1617 | */ |
| 1618 | wm = 63; |
| 1619 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1620 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1621 | dev_priv->wm.pri_latency[level] * 10); |
| 1622 | } |
| 1623 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1624 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1625 | } |
| 1626 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1627 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1628 | { |
| 1629 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1630 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1631 | } |
| 1632 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1633 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1634 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1635 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1636 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1637 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1638 | 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] | 1639 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1640 | int num_active_planes = hweight8(active_planes); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1641 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1642 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1643 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1644 | unsigned int total_rate; |
| 1645 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1646 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1647 | /* |
| 1648 | * When enabling sprite0 after sprite1 has already been enabled |
| 1649 | * we tend to get an underrun unless sprite0 already has some |
| 1650 | * FIFO space allcoated. Hence we always allocate at least one |
| 1651 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1652 | * |
| 1653 | * All other plane enable sequences appear immune to this problem. |
| 1654 | */ |
| 1655 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1656 | sprite0_fifo_extra = 1; |
| 1657 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1658 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1659 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1660 | raw->plane[PLANE_SPRITE1] + |
| 1661 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1662 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1663 | if (total_rate > fifo_size) |
| 1664 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1665 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1666 | if (total_rate == 0) |
| 1667 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1668 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1669 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1670 | unsigned int rate; |
| 1671 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1672 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1673 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1674 | continue; |
| 1675 | } |
| 1676 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1677 | rate = raw->plane[plane_id]; |
| 1678 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1679 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1680 | } |
| 1681 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1682 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1683 | fifo_left -= sprite0_fifo_extra; |
| 1684 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1685 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1686 | |
| 1687 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1688 | |
| 1689 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1690 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1691 | int plane_extra; |
| 1692 | |
| 1693 | if (fifo_left == 0) |
| 1694 | break; |
| 1695 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1696 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1697 | continue; |
| 1698 | |
| 1699 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1700 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1701 | fifo_left -= plane_extra; |
| 1702 | } |
| 1703 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1704 | WARN_ON(active_planes != 0 && fifo_left != 0); |
| 1705 | |
| 1706 | /* give it all to the first plane if none are active */ |
| 1707 | if (active_planes == 0) { |
| 1708 | WARN_ON(fifo_left != fifo_size); |
| 1709 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1710 | } |
| 1711 | |
| 1712 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1713 | } |
| 1714 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1715 | /* mark all levels starting from 'level' as invalid */ |
| 1716 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1717 | struct vlv_wm_state *wm_state, int level) |
| 1718 | { |
| 1719 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1720 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1721 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1722 | enum plane_id plane_id; |
| 1723 | |
| 1724 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1725 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1726 | |
| 1727 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1728 | wm_state->sr[level].plane = USHRT_MAX; |
| 1729 | } |
| 1730 | } |
| 1731 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1732 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1733 | { |
| 1734 | if (wm > fifo_size) |
| 1735 | return USHRT_MAX; |
| 1736 | else |
| 1737 | return fifo_size - wm; |
| 1738 | } |
| 1739 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1740 | /* |
| 1741 | * Starting from 'level' set all higher |
| 1742 | * levels to 'value' in the "raw" watermarks. |
| 1743 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1744 | 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] | 1745 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1746 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1747 | 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] | 1748 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1749 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1750 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1751 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1752 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1753 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1754 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1755 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1756 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1757 | |
| 1758 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1759 | } |
| 1760 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1761 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1762 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1763 | { |
| 1764 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1765 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1766 | 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] | 1767 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1768 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1769 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1770 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1771 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1772 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1776 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1777 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1778 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1779 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1780 | if (wm > max_wm) |
| 1781 | break; |
| 1782 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1783 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1784 | raw->plane[plane_id] = wm; |
| 1785 | } |
| 1786 | |
| 1787 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1788 | 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] | 1789 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1790 | out: |
| 1791 | if (dirty) |
Ville Syrjälä | 57a6528 | 2017-04-21 21:14:22 +0300 | [diff] [blame] | 1792 | 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] | 1793 | plane->base.name, |
| 1794 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1795 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1796 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
| 1797 | |
| 1798 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1799 | } |
| 1800 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1801 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1802 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1803 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1804 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1805 | &crtc_state->wm.vlv.raw[level]; |
| 1806 | const struct vlv_fifo_state *fifo_state = |
| 1807 | &crtc_state->wm.vlv.fifo_state; |
| 1808 | |
| 1809 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1810 | } |
| 1811 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1812 | 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] | 1813 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1814 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1815 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1816 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1817 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | 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] | 1821 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1822 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1823 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1824 | struct intel_atomic_state *state = |
| 1825 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1826 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1827 | const struct vlv_fifo_state *fifo_state = |
| 1828 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1829 | int num_active_planes = hweight8(crtc_state->active_planes & |
| 1830 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1831 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->base); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1832 | const struct intel_plane_state *old_plane_state; |
| 1833 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1834 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1835 | enum plane_id plane_id; |
| 1836 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1837 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1838 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1839 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1840 | old_plane_state, |
| 1841 | new_plane_state, i) { |
| 1842 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1843 | old_plane_state->base.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1844 | continue; |
| 1845 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1846 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1847 | dirty |= BIT(plane->id); |
| 1848 | } |
| 1849 | |
| 1850 | /* |
| 1851 | * DSPARB registers may have been reset due to the |
| 1852 | * power well being turned off. Make sure we restore |
| 1853 | * them to a consistent state even if no primary/sprite |
| 1854 | * planes are initially active. |
| 1855 | */ |
| 1856 | if (needs_modeset) |
| 1857 | crtc_state->fifo_changed = true; |
| 1858 | |
| 1859 | if (!dirty) |
| 1860 | return 0; |
| 1861 | |
| 1862 | /* cursor changes don't warrant a FIFO recompute */ |
| 1863 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1864 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1865 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1866 | const struct vlv_fifo_state *old_fifo_state = |
| 1867 | &old_crtc_state->wm.vlv.fifo_state; |
| 1868 | |
| 1869 | ret = vlv_compute_fifo(crtc_state); |
| 1870 | if (ret) |
| 1871 | return ret; |
| 1872 | |
| 1873 | if (needs_modeset || |
| 1874 | memcmp(old_fifo_state, fifo_state, |
| 1875 | sizeof(*fifo_state)) != 0) |
| 1876 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1877 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1878 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1879 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1880 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1881 | /* |
| 1882 | * Note that enabling cxsr with no primary/sprite planes |
| 1883 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1884 | * with exactly one enabled primary/sprite plane. |
| 1885 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1886 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1887 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1888 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1889 | const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 1890 | 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] | 1891 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1892 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1893 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1894 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1895 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1896 | wm_state->wm[level].plane[plane_id] = |
| 1897 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1898 | fifo_state->plane[plane_id]); |
| 1899 | } |
| 1900 | |
| 1901 | wm_state->sr[level].plane = |
| 1902 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1903 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1904 | raw->plane[PLANE_SPRITE1]), |
| 1905 | sr_fifo_size); |
| 1906 | |
| 1907 | wm_state->sr[level].cursor = |
| 1908 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1909 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1910 | } |
| 1911 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1912 | if (level == 0) |
| 1913 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1914 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1915 | /* limit to only levels we can actually handle */ |
| 1916 | wm_state->num_levels = level; |
| 1917 | |
| 1918 | /* invalidate the higher levels */ |
| 1919 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1920 | |
| 1921 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1922 | } |
| 1923 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1924 | #define VLV_FIFO(plane, value) \ |
| 1925 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1926 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1927 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
| 1928 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1929 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1930 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1931 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1932 | struct intel_uncore *uncore = &dev_priv->uncore; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1933 | const struct vlv_fifo_state *fifo_state = |
| 1934 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1935 | int sprite0_start, sprite1_start, fifo_size; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1936 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1937 | if (!crtc_state->fifo_changed) |
| 1938 | return; |
| 1939 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1940 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 1941 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 1942 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1943 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1944 | WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63); |
| 1945 | WARN_ON(fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1946 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1947 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 1948 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1949 | /* |
| 1950 | * uncore.lock serves a double purpose here. It allows us to |
| 1951 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 1952 | * it protects the DSPARB registers from getting clobbered by |
| 1953 | * parallel updates from multiple pipes. |
| 1954 | * |
| 1955 | * intel_pipe_update_start() has already disabled interrupts |
| 1956 | * for us, so a plain spin_lock() is sufficient here. |
| 1957 | */ |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1958 | spin_lock(&uncore->lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1959 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1960 | switch (crtc->pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1961 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1962 | case PIPE_A: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1963 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 1964 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1965 | |
| 1966 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1967 | VLV_FIFO(SPRITEB, 0xff)); |
| 1968 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1969 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1970 | |
| 1971 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1972 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1973 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1974 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1975 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1976 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 1977 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1978 | break; |
| 1979 | case PIPE_B: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1980 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 1981 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1982 | |
| 1983 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 1984 | VLV_FIFO(SPRITED, 0xff)); |
| 1985 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 1986 | VLV_FIFO(SPRITED, sprite1_start)); |
| 1987 | |
| 1988 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 1989 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 1990 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 1991 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 1992 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1993 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 1994 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1995 | break; |
| 1996 | case PIPE_C: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1997 | dsparb3 = intel_uncore_read_fw(uncore, DSPARB3); |
| 1998 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1999 | |
| 2000 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2001 | VLV_FIFO(SPRITEF, 0xff)); |
| 2002 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2003 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2004 | |
| 2005 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2006 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2007 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2008 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2009 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2010 | intel_uncore_write_fw(uncore, DSPARB3, dsparb3); |
| 2011 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2012 | break; |
| 2013 | default: |
| 2014 | break; |
| 2015 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2016 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2017 | intel_uncore_posting_read_fw(uncore, DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2018 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2019 | spin_unlock(&uncore->lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | #undef VLV_FIFO |
| 2023 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2024 | 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] | 2025 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2026 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2027 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2028 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
| 2029 | struct intel_atomic_state *intel_state = |
| 2030 | to_intel_atomic_state(new_crtc_state->base.state); |
| 2031 | const struct intel_crtc_state *old_crtc_state = |
| 2032 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 2033 | 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] | 2034 | int level; |
| 2035 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2036 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 2037 | *intermediate = *optimal; |
| 2038 | |
| 2039 | intermediate->cxsr = false; |
| 2040 | goto out; |
| 2041 | } |
| 2042 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2043 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2044 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2045 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2046 | |
| 2047 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2048 | enum plane_id plane_id; |
| 2049 | |
| 2050 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2051 | intermediate->wm[level].plane[plane_id] = |
| 2052 | min(optimal->wm[level].plane[plane_id], |
| 2053 | active->wm[level].plane[plane_id]); |
| 2054 | } |
| 2055 | |
| 2056 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2057 | active->sr[level].plane); |
| 2058 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2059 | active->sr[level].cursor); |
| 2060 | } |
| 2061 | |
| 2062 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2063 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2064 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2065 | /* |
| 2066 | * If our intermediate WM are identical to the final WM, then we can |
| 2067 | * omit the post-vblank programming; only update if it's different. |
| 2068 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2069 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2070 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2071 | |
| 2072 | return 0; |
| 2073 | } |
| 2074 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2075 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2076 | struct vlv_wm_values *wm) |
| 2077 | { |
| 2078 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2079 | int num_active_pipes = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2080 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2081 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2082 | wm->cxsr = true; |
| 2083 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2084 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2085 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2086 | |
| 2087 | if (!crtc->active) |
| 2088 | continue; |
| 2089 | |
| 2090 | if (!wm_state->cxsr) |
| 2091 | wm->cxsr = false; |
| 2092 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2093 | num_active_pipes++; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2094 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2095 | } |
| 2096 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2097 | if (num_active_pipes != 1) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2098 | wm->cxsr = false; |
| 2099 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2100 | if (num_active_pipes > 1) |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2101 | wm->level = VLV_WM_LEVEL_PM2; |
| 2102 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2103 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2104 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2105 | enum pipe pipe = crtc->pipe; |
| 2106 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2107 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2108 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2109 | wm->sr = wm_state->sr[wm->level]; |
| 2110 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2111 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2112 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2113 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2114 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2118 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2119 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2120 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2121 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2122 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2123 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2124 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2125 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2126 | return; |
| 2127 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2128 | 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] | 2129 | chv_set_memory_dvfs(dev_priv, false); |
| 2130 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2131 | 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] | 2132 | chv_set_memory_pm5(dev_priv, false); |
| 2133 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2134 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2135 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2136 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2137 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2138 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2139 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2140 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2141 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2142 | 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] | 2143 | chv_set_memory_pm5(dev_priv, true); |
| 2144 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2145 | 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] | 2146 | chv_set_memory_dvfs(dev_priv, true); |
| 2147 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2148 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2149 | } |
| 2150 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2151 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
| 2152 | struct intel_crtc_state *crtc_state) |
| 2153 | { |
| 2154 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2155 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2156 | |
| 2157 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2158 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2159 | vlv_program_watermarks(dev_priv); |
| 2160 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2161 | } |
| 2162 | |
| 2163 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
| 2164 | struct intel_crtc_state *crtc_state) |
| 2165 | { |
| 2166 | 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] | 2167 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2168 | |
| 2169 | if (!crtc_state->wm.need_postvbl_update) |
| 2170 | return; |
| 2171 | |
| 2172 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 2173 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2174 | vlv_program_watermarks(dev_priv); |
| 2175 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2176 | } |
| 2177 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2178 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2179 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2180 | 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] | 2181 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2182 | int srwm = 1; |
| 2183 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2184 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2185 | |
| 2186 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2187 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2188 | if (crtc) { |
| 2189 | /* self-refresh has much higher latency */ |
| 2190 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2191 | const struct drm_display_mode *adjusted_mode = |
| 2192 | &crtc->config->base.adjusted_mode; |
| 2193 | const struct drm_framebuffer *fb = |
| 2194 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2195 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2196 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2197 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2198 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2199 | int entries; |
| 2200 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2201 | entries = intel_wm_method2(clock, htotal, |
| 2202 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2203 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2204 | srwm = I965_FIFO_SIZE - entries; |
| 2205 | if (srwm < 0) |
| 2206 | srwm = 1; |
| 2207 | srwm &= 0x1ff; |
| 2208 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 2209 | entries, srwm); |
| 2210 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2211 | entries = intel_wm_method2(clock, htotal, |
| 2212 | crtc->base.cursor->state->crtc_w, 4, |
| 2213 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2214 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2215 | i965_cursor_wm_info.cacheline_size) + |
| 2216 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2217 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2218 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2219 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2220 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2221 | |
| 2222 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 2223 | "cursor %d\n", srwm, cursor_sr); |
| 2224 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2225 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2226 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2227 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2228 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2229 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2233 | srwm); |
| 2234 | |
| 2235 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2236 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2237 | FW_WM(8, CURSORB) | |
| 2238 | FW_WM(8, PLANEB) | |
| 2239 | FW_WM(8, PLANEA)); |
| 2240 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2241 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2242 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2243 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2244 | |
| 2245 | if (cxsr_enabled) |
| 2246 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2247 | } |
| 2248 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2249 | #undef FW_WM |
| 2250 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2251 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2252 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2253 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2254 | const struct intel_watermark_params *wm_info; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2255 | u32 fwater_lo; |
| 2256 | u32 fwater_hi; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2257 | int cwm, srwm = 1; |
| 2258 | int fifo_size; |
| 2259 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2260 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2261 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2262 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2263 | wm_info = &i945_wm_info; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2264 | else if (!IS_GEN(dev_priv, 2)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2265 | wm_info = &i915_wm_info; |
| 2266 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2267 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2268 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2269 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_A); |
| 2270 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2271 | if (intel_crtc_active(crtc)) { |
| 2272 | const struct drm_display_mode *adjusted_mode = |
| 2273 | &crtc->config->base.adjusted_mode; |
| 2274 | const struct drm_framebuffer *fb = |
| 2275 | crtc->base.primary->state->fb; |
| 2276 | int cpp; |
| 2277 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2278 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2279 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2280 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2281 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2282 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2283 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2284 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2285 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2286 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2287 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2288 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2289 | if (planea_wm > (long)wm_info->max_wm) |
| 2290 | planea_wm = wm_info->max_wm; |
| 2291 | } |
| 2292 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2293 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2294 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2295 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2296 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_B); |
| 2297 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2298 | if (intel_crtc_active(crtc)) { |
| 2299 | const struct drm_display_mode *adjusted_mode = |
| 2300 | &crtc->config->base.adjusted_mode; |
| 2301 | const struct drm_framebuffer *fb = |
| 2302 | crtc->base.primary->state->fb; |
| 2303 | int cpp; |
| 2304 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2305 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2306 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2307 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2308 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2309 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2310 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2311 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2312 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2313 | if (enabled == NULL) |
| 2314 | enabled = crtc; |
| 2315 | else |
| 2316 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2317 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2318 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2319 | if (planeb_wm > (long)wm_info->max_wm) |
| 2320 | planeb_wm = wm_info->max_wm; |
| 2321 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2322 | |
| 2323 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2324 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2325 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2326 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2327 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2328 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2329 | |
| 2330 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2331 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2332 | enabled = NULL; |
| 2333 | } |
| 2334 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2335 | /* |
| 2336 | * Overlay gets an aggressive default since video jitter is bad. |
| 2337 | */ |
| 2338 | cwm = 2; |
| 2339 | |
| 2340 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2341 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2342 | |
| 2343 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2344 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2345 | /* self-refresh has much higher latency */ |
| 2346 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2347 | const struct drm_display_mode *adjusted_mode = |
| 2348 | &enabled->config->base.adjusted_mode; |
| 2349 | const struct drm_framebuffer *fb = |
| 2350 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2351 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2352 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2353 | int hdisplay = enabled->config->pipe_src_w; |
| 2354 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2355 | int entries; |
| 2356 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2357 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2358 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2359 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2360 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2361 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2362 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2363 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2364 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 2365 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 2366 | srwm = wm_info->fifo_size - entries; |
| 2367 | if (srwm < 0) |
| 2368 | srwm = 1; |
| 2369 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2370 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2371 | I915_WRITE(FW_BLC_SELF, |
| 2372 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2373 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2374 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2375 | } |
| 2376 | |
| 2377 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2378 | planea_wm, planeb_wm, cwm, srwm); |
| 2379 | |
| 2380 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2381 | fwater_hi = (cwm & 0x1f); |
| 2382 | |
| 2383 | /* Set request length to 8 cachelines per fetch */ |
| 2384 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2385 | fwater_hi = fwater_hi | (1 << 8); |
| 2386 | |
| 2387 | I915_WRITE(FW_BLC, fwater_lo); |
| 2388 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2389 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2390 | if (enabled) |
| 2391 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2392 | } |
| 2393 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2394 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2395 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2396 | 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] | 2397 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2398 | const struct drm_display_mode *adjusted_mode; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2399 | u32 fwater_lo; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2400 | int planea_wm; |
| 2401 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2402 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2403 | if (crtc == NULL) |
| 2404 | return; |
| 2405 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2406 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2407 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2408 | &i845_wm_info, |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2409 | dev_priv->display.get_fifo_size(dev_priv, PLANE_A), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2410 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2411 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2412 | fwater_lo |= (3<<8) | planea_wm; |
| 2413 | |
| 2414 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 2415 | |
| 2416 | I915_WRITE(FW_BLC, fwater_lo); |
| 2417 | } |
| 2418 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2419 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2420 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2421 | unsigned int cpp, |
| 2422 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2423 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2424 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2425 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2426 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2427 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2428 | |
| 2429 | return ret; |
| 2430 | } |
| 2431 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2432 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2433 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2434 | unsigned int htotal, |
| 2435 | unsigned int width, |
| 2436 | unsigned int cpp, |
| 2437 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2438 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2439 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2440 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2441 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2442 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2443 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2444 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2445 | return ret; |
| 2446 | } |
| 2447 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2448 | 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] | 2449 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2450 | /* |
| 2451 | * Neither of these should be possible since this function shouldn't be |
| 2452 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2453 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2454 | * elsewhere in the driver. |
| 2455 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2456 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2457 | return 0; |
| 2458 | if (WARN_ON(!horiz_pixels)) |
| 2459 | return 0; |
| 2460 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2461 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2462 | } |
| 2463 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2464 | struct ilk_wm_maximums { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2465 | u16 pri; |
| 2466 | u16 spr; |
| 2467 | u16 cur; |
| 2468 | u16 fbc; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2469 | }; |
| 2470 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2471 | /* |
| 2472 | * For both WM_PIPE and WM_LP. |
| 2473 | * mem_value must be in 0.1us units. |
| 2474 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2475 | static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state, |
| 2476 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2477 | u32 mem_value, bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2478 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2479 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2480 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2481 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2482 | if (mem_value == 0) |
| 2483 | return U32_MAX; |
| 2484 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2485 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2486 | return 0; |
| 2487 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2488 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2489 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2490 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2491 | |
| 2492 | if (!is_lp) |
| 2493 | return method1; |
| 2494 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2495 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
| 2496 | crtc_state->base.adjusted_mode.crtc_htotal, |
| 2497 | drm_rect_width(&plane_state->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2498 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2499 | |
| 2500 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2501 | } |
| 2502 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2503 | /* |
| 2504 | * For both WM_PIPE and WM_LP. |
| 2505 | * mem_value must be in 0.1us units. |
| 2506 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2507 | static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state, |
| 2508 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2509 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2510 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2511 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2512 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2513 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2514 | if (mem_value == 0) |
| 2515 | return U32_MAX; |
| 2516 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2517 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2518 | return 0; |
| 2519 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2520 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2521 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2522 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
| 2523 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
| 2524 | crtc_state->base.adjusted_mode.crtc_htotal, |
| 2525 | drm_rect_width(&plane_state->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2526 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2527 | return min(method1, method2); |
| 2528 | } |
| 2529 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2530 | /* |
| 2531 | * For both WM_PIPE and WM_LP. |
| 2532 | * mem_value must be in 0.1us units. |
| 2533 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2534 | static u32 ilk_compute_cur_wm(const struct intel_crtc_state *crtc_state, |
| 2535 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2536 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2537 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2538 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2539 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2540 | if (mem_value == 0) |
| 2541 | return U32_MAX; |
| 2542 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2543 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2544 | return 0; |
| 2545 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2546 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2547 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2548 | return ilk_wm_method2(crtc_state->pixel_rate, |
| 2549 | crtc_state->base.adjusted_mode.crtc_htotal, |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 2550 | drm_rect_width(&plane_state->base.dst), |
| 2551 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2552 | } |
| 2553 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2554 | /* Only for WM_LP. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2555 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 2556 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2557 | u32 pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2558 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2559 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2560 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2561 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2562 | return 0; |
| 2563 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2564 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2565 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2566 | 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] | 2567 | } |
| 2568 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2569 | static unsigned int |
| 2570 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2571 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2572 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2573 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2574 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2575 | return 768; |
| 2576 | else |
| 2577 | return 512; |
| 2578 | } |
| 2579 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2580 | static unsigned int |
| 2581 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2582 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2583 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2584 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2585 | /* BDW primary/sprite plane watermarks */ |
| 2586 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2587 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2588 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2589 | return level == 0 ? 127 : 1023; |
| 2590 | else if (!is_sprite) |
| 2591 | /* ILK/SNB primary plane watermarks */ |
| 2592 | return level == 0 ? 127 : 511; |
| 2593 | else |
| 2594 | /* ILK/SNB sprite plane watermarks */ |
| 2595 | return level == 0 ? 63 : 255; |
| 2596 | } |
| 2597 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2598 | static unsigned int |
| 2599 | 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] | 2600 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2601 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2602 | return level == 0 ? 63 : 255; |
| 2603 | else |
| 2604 | return level == 0 ? 31 : 63; |
| 2605 | } |
| 2606 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2607 | 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] | 2608 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2609 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2610 | return 31; |
| 2611 | else |
| 2612 | return 15; |
| 2613 | } |
| 2614 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2615 | /* Calculate the maximum primary/sprite plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2616 | 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] | 2617 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2618 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2619 | enum intel_ddb_partitioning ddb_partitioning, |
| 2620 | bool is_sprite) |
| 2621 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2622 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2623 | |
| 2624 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2625 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2626 | return 0; |
| 2627 | |
| 2628 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2629 | if (level == 0 || config->num_pipes_active > 1) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 2630 | fifo_size /= INTEL_NUM_PIPES(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2631 | |
| 2632 | /* |
| 2633 | * For some reason the non self refresh |
| 2634 | * FIFO size is only half of the self |
| 2635 | * refresh FIFO size on ILK/SNB. |
| 2636 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2637 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2638 | fifo_size /= 2; |
| 2639 | } |
| 2640 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2641 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2642 | /* level 0 is always calculated with 1:1 split */ |
| 2643 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2644 | if (is_sprite) |
| 2645 | fifo_size *= 5; |
| 2646 | fifo_size /= 6; |
| 2647 | } else { |
| 2648 | fifo_size /= 2; |
| 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2653 | 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] | 2654 | } |
| 2655 | |
| 2656 | /* Calculate the maximum cursor plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2657 | 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] | 2658 | int level, |
| 2659 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2660 | { |
| 2661 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2662 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2663 | return 64; |
| 2664 | |
| 2665 | /* otherwise just report max that registers can hold */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2666 | return ilk_cursor_wm_reg_max(dev_priv, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2667 | } |
| 2668 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2669 | 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] | 2670 | int level, |
| 2671 | const struct intel_wm_config *config, |
| 2672 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2673 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2674 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2675 | max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false); |
| 2676 | max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true); |
| 2677 | max->cur = ilk_cursor_wm_max(dev_priv, level, config); |
| 2678 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2679 | } |
| 2680 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2681 | 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] | 2682 | int level, |
| 2683 | struct ilk_wm_maximums *max) |
| 2684 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2685 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2686 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2687 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2688 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2689 | } |
| 2690 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2691 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2692 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2693 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2694 | { |
| 2695 | bool ret; |
| 2696 | |
| 2697 | /* already determined to be invalid? */ |
| 2698 | if (!result->enable) |
| 2699 | return false; |
| 2700 | |
| 2701 | result->enable = result->pri_val <= max->pri && |
| 2702 | result->spr_val <= max->spr && |
| 2703 | result->cur_val <= max->cur; |
| 2704 | |
| 2705 | ret = result->enable; |
| 2706 | |
| 2707 | /* |
| 2708 | * HACK until we can pre-compute everything, |
| 2709 | * and thus fail gracefully if LP0 watermarks |
| 2710 | * are exceeded... |
| 2711 | */ |
| 2712 | if (level == 0 && !result->enable) { |
| 2713 | if (result->pri_val > max->pri) |
| 2714 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2715 | level, result->pri_val, max->pri); |
| 2716 | if (result->spr_val > max->spr) |
| 2717 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2718 | level, result->spr_val, max->spr); |
| 2719 | if (result->cur_val > max->cur) |
| 2720 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2721 | level, result->cur_val, max->cur); |
| 2722 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2723 | result->pri_val = min_t(u32, result->pri_val, max->pri); |
| 2724 | result->spr_val = min_t(u32, result->spr_val, max->spr); |
| 2725 | result->cur_val = min_t(u32, result->cur_val, max->cur); |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2726 | result->enable = true; |
| 2727 | } |
| 2728 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2729 | return ret; |
| 2730 | } |
| 2731 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2732 | 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] | 2733 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2734 | int level, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2735 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2736 | const struct intel_plane_state *pristate, |
| 2737 | const struct intel_plane_state *sprstate, |
| 2738 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2739 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2740 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2741 | u16 pri_latency = dev_priv->wm.pri_latency[level]; |
| 2742 | u16 spr_latency = dev_priv->wm.spr_latency[level]; |
| 2743 | u16 cur_latency = dev_priv->wm.cur_latency[level]; |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2744 | |
| 2745 | /* WM1+ latency values stored in 0.5us units */ |
| 2746 | if (level > 0) { |
| 2747 | pri_latency *= 5; |
| 2748 | spr_latency *= 5; |
| 2749 | cur_latency *= 5; |
| 2750 | } |
| 2751 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2752 | if (pristate) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2753 | result->pri_val = ilk_compute_pri_wm(crtc_state, pristate, |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2754 | pri_latency, level); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2755 | 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] | 2756 | } |
| 2757 | |
| 2758 | if (sprstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2759 | result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2760 | |
| 2761 | if (curstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2762 | result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2763 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2764 | result->enable = true; |
| 2765 | } |
| 2766 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2767 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2768 | hsw_compute_linetime_wm(const struct intel_crtc_state *crtc_state) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2769 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2770 | const struct intel_atomic_state *intel_state = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2771 | to_intel_atomic_state(crtc_state->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2772 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2773 | &crtc_state->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2774 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2775 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2776 | if (!crtc_state->base.active) |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2777 | return 0; |
| 2778 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2779 | return 0; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2780 | if (WARN_ON(intel_state->cdclk.logical.cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2781 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2782 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2783 | /* The WM are computed with base on how long it takes to fill a single |
| 2784 | * row at the given clock rate, multiplied by 8. |
| 2785 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2786 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2787 | adjusted_mode->crtc_clock); |
| 2788 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2789 | intel_state->cdclk.logical.cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2790 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2791 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2792 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2793 | } |
| 2794 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2795 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2796 | u16 wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2797 | { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2798 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 2799 | |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2800 | if (INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2801 | u32 val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2802 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2803 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2804 | |
| 2805 | /* read the first set of memory latencies[0:3] */ |
| 2806 | val = 0; /* data0 to be programmed to 0 for first set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2807 | ret = sandybridge_pcode_read(dev_priv, |
| 2808 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2809 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2810 | |
| 2811 | if (ret) { |
| 2812 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2813 | return; |
| 2814 | } |
| 2815 | |
| 2816 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2817 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2818 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2819 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2820 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2821 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2822 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2823 | |
| 2824 | /* read the second set of memory latencies[4:7] */ |
| 2825 | val = 1; /* data0 to be programmed to 1 for second set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2826 | ret = sandybridge_pcode_read(dev_priv, |
| 2827 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2828 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2829 | if (ret) { |
| 2830 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2831 | return; |
| 2832 | } |
| 2833 | |
| 2834 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2835 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2836 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2837 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2838 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2839 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2840 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2841 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2842 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2843 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2844 | * need to be disabled. We make sure to sanitize the values out |
| 2845 | * of the punit to satisfy this requirement. |
| 2846 | */ |
| 2847 | for (level = 1; level <= max_level; level++) { |
| 2848 | if (wm[level] == 0) { |
| 2849 | for (i = level + 1; i <= max_level; i++) |
| 2850 | wm[i] = 0; |
| 2851 | break; |
| 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | /* |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2856 | * WaWmMemoryReadLatency:skl+,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2857 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2858 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2859 | * to add 2us to the various latency levels we retrieve from the |
| 2860 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2861 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2862 | if (wm[0] == 0) { |
| 2863 | wm[0] += 2; |
| 2864 | for (level = 1; level <= max_level; level++) { |
| 2865 | if (wm[level] == 0) |
| 2866 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2867 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2868 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2869 | } |
| 2870 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2871 | /* |
| 2872 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2873 | * If we could not get dimm info enable this WA to prevent from |
| 2874 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2875 | * to avoid any underrun. |
| 2876 | */ |
Ville Syrjälä | 5d6f36b | 2018-10-23 21:21:02 +0300 | [diff] [blame] | 2877 | if (dev_priv->dram_info.is_16gb_dimm) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2878 | wm[0] += 1; |
| 2879 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2880 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2881 | u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2882 | |
| 2883 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2884 | if (wm[0] == 0) |
| 2885 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2886 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2887 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2888 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2889 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2890 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2891 | u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2892 | |
| 2893 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2894 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2895 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2896 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2897 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2898 | u32 mltr = intel_uncore_read(uncore, MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2899 | |
| 2900 | /* ILK primary LP0 latency is 700 ns */ |
| 2901 | wm[0] = 7; |
| 2902 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2903 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2904 | } else { |
| 2905 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2906 | } |
| 2907 | } |
| 2908 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2909 | 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] | 2910 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2911 | { |
| 2912 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2913 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2914 | wm[0] = 13; |
| 2915 | } |
| 2916 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2917 | 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] | 2918 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2919 | { |
| 2920 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2921 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2922 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2923 | } |
| 2924 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2925 | 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] | 2926 | { |
| 2927 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2928 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2929 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2930 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2931 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2932 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2933 | return 3; |
| 2934 | else |
| 2935 | return 2; |
| 2936 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2937 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2938 | 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] | 2939 | const char *name, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2940 | const u16 wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2941 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2942 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2943 | |
| 2944 | for (level = 0; level <= max_level; level++) { |
| 2945 | unsigned int latency = wm[level]; |
| 2946 | |
| 2947 | if (latency == 0) { |
Chris Wilson | 86c1c87 | 2018-07-26 17:15:27 +0100 | [diff] [blame] | 2948 | DRM_DEBUG_KMS("%s WM%d latency not provided\n", |
| 2949 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2950 | continue; |
| 2951 | } |
| 2952 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2953 | /* |
| 2954 | * - latencies are in us on gen9. |
| 2955 | * - before then, WM1+ latency values are in 0.5us units |
| 2956 | */ |
Paulo Zanoni | dfc267a | 2017-08-09 13:52:46 -0700 | [diff] [blame] | 2957 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2958 | latency *= 10; |
| 2959 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2960 | latency *= 5; |
| 2961 | |
| 2962 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2963 | name, level, wm[level], |
| 2964 | latency / 10, latency % 10); |
| 2965 | } |
| 2966 | } |
| 2967 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2968 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2969 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2970 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2971 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2972 | |
| 2973 | if (wm[0] >= min) |
| 2974 | return false; |
| 2975 | |
| 2976 | wm[0] = max(wm[0], min); |
| 2977 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2978 | 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] | 2979 | |
| 2980 | return true; |
| 2981 | } |
| 2982 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2983 | 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] | 2984 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2985 | bool changed; |
| 2986 | |
| 2987 | /* |
| 2988 | * The BIOS provided WM memory latency values are often |
| 2989 | * inadequate for high resolution displays. Adjust them. |
| 2990 | */ |
| 2991 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2992 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2993 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2994 | |
| 2995 | if (!changed) |
| 2996 | return; |
| 2997 | |
| 2998 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2999 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3000 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3001 | 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] | 3002 | } |
| 3003 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3004 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 3005 | { |
| 3006 | /* |
| 3007 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 3008 | * LP3 usage can cause vblank interrupts to be lost. |
| 3009 | * The DEIIR bit will go high but it looks like the CPU |
| 3010 | * never gets interrupted. |
| 3011 | * |
| 3012 | * It's not clear whether other interrupt source could |
| 3013 | * be affected or if this is somehow limited to vblank |
| 3014 | * interrupts only. To play it safe we disable LP3 |
| 3015 | * watermarks entirely. |
| 3016 | */ |
| 3017 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3018 | dev_priv->wm.spr_latency[3] == 0 && |
| 3019 | dev_priv->wm.cur_latency[3] == 0) |
| 3020 | return; |
| 3021 | |
| 3022 | dev_priv->wm.pri_latency[3] = 0; |
| 3023 | dev_priv->wm.spr_latency[3] = 0; |
| 3024 | dev_priv->wm.cur_latency[3] = 0; |
| 3025 | |
| 3026 | DRM_DEBUG_KMS("LP3 watermarks disabled due to potential for lost interrupts\n"); |
| 3027 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3028 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3029 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3030 | } |
| 3031 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3032 | 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] | 3033 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3034 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3035 | |
| 3036 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3037 | sizeof(dev_priv->wm.pri_latency)); |
| 3038 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3039 | sizeof(dev_priv->wm.pri_latency)); |
| 3040 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3041 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3042 | 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] | 3043 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3044 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3045 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3046 | 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] | 3047 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3048 | if (IS_GEN(dev_priv, 6)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3049 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3050 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3051 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3052 | } |
| 3053 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3054 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3055 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3056 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3057 | 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] | 3058 | } |
| 3059 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3060 | 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] | 3061 | struct intel_pipe_wm *pipe_wm) |
| 3062 | { |
| 3063 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3064 | const struct intel_wm_config config = { |
| 3065 | .num_pipes_active = 1, |
| 3066 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3067 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3068 | }; |
| 3069 | struct ilk_wm_maximums max; |
| 3070 | |
| 3071 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3072 | 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] | 3073 | |
| 3074 | /* At least LP0 must be valid */ |
| 3075 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 3076 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 3077 | return false; |
| 3078 | } |
| 3079 | |
| 3080 | return true; |
| 3081 | } |
| 3082 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3083 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3084 | static int ilk_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3085 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3086 | struct drm_atomic_state *state = crtc_state->base.state; |
| 3087 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3088 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3089 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3090 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3091 | struct intel_plane *plane; |
| 3092 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3093 | const struct intel_plane_state *pristate = NULL; |
| 3094 | const struct intel_plane_state *sprstate = NULL; |
| 3095 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3096 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3097 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3098 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3099 | pipe_wm = &crtc_state->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3100 | |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3101 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 3102 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 3103 | pristate = plane_state; |
| 3104 | else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
| 3105 | sprstate = plane_state; |
| 3106 | else if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 3107 | curstate = plane_state; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3110 | pipe_wm->pipe_enabled = crtc_state->base.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3111 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3112 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 3113 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 3114 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 3115 | 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] | 3116 | } |
| 3117 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3118 | usable_level = max_level; |
| 3119 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3120 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3121 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3122 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3123 | |
| 3124 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3125 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3126 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3127 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3128 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3129 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3130 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3131 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3132 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3133 | pipe_wm->linetime = hsw_compute_linetime_wm(crtc_state); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3134 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3135 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3136 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3137 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3138 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3139 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3140 | for (level = 1; level <= usable_level; level++) { |
| 3141 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3142 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3143 | ilk_compute_wm_level(dev_priv, intel_crtc, level, crtc_state, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3144 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3145 | |
| 3146 | /* |
| 3147 | * Disable any watermark level that exceeds the |
| 3148 | * register maximums since such watermarks are |
| 3149 | * always invalid. |
| 3150 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3151 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3152 | memset(wm, 0, sizeof(*wm)); |
| 3153 | break; |
| 3154 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3155 | } |
| 3156 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3157 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3161 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3162 | * state and the new state. These can be programmed to the hardware |
| 3163 | * immediately. |
| 3164 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3165 | static int ilk_compute_intermediate_wm(struct intel_crtc_state *newstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3166 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3167 | struct intel_crtc *intel_crtc = to_intel_crtc(newstate->base.crtc); |
| 3168 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3169 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3170 | struct intel_atomic_state *intel_state = |
| 3171 | to_intel_atomic_state(newstate->base.state); |
| 3172 | const struct intel_crtc_state *oldstate = |
| 3173 | intel_atomic_get_old_crtc_state(intel_state, intel_crtc); |
| 3174 | const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3175 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3176 | |
| 3177 | /* |
| 3178 | * Start with the final, target watermarks, then combine with the |
| 3179 | * currently active watermarks to get values that are safe both before |
| 3180 | * and after the vblank. |
| 3181 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3182 | *a = newstate->wm.ilk.optimal; |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 3183 | if (!newstate->base.active || drm_atomic_crtc_needs_modeset(&newstate->base) || |
| 3184 | intel_state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3185 | return 0; |
| 3186 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3187 | a->pipe_enabled |= b->pipe_enabled; |
| 3188 | a->sprites_enabled |= b->sprites_enabled; |
| 3189 | a->sprites_scaled |= b->sprites_scaled; |
| 3190 | |
| 3191 | for (level = 0; level <= max_level; level++) { |
| 3192 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3193 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3194 | |
| 3195 | a_wm->enable &= b_wm->enable; |
| 3196 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3197 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3198 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3199 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3200 | } |
| 3201 | |
| 3202 | /* |
| 3203 | * We need to make sure that these merged watermark values are |
| 3204 | * actually a valid configuration themselves. If they're not, |
| 3205 | * there's no safe way to transition from the old state to |
| 3206 | * the new state, so we need to fail the atomic transaction. |
| 3207 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3208 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3209 | return -EINVAL; |
| 3210 | |
| 3211 | /* |
| 3212 | * If our intermediate WM are identical to the final WM, then we can |
| 3213 | * omit the post-vblank programming; only update if it's different. |
| 3214 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3215 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3216 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3217 | |
| 3218 | return 0; |
| 3219 | } |
| 3220 | |
| 3221 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3222 | * Merge the watermarks from all active pipes for a specific level. |
| 3223 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3224 | 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] | 3225 | int level, |
| 3226 | struct intel_wm_level *ret_wm) |
| 3227 | { |
| 3228 | const struct intel_crtc *intel_crtc; |
| 3229 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3230 | ret_wm->enable = true; |
| 3231 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3232 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3233 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3234 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3235 | |
| 3236 | if (!active->pipe_enabled) |
| 3237 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3238 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3239 | /* |
| 3240 | * The watermark values may have been used in the past, |
| 3241 | * so we must maintain them in the registers for some |
| 3242 | * time even if the level is now disabled. |
| 3243 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3244 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3245 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3246 | |
| 3247 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3248 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3249 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3250 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3251 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | /* |
| 3255 | * Merge all low power watermarks for all active pipes. |
| 3256 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3257 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3258 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3259 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3260 | struct intel_pipe_wm *merged) |
| 3261 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3262 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3263 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3264 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3265 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3266 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3267 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3268 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3269 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3270 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3271 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3272 | |
| 3273 | /* merge each WM1+ level */ |
| 3274 | for (level = 1; level <= max_level; level++) { |
| 3275 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3276 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3277 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3278 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3279 | if (level > last_enabled_level) |
| 3280 | wm->enable = false; |
| 3281 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3282 | /* make sure all following levels get disabled */ |
| 3283 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3284 | |
| 3285 | /* |
| 3286 | * The spec says it is preferred to disable |
| 3287 | * FBC WMs instead of disabling a WM level. |
| 3288 | */ |
| 3289 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3290 | if (wm->enable) |
| 3291 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3292 | wm->fbc_val = 0; |
| 3293 | } |
| 3294 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3295 | |
| 3296 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3297 | /* |
| 3298 | * FIXME this is racy. FBC might get enabled later. |
| 3299 | * What we should check here is whether FBC can be |
| 3300 | * enabled sometime later. |
| 3301 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3302 | if (IS_GEN(dev_priv, 5) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3303 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3304 | for (level = 2; level <= max_level; level++) { |
| 3305 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3306 | |
| 3307 | wm->enable = false; |
| 3308 | } |
| 3309 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3310 | } |
| 3311 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3312 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3313 | { |
| 3314 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3315 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3316 | } |
| 3317 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3318 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3319 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3320 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3321 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3322 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3323 | return 2 * level; |
| 3324 | else |
| 3325 | return dev_priv->wm.pri_latency[level]; |
| 3326 | } |
| 3327 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3328 | 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] | 3329 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3330 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3331 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3332 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3333 | struct intel_crtc *intel_crtc; |
| 3334 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3335 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3336 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3337 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3338 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3339 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3340 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3341 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3342 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3343 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3344 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3345 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3346 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3347 | /* |
| 3348 | * Maintain the watermark values even if the level is |
| 3349 | * disabled. Doing otherwise could cause underruns. |
| 3350 | */ |
| 3351 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3352 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3353 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3354 | r->cur_val; |
| 3355 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3356 | if (r->enable) |
| 3357 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3358 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3359 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3360 | results->wm_lp[wm_lp - 1] |= |
| 3361 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3362 | else |
| 3363 | results->wm_lp[wm_lp - 1] |= |
| 3364 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3365 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3366 | /* |
| 3367 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3368 | * level is disabled. Doing otherwise could cause underruns. |
| 3369 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3370 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3371 | WARN_ON(wm_lp != 1); |
| 3372 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3373 | } else |
| 3374 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3375 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3376 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3377 | /* LP0 register values */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3378 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3379 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3380 | const struct intel_wm_level *r = |
| 3381 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3382 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3383 | if (WARN_ON(!r->enable)) |
| 3384 | continue; |
| 3385 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3386 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3387 | |
| 3388 | results->wm_pipe[pipe] = |
| 3389 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3390 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3391 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3392 | } |
| 3393 | } |
| 3394 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3395 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3396 | * 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] | 3397 | static struct intel_pipe_wm * |
| 3398 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3399 | struct intel_pipe_wm *r1, |
| 3400 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3401 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3402 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3403 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3404 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3405 | for (level = 1; level <= max_level; level++) { |
| 3406 | if (r1->wm[level].enable) |
| 3407 | level1 = level; |
| 3408 | if (r2->wm[level].enable) |
| 3409 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3410 | } |
| 3411 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3412 | if (level1 == level2) { |
| 3413 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3414 | return r2; |
| 3415 | else |
| 3416 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3417 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3418 | return r1; |
| 3419 | } else { |
| 3420 | return r2; |
| 3421 | } |
| 3422 | } |
| 3423 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3424 | /* dirty bits used to track which watermarks need changes */ |
| 3425 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 3426 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 3427 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3428 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3429 | #define WM_DIRTY_FBC (1 << 24) |
| 3430 | #define WM_DIRTY_DDB (1 << 25) |
| 3431 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3432 | 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] | 3433 | const struct ilk_wm_values *old, |
| 3434 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3435 | { |
| 3436 | unsigned int dirty = 0; |
| 3437 | enum pipe pipe; |
| 3438 | int wm_lp; |
| 3439 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3440 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3441 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 3442 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 3443 | /* Must disable LP1+ watermarks too */ |
| 3444 | dirty |= WM_DIRTY_LP_ALL; |
| 3445 | } |
| 3446 | |
| 3447 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3448 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3449 | /* Must disable LP1+ watermarks too */ |
| 3450 | dirty |= WM_DIRTY_LP_ALL; |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3455 | dirty |= WM_DIRTY_FBC; |
| 3456 | /* Must disable LP1+ watermarks too */ |
| 3457 | dirty |= WM_DIRTY_LP_ALL; |
| 3458 | } |
| 3459 | |
| 3460 | if (old->partitioning != new->partitioning) { |
| 3461 | dirty |= WM_DIRTY_DDB; |
| 3462 | /* Must disable LP1+ watermarks too */ |
| 3463 | dirty |= WM_DIRTY_LP_ALL; |
| 3464 | } |
| 3465 | |
| 3466 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3467 | if (dirty & WM_DIRTY_LP_ALL) |
| 3468 | return dirty; |
| 3469 | |
| 3470 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3471 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3472 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3473 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3474 | break; |
| 3475 | } |
| 3476 | |
| 3477 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3478 | for (; wm_lp <= 3; wm_lp++) |
| 3479 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3480 | |
| 3481 | return dirty; |
| 3482 | } |
| 3483 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3484 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3485 | unsigned int dirty) |
| 3486 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3487 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3488 | bool changed = false; |
| 3489 | |
| 3490 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3491 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3492 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3493 | changed = true; |
| 3494 | } |
| 3495 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3496 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3497 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3498 | changed = true; |
| 3499 | } |
| 3500 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3501 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3502 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3503 | changed = true; |
| 3504 | } |
| 3505 | |
| 3506 | /* |
| 3507 | * Don't touch WM1S_LP_EN here. |
| 3508 | * Doing so could cause underruns. |
| 3509 | */ |
| 3510 | |
| 3511 | return changed; |
| 3512 | } |
| 3513 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3514 | /* |
| 3515 | * The spec says we shouldn't write when we don't need, because every write |
| 3516 | * causes WMs to be re-evaluated, expending some power. |
| 3517 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3518 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3519 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3520 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3521 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3522 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3523 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3524 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3525 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3526 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3527 | return; |
| 3528 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3529 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3530 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3531 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3532 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3533 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3534 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3535 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3536 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 3537 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3538 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3539 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3540 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3541 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3542 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3543 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 3544 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3545 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3546 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3547 | val = I915_READ(WM_MISC); |
| 3548 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3549 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3550 | else |
| 3551 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3552 | I915_WRITE(WM_MISC, val); |
| 3553 | } else { |
| 3554 | val = I915_READ(DISP_ARB_CTL2); |
| 3555 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3556 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3557 | else |
| 3558 | val |= DISP_DATA_PARTITION_5_6; |
| 3559 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3560 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3561 | } |
| 3562 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3563 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3564 | val = I915_READ(DISP_ARB_CTL); |
| 3565 | if (results->enable_fbc_wm) |
| 3566 | val &= ~DISP_FBC_WM_DIS; |
| 3567 | else |
| 3568 | val |= DISP_FBC_WM_DIS; |
| 3569 | I915_WRITE(DISP_ARB_CTL, val); |
| 3570 | } |
| 3571 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3572 | if (dirty & WM_DIRTY_LP(1) && |
| 3573 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3574 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3575 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3576 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3577 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3578 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3579 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3580 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3581 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3582 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3583 | 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] | 3584 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3585 | 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] | 3586 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3587 | 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] | 3588 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3589 | |
| 3590 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3591 | } |
| 3592 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3593 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3594 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3595 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3596 | |
| 3597 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3598 | } |
| 3599 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3600 | static u8 intel_enabled_dbuf_slices_num(struct drm_i915_private *dev_priv) |
| 3601 | { |
| 3602 | u8 enabled_slices; |
| 3603 | |
| 3604 | /* Slice 1 will always be enabled */ |
| 3605 | enabled_slices = 1; |
| 3606 | |
| 3607 | /* Gen prior to GEN11 have only one DBuf slice */ |
| 3608 | if (INTEL_GEN(dev_priv) < 11) |
| 3609 | return enabled_slices; |
| 3610 | |
Imre Deak | 209d735 | 2019-03-07 12:32:35 +0200 | [diff] [blame] | 3611 | /* |
| 3612 | * FIXME: for now we'll only ever use 1 slice; pretend that we have |
| 3613 | * only that 1 slice enabled until we have a proper way for on-demand |
| 3614 | * toggling of the second slice. |
| 3615 | */ |
| 3616 | if (0 && I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3617 | enabled_slices++; |
| 3618 | |
| 3619 | return enabled_slices; |
| 3620 | } |
| 3621 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3622 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3623 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3624 | * so assume we'll always need it in order to avoid underruns. |
| 3625 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3626 | 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] | 3627 | { |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3628 | return IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3629 | } |
| 3630 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3631 | static bool |
| 3632 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3633 | { |
Lucas De Marchi | 8ffa439 | 2019-09-04 14:34:18 -0700 | [diff] [blame] | 3634 | /* HACK! */ |
| 3635 | if (IS_GEN(dev_priv, 12)) |
| 3636 | return false; |
| 3637 | |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3638 | return (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) && |
| 3639 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3640 | } |
| 3641 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3642 | static void |
| 3643 | skl_setup_sagv_block_time(struct drm_i915_private *dev_priv) |
| 3644 | { |
James Ausmus | da80f04 | 2019-10-09 10:23:15 -0700 | [diff] [blame] | 3645 | if (INTEL_GEN(dev_priv) >= 12) { |
| 3646 | u32 val = 0; |
| 3647 | int ret; |
| 3648 | |
| 3649 | ret = sandybridge_pcode_read(dev_priv, |
| 3650 | GEN12_PCODE_READ_SAGV_BLOCK_TIME_US, |
| 3651 | &val, NULL); |
| 3652 | if (!ret) { |
| 3653 | dev_priv->sagv_block_time_us = val; |
| 3654 | return; |
| 3655 | } |
| 3656 | |
| 3657 | DRM_DEBUG_DRIVER("Couldn't read SAGV block time!\n"); |
| 3658 | } else if (IS_GEN(dev_priv, 11)) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3659 | dev_priv->sagv_block_time_us = 10; |
| 3660 | return; |
| 3661 | } else if (IS_GEN(dev_priv, 10)) { |
| 3662 | dev_priv->sagv_block_time_us = 20; |
| 3663 | return; |
| 3664 | } else if (IS_GEN(dev_priv, 9)) { |
| 3665 | dev_priv->sagv_block_time_us = 30; |
| 3666 | return; |
| 3667 | } else { |
| 3668 | MISSING_CASE(INTEL_GEN(dev_priv)); |
| 3669 | } |
| 3670 | |
| 3671 | /* Default to an unusable block time */ |
| 3672 | dev_priv->sagv_block_time_us = -1; |
| 3673 | } |
| 3674 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3675 | /* |
| 3676 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3677 | * depending on power and performance requirements. The display engine access |
| 3678 | * to system memory is blocked during the adjustment time. Because of the |
| 3679 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3680 | * underruns if we don't meet all of the following requirements: |
| 3681 | * |
| 3682 | * - <= 1 pipe enabled |
| 3683 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3684 | * - We're not using an interlaced display configuration |
| 3685 | */ |
| 3686 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3687 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3688 | { |
| 3689 | int ret; |
| 3690 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3691 | if (!intel_has_sagv(dev_priv)) |
| 3692 | return 0; |
| 3693 | |
| 3694 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3695 | return 0; |
| 3696 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3697 | DRM_DEBUG_KMS("Enabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3698 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3699 | GEN9_SAGV_ENABLE); |
| 3700 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3701 | /* We don't need to wait for SAGV when enabling */ |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3702 | |
| 3703 | /* |
| 3704 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3705 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3706 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3707 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3708 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3709 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3710 | return 0; |
| 3711 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3712 | DRM_ERROR("Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3713 | return ret; |
| 3714 | } |
| 3715 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3716 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3717 | return 0; |
| 3718 | } |
| 3719 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3720 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3721 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3722 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3723 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3724 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3725 | if (!intel_has_sagv(dev_priv)) |
| 3726 | return 0; |
| 3727 | |
| 3728 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3729 | return 0; |
| 3730 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3731 | DRM_DEBUG_KMS("Disabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3732 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3733 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3734 | GEN9_SAGV_DISABLE, |
| 3735 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3736 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3737 | /* |
| 3738 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3739 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3740 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3741 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3742 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3743 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3744 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3745 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3746 | DRM_ERROR("Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3747 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3748 | } |
| 3749 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3750 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3751 | return 0; |
| 3752 | } |
| 3753 | |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3754 | bool intel_can_enable_sagv(struct intel_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3755 | { |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3756 | struct drm_device *dev = state->base.dev; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3757 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3758 | struct intel_crtc *crtc; |
| 3759 | struct intel_plane *plane; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3760 | struct intel_crtc_state *crtc_state; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3761 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3762 | int level, latency; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3763 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3764 | if (!intel_has_sagv(dev_priv)) |
| 3765 | return false; |
| 3766 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3767 | /* |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3768 | * If there are no active CRTCs, no additional checks need be performed |
| 3769 | */ |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3770 | if (hweight8(state->active_pipes) == 0) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3771 | return true; |
Lucas De Marchi | da17223 | 2019-04-04 16:04:26 -0700 | [diff] [blame] | 3772 | |
| 3773 | /* |
| 3774 | * SKL+ workaround: bspec recommends we disable SAGV when we have |
| 3775 | * more then one pipe enabled |
| 3776 | */ |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3777 | if (hweight8(state->active_pipes) > 1) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3778 | return false; |
| 3779 | |
| 3780 | /* Since we're now guaranteed to only have one active CRTC... */ |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 3781 | pipe = ffs(state->active_pipes) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 3782 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3783 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3784 | |
Paulo Zanoni | c89cadd | 2016-10-10 17:30:59 -0300 | [diff] [blame] | 3785 | if (crtc->base.state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3786 | return false; |
| 3787 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3788 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3789 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3790 | &crtc_state->wm.skl.optimal.planes[plane->id]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3791 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3792 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3793 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3794 | continue; |
| 3795 | |
| 3796 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3797 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3798 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3799 | { } |
| 3800 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3801 | latency = dev_priv->wm.skl_latency[level]; |
| 3802 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3803 | if (skl_needs_memory_bw_wa(dev_priv) && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3804 | plane->base.state->fb->modifier == |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3805 | I915_FORMAT_MOD_X_TILED) |
| 3806 | latency += 15; |
| 3807 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3808 | /* |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3809 | * If any of the planes on this pipe don't enable wm levels that |
| 3810 | * incur memory latencies higher than sagv_block_time_us we |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3811 | * can't enable SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3812 | */ |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3813 | if (latency < dev_priv->sagv_block_time_us) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3814 | return false; |
| 3815 | } |
| 3816 | |
| 3817 | return true; |
| 3818 | } |
| 3819 | |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3820 | static u16 intel_get_ddb_size(struct drm_i915_private *dev_priv, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3821 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3822 | const u64 total_data_rate, |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3823 | const int num_active, |
| 3824 | struct skl_ddb_allocation *ddb) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3825 | { |
| 3826 | const struct drm_display_mode *adjusted_mode; |
| 3827 | u64 total_data_bw; |
| 3828 | u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3829 | |
| 3830 | WARN_ON(ddb_size == 0); |
| 3831 | |
| 3832 | if (INTEL_GEN(dev_priv) < 11) |
| 3833 | return ddb_size - 4; /* 4 blocks for bypass path allocation */ |
| 3834 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3835 | adjusted_mode = &crtc_state->base.adjusted_mode; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3836 | total_data_bw = total_data_rate * drm_mode_vrefresh(adjusted_mode); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3837 | |
| 3838 | /* |
| 3839 | * 12GB/s is maximum BW supported by single DBuf slice. |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3840 | * |
| 3841 | * FIXME dbuf slice code is broken: |
| 3842 | * - must wait for planes to stop using the slice before powering it off |
| 3843 | * - plane straddling both slices is illegal in multi-pipe scenarios |
| 3844 | * - should validate we stay within the hw bandwidth limits |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3845 | */ |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3846 | if (0 && (num_active > 1 || total_data_bw >= GBps(12))) { |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3847 | ddb->enabled_slices = 2; |
| 3848 | } else { |
| 3849 | ddb->enabled_slices = 1; |
| 3850 | ddb_size /= 2; |
| 3851 | } |
| 3852 | |
| 3853 | return ddb_size; |
| 3854 | } |
| 3855 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3856 | static void |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 3857 | skl_ddb_get_pipe_allocation_limits(struct drm_i915_private *dev_priv, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3858 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3859 | const u64 total_data_rate, |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3860 | struct skl_ddb_allocation *ddb, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3861 | struct skl_ddb_entry *alloc, /* out */ |
| 3862 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3863 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3864 | struct drm_atomic_state *state = crtc_state->base.state; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3865 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3866 | struct drm_crtc *for_crtc = crtc_state->base.crtc; |
| 3867 | const struct intel_crtc *crtc; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3868 | u32 pipe_width = 0, total_width = 0, width_before_pipe = 0; |
| 3869 | enum pipe for_pipe = to_intel_crtc(for_crtc)->pipe; |
| 3870 | u16 ddb_size; |
| 3871 | u32 i; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3872 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3873 | if (WARN_ON(!state) || !crtc_state->base.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3874 | alloc->start = 0; |
| 3875 | alloc->end = 0; |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3876 | *num_active = hweight8(dev_priv->active_pipes); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3877 | return; |
| 3878 | } |
| 3879 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3880 | if (intel_state->active_pipe_changes) |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3881 | *num_active = hweight8(intel_state->active_pipes); |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3882 | else |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 3883 | *num_active = hweight8(dev_priv->active_pipes); |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3884 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3885 | 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] | 3886 | *num_active, ddb); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3887 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3888 | /* |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3889 | * If the state doesn't change the active CRTC's or there is no |
| 3890 | * modeset request, then there's no need to recalculate; |
| 3891 | * the existing pipe allocation limits should remain unchanged. |
| 3892 | * Note that we're safe from racing commits since any racing commit |
| 3893 | * that changes the active CRTC list or do modeset would need to |
| 3894 | * grab _all_ crtc locks, including the one we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3895 | */ |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3896 | if (!intel_state->active_pipe_changes && !intel_state->modeset) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 3897 | /* |
| 3898 | * alloc may be cleared by clear_intel_crtc_state, |
| 3899 | * copy from old state to be sure |
| 3900 | */ |
| 3901 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3902 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3903 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3904 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3905 | /* |
| 3906 | * Watermark/ddb requirement highly depends upon width of the |
| 3907 | * framebuffer, So instead of allocating DDB equally among pipes |
| 3908 | * distribute DDB based on resolution/width of the display. |
| 3909 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3910 | for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) { |
| 3911 | const struct drm_display_mode *adjusted_mode = |
| 3912 | &crtc_state->base.adjusted_mode; |
| 3913 | enum pipe pipe = crtc->pipe; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3914 | int hdisplay, vdisplay; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3915 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3916 | if (!crtc_state->base.enable) |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3917 | continue; |
| 3918 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3919 | drm_mode_get_hv_timing(adjusted_mode, &hdisplay, &vdisplay); |
| 3920 | total_width += hdisplay; |
| 3921 | |
| 3922 | if (pipe < for_pipe) |
| 3923 | width_before_pipe += hdisplay; |
| 3924 | else if (pipe == for_pipe) |
| 3925 | pipe_width = hdisplay; |
| 3926 | } |
| 3927 | |
| 3928 | alloc->start = ddb_size * width_before_pipe / total_width; |
| 3929 | alloc->end = ddb_size * (width_before_pipe + pipe_width) / total_width; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3932 | static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 3933 | int width, const struct drm_format_info *format, |
| 3934 | u64 modifier, unsigned int rotation, |
| 3935 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 3936 | int color_plane); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3937 | 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] | 3938 | int level, |
| 3939 | const struct skl_wm_params *wp, |
| 3940 | const struct skl_wm_level *result_prev, |
| 3941 | struct skl_wm_level *result /* out */); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3942 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3943 | static unsigned int |
| 3944 | skl_cursor_allocation(const struct intel_crtc_state *crtc_state, |
| 3945 | int num_active) |
| 3946 | { |
| 3947 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 3948 | int level, max_level = ilk_wm_max_level(dev_priv); |
| 3949 | struct skl_wm_level wm = {}; |
| 3950 | int ret, min_ddb_alloc = 0; |
| 3951 | struct skl_wm_params wp; |
| 3952 | |
| 3953 | ret = skl_compute_wm_params(crtc_state, 256, |
| 3954 | drm_format_info(DRM_FORMAT_ARGB8888), |
| 3955 | DRM_FORMAT_MOD_LINEAR, |
| 3956 | DRM_MODE_ROTATE_0, |
| 3957 | crtc_state->pixel_rate, &wp, 0); |
| 3958 | WARN_ON(ret); |
| 3959 | |
| 3960 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | 6086e47 | 2019-03-21 19:51:28 +0200 | [diff] [blame] | 3961 | skl_compute_plane_wm(crtc_state, level, &wp, &wm, &wm); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3962 | if (wm.min_ddb_alloc == U16_MAX) |
| 3963 | break; |
| 3964 | |
| 3965 | min_ddb_alloc = wm.min_ddb_alloc; |
| 3966 | } |
| 3967 | |
| 3968 | return max(num_active == 1 ? 32 : 8, min_ddb_alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3969 | } |
| 3970 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3971 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 3972 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3973 | { |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3974 | |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 3975 | entry->start = reg & DDB_ENTRY_MASK; |
| 3976 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3977 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3978 | if (entry->end) |
| 3979 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3980 | } |
| 3981 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3982 | static void |
| 3983 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 3984 | const enum pipe pipe, |
| 3985 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3986 | struct skl_ddb_entry *ddb_y, |
| 3987 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3988 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3989 | u32 val, val2; |
| 3990 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3991 | |
| 3992 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 3993 | if (plane_id == PLANE_CURSOR) { |
| 3994 | val = I915_READ(CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3995 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3996 | return; |
| 3997 | } |
| 3998 | |
| 3999 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
| 4000 | |
| 4001 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4002 | if (val & PLANE_CTL_ENABLE) |
| 4003 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 4004 | val & PLANE_CTL_ORDER_RGBX, |
| 4005 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4006 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4007 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4008 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 4009 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4010 | } else { |
| 4011 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
Paulo Zanoni | 12a6c93 | 2018-07-31 17:46:14 -0700 | [diff] [blame] | 4012 | val2 = I915_READ(PLANE_NV12_BUF_CFG(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4013 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4014 | if (fourcc && |
| 4015 | drm_format_info_is_yuv_semiplanar(drm_format_info(fourcc))) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4016 | swap(val, val2); |
| 4017 | |
| 4018 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4019 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4020 | } |
| 4021 | } |
| 4022 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4023 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 4024 | struct skl_ddb_entry *ddb_y, |
| 4025 | struct skl_ddb_entry *ddb_uv) |
| 4026 | { |
| 4027 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4028 | enum intel_display_power_domain power_domain; |
| 4029 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4030 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4031 | enum plane_id plane_id; |
| 4032 | |
| 4033 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4034 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 4035 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4036 | return; |
| 4037 | |
| 4038 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4039 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4040 | plane_id, |
| 4041 | &ddb_y[plane_id], |
| 4042 | &ddb_uv[plane_id]); |
| 4043 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4044 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4045 | } |
| 4046 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 4047 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 4048 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4049 | { |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 4050 | ddb->enabled_slices = intel_enabled_dbuf_slices_num(dev_priv); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4053 | /* |
| 4054 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4055 | * The bspec defines downscale amount as: |
| 4056 | * |
| 4057 | * """ |
| 4058 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4059 | * Horizontal destination size] |
| 4060 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4061 | * Vertical destination size] |
| 4062 | * Total down scale amount = Horizontal down scale amount * |
| 4063 | * Vertical down scale amount |
| 4064 | * """ |
| 4065 | * |
| 4066 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4067 | * Caller should take care of dividing & rounding off the value. |
| 4068 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4069 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4070 | skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state, |
| 4071 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4072 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4073 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4074 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4075 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4076 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4077 | if (WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4078 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4079 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 4080 | /* |
| 4081 | * Src coordinates are already rotated by 270 degrees for |
| 4082 | * the 90/270 degree plane rotation cases (to match the |
| 4083 | * GTT mapping), hence no need to account for rotation here. |
| 4084 | * |
| 4085 | * n.b., src is 16.16 fixed point, dst is whole integer. |
| 4086 | */ |
| 4087 | src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 4088 | src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 4089 | dst_w = drm_rect_width(&plane_state->base.dst); |
| 4090 | dst_h = drm_rect_height(&plane_state->base.dst); |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4091 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4092 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4093 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4094 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4095 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4096 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4097 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4100 | static uint_fixed_16_16_t |
| 4101 | skl_pipe_downscale_amount(const struct intel_crtc_state *crtc_state) |
| 4102 | { |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4103 | uint_fixed_16_16_t pipe_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4104 | |
| 4105 | if (!crtc_state->base.enable) |
| 4106 | return pipe_downscale; |
| 4107 | |
| 4108 | if (crtc_state->pch_pfit.enabled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4109 | u32 src_w, src_h, dst_w, dst_h; |
| 4110 | u32 pfit_size = crtc_state->pch_pfit.size; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4111 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4112 | uint_fixed_16_16_t downscale_h, downscale_w; |
| 4113 | |
| 4114 | src_w = crtc_state->pipe_src_w; |
| 4115 | src_h = crtc_state->pipe_src_h; |
| 4116 | dst_w = pfit_size >> 16; |
| 4117 | dst_h = pfit_size & 0xffff; |
| 4118 | |
| 4119 | if (!dst_w || !dst_h) |
| 4120 | return pipe_downscale; |
| 4121 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4122 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4123 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4124 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4125 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4126 | |
| 4127 | pipe_downscale = mul_fixed16(downscale_w, downscale_h); |
| 4128 | } |
| 4129 | |
| 4130 | return pipe_downscale; |
| 4131 | } |
| 4132 | |
| 4133 | int skl_check_pipe_max_pixel_rate(struct intel_crtc *intel_crtc, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4134 | struct intel_crtc_state *crtc_state) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4135 | { |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 4136 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4137 | struct drm_atomic_state *state = crtc_state->base.state; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4138 | const struct intel_plane_state *plane_state; |
| 4139 | struct intel_plane *plane; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4140 | int crtc_clock, dotclk; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4141 | u32 pipe_max_pixel_rate; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4142 | uint_fixed_16_16_t pipe_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4143 | uint_fixed_16_16_t max_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4144 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4145 | if (!crtc_state->base.enable) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4146 | return 0; |
| 4147 | |
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) { |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4149 | uint_fixed_16_16_t plane_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4150 | uint_fixed_16_16_t fp_9_div_8 = div_fixed16(9, 8); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4151 | int bpp; |
| 4152 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4153 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4154 | continue; |
| 4155 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4156 | if (WARN_ON(!plane_state->base.fb)) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4157 | return -EINVAL; |
| 4158 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4159 | plane_downscale = skl_plane_downscale_amount(crtc_state, plane_state); |
| 4160 | bpp = plane_state->base.fb->format->cpp[0] * 8; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4161 | if (bpp == 64) |
| 4162 | plane_downscale = mul_fixed16(plane_downscale, |
| 4163 | fp_9_div_8); |
| 4164 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4165 | max_downscale = max_fixed16(plane_downscale, max_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4166 | } |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4167 | pipe_downscale = skl_pipe_downscale_amount(crtc_state); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4168 | |
| 4169 | pipe_downscale = mul_fixed16(pipe_downscale, max_downscale); |
| 4170 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4171 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4172 | dotclk = to_intel_atomic_state(state)->cdclk.logical.cdclk; |
| 4173 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 4174 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4175 | dotclk *= 2; |
| 4176 | |
| 4177 | pipe_max_pixel_rate = div_round_up_u32_fixed16(dotclk, pipe_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4178 | |
| 4179 | if (pipe_max_pixel_rate < crtc_clock) { |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4180 | DRM_DEBUG_KMS("Max supported pixel clock with scaling exceeded\n"); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4181 | return -EINVAL; |
| 4182 | } |
| 4183 | |
| 4184 | return 0; |
| 4185 | } |
| 4186 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4187 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4188 | skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state, |
| 4189 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4190 | int color_plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4191 | { |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4192 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 4193 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4194 | u32 data_rate; |
| 4195 | u32 width = 0, height = 0; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4196 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4197 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4198 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4199 | if (!plane_state->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4200 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4201 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4202 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4203 | return 0; |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4204 | |
| 4205 | if (color_plane == 1 && |
| 4206 | !drm_format_info_is_yuv_semiplanar(fb->format)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4207 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4208 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4209 | /* |
| 4210 | * Src coordinates are already rotated by 270 degrees for |
| 4211 | * the 90/270 degree plane rotation cases (to match the |
| 4212 | * GTT mapping), hence no need to account for rotation here. |
| 4213 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4214 | width = drm_rect_width(&plane_state->base.src) >> 16; |
| 4215 | height = drm_rect_height(&plane_state->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4216 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4217 | /* UV plane does 1/2 pixel sub-sampling */ |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4218 | if (color_plane == 1) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4219 | width /= 2; |
| 4220 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4221 | } |
| 4222 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4223 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4224 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4225 | down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4226 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4227 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4228 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4229 | rate *= fb->format->cpp[color_plane]; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4230 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4231 | } |
| 4232 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4233 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4234 | skl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4235 | u64 *plane_data_rate, |
| 4236 | u64 *uv_plane_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4237 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4238 | struct drm_atomic_state *state = crtc_state->base.state; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4239 | struct intel_plane *plane; |
| 4240 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4241 | u64 total_data_rate = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4242 | |
| 4243 | if (WARN_ON(!state)) |
| 4244 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4245 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4246 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4247 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 4248 | enum plane_id plane_id = plane->id; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4249 | u64 rate; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4250 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4251 | /* packed/y */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4252 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4253 | plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4254 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4255 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4256 | /* uv-plane */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4257 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4258 | uv_plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4259 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | return total_data_rate; |
| 4263 | } |
| 4264 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4265 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4266 | icl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4267 | u64 *plane_data_rate) |
| 4268 | { |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4269 | struct intel_plane *plane; |
| 4270 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4271 | u64 total_data_rate = 0; |
| 4272 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4273 | if (WARN_ON(!crtc_state->base.state)) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4274 | return 0; |
| 4275 | |
| 4276 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4277 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 4278 | enum plane_id plane_id = plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4279 | u64 rate; |
| 4280 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4281 | if (!plane_state->planar_linked_plane) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4282 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4283 | plane_data_rate[plane_id] = rate; |
| 4284 | total_data_rate += rate; |
| 4285 | } else { |
| 4286 | enum plane_id y_plane_id; |
| 4287 | |
| 4288 | /* |
| 4289 | * The slave plane might not iterate in |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4290 | * intel_atomic_crtc_state_for_each_plane_state(), |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4291 | * and needs the master plane state which may be |
| 4292 | * NULL if we try get_new_plane_state(), so we |
| 4293 | * always calculate from the master. |
| 4294 | */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4295 | if (plane_state->planar_slave) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4296 | continue; |
| 4297 | |
| 4298 | /* Y plane rate is calculated on the slave */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4299 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4300 | y_plane_id = plane_state->planar_linked_plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4301 | plane_data_rate[y_plane_id] = rate; |
| 4302 | total_data_rate += rate; |
| 4303 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4304 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4305 | plane_data_rate[plane_id] = rate; |
| 4306 | total_data_rate += rate; |
| 4307 | } |
| 4308 | } |
| 4309 | |
| 4310 | return total_data_rate; |
| 4311 | } |
| 4312 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4313 | static int |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4314 | skl_allocate_pipe_ddb(struct intel_crtc_state *crtc_state, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4315 | struct skl_ddb_allocation *ddb /* out */) |
| 4316 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4317 | struct drm_atomic_state *state = crtc_state->base.state; |
| 4318 | struct drm_crtc *crtc = crtc_state->base.crtc; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4319 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4320 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4321 | struct skl_ddb_entry *alloc = &crtc_state->wm.skl.ddb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4322 | u16 alloc_size, start = 0; |
| 4323 | u16 total[I915_MAX_PLANES] = {}; |
| 4324 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4325 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4326 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4327 | int num_active; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4328 | u64 plane_data_rate[I915_MAX_PLANES] = {}; |
| 4329 | u64 uv_plane_data_rate[I915_MAX_PLANES] = {}; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4330 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4331 | int level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4332 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4333 | /* Clear the partitioning for disabled planes. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4334 | memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y)); |
| 4335 | 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] | 4336 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4337 | if (WARN_ON(!state)) |
| 4338 | return 0; |
| 4339 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4340 | if (!crtc_state->base.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4341 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4342 | return 0; |
| 4343 | } |
| 4344 | |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4345 | if (INTEL_GEN(dev_priv) >= 11) |
| 4346 | total_data_rate = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4347 | icl_get_total_relative_data_rate(crtc_state, |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4348 | plane_data_rate); |
| 4349 | else |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4350 | total_data_rate = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4351 | skl_get_total_relative_data_rate(crtc_state, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4352 | plane_data_rate, |
| 4353 | uv_plane_data_rate); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4354 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4355 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4356 | 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] | 4357 | ddb, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4358 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 4359 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4360 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4361 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4362 | /* Allocate fixed number of blocks for cursor. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4363 | total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4364 | alloc_size -= total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4365 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4366 | alloc->end - total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4367 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4368 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4369 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4370 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4371 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4372 | /* |
| 4373 | * Find the highest watermark level for which we can satisfy the block |
| 4374 | * requirement of active planes. |
| 4375 | */ |
| 4376 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 4377 | blocks = 0; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4378 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4379 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4380 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 4381 | |
| 4382 | if (plane_id == PLANE_CURSOR) { |
| 4383 | if (WARN_ON(wm->wm[level].min_ddb_alloc > |
| 4384 | total[PLANE_CURSOR])) { |
| 4385 | blocks = U32_MAX; |
| 4386 | break; |
| 4387 | } |
| 4388 | continue; |
| 4389 | } |
| 4390 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4391 | blocks += wm->wm[level].min_ddb_alloc; |
| 4392 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4393 | } |
| 4394 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame] | 4395 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4396 | alloc_size -= blocks; |
| 4397 | break; |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | if (level < 0) { |
| 4402 | DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); |
| 4403 | DRM_DEBUG_KMS("minimum required %d/%d\n", blocks, |
| 4404 | alloc_size); |
| 4405 | return -EINVAL; |
| 4406 | } |
| 4407 | |
| 4408 | /* |
| 4409 | * Grant each plane the blocks it requires at the highest achievable |
| 4410 | * watermark level, plus an extra share of the leftover blocks |
| 4411 | * proportional to its relative data rate. |
| 4412 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4413 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4414 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4415 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4416 | u64 rate; |
| 4417 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4418 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4419 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4420 | continue; |
| 4421 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4422 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4423 | * We've accounted for all active planes; remaining planes are |
| 4424 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4425 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4426 | if (total_data_rate == 0) |
| 4427 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4428 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4429 | rate = plane_data_rate[plane_id]; |
| 4430 | extra = min_t(u16, alloc_size, |
| 4431 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4432 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4433 | total[plane_id] = wm->wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4434 | alloc_size -= extra; |
| 4435 | total_data_rate -= rate; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4436 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4437 | if (total_data_rate == 0) |
| 4438 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4439 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4440 | rate = uv_plane_data_rate[plane_id]; |
| 4441 | extra = min_t(u16, alloc_size, |
| 4442 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4443 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4444 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4445 | alloc_size -= extra; |
| 4446 | total_data_rate -= rate; |
| 4447 | } |
| 4448 | WARN_ON(alloc_size != 0 || total_data_rate != 0); |
| 4449 | |
| 4450 | /* Set the actual DDB start/end points for each plane */ |
| 4451 | start = alloc->start; |
| 4452 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4453 | struct skl_ddb_entry *plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4454 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4455 | struct skl_ddb_entry *uv_plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4456 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4457 | |
| 4458 | if (plane_id == PLANE_CURSOR) |
| 4459 | continue; |
| 4460 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4461 | /* Gen11+ uses a separate plane for UV watermarks */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4462 | WARN_ON(INTEL_GEN(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4463 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4464 | /* Leave disabled planes at (0,0) */ |
| 4465 | if (total[plane_id]) { |
| 4466 | plane_alloc->start = start; |
| 4467 | start += total[plane_id]; |
| 4468 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4469 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4470 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4471 | if (uv_total[plane_id]) { |
| 4472 | uv_plane_alloc->start = start; |
| 4473 | start += uv_total[plane_id]; |
| 4474 | uv_plane_alloc->end = start; |
| 4475 | } |
| 4476 | } |
| 4477 | |
| 4478 | /* |
| 4479 | * When we calculated watermark values we didn't know how high |
| 4480 | * of a level we'd actually be able to hit, so we just marked |
| 4481 | * all levels as "enabled." Go back now and disable the ones |
| 4482 | * that aren't actually possible. |
| 4483 | */ |
| 4484 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
| 4485 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4486 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4487 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | a301cb0 | 2019-03-12 22:58:41 +0200 | [diff] [blame] | 4488 | |
| 4489 | /* |
| 4490 | * We only disable the watermarks for each plane if |
| 4491 | * they exceed the ddb allocation of said plane. This |
| 4492 | * is done so that we don't end up touching cursor |
| 4493 | * watermarks needlessly when some other plane reduces |
| 4494 | * our max possible watermark level. |
| 4495 | * |
| 4496 | * Bspec has this to say about the PLANE_WM enable bit: |
| 4497 | * "All the watermarks at this level for all enabled |
| 4498 | * planes must be enabled before the level will be used." |
| 4499 | * So this is actually safe to do. |
| 4500 | */ |
| 4501 | if (wm->wm[level].min_ddb_alloc > total[plane_id] || |
| 4502 | wm->uv_wm[level].min_ddb_alloc > uv_total[plane_id]) |
| 4503 | memset(&wm->wm[level], 0, sizeof(wm->wm[level])); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4504 | |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4505 | /* |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 4506 | * Wa_1408961008:icl, ehl |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4507 | * Underruns with WM1+ disabled |
| 4508 | */ |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 4509 | if (IS_GEN(dev_priv, 11) && |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4510 | level == 1 && wm->wm[0].plane_en) { |
| 4511 | 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] | 4512 | wm->wm[level].plane_res_l = wm->wm[0].plane_res_l; |
| 4513 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4514 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | /* |
| 4519 | * Go back and disable the transition watermark if it turns out we |
| 4520 | * don't have enough DDB blocks for it. |
| 4521 | */ |
| 4522 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4523 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4524 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4525 | |
Ville Syrjälä | b19c9bc | 2018-12-21 19:14:31 +0200 | [diff] [blame] | 4526 | if (wm->trans_wm.plane_res_b >= total[plane_id]) |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4527 | memset(&wm->trans_wm, 0, sizeof(wm->trans_wm)); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4528 | } |
| 4529 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4530 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4531 | } |
| 4532 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4533 | /* |
| 4534 | * 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] | 4535 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4536 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 4537 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 4538 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4539 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4540 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 4541 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4542 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4543 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4544 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4545 | |
| 4546 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4547 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4548 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4549 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4550 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4551 | |
| 4552 | if (INTEL_GEN(dev_priv) >= 10) |
| 4553 | ret = add_fixed16_u32(ret, 1); |
| 4554 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4555 | return ret; |
| 4556 | } |
| 4557 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4558 | static uint_fixed_16_16_t |
| 4559 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 4560 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4561 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4562 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4563 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4564 | |
| 4565 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4566 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4567 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4568 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4569 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 4570 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4571 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4572 | return ret; |
| 4573 | } |
| 4574 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4575 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4576 | intel_get_linetime_us(const struct intel_crtc_state *crtc_state) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4577 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4578 | u32 pixel_rate; |
| 4579 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4580 | uint_fixed_16_16_t linetime_us; |
| 4581 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4582 | if (!crtc_state->base.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4583 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4584 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4585 | pixel_rate = crtc_state->pixel_rate; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4586 | |
| 4587 | if (WARN_ON(pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4588 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4589 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4590 | crtc_htotal = crtc_state->base.adjusted_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4591 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4592 | |
| 4593 | return linetime_us; |
| 4594 | } |
| 4595 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4596 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4597 | skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *crtc_state, |
| 4598 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4599 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4600 | u64 adjusted_pixel_rate; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4601 | uint_fixed_16_16_t downscale_amount; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4602 | |
| 4603 | /* Shouldn't reach here on disabled planes... */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4604 | if (WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4605 | return 0; |
| 4606 | |
| 4607 | /* |
| 4608 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 4609 | * with additional adjustments for plane-specific scaling. |
| 4610 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4611 | adjusted_pixel_rate = crtc_state->pixel_rate; |
| 4612 | downscale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4613 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4614 | return mul_round_up_u32_fixed16(adjusted_pixel_rate, |
| 4615 | downscale_amount); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4616 | } |
| 4617 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4618 | static int |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4619 | skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 4620 | int width, const struct drm_format_info *format, |
| 4621 | u64 modifier, unsigned int rotation, |
| 4622 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 4623 | int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4624 | { |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4625 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4626 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4627 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4628 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4629 | /* only planar format has two planes */ |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4630 | if (color_plane == 1 && !drm_format_info_is_yuv_semiplanar(format)) { |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4631 | DRM_DEBUG_KMS("Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4632 | return -EINVAL; |
| 4633 | } |
| 4634 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4635 | wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED || |
| 4636 | modifier == I915_FORMAT_MOD_Yf_TILED || |
| 4637 | modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4638 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4639 | wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED; |
| 4640 | wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4641 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4642 | wp->is_planar = drm_format_info_is_yuv_semiplanar(format); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4643 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4644 | wp->width = width; |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 4645 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4646 | wp->width /= 2; |
| 4647 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4648 | wp->cpp = format->cpp[color_plane]; |
| 4649 | wp->plane_pixel_rate = plane_pixel_rate; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4650 | |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4651 | if (INTEL_GEN(dev_priv) >= 11 && |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4652 | modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4653 | wp->dbuf_block_size = 256; |
| 4654 | else |
| 4655 | wp->dbuf_block_size = 512; |
| 4656 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4657 | if (drm_rotation_90_or_270(rotation)) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4658 | switch (wp->cpp) { |
| 4659 | case 1: |
| 4660 | wp->y_min_scanlines = 16; |
| 4661 | break; |
| 4662 | case 2: |
| 4663 | wp->y_min_scanlines = 8; |
| 4664 | break; |
| 4665 | case 4: |
| 4666 | wp->y_min_scanlines = 4; |
| 4667 | break; |
| 4668 | default: |
| 4669 | MISSING_CASE(wp->cpp); |
| 4670 | return -EINVAL; |
| 4671 | } |
| 4672 | } else { |
| 4673 | wp->y_min_scanlines = 4; |
| 4674 | } |
| 4675 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4676 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4677 | wp->y_min_scanlines *= 2; |
| 4678 | |
| 4679 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 4680 | if (wp->y_tiled) { |
| 4681 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4682 | wp->y_min_scanlines, |
| 4683 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4684 | |
| 4685 | if (INTEL_GEN(dev_priv) >= 10) |
| 4686 | interm_pbpl++; |
| 4687 | |
| 4688 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 4689 | wp->y_min_scanlines); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4690 | } else if (wp->x_tiled && IS_GEN(dev_priv, 9)) { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4691 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4692 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4693 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4694 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4695 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4696 | wp->dbuf_block_size) + 1; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4697 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4698 | } |
| 4699 | |
| 4700 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 4701 | wp->plane_blocks_per_line); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4702 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4703 | wp->linetime_us = fixed16_to_u32_round_up( |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4704 | intel_get_linetime_us(crtc_state)); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4705 | |
| 4706 | return 0; |
| 4707 | } |
| 4708 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4709 | static int |
| 4710 | skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state, |
| 4711 | const struct intel_plane_state *plane_state, |
| 4712 | struct skl_wm_params *wp, int color_plane) |
| 4713 | { |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4714 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 4715 | int width; |
| 4716 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 4717 | /* |
| 4718 | * Src coordinates are already rotated by 270 degrees for |
| 4719 | * the 90/270 degree plane rotation cases (to match the |
| 4720 | * GTT mapping), hence no need to account for rotation here. |
| 4721 | */ |
| 4722 | width = drm_rect_width(&plane_state->base.src) >> 16; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4723 | |
| 4724 | return skl_compute_wm_params(crtc_state, width, |
| 4725 | fb->format, fb->modifier, |
| 4726 | plane_state->base.rotation, |
| 4727 | skl_adjusted_plane_pixel_rate(crtc_state, plane_state), |
| 4728 | wp, color_plane); |
| 4729 | } |
| 4730 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4731 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 4732 | { |
| 4733 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 4734 | return true; |
| 4735 | |
| 4736 | /* The number of lines are ignored for the level 0 watermark. */ |
| 4737 | return level > 0; |
| 4738 | } |
| 4739 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4740 | 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] | 4741 | int level, |
| 4742 | const struct skl_wm_params *wp, |
| 4743 | const struct skl_wm_level *result_prev, |
| 4744 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4745 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4746 | 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] | 4747 | u32 latency = dev_priv->wm.skl_latency[level]; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4748 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4749 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4750 | u32 res_blocks, res_lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 4751 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4752 | if (latency == 0) { |
| 4753 | /* reject it */ |
| 4754 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4755 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4756 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4757 | |
Ville Syrjälä | 25312ef | 2019-05-03 20:38:05 +0300 | [diff] [blame] | 4758 | /* |
| 4759 | * WaIncreaseLatencyIPCEnabled: kbl,cfl |
| 4760 | * Display WA #1141: kbl,cfl |
| 4761 | */ |
Ville Syrjälä | 5a7d202 | 2019-05-03 20:38:06 +0300 | [diff] [blame] | 4762 | if ((IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) || |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4763 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 4764 | latency += 4; |
| 4765 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4766 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4767 | latency += 15; |
| 4768 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4769 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4770 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4771 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4772 | crtc_state->base.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4773 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4774 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4775 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4776 | if (wp->y_tiled) { |
| 4777 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4778 | } else { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4779 | if ((wp->cpp * crtc_state->base.adjusted_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4780 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4781 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 4782 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4783 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4784 | if (IS_GEN(dev_priv, 9) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4785 | !IS_GEMINILAKE(dev_priv)) |
| 4786 | selected_result = min_fixed16(method1, method2); |
| 4787 | else |
| 4788 | selected_result = method2; |
| 4789 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4790 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4791 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4792 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4793 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4794 | res_blocks = fixed16_to_u32_round_up(selected_result) + 1; |
Kumar, Mahesh | d273ecc | 2017-05-17 17:28:22 +0530 | [diff] [blame] | 4795 | res_lines = div_round_up_fixed16(selected_result, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4796 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4797 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4798 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) { |
| 4799 | /* Display WA #1125: skl,bxt,kbl */ |
| 4800 | if (level == 0 && wp->rc_surface) |
| 4801 | res_blocks += |
| 4802 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 4803 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4804 | /* Display WA #1126: skl,bxt,kbl */ |
| 4805 | if (level >= 1 && level <= 7) { |
| 4806 | if (wp->y_tiled) { |
| 4807 | res_blocks += |
| 4808 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 4809 | res_lines += wp->y_min_scanlines; |
| 4810 | } else { |
| 4811 | res_blocks++; |
| 4812 | } |
| 4813 | |
| 4814 | /* |
| 4815 | * Make sure result blocks for higher latency levels are |
| 4816 | * atleast as high as level below the current level. |
| 4817 | * Assumption in DDB algorithm optimization for special |
| 4818 | * cases. Also covers Display WA #1125 for RC. |
| 4819 | */ |
| 4820 | if (result_prev->plane_res_b > res_blocks) |
| 4821 | res_blocks = result_prev->plane_res_b; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4822 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4823 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4824 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4825 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4826 | if (wp->y_tiled) { |
| 4827 | int extra_lines; |
| 4828 | |
| 4829 | if (res_lines % wp->y_min_scanlines == 0) |
| 4830 | extra_lines = wp->y_min_scanlines; |
| 4831 | else |
| 4832 | extra_lines = wp->y_min_scanlines * 2 - |
| 4833 | res_lines % wp->y_min_scanlines; |
| 4834 | |
| 4835 | min_ddb_alloc = mul_round_up_u32_fixed16(res_lines + extra_lines, |
| 4836 | wp->plane_blocks_per_line); |
| 4837 | } else { |
| 4838 | min_ddb_alloc = res_blocks + |
| 4839 | DIV_ROUND_UP(res_blocks, 10); |
| 4840 | } |
| 4841 | } |
| 4842 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4843 | if (!skl_wm_has_lines(dev_priv, level)) |
| 4844 | res_lines = 0; |
| 4845 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4846 | if (res_lines > 31) { |
| 4847 | /* reject it */ |
| 4848 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4849 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4850 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4851 | |
| 4852 | /* |
| 4853 | * If res_lines is valid, assume we can use this watermark level |
| 4854 | * for now. We'll come back and disable it after we calculate the |
| 4855 | * DDB allocation if it turns out we don't actually have enough |
| 4856 | * blocks to satisfy it. |
| 4857 | */ |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4858 | result->plane_res_b = res_blocks; |
| 4859 | result->plane_res_l = res_lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4860 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
| 4861 | result->min_ddb_alloc = max(min_ddb_alloc, res_blocks) + 1; |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4862 | result->plane_en = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4865 | static void |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4866 | skl_compute_wm_levels(const struct intel_crtc_state *crtc_state, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4867 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4868 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4869 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4870 | 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] | 4871 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4872 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4873 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4874 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4875 | struct skl_wm_level *result = &levels[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4876 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4877 | skl_compute_plane_wm(crtc_state, level, wm_params, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4878 | result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4879 | |
| 4880 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4881 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4882 | } |
| 4883 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4884 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4885 | skl_compute_linetime_wm(const struct intel_crtc_state *crtc_state) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4886 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4887 | struct drm_atomic_state *state = crtc_state->base.state; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4888 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4889 | uint_fixed_16_16_t linetime_us; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4890 | u32 linetime_wm; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4891 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4892 | linetime_us = intel_get_linetime_us(crtc_state); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4893 | 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] | 4894 | |
Ville Syrjälä | 717671c | 2018-12-21 19:14:36 +0200 | [diff] [blame] | 4895 | /* Display WA #1135: BXT:ALL GLK:ALL */ |
| 4896 | if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled) |
Kumar, Mahesh | 446e850 | 2017-08-17 19:15:25 +0530 | [diff] [blame] | 4897 | linetime_wm /= 2; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4898 | |
| 4899 | return linetime_wm; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4900 | } |
| 4901 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4902 | 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] | 4903 | const struct skl_wm_params *wp, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4904 | struct skl_plane_wm *wm) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4905 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4906 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4907 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4908 | u16 trans_min, trans_y_tile_min; |
| 4909 | const u16 trans_amount = 10; /* This is configurable amount */ |
| 4910 | u16 wm0_sel_res_b, trans_offset_b, res_blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4911 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4912 | /* Transition WM are not recommended by HW team for GEN9 */ |
| 4913 | if (INTEL_GEN(dev_priv) <= 9) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4914 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4915 | |
| 4916 | /* Transition WM don't make any sense if ipc is disabled */ |
| 4917 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4918 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4919 | |
Paulo Zanoni | 91961a8 | 2018-10-04 16:15:56 -0700 | [diff] [blame] | 4920 | trans_min = 14; |
| 4921 | if (INTEL_GEN(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4922 | trans_min = 4; |
| 4923 | |
| 4924 | trans_offset_b = trans_min + trans_amount; |
| 4925 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4926 | /* |
| 4927 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 4928 | * not Result Blocks (the integer value). Pay attention to the capital |
| 4929 | * letters. The value wm_l0->plane_res_b is actually Result Blocks, but |
| 4930 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 4931 | * and since we later will have to get the ceiling of the sum in the |
| 4932 | * transition watermarks calculation, we can just pretend Selected |
| 4933 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 4934 | * current platforms. |
| 4935 | */ |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 4936 | wm0_sel_res_b = wm->wm[0].plane_res_b - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4937 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4938 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4939 | trans_y_tile_min = |
| 4940 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4941 | res_blocks = max(wm0_sel_res_b, trans_y_tile_min) + |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4942 | trans_offset_b; |
| 4943 | } else { |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4944 | res_blocks = wm0_sel_res_b + trans_offset_b; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4945 | |
| 4946 | /* WA BUG:1938466 add one block for non y-tile planes */ |
| 4947 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_A0)) |
| 4948 | res_blocks += 1; |
| 4949 | |
| 4950 | } |
| 4951 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4952 | /* |
| 4953 | * Just assume we can enable the transition watermark. After |
| 4954 | * computing the DDB we'll come back and disable it if that |
| 4955 | * assumption turns out to be false. |
| 4956 | */ |
| 4957 | wm->trans_wm.plane_res_b = res_blocks + 1; |
| 4958 | wm->trans_wm.plane_en = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4959 | } |
| 4960 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4961 | 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] | 4962 | const struct intel_plane_state *plane_state, |
| 4963 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4964 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4965 | 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] | 4966 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4967 | int ret; |
| 4968 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4969 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4970 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4971 | if (ret) |
| 4972 | return ret; |
| 4973 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4974 | skl_compute_wm_levels(crtc_state, &wm_params, wm->wm); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4975 | skl_compute_transition_wm(crtc_state, &wm_params, wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4976 | |
| 4977 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4978 | } |
| 4979 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4980 | 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] | 4981 | const struct intel_plane_state *plane_state, |
| 4982 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4983 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4984 | struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 4985 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4986 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4987 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4988 | wm->is_planar = true; |
| 4989 | |
| 4990 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4991 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4992 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4993 | if (ret) |
| 4994 | return ret; |
| 4995 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4996 | skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4997 | |
| 4998 | return 0; |
| 4999 | } |
| 5000 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5001 | 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] | 5002 | const struct intel_plane_state *plane_state) |
| 5003 | { |
| 5004 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 5005 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 5006 | enum plane_id plane_id = plane->id; |
| 5007 | int ret; |
| 5008 | |
| 5009 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 5010 | return 0; |
| 5011 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5012 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5013 | plane_id, 0); |
| 5014 | if (ret) |
| 5015 | return ret; |
| 5016 | |
| 5017 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5018 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5019 | plane_id); |
| 5020 | if (ret) |
| 5021 | return ret; |
| 5022 | } |
| 5023 | |
| 5024 | return 0; |
| 5025 | } |
| 5026 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5027 | 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] | 5028 | const struct intel_plane_state *plane_state) |
| 5029 | { |
| 5030 | enum plane_id plane_id = to_intel_plane(plane_state->base.plane)->id; |
| 5031 | int ret; |
| 5032 | |
| 5033 | /* Watermarks calculated in master */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5034 | if (plane_state->planar_slave) |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5035 | return 0; |
| 5036 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5037 | if (plane_state->planar_linked_plane) { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5038 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5039 | 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] | 5040 | |
| 5041 | WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state)); |
| 5042 | WARN_ON(!fb->format->is_yuv || |
| 5043 | fb->format->num_planes == 1); |
| 5044 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5045 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5046 | y_plane_id, 0); |
| 5047 | if (ret) |
| 5048 | return ret; |
| 5049 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5050 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5051 | plane_id, 1); |
| 5052 | if (ret) |
| 5053 | return ret; |
| 5054 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5055 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5056 | plane_id, 0); |
| 5057 | if (ret) |
| 5058 | return ret; |
| 5059 | } |
| 5060 | |
| 5061 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5062 | } |
| 5063 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5064 | static int skl_build_pipe_wm(struct intel_crtc_state *crtc_state) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5065 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5066 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 5067 | struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5068 | struct intel_plane *plane; |
| 5069 | const struct intel_plane_state *plane_state; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5070 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5071 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 5072 | /* |
| 5073 | * We'll only calculate watermarks for planes that are actually |
| 5074 | * enabled, so make sure all other planes are set as disabled. |
| 5075 | */ |
| 5076 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 5077 | |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5078 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, |
| 5079 | crtc_state) { |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5080 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5081 | if (INTEL_GEN(dev_priv) >= 11) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5082 | ret = icl_build_plane_wm(crtc_state, plane_state); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5083 | else |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5084 | ret = skl_build_plane_wm(crtc_state, plane_state); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5085 | if (ret) |
| 5086 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5087 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5088 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5089 | pipe_wm->linetime = skl_compute_linetime_wm(crtc_state); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5090 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5091 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5092 | } |
| 5093 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5094 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 5095 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5096 | const struct skl_ddb_entry *entry) |
| 5097 | { |
| 5098 | if (entry->end) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5099 | I915_WRITE_FW(reg, (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5100 | else |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5101 | I915_WRITE_FW(reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5102 | } |
| 5103 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5104 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5105 | i915_reg_t reg, |
| 5106 | const struct skl_wm_level *level) |
| 5107 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5108 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5109 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5110 | if (level->plane_en) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5111 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5112 | if (level->ignore_lines) |
| 5113 | val |= PLANE_WM_IGNORE_LINES; |
| 5114 | val |= level->plane_res_b; |
| 5115 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5116 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5117 | I915_WRITE_FW(reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5118 | } |
| 5119 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5120 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5121 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5122 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5123 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5124 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5125 | enum plane_id plane_id = plane->id; |
| 5126 | enum pipe pipe = plane->pipe; |
| 5127 | const struct skl_plane_wm *wm = |
| 5128 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5129 | const struct skl_ddb_entry *ddb_y = |
| 5130 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5131 | const struct skl_ddb_entry *ddb_uv = |
| 5132 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5133 | |
| 5134 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5135 | 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] | 5136 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5137 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5138 | 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] | 5139 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5140 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5141 | if (INTEL_GEN(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5142 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5143 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5144 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5145 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5146 | |
| 5147 | if (wm->is_planar) |
| 5148 | swap(ddb_y, ddb_uv); |
| 5149 | |
| 5150 | skl_ddb_entry_write(dev_priv, |
| 5151 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5152 | skl_ddb_entry_write(dev_priv, |
| 5153 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5154 | } |
| 5155 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5156 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5157 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5158 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5159 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5160 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5161 | enum plane_id plane_id = plane->id; |
| 5162 | enum pipe pipe = plane->pipe; |
| 5163 | const struct skl_plane_wm *wm = |
| 5164 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5165 | const struct skl_ddb_entry *ddb = |
| 5166 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5167 | |
| 5168 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5169 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 5170 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5171 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5172 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5173 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5174 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5175 | } |
| 5176 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5177 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5178 | const struct skl_wm_level *l2) |
| 5179 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5180 | return l1->plane_en == l2->plane_en && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5181 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5182 | l1->plane_res_l == l2->plane_res_l && |
| 5183 | l1->plane_res_b == l2->plane_res_b; |
| 5184 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5185 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5186 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5187 | const struct skl_plane_wm *wm1, |
| 5188 | const struct skl_plane_wm *wm2) |
| 5189 | { |
| 5190 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5191 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5192 | for (level = 0; level <= max_level; level++) { |
| 5193 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level]) || |
| 5194 | !skl_wm_level_equals(&wm1->uv_wm[level], &wm2->uv_wm[level])) |
| 5195 | return false; |
| 5196 | } |
| 5197 | |
| 5198 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5199 | } |
| 5200 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5201 | static bool skl_pipe_wm_equals(struct intel_crtc *crtc, |
| 5202 | const struct skl_pipe_wm *wm1, |
| 5203 | const struct skl_pipe_wm *wm2) |
| 5204 | { |
| 5205 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5206 | enum plane_id plane_id; |
| 5207 | |
| 5208 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5209 | if (!skl_plane_wm_equals(dev_priv, |
| 5210 | &wm1->planes[plane_id], |
| 5211 | &wm2->planes[plane_id])) |
| 5212 | return false; |
| 5213 | } |
| 5214 | |
| 5215 | return wm1->linetime == wm2->linetime; |
| 5216 | } |
| 5217 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5218 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 5219 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5220 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5221 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5222 | } |
| 5223 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5224 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 5225 | const struct skl_ddb_entry *entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5226 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5227 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5228 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5229 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5230 | for (i = 0; i < num_entries; i++) { |
| 5231 | if (i != ignore_idx && |
| 5232 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5233 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 5234 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5235 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5236 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5237 | } |
| 5238 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 5239 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5240 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 5241 | struct intel_crtc_state *new_crtc_state) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5242 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5243 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->base.state); |
| 5244 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5245 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5246 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5247 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5248 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5249 | struct intel_plane_state *plane_state; |
| 5250 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5251 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5252 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 5253 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 5254 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 5255 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5256 | continue; |
| 5257 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5258 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5259 | if (IS_ERR(plane_state)) |
| 5260 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 5261 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5262 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | return 0; |
| 5266 | } |
| 5267 | |
| 5268 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5269 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5270 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5271 | const struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5272 | struct skl_ddb_allocation *ddb = &state->wm_results.ddb; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5273 | struct intel_crtc_state *old_crtc_state; |
| 5274 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5275 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5276 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5277 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 5278 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 5279 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5280 | 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] | 5281 | new_crtc_state, i) { |
| 5282 | ret = skl_allocate_pipe_ddb(new_crtc_state, ddb); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5283 | if (ret) |
| 5284 | return ret; |
| 5285 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5286 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 5287 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5288 | if (ret) |
| 5289 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | return 0; |
| 5293 | } |
| 5294 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5295 | static char enast(bool enable) |
| 5296 | { |
| 5297 | return enable ? '*' : ' '; |
| 5298 | } |
| 5299 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 5300 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5301 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5302 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5303 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5304 | const struct intel_crtc_state *old_crtc_state; |
| 5305 | const struct intel_crtc_state *new_crtc_state; |
| 5306 | struct intel_plane *plane; |
| 5307 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5308 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5309 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5310 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 5311 | return; |
| 5312 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5313 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 5314 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5315 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 5316 | |
| 5317 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 5318 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 5319 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5320 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5321 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5322 | const struct skl_ddb_entry *old, *new; |
| 5323 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5324 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5325 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5326 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5327 | if (skl_ddb_entry_equal(old, new)) |
| 5328 | continue; |
| 5329 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5330 | 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] | 5331 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5332 | old->start, old->end, new->start, new->end, |
| 5333 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
| 5334 | } |
| 5335 | |
| 5336 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5337 | enum plane_id plane_id = plane->id; |
| 5338 | const struct skl_plane_wm *old_wm, *new_wm; |
| 5339 | |
| 5340 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 5341 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 5342 | |
| 5343 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 5344 | continue; |
| 5345 | |
| 5346 | DRM_DEBUG_KMS("[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm" |
| 5347 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm\n", |
| 5348 | plane->base.base.id, plane->base.name, |
| 5349 | enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en), |
| 5350 | enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en), |
| 5351 | enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en), |
| 5352 | enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en), |
| 5353 | enast(old_wm->trans_wm.plane_en), |
| 5354 | enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en), |
| 5355 | enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en), |
| 5356 | enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en), |
| 5357 | enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en), |
| 5358 | enast(new_wm->trans_wm.plane_en)); |
| 5359 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5360 | 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" |
| 5361 | " -> %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] | 5362 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5363 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l, |
| 5364 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l, |
| 5365 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l, |
| 5366 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l, |
| 5367 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l, |
| 5368 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l, |
| 5369 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l, |
| 5370 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l, |
| 5371 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l, |
| 5372 | |
| 5373 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l, |
| 5374 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l, |
| 5375 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l, |
| 5376 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l, |
| 5377 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l, |
| 5378 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l, |
| 5379 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l, |
| 5380 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l, |
| 5381 | 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] | 5382 | |
| 5383 | DRM_DEBUG_KMS("[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5384 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5385 | plane->base.base.id, plane->base.name, |
| 5386 | old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b, |
| 5387 | old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b, |
| 5388 | old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b, |
| 5389 | old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b, |
| 5390 | old_wm->trans_wm.plane_res_b, |
| 5391 | new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b, |
| 5392 | new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b, |
| 5393 | new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b, |
| 5394 | new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b, |
| 5395 | new_wm->trans_wm.plane_res_b); |
| 5396 | |
| 5397 | DRM_DEBUG_KMS("[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5398 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5399 | plane->base.base.id, plane->base.name, |
| 5400 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 5401 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 5402 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 5403 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 5404 | old_wm->trans_wm.min_ddb_alloc, |
| 5405 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 5406 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 5407 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 5408 | new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc, |
| 5409 | new_wm->trans_wm.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5410 | } |
| 5411 | } |
| 5412 | } |
| 5413 | |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5414 | static int intel_add_all_pipes(struct intel_atomic_state *state) |
| 5415 | { |
| 5416 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5417 | struct intel_crtc *crtc; |
| 5418 | |
| 5419 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5420 | struct intel_crtc_state *crtc_state; |
| 5421 | |
| 5422 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 5423 | if (IS_ERR(crtc_state)) |
| 5424 | return PTR_ERR(crtc_state); |
| 5425 | } |
| 5426 | |
| 5427 | return 0; |
| 5428 | } |
| 5429 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5430 | static int |
Ville Syrjälä | d7a1458 | 2019-10-11 23:09:42 +0300 | [diff] [blame] | 5431 | skl_ddb_add_affected_pipes(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5432 | { |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5433 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Ville Syrjälä | d7a1458 | 2019-10-11 23:09:42 +0300 | [diff] [blame] | 5434 | int ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5435 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5436 | /* |
| 5437 | * If this is our first atomic update following hardware readout, |
| 5438 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 5439 | * pretend that all pipes switched active status so that we'll |
| 5440 | * ensure a full DDB recompute. |
| 5441 | */ |
| 5442 | if (dev_priv->wm.distrust_bios_wm) { |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5443 | ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5444 | state->base.acquire_ctx); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5445 | if (ret) |
| 5446 | return ret; |
| 5447 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5448 | state->active_pipe_changes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5449 | |
| 5450 | /* |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 5451 | * We usually only initialize state->active_pipes if we |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5452 | * we're doing a modeset; make sure this field is always |
| 5453 | * initialized during the sanitization process that happens |
| 5454 | * on the first commit too. |
| 5455 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5456 | if (!state->modeset) |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 5457 | state->active_pipes = dev_priv->active_pipes; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | /* |
| 5461 | * If the modeset changes which CRTC's are active, we need to |
| 5462 | * recompute the DDB allocation for *all* active pipes, even |
| 5463 | * those that weren't otherwise being modified in any way by this |
| 5464 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 5465 | * when new active CRTC's are added, it's possible for a pipe that |
| 5466 | * we were already using and aren't changing at all here to suddenly |
| 5467 | * become invalid if its DDB needs exceeds its new allocation. |
| 5468 | * |
| 5469 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 5470 | * any other display updates race with this transaction, so we need |
| 5471 | * to grab the lock on *all* CRTC's. |
| 5472 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5473 | if (state->active_pipe_changes || state->modeset) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5474 | state->wm_results.dirty_pipes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5475 | |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5476 | ret = intel_add_all_pipes(state); |
| 5477 | if (ret) |
| 5478 | return ret; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | return 0; |
| 5482 | } |
| 5483 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5484 | /* |
| 5485 | * To make sure the cursor watermark registers are always consistent |
| 5486 | * with our computed state the following scenario needs special |
| 5487 | * treatment: |
| 5488 | * |
| 5489 | * 1. enable cursor |
| 5490 | * 2. move cursor entirely offscreen |
| 5491 | * 3. disable cursor |
| 5492 | * |
| 5493 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 5494 | * (since we consider an offscreen cursor still active for the purposes |
| 5495 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 5496 | * because the actual plane visibility isn't changing, and we don't |
| 5497 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 5498 | * force step 3. to call .disable_plane() to update the watermark |
| 5499 | * registers properly. |
| 5500 | * |
| 5501 | * Other planes do not suffer from this issues as their watermarks are |
| 5502 | * calculated based on the actual plane visibility. The only time this |
| 5503 | * can trigger for the other planes is during the initial readout as the |
| 5504 | * default value of the watermarks registers is not zero. |
| 5505 | */ |
| 5506 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 5507 | struct intel_crtc *crtc) |
| 5508 | { |
| 5509 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5510 | const struct intel_crtc_state *old_crtc_state = |
| 5511 | intel_atomic_get_old_crtc_state(state, crtc); |
| 5512 | struct intel_crtc_state *new_crtc_state = |
| 5513 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5514 | struct intel_plane *plane; |
| 5515 | |
| 5516 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5517 | struct intel_plane_state *plane_state; |
| 5518 | enum plane_id plane_id = plane->id; |
| 5519 | |
| 5520 | /* |
| 5521 | * Force a full wm update for every plane on modeset. |
| 5522 | * Required because the reset value of the wm registers |
| 5523 | * is non-zero, whereas we want all disabled planes to |
| 5524 | * have zero watermarks. So if we turn off the relevant |
| 5525 | * power well the hardware state will go out of sync |
| 5526 | * with the software state. |
| 5527 | */ |
| 5528 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->base) && |
| 5529 | skl_plane_wm_equals(dev_priv, |
| 5530 | &old_crtc_state->wm.skl.optimal.planes[plane_id], |
| 5531 | &new_crtc_state->wm.skl.optimal.planes[plane_id])) |
| 5532 | continue; |
| 5533 | |
| 5534 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 5535 | if (IS_ERR(plane_state)) |
| 5536 | return PTR_ERR(plane_state); |
| 5537 | |
| 5538 | new_crtc_state->update_planes |= BIT(plane_id); |
| 5539 | } |
| 5540 | |
| 5541 | return 0; |
| 5542 | } |
| 5543 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5544 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5545 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5546 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5547 | struct intel_crtc *crtc; |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5548 | struct intel_crtc_state *new_crtc_state; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5549 | struct intel_crtc_state *old_crtc_state; |
| 5550 | struct skl_ddb_values *results = &state->wm_results; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5551 | int ret, i; |
| 5552 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5553 | /* Clear all dirty flags */ |
| 5554 | results->dirty_pipes = 0; |
| 5555 | |
Ville Syrjälä | d7a1458 | 2019-10-11 23:09:42 +0300 | [diff] [blame] | 5556 | ret = skl_ddb_add_affected_pipes(state); |
| 5557 | if (ret) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5558 | return ret; |
| 5559 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5560 | /* |
| 5561 | * Calculate WM's for all pipes that are part of this transaction. |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5562 | * 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] | 5563 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 5564 | * pipe allocations had to change. |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5565 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5566 | 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] | 5567 | new_crtc_state, i) { |
| 5568 | ret = skl_build_pipe_wm(new_crtc_state); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5569 | if (ret) |
| 5570 | return ret; |
| 5571 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5572 | ret = skl_wm_add_affected_planes(state, crtc); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5573 | if (ret) |
| 5574 | return ret; |
| 5575 | |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5576 | if (!skl_pipe_wm_equals(crtc, |
| 5577 | &old_crtc_state->wm.skl.optimal, |
| 5578 | &new_crtc_state->wm.skl.optimal)) |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5579 | results->dirty_pipes |= BIT(crtc->pipe); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5580 | } |
| 5581 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5582 | ret = skl_compute_ddb(state); |
| 5583 | if (ret) |
| 5584 | return ret; |
| 5585 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5586 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5587 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5588 | return 0; |
| 5589 | } |
| 5590 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5591 | static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5592 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5593 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5594 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5595 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5596 | struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5597 | enum pipe pipe = crtc->pipe; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5598 | |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5599 | if ((state->wm_results.dirty_pipes & BIT(crtc->pipe)) == 0) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5600 | return; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5601 | |
| 5602 | I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime); |
| 5603 | } |
| 5604 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5605 | static void skl_initial_wm(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5606 | struct intel_crtc_state *crtc_state) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5607 | { |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5608 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5609 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5610 | struct skl_ddb_values *results = &state->wm_results; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 5611 | |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5612 | if ((results->dirty_pipes & BIT(crtc->pipe)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5613 | return; |
| 5614 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5615 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5616 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5617 | if (crtc_state->base.active_changed) |
| 5618 | skl_atomic_update_crtc_wm(state, crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5619 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5620 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5621 | } |
| 5622 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5623 | 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] | 5624 | struct intel_wm_config *config) |
| 5625 | { |
| 5626 | struct intel_crtc *crtc; |
| 5627 | |
| 5628 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5629 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5630 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 5631 | |
| 5632 | if (!wm->pipe_enabled) |
| 5633 | continue; |
| 5634 | |
| 5635 | config->sprites_enabled |= wm->sprites_enabled; |
| 5636 | config->sprites_scaled |= wm->sprites_scaled; |
| 5637 | config->num_pipes_active++; |
| 5638 | } |
| 5639 | } |
| 5640 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5641 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 5642 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5643 | 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] | 5644 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5645 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5646 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5647 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 5648 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5649 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5650 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5651 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 5652 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 5653 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5654 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5655 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5656 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5657 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 5658 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5659 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5660 | 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] | 5661 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5662 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5663 | } |
| 5664 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5665 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5666 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5667 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5668 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 5669 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5670 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 5671 | } |
| 5672 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5673 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5674 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5675 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5676 | 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] | 5677 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5678 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5679 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 5680 | crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5681 | ilk_program_watermarks(dev_priv); |
| 5682 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5683 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5684 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5685 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5686 | struct intel_crtc_state *crtc_state) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5687 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5688 | 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] | 5689 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5690 | |
| 5691 | if (!crtc_state->wm.need_postvbl_update) |
| 5692 | return; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5693 | |
| 5694 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 5695 | crtc->wm.active.ilk = crtc_state->wm.ilk.optimal; |
| 5696 | ilk_program_watermarks(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5697 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5698 | } |
| 5699 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5700 | static inline void skl_wm_level_from_reg_val(u32 val, |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5701 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5702 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5703 | level->plane_en = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5704 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5705 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 5706 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 5707 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5708 | } |
| 5709 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5710 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5711 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5712 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5713 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5714 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5715 | int level, max_level; |
| 5716 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5717 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5718 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5719 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5720 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5721 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5722 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5723 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5724 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5725 | if (plane_id != PLANE_CURSOR) |
| 5726 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5727 | else |
| 5728 | val = I915_READ(CUR_WM(pipe, level)); |
| 5729 | |
| 5730 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 5731 | } |
| 5732 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5733 | if (plane_id != PLANE_CURSOR) |
| 5734 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5735 | else |
| 5736 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 5737 | |
| 5738 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 5739 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5740 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5741 | if (!crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5742 | return; |
| 5743 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5744 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5745 | } |
| 5746 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5747 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5748 | { |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5749 | struct skl_ddb_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5750 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5751 | struct intel_crtc *crtc; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5752 | struct intel_crtc_state *crtc_state; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5753 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5754 | skl_ddb_get_hw_state(dev_priv, ddb); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5755 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5756 | crtc_state = to_intel_crtc_state(crtc->base.state); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5757 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5758 | 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] | 5759 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5760 | if (crtc->active) |
Ville Syrjälä | 36b53a2 | 2019-10-11 23:09:44 +0300 | [diff] [blame] | 5761 | hw->dirty_pipes |= BIT(crtc->pipe); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5762 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5763 | |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 5764 | if (dev_priv->active_pipes) { |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5765 | /* Fully recompute DDB on first atomic commit */ |
| 5766 | dev_priv->wm.distrust_bios_wm = true; |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5767 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5768 | } |
| 5769 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5770 | 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] | 5771 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5772 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5773 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5774 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5775 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 5776 | struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5777 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5778 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5779 | [PIPE_A] = WM0_PIPEA_ILK, |
| 5780 | [PIPE_B] = WM0_PIPEB_ILK, |
| 5781 | [PIPE_C] = WM0_PIPEC_IVB, |
| 5782 | }; |
| 5783 | |
| 5784 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5785 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 5786 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5787 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 5788 | memset(active, 0, sizeof(*active)); |
| 5789 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5790 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 5791 | |
| 5792 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5793 | u32 tmp = hw->wm_pipe[pipe]; |
| 5794 | |
| 5795 | /* |
| 5796 | * For active pipes LP0 watermark is marked as |
| 5797 | * enabled, and LP1+ watermaks as disabled since |
| 5798 | * we can't really reverse compute them in case |
| 5799 | * multiple pipes are active. |
| 5800 | */ |
| 5801 | active->wm[0].enable = true; |
| 5802 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 5803 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 5804 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 5805 | active->linetime = hw->wm_linetime[pipe]; |
| 5806 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5807 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5808 | |
| 5809 | /* |
| 5810 | * For inactive pipes, all watermark levels |
| 5811 | * should be marked as enabled but zeroed, |
| 5812 | * which is what we'd compute them to. |
| 5813 | */ |
| 5814 | for (level = 0; level <= max_level; level++) |
| 5815 | active->wm[level].enable = true; |
| 5816 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5817 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5818 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5819 | } |
| 5820 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5821 | #define _FW_WM(value, plane) \ |
| 5822 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 5823 | #define _FW_WM_VLV(value, plane) \ |
| 5824 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 5825 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5826 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 5827 | struct g4x_wm_values *wm) |
| 5828 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5829 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5830 | |
| 5831 | tmp = I915_READ(DSPFW1); |
| 5832 | wm->sr.plane = _FW_WM(tmp, SR); |
| 5833 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5834 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 5835 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 5836 | |
| 5837 | tmp = I915_READ(DSPFW2); |
| 5838 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 5839 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 5840 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 5841 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 5842 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5843 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 5844 | |
| 5845 | tmp = I915_READ(DSPFW3); |
| 5846 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 5847 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5848 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 5849 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 5850 | } |
| 5851 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5852 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 5853 | struct vlv_wm_values *wm) |
| 5854 | { |
| 5855 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5856 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5857 | |
| 5858 | for_each_pipe(dev_priv, pipe) { |
| 5859 | tmp = I915_READ(VLV_DDL(pipe)); |
| 5860 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5861 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5862 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5863 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5864 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5865 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5866 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5867 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5868 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 5869 | } |
| 5870 | |
| 5871 | tmp = I915_READ(DSPFW1); |
| 5872 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5873 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5874 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 5875 | 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] | 5876 | |
| 5877 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5878 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 5879 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5880 | 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] | 5881 | |
| 5882 | tmp = I915_READ(DSPFW3); |
| 5883 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5884 | |
| 5885 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5886 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5887 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5888 | 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] | 5889 | |
| 5890 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5891 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 5892 | 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] | 5893 | |
| 5894 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5895 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 5896 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5897 | |
| 5898 | tmp = I915_READ(DSPHOWM); |
| 5899 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5900 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 5901 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 5902 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 5903 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5904 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5905 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5906 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5907 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5908 | 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] | 5909 | } else { |
| 5910 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5911 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5912 | 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] | 5913 | |
| 5914 | tmp = I915_READ(DSPHOWM); |
| 5915 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5916 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5917 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5918 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5919 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5920 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5921 | 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] | 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | #undef _FW_WM |
| 5926 | #undef _FW_WM_VLV |
| 5927 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5928 | 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] | 5929 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5930 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 5931 | struct intel_crtc *crtc; |
| 5932 | |
| 5933 | g4x_read_wm_values(dev_priv, wm); |
| 5934 | |
| 5935 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 5936 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5937 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5938 | struct intel_crtc_state *crtc_state = |
| 5939 | to_intel_crtc_state(crtc->base.state); |
| 5940 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 5941 | struct g4x_pipe_wm *raw; |
| 5942 | enum pipe pipe = crtc->pipe; |
| 5943 | enum plane_id plane_id; |
| 5944 | int level, max_level; |
| 5945 | |
| 5946 | active->cxsr = wm->cxsr; |
| 5947 | active->hpll_en = wm->hpll_en; |
| 5948 | active->fbc_en = wm->fbc_en; |
| 5949 | |
| 5950 | active->sr = wm->sr; |
| 5951 | active->hpll = wm->hpll; |
| 5952 | |
| 5953 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5954 | active->wm.plane[plane_id] = |
| 5955 | wm->pipe[pipe].plane[plane_id]; |
| 5956 | } |
| 5957 | |
| 5958 | if (wm->cxsr && wm->hpll_en) |
| 5959 | max_level = G4X_WM_LEVEL_HPLL; |
| 5960 | else if (wm->cxsr) |
| 5961 | max_level = G4X_WM_LEVEL_SR; |
| 5962 | else |
| 5963 | max_level = G4X_WM_LEVEL_NORMAL; |
| 5964 | |
| 5965 | level = G4X_WM_LEVEL_NORMAL; |
| 5966 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5967 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5968 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 5969 | |
| 5970 | if (++level > max_level) |
| 5971 | goto out; |
| 5972 | |
| 5973 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5974 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 5975 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 5976 | raw->plane[PLANE_SPRITE0] = 0; |
| 5977 | raw->fbc = active->sr.fbc; |
| 5978 | |
| 5979 | if (++level > max_level) |
| 5980 | goto out; |
| 5981 | |
| 5982 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5983 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 5984 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 5985 | raw->plane[PLANE_SPRITE0] = 0; |
| 5986 | raw->fbc = active->hpll.fbc; |
| 5987 | |
| 5988 | out: |
| 5989 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5990 | g4x_raw_plane_wm_set(crtc_state, level, |
| 5991 | plane_id, USHRT_MAX); |
| 5992 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 5993 | |
| 5994 | crtc_state->wm.g4x.optimal = *active; |
| 5995 | crtc_state->wm.g4x.intermediate = *active; |
| 5996 | |
| 5997 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 5998 | pipe_name(pipe), |
| 5999 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6000 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6001 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
| 6002 | } |
| 6003 | |
| 6004 | DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 6005 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 6006 | DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 6007 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 6008 | DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", |
| 6009 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
| 6010 | } |
| 6011 | |
| 6012 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6013 | { |
| 6014 | struct intel_plane *plane; |
| 6015 | struct intel_crtc *crtc; |
| 6016 | |
| 6017 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6018 | |
| 6019 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6020 | struct intel_crtc *crtc = |
| 6021 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6022 | struct intel_crtc_state *crtc_state = |
| 6023 | to_intel_crtc_state(crtc->base.state); |
| 6024 | struct intel_plane_state *plane_state = |
| 6025 | to_intel_plane_state(plane->base.state); |
| 6026 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 6027 | enum plane_id plane_id = plane->id; |
| 6028 | int level; |
| 6029 | |
| 6030 | if (plane_state->base.visible) |
| 6031 | continue; |
| 6032 | |
| 6033 | for (level = 0; level < 3; level++) { |
| 6034 | struct g4x_pipe_wm *raw = |
| 6035 | &crtc_state->wm.g4x.raw[level]; |
| 6036 | |
| 6037 | raw->plane[plane_id] = 0; |
| 6038 | wm_state->wm.plane[plane_id] = 0; |
| 6039 | } |
| 6040 | |
| 6041 | if (plane_id == PLANE_PRIMARY) { |
| 6042 | for (level = 0; level < 3; level++) { |
| 6043 | struct g4x_pipe_wm *raw = |
| 6044 | &crtc_state->wm.g4x.raw[level]; |
| 6045 | raw->fbc = 0; |
| 6046 | } |
| 6047 | |
| 6048 | wm_state->sr.fbc = 0; |
| 6049 | wm_state->hpll.fbc = 0; |
| 6050 | wm_state->fbc_en = false; |
| 6051 | } |
| 6052 | } |
| 6053 | |
| 6054 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6055 | struct intel_crtc_state *crtc_state = |
| 6056 | to_intel_crtc_state(crtc->base.state); |
| 6057 | |
| 6058 | crtc_state->wm.g4x.intermediate = |
| 6059 | crtc_state->wm.g4x.optimal; |
| 6060 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 6061 | } |
| 6062 | |
| 6063 | g4x_program_watermarks(dev_priv); |
| 6064 | |
| 6065 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6066 | } |
| 6067 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6068 | 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] | 6069 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6070 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 6071 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6072 | u32 val; |
| 6073 | |
| 6074 | vlv_read_wm_values(dev_priv, wm); |
| 6075 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6076 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 6077 | wm->level = VLV_WM_LEVEL_PM2; |
| 6078 | |
| 6079 | if (IS_CHERRYVIEW(dev_priv)) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6080 | vlv_punit_get(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6081 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 6082 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6083 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 6084 | wm->level = VLV_WM_LEVEL_PM5; |
| 6085 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6086 | /* |
| 6087 | * If DDR DVFS is disabled in the BIOS, Punit |
| 6088 | * will never ack the request. So if that happens |
| 6089 | * assume we don't have to enable/disable DDR DVFS |
| 6090 | * dynamically. To test that just set the REQ_ACK |
| 6091 | * bit to poke the Punit, but don't change the |
| 6092 | * HIGH/LOW bits so that we don't actually change |
| 6093 | * the current state. |
| 6094 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6095 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6096 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 6097 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 6098 | |
| 6099 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 6100 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 6101 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 6102 | "assuming DDR DVFS is disabled\n"); |
| 6103 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 6104 | } else { |
| 6105 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 6106 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 6107 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 6108 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6109 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6110 | vlv_punit_put(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6111 | } |
| 6112 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6113 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6114 | struct intel_crtc_state *crtc_state = |
| 6115 | to_intel_crtc_state(crtc->base.state); |
| 6116 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 6117 | const struct vlv_fifo_state *fifo_state = |
| 6118 | &crtc_state->wm.vlv.fifo_state; |
| 6119 | enum pipe pipe = crtc->pipe; |
| 6120 | enum plane_id plane_id; |
| 6121 | int level; |
| 6122 | |
| 6123 | vlv_get_fifo_size(crtc_state); |
| 6124 | |
| 6125 | active->num_levels = wm->level + 1; |
| 6126 | active->cxsr = wm->cxsr; |
| 6127 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6128 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6129 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6130 | &crtc_state->wm.vlv.raw[level]; |
| 6131 | |
| 6132 | active->sr[level].plane = wm->sr.plane; |
| 6133 | active->sr[level].cursor = wm->sr.cursor; |
| 6134 | |
| 6135 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6136 | active->wm[level].plane[plane_id] = |
| 6137 | wm->pipe[pipe].plane[plane_id]; |
| 6138 | |
| 6139 | raw->plane[plane_id] = |
| 6140 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 6141 | fifo_state->plane[plane_id]); |
| 6142 | } |
| 6143 | } |
| 6144 | |
| 6145 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6146 | vlv_raw_plane_wm_set(crtc_state, level, |
| 6147 | plane_id, USHRT_MAX); |
| 6148 | vlv_invalidate_wms(crtc, active, level); |
| 6149 | |
| 6150 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 6151 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6152 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6153 | 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] | 6154 | pipe_name(pipe), |
| 6155 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6156 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6157 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 6158 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6159 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6160 | |
| 6161 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 6162 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 6163 | } |
| 6164 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6165 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6166 | { |
| 6167 | struct intel_plane *plane; |
| 6168 | struct intel_crtc *crtc; |
| 6169 | |
| 6170 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6171 | |
| 6172 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6173 | struct intel_crtc *crtc = |
| 6174 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6175 | struct intel_crtc_state *crtc_state = |
| 6176 | to_intel_crtc_state(crtc->base.state); |
| 6177 | struct intel_plane_state *plane_state = |
| 6178 | to_intel_plane_state(plane->base.state); |
| 6179 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 6180 | const struct vlv_fifo_state *fifo_state = |
| 6181 | &crtc_state->wm.vlv.fifo_state; |
| 6182 | enum plane_id plane_id = plane->id; |
| 6183 | int level; |
| 6184 | |
| 6185 | if (plane_state->base.visible) |
| 6186 | continue; |
| 6187 | |
| 6188 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6189 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6190 | &crtc_state->wm.vlv.raw[level]; |
| 6191 | |
| 6192 | raw->plane[plane_id] = 0; |
| 6193 | |
| 6194 | wm_state->wm[level].plane[plane_id] = |
| 6195 | vlv_invert_wm_value(raw->plane[plane_id], |
| 6196 | fifo_state->plane[plane_id]); |
| 6197 | } |
| 6198 | } |
| 6199 | |
| 6200 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6201 | struct intel_crtc_state *crtc_state = |
| 6202 | to_intel_crtc_state(crtc->base.state); |
| 6203 | |
| 6204 | crtc_state->wm.vlv.intermediate = |
| 6205 | crtc_state->wm.vlv.optimal; |
| 6206 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 6207 | } |
| 6208 | |
| 6209 | vlv_program_watermarks(dev_priv); |
| 6210 | |
| 6211 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6212 | } |
| 6213 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6214 | /* |
| 6215 | * FIXME should probably kill this and improve |
| 6216 | * the real watermark readout/sanitation instead |
| 6217 | */ |
| 6218 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 6219 | { |
| 6220 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 6221 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 6222 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 6223 | |
| 6224 | /* |
| 6225 | * Don't touch WM1S_LP_EN here. |
| 6226 | * Doing so could cause underruns. |
| 6227 | */ |
| 6228 | } |
| 6229 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6230 | 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] | 6231 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6232 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6233 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6234 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6235 | ilk_init_lp_watermarks(dev_priv); |
| 6236 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6237 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6238 | ilk_pipe_wm_get_hw_state(crtc); |
| 6239 | |
| 6240 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 6241 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 6242 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 6243 | |
| 6244 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 6245 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 6246 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 6247 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 6248 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6249 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6250 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6251 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 6252 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 6253 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6254 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 6255 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6256 | |
| 6257 | hw->enable_fbc_wm = |
| 6258 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 6259 | } |
| 6260 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6261 | /** |
| 6262 | * intel_update_watermarks - update FIFO watermark values based on current modes |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 6263 | * @crtc: the #intel_crtc on which to compute the WM |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6264 | * |
| 6265 | * Calculate watermark values for the various WM regs based on current mode |
| 6266 | * and plane configuration. |
| 6267 | * |
| 6268 | * There are several cases to deal with here: |
| 6269 | * - normal (i.e. non-self-refresh) |
| 6270 | * - self-refresh (SR) mode |
| 6271 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 6272 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 6273 | * lines), so need to account for TLB latency |
| 6274 | * |
| 6275 | * The normal calculation is: |
| 6276 | * watermark = dotclock * bytes per pixel * latency |
| 6277 | * where latency is platform & configuration dependent (we assume pessimal |
| 6278 | * values here). |
| 6279 | * |
| 6280 | * The SR calculation is: |
| 6281 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 6282 | * bytes per pixel |
| 6283 | * where |
| 6284 | * line time = htotal / dotclock |
| 6285 | * surface width = hdisplay for normal plane and 64 for cursor |
| 6286 | * and latency is assumed to be high, as above. |
| 6287 | * |
| 6288 | * The final value programmed to the register should always be rounded up, |
| 6289 | * and include an extra 2 entries to account for clock crossings. |
| 6290 | * |
| 6291 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 6292 | * to set the non-SR watermarks to 8. |
| 6293 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6294 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6295 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6296 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6297 | |
| 6298 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 6299 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6300 | } |
| 6301 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6302 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 6303 | { |
| 6304 | u32 val; |
| 6305 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 6306 | if (!HAS_IPC(dev_priv)) |
| 6307 | return; |
| 6308 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6309 | val = I915_READ(DISP_ARB_CTL2); |
| 6310 | |
| 6311 | if (dev_priv->ipc_enabled) |
| 6312 | val |= DISP_IPC_ENABLE; |
| 6313 | else |
| 6314 | val &= ~DISP_IPC_ENABLE; |
| 6315 | |
| 6316 | I915_WRITE(DISP_ARB_CTL2, val); |
| 6317 | } |
| 6318 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6319 | static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv) |
| 6320 | { |
| 6321 | /* Display WA #0477 WaDisableIPC: skl */ |
| 6322 | if (IS_SKYLAKE(dev_priv)) |
| 6323 | return false; |
| 6324 | |
| 6325 | /* Display WA #1141: SKL:all KBL:all CFL */ |
| 6326 | if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) |
| 6327 | return dev_priv->dram_info.symmetric_memory; |
| 6328 | |
| 6329 | return true; |
| 6330 | } |
| 6331 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6332 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 6333 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6334 | if (!HAS_IPC(dev_priv)) |
| 6335 | return; |
| 6336 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6337 | dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv); |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 6338 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6339 | intel_enable_ipc(dev_priv); |
| 6340 | } |
| 6341 | |
Jani Nikula | e282891 | 2016-01-18 09:19:47 +0200 | [diff] [blame] | 6342 | /* |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6343 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6344 | */ |
| 6345 | DEFINE_SPINLOCK(mchdev_lock); |
| 6346 | |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6347 | bool ironlake_set_drps(struct drm_i915_private *i915, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6348 | { |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6349 | struct intel_uncore *uncore = &i915->uncore; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6350 | u16 rgvswctl; |
| 6351 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 6352 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6353 | |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6354 | rgvswctl = intel_uncore_read16(uncore, MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6355 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 6356 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 6357 | return false; /* still busy with another command */ |
| 6358 | } |
| 6359 | |
| 6360 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 6361 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6362 | intel_uncore_write16(uncore, MEMSWCTL, rgvswctl); |
| 6363 | intel_uncore_posting_read16(uncore, MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6364 | |
| 6365 | rgvswctl |= MEMCTL_CMD_STS; |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6366 | intel_uncore_write16(uncore, MEMSWCTL, rgvswctl); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6367 | |
| 6368 | return true; |
| 6369 | } |
| 6370 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6371 | static void ironlake_enable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6372 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6373 | struct intel_uncore *uncore = &dev_priv->uncore; |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 6374 | u32 rgvmodectl; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6375 | u8 fmax, fmin, fstart, vstart; |
| 6376 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6377 | spin_lock_irq(&mchdev_lock); |
| 6378 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6379 | rgvmodectl = intel_uncore_read(uncore, MEMMODECTL); |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 6380 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6381 | /* Enable temp reporting */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6382 | intel_uncore_write16(uncore, PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 6383 | intel_uncore_write16(uncore, TSC1, I915_READ(TSC1) | TSE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6384 | |
| 6385 | /* 100ms RC evaluation intervals */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6386 | intel_uncore_write(uncore, RCUPEI, 100000); |
| 6387 | intel_uncore_write(uncore, RCDNEI, 100000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6388 | |
| 6389 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6390 | intel_uncore_write(uncore, RCBMAXAVG, 90000); |
| 6391 | intel_uncore_write(uncore, RCBMINAVG, 80000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6392 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6393 | intel_uncore_write(uncore, MEMIHYST, 1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6394 | |
| 6395 | /* Set up min, max, and cur for interrupt handling */ |
| 6396 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 6397 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 6398 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 6399 | MEMMODE_FSTART_SHIFT; |
| 6400 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6401 | vstart = (intel_uncore_read(uncore, PXVFREQ(fstart)) & |
| 6402 | PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6403 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6404 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 6405 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6406 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6407 | dev_priv->ips.max_delay = fstart; |
| 6408 | dev_priv->ips.min_delay = fmin; |
| 6409 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6410 | |
| 6411 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 6412 | fmax, fmin, fstart); |
| 6413 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6414 | intel_uncore_write(uncore, |
| 6415 | MEMINTREN, |
| 6416 | MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6417 | |
| 6418 | /* |
| 6419 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 6420 | */ |
| 6421 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6422 | intel_uncore_write(uncore, VIDSTART, vstart); |
| 6423 | intel_uncore_posting_read(uncore, VIDSTART); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6424 | |
| 6425 | rgvmodectl |= MEMMODE_SWMODE_EN; |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6426 | intel_uncore_write(uncore, MEMMODECTL, rgvmodectl); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6427 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6428 | if (wait_for_atomic((intel_uncore_read(uncore, MEMSWCTL) & |
| 6429 | MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6430 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6431 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6432 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6433 | ironlake_set_drps(dev_priv, fstart); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6434 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6435 | dev_priv->ips.last_count1 = |
| 6436 | intel_uncore_read(uncore, DMIEC) + |
| 6437 | intel_uncore_read(uncore, DDREC) + |
| 6438 | intel_uncore_read(uncore, CSIEC); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6439 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6440 | dev_priv->ips.last_count2 = intel_uncore_read(uncore, GFXEC); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 6441 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6442 | |
| 6443 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6444 | } |
| 6445 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6446 | static void ironlake_disable_drps(struct drm_i915_private *i915) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6447 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6448 | struct intel_uncore *uncore = &i915->uncore; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6449 | u16 rgvswctl; |
| 6450 | |
| 6451 | spin_lock_irq(&mchdev_lock); |
| 6452 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6453 | rgvswctl = intel_uncore_read16(uncore, MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6454 | |
| 6455 | /* Ack interrupts, disable EFC interrupt */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6456 | intel_uncore_write(uncore, |
| 6457 | MEMINTREN, |
| 6458 | intel_uncore_read(uncore, MEMINTREN) & |
| 6459 | ~MEMINT_EVAL_CHG_EN); |
| 6460 | intel_uncore_write(uncore, MEMINTRSTS, MEMINT_EVAL_CHG); |
| 6461 | intel_uncore_write(uncore, |
| 6462 | DEIER, |
| 6463 | intel_uncore_read(uncore, DEIER) & ~DE_PCU_EVENT); |
| 6464 | intel_uncore_write(uncore, DEIIR, DE_PCU_EVENT); |
| 6465 | intel_uncore_write(uncore, |
| 6466 | DEIMR, |
| 6467 | intel_uncore_read(uncore, DEIMR) | DE_PCU_EVENT); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6468 | |
| 6469 | /* Go back to the starting frequency */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6470 | ironlake_set_drps(i915, i915->ips.fstart); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6471 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6472 | rgvswctl |= MEMCTL_CMD_STS; |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6473 | intel_uncore_write(uncore, MEMSWCTL, rgvswctl); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6474 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6475 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6476 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6477 | } |
| 6478 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 6479 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 6480 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 6481 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 6482 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 6483 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6484 | static u32 intel_rps_limits(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6485 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6486 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6487 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6488 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6489 | /* Only set the down limit when we've reached the lowest level to avoid |
| 6490 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 6491 | * race in the hw when coming out of rc6: There's a tiny window where |
| 6492 | * the hw runs at the minimal clock before selecting the desired |
| 6493 | * frequency, if the down threshold expires in that window we will not |
| 6494 | * receive a down interrupt. */ |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6495 | if (INTEL_GEN(dev_priv) >= 9) { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6496 | limits = (rps->max_freq_softlimit) << 23; |
| 6497 | if (val <= rps->min_freq_softlimit) |
| 6498 | limits |= (rps->min_freq_softlimit) << 14; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6499 | } else { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6500 | limits = rps->max_freq_softlimit << 24; |
| 6501 | if (val <= rps->min_freq_softlimit) |
| 6502 | limits |= rps->min_freq_softlimit << 16; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6503 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6504 | |
| 6505 | return limits; |
| 6506 | } |
| 6507 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6508 | static void rps_set_power(struct drm_i915_private *dev_priv, int new_power) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6509 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6510 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6511 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 6512 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6513 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6514 | lockdep_assert_held(&rps->power.mutex); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6515 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6516 | if (new_power == rps->power.mode) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6517 | return; |
| 6518 | |
| 6519 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 6520 | switch (new_power) { |
| 6521 | case LOW_POWER: |
| 6522 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6523 | ei_up = 16000; |
| 6524 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6525 | |
| 6526 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6527 | ei_down = 32000; |
| 6528 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6529 | break; |
| 6530 | |
| 6531 | case BETWEEN: |
| 6532 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6533 | ei_up = 13000; |
| 6534 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6535 | |
| 6536 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6537 | ei_down = 32000; |
| 6538 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6539 | break; |
| 6540 | |
| 6541 | case HIGH_POWER: |
| 6542 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6543 | ei_up = 10000; |
| 6544 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6545 | |
| 6546 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6547 | ei_down = 32000; |
| 6548 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6549 | break; |
| 6550 | } |
| 6551 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6552 | /* When byt can survive without system hang with dynamic |
| 6553 | * sw freq adjustments, this restriction can be lifted. |
| 6554 | */ |
| 6555 | if (IS_VALLEYVIEW(dev_priv)) |
| 6556 | goto skip_hw_write; |
| 6557 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6558 | I915_WRITE(GEN6_RP_UP_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6559 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6560 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6561 | GT_INTERVAL_FROM_US(dev_priv, |
| 6562 | ei_up * threshold_up / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6563 | |
| 6564 | I915_WRITE(GEN6_RP_DOWN_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6565 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6566 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6567 | GT_INTERVAL_FROM_US(dev_priv, |
| 6568 | ei_down * threshold_down / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6569 | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6570 | I915_WRITE(GEN6_RP_CONTROL, |
Mika Kuoppala | 1071d0f | 2019-04-10 16:24:36 +0300 | [diff] [blame] | 6571 | (INTEL_GEN(dev_priv) > 9 ? 0 : GEN6_RP_MEDIA_TURBO) | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6572 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6573 | GEN6_RP_MEDIA_IS_GFX | |
| 6574 | GEN6_RP_ENABLE | |
| 6575 | GEN6_RP_UP_BUSY_AVG | |
| 6576 | GEN6_RP_DOWN_IDLE_AVG); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6577 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6578 | skip_hw_write: |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6579 | rps->power.mode = new_power; |
| 6580 | rps->power.up_threshold = threshold_up; |
| 6581 | rps->power.down_threshold = threshold_down; |
| 6582 | } |
| 6583 | |
| 6584 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 6585 | { |
| 6586 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6587 | int new_power; |
| 6588 | |
| 6589 | new_power = rps->power.mode; |
| 6590 | switch (rps->power.mode) { |
| 6591 | case LOW_POWER: |
| 6592 | if (val > rps->efficient_freq + 1 && |
| 6593 | val > rps->cur_freq) |
| 6594 | new_power = BETWEEN; |
| 6595 | break; |
| 6596 | |
| 6597 | case BETWEEN: |
| 6598 | if (val <= rps->efficient_freq && |
| 6599 | val < rps->cur_freq) |
| 6600 | new_power = LOW_POWER; |
| 6601 | else if (val >= rps->rp0_freq && |
| 6602 | val > rps->cur_freq) |
| 6603 | new_power = HIGH_POWER; |
| 6604 | break; |
| 6605 | |
| 6606 | case HIGH_POWER: |
| 6607 | if (val < (rps->rp1_freq + rps->rp0_freq) >> 1 && |
| 6608 | val < rps->cur_freq) |
| 6609 | new_power = BETWEEN; |
| 6610 | break; |
| 6611 | } |
| 6612 | /* Max/min bins are special */ |
| 6613 | if (val <= rps->min_freq_softlimit) |
| 6614 | new_power = LOW_POWER; |
| 6615 | if (val >= rps->max_freq_softlimit) |
| 6616 | new_power = HIGH_POWER; |
| 6617 | |
| 6618 | mutex_lock(&rps->power.mutex); |
| 6619 | if (rps->power.interactive) |
| 6620 | new_power = HIGH_POWER; |
| 6621 | rps_set_power(dev_priv, new_power); |
| 6622 | mutex_unlock(&rps->power.mutex); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6623 | } |
| 6624 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6625 | void intel_rps_mark_interactive(struct drm_i915_private *i915, bool interactive) |
| 6626 | { |
| 6627 | struct intel_rps *rps = &i915->gt_pm.rps; |
| 6628 | |
| 6629 | if (INTEL_GEN(i915) < 6) |
| 6630 | return; |
| 6631 | |
| 6632 | mutex_lock(&rps->power.mutex); |
| 6633 | if (interactive) { |
| 6634 | if (!rps->power.interactive++ && READ_ONCE(i915->gt.awake)) |
| 6635 | rps_set_power(i915, HIGH_POWER); |
| 6636 | } else { |
| 6637 | GEM_BUG_ON(!rps->power.interactive); |
| 6638 | rps->power.interactive--; |
| 6639 | } |
| 6640 | mutex_unlock(&rps->power.mutex); |
| 6641 | } |
| 6642 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6643 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 6644 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6645 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6646 | u32 mask = 0; |
| 6647 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6648 | /* We use UP_EI_EXPIRED interupts for both up/down in manual mode */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6649 | if (val > rps->min_freq_softlimit) |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6650 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6651 | if (val < rps->max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 6652 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6653 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 6654 | mask &= dev_priv->pm_rps_events; |
| 6655 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 6656 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6657 | } |
| 6658 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6659 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 6660 | * called when the range (min_delay and max_delay) is modified so that we can |
| 6661 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6662 | static int gen6_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6663 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6664 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6665 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6666 | /* min/max delay may still have been modified so be sure to |
| 6667 | * write the limits value. |
| 6668 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6669 | if (val != rps->cur_freq) { |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6670 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6671 | |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6672 | if (INTEL_GEN(dev_priv) >= 9) |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 6673 | I915_WRITE(GEN6_RPNSWREQ, |
| 6674 | GEN9_FREQUENCY(val)); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6675 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6676 | I915_WRITE(GEN6_RPNSWREQ, |
| 6677 | HSW_FREQUENCY(val)); |
| 6678 | else |
| 6679 | I915_WRITE(GEN6_RPNSWREQ, |
| 6680 | GEN6_FREQUENCY(val) | |
| 6681 | GEN6_OFFSET(0) | |
| 6682 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6683 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6684 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6685 | /* Make sure we continue to get interrupts |
| 6686 | * until we hit the minimum or maximum frequencies. |
| 6687 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6688 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6689 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6690 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6691 | rps->cur_freq = val; |
Mika Kuoppala | 0f94592 | 2015-11-17 18:14:26 +0200 | [diff] [blame] | 6692 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6693 | |
| 6694 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6695 | } |
| 6696 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6697 | static int valleyview_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6698 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6699 | int err; |
| 6700 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6701 | if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1), |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6702 | "Odd GPU freq value\n")) |
| 6703 | val &= ~1; |
| 6704 | |
Deepak S | cd25dd5 | 2015-07-10 18:31:40 +0530 | [diff] [blame] | 6705 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 6706 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6707 | if (val != dev_priv->gt_pm.rps.cur_freq) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6708 | vlv_punit_get(dev_priv); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6709 | err = vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6710 | vlv_punit_put(dev_priv); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6711 | if (err) |
| 6712 | return err; |
| 6713 | |
Chris Wilson | db4c5e0 | 2017-02-10 15:03:46 +0000 | [diff] [blame] | 6714 | gen6_set_rps_thresholds(dev_priv, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 6715 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6716 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6717 | dev_priv->gt_pm.rps.cur_freq = val; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6718 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6719 | |
| 6720 | return 0; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6721 | } |
| 6722 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6723 | /* vlv_set_rps_idle: Set the frequency to idle, if Gfx clocks are down |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6724 | * |
| 6725 | * * If Gfx is Idle, then |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6726 | * 1. Forcewake Media well. |
| 6727 | * 2. Request idle freq. |
| 6728 | * 3. Release Forcewake of Media well. |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6729 | */ |
| 6730 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 6731 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6732 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6733 | u32 val = rps->idle_freq; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6734 | int err; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 6735 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6736 | if (rps->cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6737 | return; |
| 6738 | |
Chris Wilson | c9efef7 | 2017-01-02 15:28:45 +0000 | [diff] [blame] | 6739 | /* The punit delays the write of the frequency and voltage until it |
| 6740 | * determines the GPU is awake. During normal usage we don't want to |
| 6741 | * waste power changing the frequency if the GPU is sleeping (rc6). |
| 6742 | * However, the GPU and driver is now idle and we do not want to delay |
| 6743 | * switching to minimum voltage (reducing power whilst idle) as we do |
| 6744 | * not expect to be woken in the near future and so must flush the |
| 6745 | * change by waking the device. |
| 6746 | * |
| 6747 | * We choose to take the media powerwell (either would do to trick the |
| 6748 | * punit into committing the voltage change) as that takes a lot less |
| 6749 | * power than the render powerwell. |
| 6750 | */ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6751 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6752 | err = valleyview_set_rps(dev_priv, val); |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6753 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6754 | |
| 6755 | if (err) |
| 6756 | DRM_ERROR("Failed to set RPS for idle\n"); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6757 | } |
| 6758 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6759 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 6760 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6761 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6762 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6763 | mutex_lock(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6764 | if (rps->enabled) { |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6765 | u8 freq; |
| 6766 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6767 | if (dev_priv->pm_rps_events & GEN6_PM_RP_UP_EI_EXPIRED) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6768 | gen6_rps_reset_ei(dev_priv); |
| 6769 | I915_WRITE(GEN6_PMINTRMSK, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6770 | gen6_rps_pm_mask(dev_priv, rps->cur_freq)); |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 6771 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6772 | gen6_enable_rps_interrupts(dev_priv); |
| 6773 | |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6774 | /* Use the user's desired frequency as a guide, but for better |
| 6775 | * performance, jump directly to RPe as our starting frequency. |
| 6776 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6777 | freq = max(rps->cur_freq, |
| 6778 | rps->efficient_freq); |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6779 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6780 | if (intel_set_rps(dev_priv, |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6781 | clamp(freq, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6782 | rps->min_freq_softlimit, |
| 6783 | rps->max_freq_softlimit))) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6784 | DRM_DEBUG_DRIVER("Failed to set idle frequency\n"); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6785 | } |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6786 | mutex_unlock(&rps->lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6787 | } |
| 6788 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6789 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 6790 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6791 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6792 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6793 | /* Flush our bottom-half so that it does not race with us |
| 6794 | * setting the idle frequency and so that it is bounded by |
| 6795 | * our rpm wakeref. And then disable the interrupts to stop any |
| 6796 | * futher RPS reclocking whilst we are asleep. |
| 6797 | */ |
| 6798 | gen6_disable_rps_interrupts(dev_priv); |
| 6799 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6800 | mutex_lock(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6801 | if (rps->enabled) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6802 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6803 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6804 | else |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6805 | gen6_set_rps(dev_priv, rps->idle_freq); |
| 6806 | rps->last_adj = 0; |
Ville Syrjälä | 12c100b | 2016-05-23 17:42:48 +0300 | [diff] [blame] | 6807 | I915_WRITE(GEN6_PMINTRMSK, |
| 6808 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6809 | } |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6810 | mutex_unlock(&rps->lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6811 | } |
| 6812 | |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 6813 | void gen6_rps_boost(struct i915_request *rq) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6814 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6815 | struct intel_rps *rps = &rq->i915->gt_pm.rps; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6816 | unsigned long flags; |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6817 | bool boost; |
| 6818 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6819 | /* This is intentionally racy! We peek at the state here, then |
| 6820 | * validate inside the RPS worker. |
| 6821 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6822 | if (!rps->enabled) |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6823 | return; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6824 | |
Chris Wilson | 0e21834 | 2019-01-21 22:21:02 +0000 | [diff] [blame] | 6825 | if (i915_request_signaled(rq)) |
Chris Wilson | 253a281 | 2018-02-06 14:31:37 +0000 | [diff] [blame] | 6826 | return; |
| 6827 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 6828 | /* Serializes with i915_request_retire() */ |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6829 | boost = false; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6830 | spin_lock_irqsave(&rq->lock, flags); |
Lionel Landwerlin | 2a98f4e | 2019-07-09 17:42:27 +0100 | [diff] [blame] | 6831 | if (!i915_request_has_waitboost(rq) && |
| 6832 | !dma_fence_is_signaled_locked(&rq->fence)) { |
Chris Wilson | 253a281 | 2018-02-06 14:31:37 +0000 | [diff] [blame] | 6833 | boost = !atomic_fetch_inc(&rps->num_waiters); |
Lionel Landwerlin | 2a98f4e | 2019-07-09 17:42:27 +0100 | [diff] [blame] | 6834 | rq->flags |= I915_REQUEST_WAITBOOST; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6835 | } |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6836 | spin_unlock_irqrestore(&rq->lock, flags); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6837 | if (!boost) |
| 6838 | return; |
| 6839 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6840 | if (READ_ONCE(rps->cur_freq) < rps->boost_freq) |
| 6841 | schedule_work(&rps->work); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6842 | |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 6843 | atomic_inc(&rps->boosts); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6844 | } |
| 6845 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6846 | int intel_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6847 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6848 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6849 | int err; |
| 6850 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6851 | lockdep_assert_held(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6852 | GEM_BUG_ON(val > rps->max_freq); |
| 6853 | GEM_BUG_ON(val < rps->min_freq); |
Chris Wilson | cfd1c48 | 2017-02-20 09:47:07 +0000 | [diff] [blame] | 6854 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6855 | if (!rps->enabled) { |
| 6856 | rps->cur_freq = val; |
Chris Wilson | 76e4e4b | 2017-02-20 09:47:08 +0000 | [diff] [blame] | 6857 | return 0; |
| 6858 | } |
| 6859 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6860 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6861 | err = valleyview_set_rps(dev_priv, val); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6862 | else |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6863 | err = gen6_set_rps(dev_priv, val); |
| 6864 | |
| 6865 | return err; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6866 | } |
| 6867 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6868 | static void gen9_disable_rps(struct drm_i915_private *dev_priv) |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6869 | { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6870 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6871 | } |
| 6872 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6873 | static void gen6_disable_rps(struct drm_i915_private *dev_priv) |
| 6874 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6875 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6876 | I915_WRITE(GEN6_RP_CONTROL, 0); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6877 | } |
| 6878 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6879 | static void cherryview_disable_rps(struct drm_i915_private *dev_priv) |
| 6880 | { |
| 6881 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6882 | } |
| 6883 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6884 | static void valleyview_disable_rps(struct drm_i915_private *dev_priv) |
| 6885 | { |
| 6886 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6887 | } |
| 6888 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6889 | static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6890 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6891 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6892 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6893 | /* All of these values are in units of 50MHz */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6894 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6895 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 6896 | if (IS_GEN9_LP(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6897 | u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6898 | rps->rp0_freq = (rp_state_cap >> 16) & 0xff; |
| 6899 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 6900 | rps->min_freq = (rp_state_cap >> 0) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 6901 | } else { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6902 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6903 | rps->rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 6904 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 6905 | rps->min_freq = (rp_state_cap >> 16) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 6906 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6907 | /* hw_max = RP0 until we check for overclocking */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6908 | rps->max_freq = rps->rp0_freq; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6909 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6910 | rps->efficient_freq = rps->rp1_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6911 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) || |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 6912 | IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6913 | u32 ddcc_status = 0; |
| 6914 | |
| 6915 | if (sandybridge_pcode_read(dev_priv, |
| 6916 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 6917 | &ddcc_status, NULL) == 0) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6918 | rps->efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 6919 | clamp_t(u8, |
| 6920 | ((ddcc_status >> 8) & 0xff), |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6921 | rps->min_freq, |
| 6922 | rps->max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6923 | } |
| 6924 | |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 6925 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 6926 | /* Store the frequency values in 16.66 MHZ units, which is |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6927 | * the natural hardware unit for SKL |
| 6928 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6929 | rps->rp0_freq *= GEN9_FREQ_SCALER; |
| 6930 | rps->rp1_freq *= GEN9_FREQ_SCALER; |
| 6931 | rps->min_freq *= GEN9_FREQ_SCALER; |
| 6932 | rps->max_freq *= GEN9_FREQ_SCALER; |
| 6933 | rps->efficient_freq *= GEN9_FREQ_SCALER; |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 6934 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6935 | } |
| 6936 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6937 | static void reset_rps(struct drm_i915_private *dev_priv, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6938 | int (*set)(struct drm_i915_private *, u8)) |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6939 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6940 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6941 | u8 freq = rps->cur_freq; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6942 | |
| 6943 | /* force a reset */ |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6944 | rps->power.mode = -1; |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6945 | rps->cur_freq = -1; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6946 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6947 | if (set(dev_priv, freq)) |
| 6948 | DRM_ERROR("Failed to reset RPS to initial values\n"); |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6949 | } |
| 6950 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6951 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6952 | static void gen9_enable_rps(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6953 | { |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6954 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6955 | |
David Weinehall | 36fe778 | 2017-11-17 10:01:46 +0200 | [diff] [blame] | 6956 | /* Program defaults and thresholds for RPS */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6957 | if (IS_GEN(dev_priv, 9)) |
David Weinehall | 36fe778 | 2017-11-17 10:01:46 +0200 | [diff] [blame] | 6958 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 6959 | GEN9_FREQUENCY(dev_priv->gt_pm.rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6960 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6961 | /* 1 second timeout*/ |
| 6962 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 6963 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 6964 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6965 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6966 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6967 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 6968 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 6969 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6970 | reset_rps(dev_priv, gen6_set_rps); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6971 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6972 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6973 | } |
| 6974 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 6975 | static void gen8_enable_rps(struct drm_i915_private *dev_priv) |
| 6976 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6977 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6978 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6979 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 6980 | |
| 6981 | /* 1 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 6982 | I915_WRITE(GEN6_RPNSWREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6983 | HSW_FREQUENCY(rps->rp1_freq)); |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 6984 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6985 | HSW_FREQUENCY(rps->rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6986 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 6987 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6988 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6989 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 6990 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6991 | rps->max_freq_softlimit << 24 | |
| 6992 | rps->min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6993 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6994 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 6995 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 6996 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 6997 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6998 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6999 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7000 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7001 | /* 2: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7002 | I915_WRITE(GEN6_RP_CONTROL, |
| 7003 | GEN6_RP_MEDIA_TURBO | |
| 7004 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7005 | GEN6_RP_MEDIA_IS_GFX | |
| 7006 | GEN6_RP_ENABLE | |
| 7007 | GEN6_RP_UP_BUSY_AVG | |
| 7008 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7009 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7010 | reset_rps(dev_priv, gen6_set_rps); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7011 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7012 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7013 | } |
| 7014 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7015 | static void gen6_enable_rps(struct drm_i915_private *dev_priv) |
| 7016 | { |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7017 | /* Here begins a magic sequence of register writes to enable |
| 7018 | * auto-downclocking. |
| 7019 | * |
| 7020 | * Perhaps there might be some value in exposing these to |
| 7021 | * userspace... |
| 7022 | */ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7023 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7024 | |
| 7025 | /* Power down if completely idle for over 50ms */ |
| 7026 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
| 7027 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7028 | |
| 7029 | reset_rps(dev_priv, gen6_set_rps); |
| 7030 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7031 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7032 | } |
| 7033 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7034 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7035 | { |
| 7036 | u32 val, rp0; |
| 7037 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7038 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7039 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 7040 | switch (RUNTIME_INFO(dev_priv)->sseu.eu_total) { |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7041 | case 8: |
| 7042 | /* (2 * 4) config */ |
| 7043 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 7044 | break; |
| 7045 | case 12: |
| 7046 | /* (2 * 6) config */ |
| 7047 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 7048 | break; |
| 7049 | case 16: |
| 7050 | /* (2 * 8) config */ |
| 7051 | default: |
| 7052 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 7053 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 7054 | break; |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 7055 | } |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7056 | |
| 7057 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 7058 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7059 | return rp0; |
| 7060 | } |
| 7061 | |
| 7062 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7063 | { |
| 7064 | u32 val, rpe; |
| 7065 | |
| 7066 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 7067 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 7068 | |
| 7069 | return rpe; |
| 7070 | } |
| 7071 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7072 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7073 | { |
| 7074 | u32 val, rp1; |
| 7075 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7076 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 7077 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 7078 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7079 | return rp1; |
| 7080 | } |
| 7081 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 7082 | static u32 cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 7083 | { |
| 7084 | u32 val, rpn; |
| 7085 | |
| 7086 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 7087 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 7088 | FB_GFX_FREQ_FUSE_MASK); |
| 7089 | |
| 7090 | return rpn; |
| 7091 | } |
| 7092 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7093 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7094 | { |
| 7095 | u32 val, rp1; |
| 7096 | |
| 7097 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 7098 | |
| 7099 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 7100 | |
| 7101 | return rp1; |
| 7102 | } |
| 7103 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7104 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7105 | { |
| 7106 | u32 val, rp0; |
| 7107 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7108 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7109 | |
| 7110 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 7111 | /* Clamp to max */ |
| 7112 | rp0 = min_t(u32, rp0, 0xea); |
| 7113 | |
| 7114 | return rp0; |
| 7115 | } |
| 7116 | |
| 7117 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7118 | { |
| 7119 | u32 val, rpe; |
| 7120 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7121 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_LO); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7122 | rpe = (val & FB_FMAX_VMIN_FREQ_LO_MASK) >> FB_FMAX_VMIN_FREQ_LO_SHIFT; |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7123 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_HI); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7124 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 7125 | |
| 7126 | return rpe; |
| 7127 | } |
| 7128 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7129 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7130 | { |
Imre Deak | 3614603 | 2014-12-04 18:39:35 +0200 | [diff] [blame] | 7131 | u32 val; |
| 7132 | |
| 7133 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
| 7134 | /* |
| 7135 | * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value |
| 7136 | * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on |
| 7137 | * a BYT-M B0 the above register contains 0xbf. Moreover when setting |
| 7138 | * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0 |
| 7139 | * to make sure it matches what Punit accepts. |
| 7140 | */ |
| 7141 | return max_t(u32, val, 0xc0); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7142 | } |
| 7143 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7144 | static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv) |
| 7145 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7146 | dev_priv->gt_pm.rps.gpll_ref_freq = |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7147 | vlv_get_cck_clock(dev_priv, "GPLL ref", |
| 7148 | CCK_GPLL_CLOCK_CONTROL, |
| 7149 | dev_priv->czclk_freq); |
| 7150 | |
| 7151 | DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7152 | dev_priv->gt_pm.rps.gpll_ref_freq); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7153 | } |
| 7154 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7155 | static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7156 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7157 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7158 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7159 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7160 | vlv_iosf_sb_get(dev_priv, |
| 7161 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7162 | BIT(VLV_IOSF_SB_NC) | |
| 7163 | BIT(VLV_IOSF_SB_CCK)); |
| 7164 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7165 | vlv_init_gpll_ref_freq(dev_priv); |
| 7166 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7167 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7168 | switch ((val >> 6) & 3) { |
| 7169 | case 0: |
| 7170 | case 1: |
| 7171 | dev_priv->mem_freq = 800; |
| 7172 | break; |
| 7173 | case 2: |
| 7174 | dev_priv->mem_freq = 1066; |
| 7175 | break; |
| 7176 | case 3: |
| 7177 | dev_priv->mem_freq = 1333; |
| 7178 | break; |
| 7179 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7180 | DRM_DEBUG_DRIVER("DDR speed: %d MHz\n", dev_priv->mem_freq); |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7181 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7182 | rps->max_freq = valleyview_rps_max_freq(dev_priv); |
| 7183 | rps->rp0_freq = rps->max_freq; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7184 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7185 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7186 | rps->max_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7187 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7188 | rps->efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7189 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7190 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7191 | rps->efficient_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7192 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7193 | rps->rp1_freq = valleyview_rps_guar_freq(dev_priv); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7194 | DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7195 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7196 | rps->rp1_freq); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7197 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7198 | rps->min_freq = valleyview_rps_min_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7199 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7200 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7201 | rps->min_freq); |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7202 | |
| 7203 | vlv_iosf_sb_put(dev_priv, |
| 7204 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7205 | BIT(VLV_IOSF_SB_NC) | |
| 7206 | BIT(VLV_IOSF_SB_CCK)); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7207 | } |
| 7208 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7209 | static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7210 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7211 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7212 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7213 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7214 | vlv_iosf_sb_get(dev_priv, |
| 7215 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7216 | BIT(VLV_IOSF_SB_NC) | |
| 7217 | BIT(VLV_IOSF_SB_CCK)); |
| 7218 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7219 | vlv_init_gpll_ref_freq(dev_priv); |
| 7220 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7221 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7222 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7223 | switch ((val >> 2) & 0x7) { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7224 | case 3: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7225 | dev_priv->mem_freq = 2000; |
| 7226 | break; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 7227 | default: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7228 | dev_priv->mem_freq = 1600; |
| 7229 | break; |
| 7230 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7231 | DRM_DEBUG_DRIVER("DDR speed: %d MHz\n", dev_priv->mem_freq); |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7232 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7233 | rps->max_freq = cherryview_rps_max_freq(dev_priv); |
| 7234 | rps->rp0_freq = rps->max_freq; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7235 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7236 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7237 | rps->max_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7238 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7239 | rps->efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7240 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7241 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7242 | rps->efficient_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7243 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7244 | rps->rp1_freq = cherryview_rps_guar_freq(dev_priv); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7245 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7246 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7247 | rps->rp1_freq); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7248 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7249 | rps->min_freq = cherryview_rps_min_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7250 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7251 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7252 | rps->min_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7253 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7254 | vlv_iosf_sb_put(dev_priv, |
| 7255 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7256 | BIT(VLV_IOSF_SB_NC) | |
| 7257 | BIT(VLV_IOSF_SB_CCK)); |
| 7258 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7259 | WARN_ONCE((rps->max_freq | rps->efficient_freq | rps->rp1_freq | |
| 7260 | rps->min_freq) & 1, |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7261 | "Odd GPU freq values\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7262 | } |
| 7263 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7264 | static void cherryview_enable_rps(struct drm_i915_private *dev_priv) |
| 7265 | { |
| 7266 | u32 val; |
| 7267 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7268 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7269 | |
| 7270 | /* 1: Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 7271 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7272 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7273 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7274 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7275 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7276 | |
| 7277 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7278 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7279 | /* 2: Enable RPS */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7280 | I915_WRITE(GEN6_RP_CONTROL, |
| 7281 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 7282 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7283 | GEN6_RP_ENABLE | |
| 7284 | GEN6_RP_UP_BUSY_AVG | |
| 7285 | GEN6_RP_DOWN_IDLE_AVG); |
| 7286 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7287 | /* Setting Fixed Bias */ |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7288 | vlv_punit_get(dev_priv); |
| 7289 | |
| 7290 | val = VLV_OVERRIDE_EN | VLV_SOC_TDP_EN | CHV_BIAS_CPU_50_SOC_50; |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7291 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7292 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7293 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7294 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7295 | vlv_punit_put(dev_priv); |
| 7296 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7297 | /* RPS code assumes GPLL is used */ |
| 7298 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7299 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7300 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7301 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7302 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7303 | reset_rps(dev_priv, valleyview_set_rps); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7304 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7305 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7306 | } |
| 7307 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7308 | static void valleyview_enable_rps(struct drm_i915_private *dev_priv) |
| 7309 | { |
| 7310 | u32 val; |
| 7311 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7312 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7313 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 7314 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7315 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7316 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7317 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7318 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7319 | |
| 7320 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7321 | |
| 7322 | I915_WRITE(GEN6_RP_CONTROL, |
| 7323 | GEN6_RP_MEDIA_TURBO | |
| 7324 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7325 | GEN6_RP_MEDIA_IS_GFX | |
| 7326 | GEN6_RP_ENABLE | |
| 7327 | GEN6_RP_UP_BUSY_AVG | |
| 7328 | GEN6_RP_DOWN_IDLE_CONT); |
| 7329 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7330 | vlv_punit_get(dev_priv); |
| 7331 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7332 | /* Setting Fixed Bias */ |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7333 | val = VLV_OVERRIDE_EN | VLV_SOC_TDP_EN | VLV_BIAS_CPU_125_SOC_875; |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7334 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7335 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7336 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7337 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7338 | vlv_punit_put(dev_priv); |
| 7339 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7340 | /* RPS code assumes GPLL is used */ |
| 7341 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7342 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7343 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7344 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7345 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7346 | reset_rps(dev_priv, valleyview_set_rps); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7347 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7348 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7349 | } |
| 7350 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7351 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 7352 | { |
| 7353 | unsigned long freq; |
| 7354 | int div = (vidfreq & 0x3f0000) >> 16; |
| 7355 | int post = (vidfreq & 0x3000) >> 12; |
| 7356 | int pre = (vidfreq & 0x7); |
| 7357 | |
| 7358 | if (!pre) |
| 7359 | return 0; |
| 7360 | |
| 7361 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 7362 | |
| 7363 | return freq; |
| 7364 | } |
| 7365 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7366 | static const struct cparams { |
| 7367 | u16 i; |
| 7368 | u16 t; |
| 7369 | u16 m; |
| 7370 | u16 c; |
| 7371 | } cparams[] = { |
| 7372 | { 1, 1333, 301, 28664 }, |
| 7373 | { 1, 1066, 294, 24460 }, |
| 7374 | { 1, 800, 294, 25192 }, |
| 7375 | { 0, 1333, 276, 27605 }, |
| 7376 | { 0, 1066, 276, 27605 }, |
| 7377 | { 0, 800, 231, 23784 }, |
| 7378 | }; |
| 7379 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7380 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7381 | { |
| 7382 | u64 total_count, diff, ret; |
| 7383 | u32 count1, count2, count3, m = 0, c = 0; |
| 7384 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 7385 | int i; |
| 7386 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7387 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7388 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7389 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7390 | |
| 7391 | /* Prevent division-by-zero if we are asking too fast. |
| 7392 | * Also, we don't get interesting results if we are polling |
| 7393 | * faster than once in 10ms, so just return the saved value |
| 7394 | * in such cases. |
| 7395 | */ |
| 7396 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7397 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7398 | |
| 7399 | count1 = I915_READ(DMIEC); |
| 7400 | count2 = I915_READ(DDREC); |
| 7401 | count3 = I915_READ(CSIEC); |
| 7402 | |
| 7403 | total_count = count1 + count2 + count3; |
| 7404 | |
| 7405 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7406 | if (total_count < dev_priv->ips.last_count1) { |
| 7407 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7408 | diff += total_count; |
| 7409 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7410 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7411 | } |
| 7412 | |
| 7413 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7414 | if (cparams[i].i == dev_priv->ips.c_m && |
| 7415 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7416 | m = cparams[i].m; |
| 7417 | c = cparams[i].c; |
| 7418 | break; |
| 7419 | } |
| 7420 | } |
| 7421 | |
| 7422 | diff = div_u64(diff, diff1); |
| 7423 | ret = ((m * diff) + c); |
| 7424 | ret = div_u64(ret, 10); |
| 7425 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7426 | dev_priv->ips.last_count1 = total_count; |
| 7427 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7428 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7429 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7430 | |
| 7431 | return ret; |
| 7432 | } |
| 7433 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7434 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 7435 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7436 | intel_wakeref_t wakeref; |
| 7437 | unsigned long val = 0; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7438 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7439 | if (!IS_GEN(dev_priv, 5)) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7440 | return 0; |
| 7441 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 7442 | with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7443 | spin_lock_irq(&mchdev_lock); |
| 7444 | val = __i915_chipset_val(dev_priv); |
| 7445 | spin_unlock_irq(&mchdev_lock); |
| 7446 | } |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7447 | |
| 7448 | return val; |
| 7449 | } |
| 7450 | |
Tvrtko Ursulin | c54f0ba | 2019-06-11 11:45:43 +0100 | [diff] [blame] | 7451 | unsigned long i915_mch_val(struct drm_i915_private *i915) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7452 | { |
| 7453 | unsigned long m, x, b; |
| 7454 | u32 tsfs; |
| 7455 | |
Tvrtko Ursulin | c54f0ba | 2019-06-11 11:45:43 +0100 | [diff] [blame] | 7456 | tsfs = intel_uncore_read(&i915->uncore, TSFS); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7457 | |
| 7458 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
Tvrtko Ursulin | c54f0ba | 2019-06-11 11:45:43 +0100 | [diff] [blame] | 7459 | x = intel_uncore_read8(&i915->uncore, TR1); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7460 | |
| 7461 | b = tsfs & TSFS_INTR_MASK; |
| 7462 | |
| 7463 | return ((m * x) / 127) - b; |
| 7464 | } |
| 7465 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7466 | static int _pxvid_to_vd(u8 pxvid) |
| 7467 | { |
| 7468 | if (pxvid == 0) |
| 7469 | return 0; |
| 7470 | |
| 7471 | if (pxvid >= 8 && pxvid < 31) |
| 7472 | pxvid = 31; |
| 7473 | |
| 7474 | return (pxvid + 2) * 125; |
| 7475 | } |
| 7476 | |
| 7477 | static u32 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7478 | { |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7479 | const int vd = _pxvid_to_vd(pxvid); |
| 7480 | const int vm = vd - 1125; |
| 7481 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7482 | if (INTEL_INFO(dev_priv)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7483 | return vm > 0 ? vm : 0; |
| 7484 | |
| 7485 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7486 | } |
| 7487 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7488 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7489 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 7490 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7491 | u32 count; |
| 7492 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7493 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7494 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 7495 | now = ktime_get_raw_ns(); |
| 7496 | diffms = now - dev_priv->ips.last_time2; |
| 7497 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7498 | |
| 7499 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7500 | if (!diffms) |
| 7501 | return; |
| 7502 | |
| 7503 | count = I915_READ(GFXEC); |
| 7504 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7505 | if (count < dev_priv->ips.last_count2) { |
| 7506 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7507 | diff += count; |
| 7508 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7509 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7510 | } |
| 7511 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7512 | dev_priv->ips.last_count2 = count; |
| 7513 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7514 | |
| 7515 | /* More magic constants... */ |
| 7516 | diff = diff * 1181; |
| 7517 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7518 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7519 | } |
| 7520 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7521 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 7522 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7523 | intel_wakeref_t wakeref; |
| 7524 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7525 | if (!IS_GEN(dev_priv, 5)) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7526 | return; |
| 7527 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 7528 | with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7529 | spin_lock_irq(&mchdev_lock); |
| 7530 | __i915_update_gfx_val(dev_priv); |
| 7531 | spin_unlock_irq(&mchdev_lock); |
| 7532 | } |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7533 | } |
| 7534 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7535 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7536 | { |
| 7537 | unsigned long t, corr, state1, corr2, state2; |
| 7538 | u32 pxvid, ext_v; |
| 7539 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7540 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7541 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7542 | pxvid = I915_READ(PXVFREQ(dev_priv->gt_pm.rps.cur_freq)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7543 | pxvid = (pxvid >> 24) & 0x7f; |
| 7544 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 7545 | |
| 7546 | state1 = ext_v; |
| 7547 | |
| 7548 | t = i915_mch_val(dev_priv); |
| 7549 | |
| 7550 | /* Revel in the empirically derived constants */ |
| 7551 | |
| 7552 | /* Correction factor in 1/100000 units */ |
| 7553 | if (t > 80) |
| 7554 | corr = ((t * 2349) + 135940); |
| 7555 | else if (t >= 50) |
| 7556 | corr = ((t * 964) + 29317); |
| 7557 | else /* < 50 */ |
| 7558 | corr = ((t * 301) + 1004); |
| 7559 | |
| 7560 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 7561 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7562 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7563 | |
| 7564 | state2 = (corr2 * state1) / 10000; |
| 7565 | state2 /= 100; /* convert to mW */ |
| 7566 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7567 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7568 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7569 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7570 | } |
| 7571 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7572 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 7573 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7574 | intel_wakeref_t wakeref; |
| 7575 | unsigned long val = 0; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7576 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7577 | if (!IS_GEN(dev_priv, 5)) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7578 | return 0; |
| 7579 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 7580 | with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7581 | spin_lock_irq(&mchdev_lock); |
| 7582 | val = __i915_gfx_val(dev_priv); |
| 7583 | spin_unlock_irq(&mchdev_lock); |
| 7584 | } |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7585 | |
| 7586 | return val; |
| 7587 | } |
| 7588 | |
Chris Wilson | adc674c | 2019-04-12 09:53:22 +0100 | [diff] [blame] | 7589 | static struct drm_i915_private __rcu *i915_mch_dev; |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7590 | |
| 7591 | static struct drm_i915_private *mchdev_get(void) |
| 7592 | { |
| 7593 | struct drm_i915_private *i915; |
| 7594 | |
| 7595 | rcu_read_lock(); |
Chris Wilson | adc674c | 2019-04-12 09:53:22 +0100 | [diff] [blame] | 7596 | i915 = rcu_dereference(i915_mch_dev); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7597 | if (!kref_get_unless_zero(&i915->drm.ref)) |
| 7598 | i915 = NULL; |
| 7599 | rcu_read_unlock(); |
| 7600 | |
| 7601 | return i915; |
| 7602 | } |
| 7603 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7604 | /** |
| 7605 | * i915_read_mch_val - return value for IPS use |
| 7606 | * |
| 7607 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 7608 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 7609 | */ |
| 7610 | unsigned long i915_read_mch_val(void) |
| 7611 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7612 | struct drm_i915_private *i915; |
| 7613 | unsigned long chipset_val = 0; |
| 7614 | unsigned long graphics_val = 0; |
| 7615 | intel_wakeref_t wakeref; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7616 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7617 | i915 = mchdev_get(); |
| 7618 | if (!i915) |
| 7619 | return 0; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7620 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 7621 | with_intel_runtime_pm(&i915->runtime_pm, wakeref) { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7622 | spin_lock_irq(&mchdev_lock); |
| 7623 | chipset_val = __i915_chipset_val(i915); |
| 7624 | graphics_val = __i915_gfx_val(i915); |
| 7625 | spin_unlock_irq(&mchdev_lock); |
| 7626 | } |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7627 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7628 | drm_dev_put(&i915->drm); |
| 7629 | return chipset_val + graphics_val; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7630 | } |
| 7631 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 7632 | |
| 7633 | /** |
| 7634 | * i915_gpu_raise - raise GPU frequency limit |
| 7635 | * |
| 7636 | * Raise the limit; IPS indicates we have thermal headroom. |
| 7637 | */ |
| 7638 | bool i915_gpu_raise(void) |
| 7639 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7640 | struct drm_i915_private *i915; |
| 7641 | |
| 7642 | i915 = mchdev_get(); |
| 7643 | if (!i915) |
| 7644 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7645 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7646 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7647 | if (i915->ips.max_delay > i915->ips.fmax) |
| 7648 | i915->ips.max_delay--; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7649 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7650 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7651 | drm_dev_put(&i915->drm); |
| 7652 | return true; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7653 | } |
| 7654 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 7655 | |
| 7656 | /** |
| 7657 | * i915_gpu_lower - lower GPU frequency limit |
| 7658 | * |
| 7659 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 7660 | * frequency maximum. |
| 7661 | */ |
| 7662 | bool i915_gpu_lower(void) |
| 7663 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7664 | struct drm_i915_private *i915; |
| 7665 | |
| 7666 | i915 = mchdev_get(); |
| 7667 | if (!i915) |
| 7668 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7669 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7670 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7671 | if (i915->ips.max_delay < i915->ips.min_delay) |
| 7672 | i915->ips.max_delay++; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7673 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7674 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7675 | drm_dev_put(&i915->drm); |
| 7676 | return true; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7677 | } |
| 7678 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 7679 | |
| 7680 | /** |
| 7681 | * i915_gpu_busy - indicate GPU business to IPS |
| 7682 | * |
| 7683 | * Tell the IPS driver whether or not the GPU is busy. |
| 7684 | */ |
| 7685 | bool i915_gpu_busy(void) |
| 7686 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7687 | struct drm_i915_private *i915; |
| 7688 | bool ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7689 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7690 | i915 = mchdev_get(); |
| 7691 | if (!i915) |
| 7692 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7693 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7694 | ret = i915->gt.awake; |
| 7695 | |
| 7696 | drm_dev_put(&i915->drm); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7697 | return ret; |
| 7698 | } |
| 7699 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 7700 | |
| 7701 | /** |
| 7702 | * i915_gpu_turbo_disable - disable graphics turbo |
| 7703 | * |
| 7704 | * Disable graphics turbo by resetting the max frequency and setting the |
| 7705 | * current frequency to the default. |
| 7706 | */ |
| 7707 | bool i915_gpu_turbo_disable(void) |
| 7708 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7709 | struct drm_i915_private *i915; |
| 7710 | bool ret; |
| 7711 | |
| 7712 | i915 = mchdev_get(); |
| 7713 | if (!i915) |
| 7714 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7715 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7716 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7717 | i915->ips.max_delay = i915->ips.fstart; |
| 7718 | ret = ironlake_set_drps(i915, i915->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7719 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7720 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7721 | drm_dev_put(&i915->drm); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7722 | return ret; |
| 7723 | } |
| 7724 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 7725 | |
| 7726 | /** |
| 7727 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 7728 | * IPS got loaded first. |
| 7729 | * |
| 7730 | * This awkward dance is so that neither module has to depend on the |
| 7731 | * other in order for IPS to do the appropriate communication of |
| 7732 | * GPU turbo limits to i915. |
| 7733 | */ |
| 7734 | static void |
| 7735 | ips_ping_for_i915_load(void) |
| 7736 | { |
| 7737 | void (*link)(void); |
| 7738 | |
| 7739 | link = symbol_get(ips_link_to_i915_driver); |
| 7740 | if (link) { |
| 7741 | link(); |
| 7742 | symbol_put(ips_link_to_i915_driver); |
| 7743 | } |
| 7744 | } |
| 7745 | |
| 7746 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 7747 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7748 | /* We only register the i915 ips part with intel-ips once everything is |
| 7749 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7750 | rcu_assign_pointer(i915_mch_dev, dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7751 | |
| 7752 | ips_ping_for_i915_load(); |
| 7753 | } |
| 7754 | |
| 7755 | void intel_gpu_ips_teardown(void) |
| 7756 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7757 | rcu_assign_pointer(i915_mch_dev, NULL); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7758 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 7759 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7760 | static void intel_init_emon(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7761 | { |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7762 | u32 lcfuse; |
| 7763 | u8 pxw[16]; |
| 7764 | int i; |
| 7765 | |
| 7766 | /* Disable to program */ |
| 7767 | I915_WRITE(ECR, 0); |
| 7768 | POSTING_READ(ECR); |
| 7769 | |
| 7770 | /* Program energy weights for various events */ |
| 7771 | I915_WRITE(SDEW, 0x15040d00); |
| 7772 | I915_WRITE(CSIEW0, 0x007f0000); |
| 7773 | I915_WRITE(CSIEW1, 0x1e220004); |
| 7774 | I915_WRITE(CSIEW2, 0x04000004); |
| 7775 | |
| 7776 | for (i = 0; i < 5; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7777 | I915_WRITE(PEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7778 | for (i = 0; i < 3; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7779 | I915_WRITE(DEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7780 | |
| 7781 | /* Program P-state weights to account for frequency power adjustment */ |
| 7782 | for (i = 0; i < 16; i++) { |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7783 | u32 pxvidfreq = I915_READ(PXVFREQ(i)); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7784 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 7785 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 7786 | PXVFREQ_PX_SHIFT; |
| 7787 | unsigned long val; |
| 7788 | |
| 7789 | val = vid * vid; |
| 7790 | val *= (freq / 1000); |
| 7791 | val *= 255; |
| 7792 | val /= (127*127*900); |
| 7793 | if (val > 0xff) |
| 7794 | DRM_ERROR("bad pxval: %ld\n", val); |
| 7795 | pxw[i] = val; |
| 7796 | } |
| 7797 | /* Render standby states get 0 weight */ |
| 7798 | pxw[14] = 0; |
| 7799 | pxw[15] = 0; |
| 7800 | |
| 7801 | for (i = 0; i < 4; i++) { |
| 7802 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 7803 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7804 | I915_WRITE(PXW(i), val); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7805 | } |
| 7806 | |
| 7807 | /* Adjust magic regs to magic values (more experimental results) */ |
| 7808 | I915_WRITE(OGW0, 0); |
| 7809 | I915_WRITE(OGW1, 0); |
| 7810 | I915_WRITE(EG0, 0x00007f00); |
| 7811 | I915_WRITE(EG1, 0x0000000e); |
| 7812 | I915_WRITE(EG2, 0x000e0000); |
| 7813 | I915_WRITE(EG3, 0x68000300); |
| 7814 | I915_WRITE(EG4, 0x42000000); |
| 7815 | I915_WRITE(EG5, 0x00140031); |
| 7816 | I915_WRITE(EG6, 0); |
| 7817 | I915_WRITE(EG7, 0); |
| 7818 | |
| 7819 | for (i = 0; i < 8; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7820 | I915_WRITE(PXWL(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7821 | |
| 7822 | /* Enable PMON + select events */ |
| 7823 | I915_WRITE(ECR, 0x80000019); |
| 7824 | |
| 7825 | lcfuse = I915_READ(LCFUSE02); |
| 7826 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7827 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7828 | } |
| 7829 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7830 | void intel_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7831 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7832 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7833 | |
Andi Shyti | c113236 | 2019-09-27 12:08:49 +0100 | [diff] [blame] | 7834 | /* Powersaving is controlled by the host when inside a VM */ |
| 7835 | if (intel_vgpu_active(dev_priv)) |
| 7836 | mkwrite_device_info(dev_priv)->has_rps = false; |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7837 | |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7838 | /* Initialize RPS limits (for userspace) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7839 | if (IS_CHERRYVIEW(dev_priv)) |
| 7840 | cherryview_init_gt_powersave(dev_priv); |
| 7841 | else if (IS_VALLEYVIEW(dev_priv)) |
| 7842 | valleyview_init_gt_powersave(dev_priv); |
Chris Wilson | 2a13ae7 | 2016-08-02 11:15:27 +0100 | [diff] [blame] | 7843 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7844 | gen6_init_rps_frequencies(dev_priv); |
| 7845 | |
| 7846 | /* Derive initial user preferences/limits from the hardware limits */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7847 | rps->max_freq_softlimit = rps->max_freq; |
| 7848 | rps->min_freq_softlimit = rps->min_freq; |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7849 | |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7850 | /* After setting max-softlimit, find the overclock max freq */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7851 | if (IS_GEN(dev_priv, 6) || |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7852 | IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
| 7853 | u32 params = 0; |
| 7854 | |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 7855 | sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, |
| 7856 | ¶ms, NULL); |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7857 | if (params & BIT(31)) { /* OC supported */ |
| 7858 | DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7859 | (rps->max_freq & 0xff) * 50, |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7860 | (params & 0xff) * 50); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7861 | rps->max_freq = params & 0xff; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7862 | } |
| 7863 | } |
| 7864 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 7865 | /* Finally allow us to boost to max by default */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7866 | rps->boost_freq = rps->max_freq; |
Chris Wilson | 844e331 | 2019-04-18 21:53:58 +0100 | [diff] [blame] | 7867 | rps->idle_freq = rps->min_freq; |
| 7868 | rps->cur_freq = rps->idle_freq; |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7869 | } |
| 7870 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7871 | void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv) |
| 7872 | { |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 7873 | dev_priv->gt_pm.rps.enabled = true; /* force RPS disabling */ |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7874 | intel_disable_gt_powersave(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7875 | |
Oscar Mateo | d02b98b | 2018-04-05 17:00:50 +0300 | [diff] [blame] | 7876 | if (INTEL_GEN(dev_priv) >= 11) |
| 7877 | gen11_reset_rps_interrupts(dev_priv); |
Chris Wilson | 61e1e37 | 2018-08-12 23:36:30 +0100 | [diff] [blame] | 7878 | else if (INTEL_GEN(dev_priv) >= 6) |
Oscar Mateo | d02b98b | 2018-04-05 17:00:50 +0300 | [diff] [blame] | 7879 | gen6_reset_rps_interrupts(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 7880 | } |
| 7881 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7882 | static void intel_disable_rps(struct drm_i915_private *dev_priv) |
| 7883 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 7884 | lockdep_assert_held(&dev_priv->gt_pm.rps.lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7885 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 7886 | if (!dev_priv->gt_pm.rps.enabled) |
| 7887 | return; |
| 7888 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7889 | if (INTEL_GEN(dev_priv) >= 9) |
| 7890 | gen9_disable_rps(dev_priv); |
| 7891 | else if (IS_CHERRYVIEW(dev_priv)) |
| 7892 | cherryview_disable_rps(dev_priv); |
| 7893 | else if (IS_VALLEYVIEW(dev_priv)) |
| 7894 | valleyview_disable_rps(dev_priv); |
| 7895 | else if (INTEL_GEN(dev_priv) >= 6) |
| 7896 | gen6_disable_rps(dev_priv); |
| 7897 | else if (IS_IRONLAKE_M(dev_priv)) |
| 7898 | ironlake_disable_drps(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 7899 | |
| 7900 | dev_priv->gt_pm.rps.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7901 | } |
| 7902 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7903 | void intel_disable_gt_powersave(struct drm_i915_private *dev_priv) |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 7904 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 7905 | mutex_lock(&dev_priv->gt_pm.rps.lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7906 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7907 | intel_disable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 7908 | if (HAS_LLC(dev_priv)) |
Andi Shyti | 0dc3c56 | 2019-10-20 19:41:39 +0100 | [diff] [blame^] | 7909 | intel_llc_disable(&dev_priv->gt.llc); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 7910 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 7911 | mutex_unlock(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7912 | } |
| 7913 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7914 | static void intel_enable_rps(struct drm_i915_private *dev_priv) |
| 7915 | { |
| 7916 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7917 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 7918 | lockdep_assert_held(&rps->lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7919 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 7920 | if (rps->enabled) |
| 7921 | return; |
| 7922 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7923 | if (IS_CHERRYVIEW(dev_priv)) { |
| 7924 | cherryview_enable_rps(dev_priv); |
| 7925 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 7926 | valleyview_enable_rps(dev_priv); |
| 7927 | } else if (INTEL_GEN(dev_priv) >= 9) { |
| 7928 | gen9_enable_rps(dev_priv); |
| 7929 | } else if (IS_BROADWELL(dev_priv)) { |
| 7930 | gen8_enable_rps(dev_priv); |
| 7931 | } else if (INTEL_GEN(dev_priv) >= 6) { |
| 7932 | gen6_enable_rps(dev_priv); |
| 7933 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 7934 | ironlake_enable_drps(dev_priv); |
| 7935 | intel_init_emon(dev_priv); |
| 7936 | } |
| 7937 | |
| 7938 | WARN_ON(rps->max_freq < rps->min_freq); |
| 7939 | WARN_ON(rps->idle_freq > rps->max_freq); |
| 7940 | |
| 7941 | WARN_ON(rps->efficient_freq < rps->min_freq); |
| 7942 | WARN_ON(rps->efficient_freq > rps->max_freq); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 7943 | |
| 7944 | rps->enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 7945 | } |
| 7946 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7947 | void intel_enable_gt_powersave(struct drm_i915_private *dev_priv) |
| 7948 | { |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7949 | /* Powersaving is controlled by the host when inside a VM */ |
| 7950 | if (intel_vgpu_active(dev_priv)) |
| 7951 | return; |
| 7952 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 7953 | mutex_lock(&dev_priv->gt_pm.rps.lock); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 7954 | |
Chris Wilson | 91cbdb8 | 2019-04-19 14:48:36 +0100 | [diff] [blame] | 7955 | if (HAS_RPS(dev_priv)) |
| 7956 | intel_enable_rps(dev_priv); |
Andi Shyti | 0dc3c56 | 2019-10-20 19:41:39 +0100 | [diff] [blame^] | 7957 | |
| 7958 | intel_llc_enable(&dev_priv->gt.llc); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 7959 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 7960 | mutex_unlock(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7961 | } |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 7962 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7963 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7964 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7965 | /* |
| 7966 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7967 | * gating for the panel power sequencer or it will fail to |
| 7968 | * start up when no ports are active. |
| 7969 | */ |
| 7970 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 7971 | } |
| 7972 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7973 | 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] | 7974 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7975 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7976 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7977 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7978 | I915_WRITE(DSPCNTR(pipe), |
| 7979 | I915_READ(DSPCNTR(pipe)) | |
| 7980 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7981 | |
| 7982 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 7983 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7984 | } |
| 7985 | } |
| 7986 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7987 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7988 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7989 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7990 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 7991 | /* |
| 7992 | * Required for FBC |
| 7993 | * WaFbcDisableDpfcClockGating:ilk |
| 7994 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7995 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 7996 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 7997 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7998 | |
| 7999 | I915_WRITE(PCH_3DCGDIS0, |
| 8000 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 8001 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 8002 | I915_WRITE(PCH_3DCGDIS1, |
| 8003 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 8004 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8005 | /* |
| 8006 | * According to the spec the following bits should be set in |
| 8007 | * order to enable memory self-refresh |
| 8008 | * The bit 22/21 of 0x42004 |
| 8009 | * The bit 5 of 0x42020 |
| 8010 | * The bit 15 of 0x45000 |
| 8011 | */ |
| 8012 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8013 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8014 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8015 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8016 | I915_WRITE(DISP_ARB_CTL, |
| 8017 | (I915_READ(DISP_ARB_CTL) | |
| 8018 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 8019 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8020 | /* |
| 8021 | * Based on the document from hardware guys the following bits |
| 8022 | * should be set unconditionally in order to enable FBC. |
| 8023 | * The bit 22 of 0x42000 |
| 8024 | * The bit 22 of 0x42004 |
| 8025 | * The bit 7,8,9 of 0x42020. |
| 8026 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8027 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8028 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8029 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8030 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8031 | ILK_FBCQ_DIS); |
| 8032 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8033 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8034 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8035 | } |
| 8036 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8037 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 8038 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8039 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8040 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8041 | ILK_ELPIN_409_SELECT); |
| 8042 | I915_WRITE(_3D_CHICKEN2, |
| 8043 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 8044 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8045 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8046 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8047 | I915_WRITE(CACHE_MODE_0, |
| 8048 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8049 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8050 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 8051 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8052 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8053 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 8054 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8055 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8056 | } |
| 8057 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8058 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8059 | { |
Ville Syrjälä | d048a26 | 2019-08-21 20:30:31 +0300 | [diff] [blame] | 8060 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8061 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8062 | |
| 8063 | /* |
| 8064 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8065 | * gating for the panel power sequencer or it will fail to |
| 8066 | * start up when no ports are active. |
| 8067 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 8068 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 8069 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 8070 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8071 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 8072 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 8073 | /* The below fixes the weird display corruption, a few pixels shifted |
| 8074 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 8075 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8076 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8077 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 8078 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 8079 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8080 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8081 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8082 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 8083 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 8084 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8085 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 8086 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8087 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8088 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8089 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 8090 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 8091 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8092 | } |
| 8093 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8094 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8095 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8096 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8097 | |
| 8098 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 8099 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 8100 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 8101 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8102 | } |
| 8103 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8104 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8105 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8106 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8107 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8108 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8109 | |
| 8110 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8111 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8112 | ILK_ELPIN_409_SELECT); |
| 8113 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8114 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 8115 | I915_WRITE(_3D_CHICKEN, |
| 8116 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 8117 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8118 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 8119 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8120 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8121 | /* |
| 8122 | * BSpec recoomends 8x4 when MSAA is used, |
| 8123 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8124 | * |
| 8125 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8126 | * disable bit, which we don't touch here, but it's good |
| 8127 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8128 | */ |
| 8129 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8130 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8131 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8132 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 8133 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8134 | |
| 8135 | I915_WRITE(GEN6_UCGCTL1, |
| 8136 | I915_READ(GEN6_UCGCTL1) | |
| 8137 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 8138 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 8139 | |
| 8140 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 8141 | * gating disable must be set. Failure to set it results in |
| 8142 | * flickering pixels due to Z write ordering failures after |
| 8143 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 8144 | * Sanctuary and Tropics, and apparently anything else with |
| 8145 | * alpha test or pixel discard. |
| 8146 | * |
| 8147 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 8148 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8149 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 8150 | * WaDisableRCCUnitClockGating:snb |
| 8151 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8152 | */ |
| 8153 | I915_WRITE(GEN6_UCGCTL2, |
| 8154 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 8155 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 8156 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 8157 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 8158 | I915_WRITE(_3D_CHICKEN3, |
| 8159 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8160 | |
| 8161 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 8162 | * Bspec says: |
| 8163 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 8164 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 8165 | */ |
| 8166 | I915_WRITE(_3D_CHICKEN3, |
| 8167 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 8168 | |
| 8169 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8170 | * According to the spec the following bits should be |
| 8171 | * set in order to enable memory self-refresh and fbc: |
| 8172 | * The bit21 and bit22 of 0x42000 |
| 8173 | * The bit21 and bit22 of 0x42004 |
| 8174 | * The bit5 and bit7 of 0x42020 |
| 8175 | * The bit14 of 0x70180 |
| 8176 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8177 | * |
| 8178 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8179 | */ |
| 8180 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8181 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8182 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 8183 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8184 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8185 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8186 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 8187 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 8188 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 8189 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8190 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8191 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 8192 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8193 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8194 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8195 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8196 | } |
| 8197 | |
| 8198 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 8199 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8200 | u32 reg = I915_READ(GEN7_FF_THREAD_MODE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8201 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8202 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8203 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8204 | * |
| 8205 | * This actually overrides the dispatch |
| 8206 | * mode for all thread types. |
| 8207 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8208 | reg &= ~GEN7_FF_SCHED_MASK; |
| 8209 | reg |= GEN7_FF_TS_SCHED_HW; |
| 8210 | reg |= GEN7_FF_VS_SCHED_HW; |
| 8211 | reg |= GEN7_FF_DS_SCHED_HW; |
| 8212 | |
| 8213 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 8214 | } |
| 8215 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8216 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8217 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8218 | /* |
| 8219 | * TODO: this bit should only be enabled when really needed, then |
| 8220 | * disabled when not needed anymore in order to save power. |
| 8221 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8222 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8223 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 8224 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 8225 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8226 | |
| 8227 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 8228 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 8229 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8230 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8231 | } |
| 8232 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8233 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8234 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8235 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8236 | u32 val = I915_READ(SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8237 | |
| 8238 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8239 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8240 | } |
| 8241 | } |
| 8242 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8243 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 8244 | int general_prio_credits, |
| 8245 | int high_prio_credits) |
| 8246 | { |
| 8247 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 8248 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8249 | |
| 8250 | /* WaTempDisableDOPClkGating:bdw */ |
| 8251 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 8252 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 8253 | |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 8254 | val = I915_READ(GEN8_L3SQCREG1); |
| 8255 | val &= ~L3_PRIO_CREDITS_MASK; |
| 8256 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 8257 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
| 8258 | I915_WRITE(GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8259 | |
| 8260 | /* |
| 8261 | * Wait at least 100 clocks before re-enabling clock gating. |
| 8262 | * See the definition of L3SQCREG1 in BSpec. |
| 8263 | */ |
| 8264 | POSTING_READ(GEN8_L3SQCREG1); |
| 8265 | udelay(1); |
| 8266 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 8267 | } |
| 8268 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 8269 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8270 | { |
| 8271 | /* This is not an Wa. Enable to reduce Sampler power */ |
| 8272 | I915_WRITE(GEN10_DFR_RATIO_EN_AND_CHICKEN, |
| 8273 | I915_READ(GEN10_DFR_RATIO_EN_AND_CHICKEN) & ~DFR_DISABLE); |
Radhakrishna Sripada | 622b3f6 | 2018-10-30 01:45:01 -0700 | [diff] [blame] | 8274 | |
| 8275 | /* WaEnable32PlaneMode:icl */ |
| 8276 | I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, |
| 8277 | _MASKED_BIT_ENABLE(GEN11_ENABLE_32_PLANE_MODE)); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 8278 | } |
| 8279 | |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 8280 | static void tgl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8281 | { |
| 8282 | u32 vd_pg_enable = 0; |
| 8283 | unsigned int i; |
| 8284 | |
| 8285 | /* This is not a WA. Enable VD HCP & MFX_ENC powergate */ |
| 8286 | for (i = 0; i < I915_MAX_VCS; i++) { |
| 8287 | if (HAS_ENGINE(dev_priv, _VCS(i))) |
| 8288 | vd_pg_enable |= VDN_HCP_POWERGATE_ENABLE(i) | |
| 8289 | VDN_MFX_POWERGATE_ENABLE(i); |
| 8290 | } |
| 8291 | |
| 8292 | I915_WRITE(POWERGATE_ENABLE, |
| 8293 | I915_READ(POWERGATE_ENABLE) | vd_pg_enable); |
| 8294 | } |
| 8295 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8296 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8297 | { |
| 8298 | if (!HAS_PCH_CNP(dev_priv)) |
| 8299 | return; |
| 8300 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 8301 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Rodrigo Vivi | 4cc6feb | 2017-09-08 16:45:33 -0700 | [diff] [blame] | 8302 | I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 8303 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8304 | } |
| 8305 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8306 | static void cnl_init_clock_gating(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8307 | { |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 8308 | u32 val; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8309 | cnp_init_clock_gating(dev_priv); |
| 8310 | |
Rodrigo Vivi | 1a25db6 | 2017-08-15 16:16:51 -0700 | [diff] [blame] | 8311 | /* This is not an Wa. Enable for better image quality */ |
| 8312 | I915_WRITE(_3D_CHICKEN3, |
| 8313 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE)); |
| 8314 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8315 | /* WaEnableChickenDCPR:cnl */ |
| 8316 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 8317 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
| 8318 | |
| 8319 | /* WaFbcWakeMemOn:cnl */ |
| 8320 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 8321 | DISP_FBC_MEMORY_WAKE); |
| 8322 | |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 8323 | val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE); |
| 8324 | /* ReadHitWriteOnlyDisable:cnl */ |
| 8325 | val |= RCCUNIT_CLKGATE_DIS; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8326 | /* WaSarbUnitClockGatingDisable:cnl (pre-prod) */ |
| 8327 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 8328 | val |= SARBUNIT_CLKGATE_DIS; |
| 8329 | I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val); |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 8330 | |
Rodrigo Vivi | a4713c5 | 2018-03-07 14:09:12 -0800 | [diff] [blame] | 8331 | /* Wa_2201832410:cnl */ |
| 8332 | val = I915_READ(SUBSLICE_UNIT_LEVEL_CLKGATE); |
| 8333 | val |= GWUNIT_CLKGATE_DIS; |
| 8334 | I915_WRITE(SUBSLICE_UNIT_LEVEL_CLKGATE, val); |
| 8335 | |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 8336 | /* WaDisableVFclkgate:cnl */ |
Rodrigo Vivi | 14941b6 | 2018-03-05 17:20:00 -0800 | [diff] [blame] | 8337 | /* WaVFUnitClockGatingDisable:cnl */ |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 8338 | val = I915_READ(UNSLICE_UNIT_LEVEL_CLKGATE); |
| 8339 | val |= VFUNIT_CLKGATE_DIS; |
| 8340 | I915_WRITE(UNSLICE_UNIT_LEVEL_CLKGATE, val); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8341 | } |
| 8342 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8343 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8344 | { |
| 8345 | cnp_init_clock_gating(dev_priv); |
| 8346 | gen9_init_clock_gating(dev_priv); |
| 8347 | |
| 8348 | /* WaFbcNukeOnHostModify:cfl */ |
| 8349 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8350 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 8351 | } |
| 8352 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8353 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8354 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8355 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8356 | |
| 8357 | /* WaDisableSDEUnitClockGating:kbl */ |
| 8358 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 8359 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8360 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 8361 | |
| 8362 | /* WaDisableGamClockGating:kbl */ |
| 8363 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 8364 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 8365 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8366 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8367 | /* WaFbcNukeOnHostModify:kbl */ |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8368 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8369 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8370 | } |
| 8371 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8372 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8373 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8374 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 8375 | |
| 8376 | /* WAC6entrylatency:skl */ |
| 8377 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 8378 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8379 | |
| 8380 | /* WaFbcNukeOnHostModify:skl */ |
| 8381 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8382 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8383 | } |
| 8384 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8385 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8386 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 8387 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8388 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8389 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 8390 | 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] | 8391 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8392 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 8393 | I915_WRITE(CHICKEN_PAR1_1, |
| 8394 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 8395 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8396 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8397 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 8398 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 8399 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 8400 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 8401 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 8402 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8403 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 8404 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 8405 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8406 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 8407 | ~(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] | 8408 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 8409 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 8410 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 8411 | |
| 8412 | /* WaDisableSDEUnitClockGating:bdw */ |
| 8413 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8414 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 8415 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8416 | /* WaProgramL3SqcReg1Default:bdw */ |
| 8417 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 8418 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 8419 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 8420 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 8421 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 8422 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8423 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 8424 | |
| 8425 | /* WaDisableDopClockGating:bdw |
| 8426 | * |
| 8427 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 8428 | * clock gating. |
| 8429 | */ |
| 8430 | I915_WRITE(GEN6_UCGCTL1, |
| 8431 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8432 | } |
| 8433 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8434 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8435 | { |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 8436 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 8437 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 8438 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 8439 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 8440 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8441 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8442 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8443 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8444 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8445 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 8446 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 8447 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8448 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8449 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8450 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 8451 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8452 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 8453 | /* enable HiZ Raw Stall Optimization */ |
| 8454 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 8455 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 8456 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8457 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8458 | I915_WRITE(CACHE_MODE_1, |
| 8459 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 8460 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8461 | /* |
| 8462 | * BSpec recommends 8x4 when MSAA is used, |
| 8463 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8464 | * |
| 8465 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8466 | * disable bit, which we don't touch here, but it's good |
| 8467 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8468 | */ |
| 8469 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8470 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8471 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 8472 | /* WaSampleCChickenBitEnable:hsw */ |
| 8473 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 8474 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 8475 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8476 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 8477 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 8478 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8479 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8480 | } |
| 8481 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8482 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8483 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8484 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8485 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8486 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8487 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8488 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 8489 | I915_WRITE(_3D_CHICKEN3, |
| 8490 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 8491 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8492 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8493 | I915_WRITE(IVB_CHICKEN3, |
| 8494 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 8495 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 8496 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8497 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8498 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8499 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 8500 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8501 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8502 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 8503 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8504 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8505 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8506 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 8507 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 8508 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8509 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8510 | I915_WRITE(GEN7_L3CNTLREG1, |
| 8511 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 8512 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8513 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8514 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8515 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8516 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 8517 | else { |
| 8518 | /* must write both registers */ |
| 8519 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8520 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8521 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 8522 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 8523 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8524 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8525 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 8526 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 8527 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 8528 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 8529 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8530 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8531 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8532 | */ |
| 8533 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 8534 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8535 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8536 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8537 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8538 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8539 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8540 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8541 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8542 | |
| 8543 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 8544 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 8545 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 8546 | /* enable HiZ Raw Stall Optimization */ |
| 8547 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 8548 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 8549 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 8550 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8551 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 8552 | I915_WRITE(CACHE_MODE_1, |
| 8553 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8554 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8555 | /* |
| 8556 | * BSpec recommends 8x4 when MSAA is used, |
| 8557 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8558 | * |
| 8559 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8560 | * disable bit, which we don't touch here, but it's good |
| 8561 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8562 | */ |
| 8563 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8564 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8565 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8566 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 8567 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 8568 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 8569 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8570 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8571 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8572 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8573 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8574 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8575 | } |
| 8576 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8577 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8578 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8579 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 8580 | I915_WRITE(_3D_CHICKEN3, |
| 8581 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 8582 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8583 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8584 | I915_WRITE(IVB_CHICKEN3, |
| 8585 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 8586 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 8587 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 8588 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8589 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8590 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 8591 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 8592 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8593 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8594 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 8595 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8596 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8597 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 8598 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 8599 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 8600 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8601 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8602 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8603 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 8604 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8605 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8606 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8607 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8608 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8609 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8610 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 8611 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 8612 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8613 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8614 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8615 | */ |
| 8616 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 8617 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8618 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 8619 | /* WaDisableL3Bank2xClockGate:vlv |
| 8620 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 8621 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 8622 | I915_WRITE(GEN7_UCGCTL4, |
| 8623 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 8624 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 8625 | /* |
| 8626 | * BSpec says this must be set, even though |
| 8627 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 8628 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 8629 | I915_WRITE(CACHE_MODE_1, |
| 8630 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 8631 | |
| 8632 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 8633 | * BSpec recommends 8x4 when MSAA is used, |
| 8634 | * however in practice 16x4 seems fastest. |
| 8635 | * |
| 8636 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8637 | * disable bit, which we don't touch here, but it's good |
| 8638 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 8639 | */ |
| 8640 | I915_WRITE(GEN7_GT_MODE, |
| 8641 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 8642 | |
| 8643 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 8644 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 8645 | * This is the hardware default actually. |
| 8646 | */ |
| 8647 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 8648 | |
| 8649 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8650 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 8651 | * Disable clock gating on th GCFG unit to prevent a delay |
| 8652 | * in the reporting of vblank events. |
| 8653 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 8654 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8655 | } |
| 8656 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8657 | 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] | 8658 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 8659 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 8660 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 8661 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8662 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 8663 | ~(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] | 8664 | |
| 8665 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 8666 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 8667 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 8668 | |
| 8669 | /* WaDisableCSUnitClockGating:chv */ |
| 8670 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 8671 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 8672 | |
| 8673 | /* WaDisableSDEUnitClockGating:chv */ |
| 8674 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8675 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8676 | |
| 8677 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8678 | * WaProgramL3SqcReg1Default:chv |
| 8679 | * See gfxspecs/Related Documents/Performance Guide/ |
| 8680 | * LSQC Setting Recommendations. |
| 8681 | */ |
| 8682 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 8683 | } |
| 8684 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8685 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8686 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8687 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8688 | |
| 8689 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 8690 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 8691 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 8692 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 8693 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 8694 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 8695 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 8696 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8697 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8698 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 8699 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8700 | |
| 8701 | /* WaDisableRenderCachePipelinedFlush */ |
| 8702 | I915_WRITE(CACHE_MODE_0, |
| 8703 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 8704 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8705 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 8706 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8707 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8708 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8709 | } |
| 8710 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8711 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8712 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 8713 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 8714 | |
| 8715 | intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 8716 | intel_uncore_write(uncore, RENCLK_GATE_D2, 0); |
| 8717 | intel_uncore_write(uncore, DSPCLK_GATE_D, 0); |
| 8718 | intel_uncore_write(uncore, RAMCLK_GATE_D, 0); |
| 8719 | intel_uncore_write16(uncore, DEUC, 0); |
| 8720 | intel_uncore_write(uncore, |
| 8721 | MI_ARB_STATE, |
| 8722 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8723 | |
| 8724 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 8725 | intel_uncore_write(uncore, |
| 8726 | CACHE_MODE_0, |
| 8727 | _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8728 | } |
| 8729 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8730 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8731 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8732 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 8733 | I965_RCC_CLOCK_GATE_DISABLE | |
| 8734 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 8735 | I965_ISC_CLOCK_GATE_DISABLE | |
| 8736 | I965_FBC_CLOCK_GATE_DISABLE); |
| 8737 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 8738 | I915_WRITE(MI_ARB_STATE, |
| 8739 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8740 | |
| 8741 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 8742 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8743 | } |
| 8744 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8745 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8746 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8747 | u32 dstate = I915_READ(D_STATE); |
| 8748 | |
| 8749 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 8750 | DSTATE_DOT_CLOCK_GATING; |
| 8751 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 8752 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8753 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 8754 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 8755 | |
| 8756 | /* IIR "flip pending" means done if this bit is set */ |
| 8757 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 8758 | |
| 8759 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 8760 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 8761 | |
| 8762 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 8763 | 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] | 8764 | |
| 8765 | I915_WRITE(MI_ARB_STATE, |
| 8766 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8767 | } |
| 8768 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8769 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8770 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8771 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 8772 | |
| 8773 | /* interrupts should cause a wake up from C3 */ |
| 8774 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 8775 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 8776 | |
| 8777 | I915_WRITE(MEM_MODE, |
| 8778 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8779 | } |
| 8780 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8781 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8782 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 8783 | I915_WRITE(MEM_MODE, |
| 8784 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 8785 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8786 | } |
| 8787 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8788 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8789 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8790 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8791 | } |
| 8792 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8793 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8794 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8795 | if (HAS_PCH_LPT(dev_priv)) |
| 8796 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8797 | } |
| 8798 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8799 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8800 | { |
| 8801 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 8802 | } |
| 8803 | |
| 8804 | /** |
| 8805 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 8806 | * @dev_priv: device private |
| 8807 | * |
| 8808 | * Setup the hooks that configure which clocks of a given platform can be |
| 8809 | * gated and also apply various GT and display specific workarounds for these |
| 8810 | * platforms. Note that some GT specific workarounds are applied separately |
| 8811 | * when GPU contexts or batchbuffers start their execution. |
| 8812 | */ |
| 8813 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 8814 | { |
Lucas De Marchi | 13e53c5 | 2019-08-17 02:38:42 -0700 | [diff] [blame] | 8815 | if (IS_GEN(dev_priv, 12)) |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 8816 | dev_priv->display.init_clock_gating = tgl_init_clock_gating; |
Lucas De Marchi | 13e53c5 | 2019-08-17 02:38:42 -0700 | [diff] [blame] | 8817 | else if (IS_GEN(dev_priv, 11)) |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 8818 | dev_priv->display.init_clock_gating = icl_init_clock_gating; |
Oscar Mateo | cc38cae | 2018-05-08 14:29:23 -0700 | [diff] [blame] | 8819 | else if (IS_CANNONLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8820 | dev_priv->display.init_clock_gating = cnl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8821 | else if (IS_COFFEELAKE(dev_priv)) |
| 8822 | dev_priv->display.init_clock_gating = cfl_init_clock_gating; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8823 | else if (IS_SKYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8824 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8825 | else if (IS_KABYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8826 | dev_priv->display.init_clock_gating = kbl_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 8827 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8828 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 8829 | else if (IS_GEMINILAKE(dev_priv)) |
| 8830 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8831 | else if (IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8832 | dev_priv->display.init_clock_gating = bdw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8833 | else if (IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8834 | dev_priv->display.init_clock_gating = chv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8835 | else if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8836 | dev_priv->display.init_clock_gating = hsw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8837 | else if (IS_IVYBRIDGE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8838 | dev_priv->display.init_clock_gating = ivb_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8839 | else if (IS_VALLEYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8840 | dev_priv->display.init_clock_gating = vlv_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8841 | else if (IS_GEN(dev_priv, 6)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8842 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8843 | else if (IS_GEN(dev_priv, 5)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8844 | dev_priv->display.init_clock_gating = ilk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8845 | else if (IS_G4X(dev_priv)) |
| 8846 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 8847 | else if (IS_I965GM(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8848 | dev_priv->display.init_clock_gating = i965gm_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 8849 | else if (IS_I965G(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8850 | dev_priv->display.init_clock_gating = i965g_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8851 | else if (IS_GEN(dev_priv, 3)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8852 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 8853 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 8854 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8855 | else if (IS_GEN(dev_priv, 2)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8856 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 8857 | else { |
| 8858 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 8859 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 8860 | } |
| 8861 | } |
| 8862 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8863 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8864 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8865 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8866 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8867 | if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 8868 | i915_pineview_get_mem_freq(dev_priv); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8869 | else if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 8870 | i915_ironlake_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8871 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 8872 | if (intel_has_sagv(dev_priv)) |
| 8873 | skl_setup_sagv_block_time(dev_priv); |
| 8874 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8875 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8876 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8877 | skl_setup_wm_latency(dev_priv); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 8878 | dev_priv->display.initial_watermarks = skl_initial_wm; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 8879 | dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 8880 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8881 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8882 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 8883 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8884 | 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] | 8885 | 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] | 8886 | (!IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8887 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 8888 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 8889 | dev_priv->display.compute_intermediate_wm = |
| 8890 | ilk_compute_intermediate_wm; |
| 8891 | dev_priv->display.initial_watermarks = |
| 8892 | ilk_initial_watermarks; |
| 8893 | dev_priv->display.optimize_watermarks = |
| 8894 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8895 | } else { |
| 8896 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 8897 | "Disable CxSR\n"); |
| 8898 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 8899 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8900 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8901 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 8902 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8903 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 8904 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8905 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 8906 | } else if (IS_G4X(dev_priv)) { |
| 8907 | g4x_setup_wm_latency(dev_priv); |
| 8908 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 8909 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 8910 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 8911 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8912 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 8913 | if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8914 | dev_priv->is_ddr3, |
| 8915 | dev_priv->fsb_freq, |
| 8916 | dev_priv->mem_freq)) { |
| 8917 | DRM_INFO("failed to find known CxSR latency " |
| 8918 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 8919 | "disabling CxSR\n", |
| 8920 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 8921 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 8922 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 8923 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8924 | dev_priv->display.update_wm = NULL; |
| 8925 | } else |
| 8926 | dev_priv->display.update_wm = pineview_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8927 | } else if (IS_GEN(dev_priv, 4)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8928 | dev_priv->display.update_wm = i965_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8929 | } else if (IS_GEN(dev_priv, 3)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8930 | dev_priv->display.update_wm = i9xx_update_wm; |
| 8931 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8932 | } else if (IS_GEN(dev_priv, 2)) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 8933 | if (INTEL_NUM_PIPES(dev_priv) == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8934 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8935 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8936 | } else { |
| 8937 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8938 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8939 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8940 | } else { |
| 8941 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8942 | } |
| 8943 | } |
| 8944 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 8945 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 8946 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8947 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8948 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 8949 | /* |
| 8950 | * N = val - 0xb7 |
| 8951 | * Slow = Fast = GPLL ref * N |
| 8952 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8953 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * (val - 0xb7), 1000); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 8954 | } |
| 8955 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 8956 | static int byt_freq_opcode(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 8957 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8958 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8959 | |
| 8960 | return DIV_ROUND_CLOSEST(1000 * val, rps->gpll_ref_freq) + 0xb7; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 8961 | } |
| 8962 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 8963 | static int chv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 8964 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8965 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8966 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 8967 | /* |
| 8968 | * N = val / 2 |
| 8969 | * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2 |
| 8970 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8971 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * val, 2 * 2 * 1000); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 8972 | } |
| 8973 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 8974 | static int chv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 8975 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8976 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8977 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 8978 | /* CHV needs even values */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8979 | return DIV_ROUND_CLOSEST(2 * 1000 * val, rps->gpll_ref_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 8980 | } |
| 8981 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8982 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 8983 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 8984 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 8985 | return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, |
| 8986 | GEN9_FREQ_SCALER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8987 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8988 | return chv_gpu_freq(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8989 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8990 | return byt_gpu_freq(dev_priv, val); |
| 8991 | else |
| 8992 | return val * GT_FREQUENCY_MULTIPLIER; |
| 8993 | } |
| 8994 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8995 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 8996 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 8997 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 8998 | return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, |
| 8999 | GT_FREQUENCY_MULTIPLIER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9000 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9001 | return chv_freq_opcode(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9002 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9003 | return byt_freq_opcode(dev_priv, val); |
| 9004 | else |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9005 | return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9006 | } |
| 9007 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 9008 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9009 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 9010 | mutex_init(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 9011 | mutex_init(&dev_priv->gt_pm.rps.power.mutex); |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9012 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9013 | atomic_set(&dev_priv->gt_pm.rps.num_waiters, 0); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 9014 | |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 9015 | dev_priv->runtime_pm.suspended = false; |
| 9016 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9017 | } |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9018 | |
Tvrtko Ursulin | c84b270 | 2017-11-21 18:18:44 +0000 | [diff] [blame] | 9019 | u32 intel_get_cagf(struct drm_i915_private *dev_priv, u32 rpstat) |
| 9020 | { |
| 9021 | u32 cagf; |
| 9022 | |
| 9023 | if (INTEL_GEN(dev_priv) >= 9) |
| 9024 | cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT; |
| 9025 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 9026 | cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT; |
| 9027 | else |
| 9028 | cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT; |
| 9029 | |
| 9030 | return cagf; |
| 9031 | } |