Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eugeni Dodonov <eugeni.dodonov@intel.com> |
| 25 | * |
| 26 | */ |
| 27 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 28 | #include <linux/cpufreq.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 29 | #include <linux/module.h> |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 30 | #include <linux/pm_runtime.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 31 | |
| 32 | #include <drm/drm_atomic_helper.h> |
| 33 | #include <drm/drm_fourcc.h> |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 34 | #include <drm/drm_plane_helper.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 35 | |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 36 | #include "display/intel_atomic.h" |
| 37 | #include "display/intel_fbc.h" |
| 38 | #include "display/intel_sprite.h" |
| 39 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 40 | #include "i915_drv.h" |
Jani Nikula | 440e2b3 | 2019-04-29 15:29:27 +0300 | [diff] [blame] | 41 | #include "i915_irq.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 42 | #include "intel_drv.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 43 | #include "intel_pm.h" |
Chris Wilson | 56c5098 | 2019-04-26 09:17:22 +0100 | [diff] [blame] | 44 | #include "intel_sideband.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 45 | #include "../../../platform/x86/intel_ips.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 46 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 47 | /** |
Jani Nikula | 18afd44 | 2016-01-18 09:19:48 +0200 | [diff] [blame] | 48 | * DOC: RC6 |
| 49 | * |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 50 | * RC6 is a special power stage which allows the GPU to enter an very |
| 51 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 52 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 53 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 54 | * |
| 55 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 56 | * among each other with the latency required to enter and leave RC6 and |
| 57 | * voltage consumed by the GPU in different states. |
| 58 | * |
| 59 | * The combination of the following flags define which states GPU is allowed |
| 60 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 61 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 62 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 63 | * which brings the most power savings; deeper states save more power, but |
| 64 | * require higher latency to switch to and wake up. |
| 65 | */ |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 66 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 67 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 68 | { |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 69 | if (HAS_LLC(dev_priv)) { |
| 70 | /* |
| 71 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
Lucas De Marchi | e0403cb | 2017-12-05 11:01:17 -0800 | [diff] [blame] | 72 | * Display WA #0390: skl,kbl |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 73 | * |
| 74 | * Must match Sampler, Pixel Back End, and Media. See |
| 75 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 76 | */ |
| 77 | I915_WRITE(CHICKEN_PAR1_1, |
| 78 | I915_READ(CHICKEN_PAR1_1) | |
| 79 | SKL_DE_COMPRESSED_HASH_MODE); |
| 80 | } |
| 81 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 82 | /* 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] | 83 | I915_WRITE(CHICKEN_PAR1_1, |
| 84 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 85 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 86 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 87 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 88 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 89 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 90 | /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl,cfl */ |
| 91 | /* WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 92 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 93 | DISP_FBC_WM_DIS | |
| 94 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 95 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 96 | /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl,cfl */ |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 97 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 98 | ILK_DPFC_DISABLE_DUMMY0); |
Praveen Paneri | 32087d1 | 2017-08-03 23:02:10 +0530 | [diff] [blame] | 99 | |
| 100 | if (IS_SKYLAKE(dev_priv)) { |
| 101 | /* WaDisableDopClockGating */ |
| 102 | I915_WRITE(GEN7_MISCCPCTL, I915_READ(GEN7_MISCCPCTL) |
| 103 | & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 104 | } |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 105 | } |
| 106 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 107 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 108 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 109 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 110 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 111 | /* WaDisableSDEUnitClockGating:bxt */ |
| 112 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 113 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 114 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 115 | /* |
| 116 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 117 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 118 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 119 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 120 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 121 | |
| 122 | /* |
| 123 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 124 | * to stay fully on. |
| 125 | */ |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 126 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 127 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 130 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 131 | { |
| 132 | gen9_init_clock_gating(dev_priv); |
| 133 | |
| 134 | /* |
| 135 | * WaDisablePWMClockGating:glk |
| 136 | * Backlight PWM may stop in the asserted state, causing backlight |
| 137 | * to stay fully on. |
| 138 | */ |
| 139 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 140 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Ander Conselvan de Oliveira | f4f4b59 | 2017-02-22 08:34:29 +0200 | [diff] [blame] | 141 | |
| 142 | /* WaDDIIOTimeout:glk */ |
| 143 | if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1)) { |
| 144 | u32 val = I915_READ(CHICKEN_MISC_2); |
| 145 | val &= ~(GLK_CL0_PWR_DOWN | |
| 146 | GLK_CL1_PWR_DOWN | |
| 147 | GLK_CL2_PWR_DOWN); |
| 148 | I915_WRITE(CHICKEN_MISC_2, val); |
| 149 | } |
| 150 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 151 | } |
| 152 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 153 | 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] | 154 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 155 | u32 tmp; |
| 156 | |
| 157 | tmp = I915_READ(CLKCFG); |
| 158 | |
| 159 | switch (tmp & CLKCFG_FSB_MASK) { |
| 160 | case CLKCFG_FSB_533: |
| 161 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 162 | break; |
| 163 | case CLKCFG_FSB_800: |
| 164 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 165 | break; |
| 166 | case CLKCFG_FSB_667: |
| 167 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 168 | break; |
| 169 | case CLKCFG_FSB_400: |
| 170 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | switch (tmp & CLKCFG_MEM_MASK) { |
| 175 | case CLKCFG_MEM_533: |
| 176 | dev_priv->mem_freq = 533; |
| 177 | break; |
| 178 | case CLKCFG_MEM_667: |
| 179 | dev_priv->mem_freq = 667; |
| 180 | break; |
| 181 | case CLKCFG_MEM_800: |
| 182 | dev_priv->mem_freq = 800; |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | /* detect pineview DDR3 setting */ |
| 187 | tmp = I915_READ(CSHRDDR3CTL); |
| 188 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 189 | } |
| 190 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 191 | 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] | 192 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 193 | u16 ddrpll, csipll; |
| 194 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 195 | ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1); |
| 196 | csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 197 | |
| 198 | switch (ddrpll & 0xff) { |
| 199 | case 0xc: |
| 200 | dev_priv->mem_freq = 800; |
| 201 | break; |
| 202 | case 0x10: |
| 203 | dev_priv->mem_freq = 1066; |
| 204 | break; |
| 205 | case 0x14: |
| 206 | dev_priv->mem_freq = 1333; |
| 207 | break; |
| 208 | case 0x18: |
| 209 | dev_priv->mem_freq = 1600; |
| 210 | break; |
| 211 | default: |
| 212 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 213 | ddrpll & 0xff); |
| 214 | dev_priv->mem_freq = 0; |
| 215 | break; |
| 216 | } |
| 217 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 218 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 219 | |
| 220 | switch (csipll & 0x3ff) { |
| 221 | case 0x00c: |
| 222 | dev_priv->fsb_freq = 3200; |
| 223 | break; |
| 224 | case 0x00e: |
| 225 | dev_priv->fsb_freq = 3733; |
| 226 | break; |
| 227 | case 0x010: |
| 228 | dev_priv->fsb_freq = 4266; |
| 229 | break; |
| 230 | case 0x012: |
| 231 | dev_priv->fsb_freq = 4800; |
| 232 | break; |
| 233 | case 0x014: |
| 234 | dev_priv->fsb_freq = 5333; |
| 235 | break; |
| 236 | case 0x016: |
| 237 | dev_priv->fsb_freq = 5866; |
| 238 | break; |
| 239 | case 0x018: |
| 240 | dev_priv->fsb_freq = 6400; |
| 241 | break; |
| 242 | default: |
| 243 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 244 | csipll & 0x3ff); |
| 245 | dev_priv->fsb_freq = 0; |
| 246 | break; |
| 247 | } |
| 248 | |
| 249 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 250 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 251 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 252 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 253 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 254 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 258 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 259 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 260 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 261 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 262 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 263 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 264 | |
| 265 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 266 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 267 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 268 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 269 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 270 | |
| 271 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 272 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 273 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 274 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 275 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 276 | |
| 277 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 278 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 279 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 280 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 281 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 282 | |
| 283 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 284 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 285 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 286 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 287 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 288 | |
| 289 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 290 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 291 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 292 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 293 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 294 | }; |
| 295 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 296 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 297 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 298 | int fsb, |
| 299 | int mem) |
| 300 | { |
| 301 | const struct cxsr_latency *latency; |
| 302 | int i; |
| 303 | |
| 304 | if (fsb == 0 || mem == 0) |
| 305 | return NULL; |
| 306 | |
| 307 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 308 | latency = &cxsr_latency_table[i]; |
| 309 | if (is_desktop == latency->is_desktop && |
| 310 | is_ddr3 == latency->is_ddr3 && |
| 311 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 312 | return latency; |
| 313 | } |
| 314 | |
| 315 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 316 | |
| 317 | return NULL; |
| 318 | } |
| 319 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 320 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 321 | { |
| 322 | u32 val; |
| 323 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 324 | vlv_punit_get(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 325 | |
| 326 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 327 | if (enable) |
| 328 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 329 | else |
| 330 | val |= FORCE_DDR_HIGH_FREQ; |
| 331 | val &= ~FORCE_DDR_LOW_FREQ; |
| 332 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 333 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 334 | |
| 335 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 336 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 337 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 338 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 339 | vlv_punit_put(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 342 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 343 | { |
| 344 | u32 val; |
| 345 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 346 | vlv_punit_get(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 347 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 348 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 349 | if (enable) |
| 350 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 351 | else |
| 352 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 353 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 354 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 355 | vlv_punit_put(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 356 | } |
| 357 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 358 | #define FW_WM(value, plane) \ |
| 359 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 360 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 361 | 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] | 362 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 363 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 364 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 365 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 366 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 367 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 368 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 369 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 370 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 371 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 372 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 373 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 374 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 375 | val = I915_READ(DSPFW3); |
| 376 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 377 | if (enable) |
| 378 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 379 | else |
| 380 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 381 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 382 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 383 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 384 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 385 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 386 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 387 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 388 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 389 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 390 | /* |
| 391 | * FIXME can't find a bit like this for 915G, and |
| 392 | * and yet it does have the related watermark in |
| 393 | * FW_BLC_SELF. What's going on? |
| 394 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 395 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 396 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 397 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 398 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 399 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 400 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 401 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 402 | } |
| 403 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 404 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 405 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 406 | DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", |
| 407 | enableddisabled(enable), |
| 408 | enableddisabled(was_enabled)); |
| 409 | |
| 410 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 411 | } |
| 412 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 413 | /** |
| 414 | * intel_set_memory_cxsr - Configure CxSR state |
| 415 | * @dev_priv: i915 device |
| 416 | * @enable: Allow vs. disallow CxSR |
| 417 | * |
| 418 | * Allow or disallow the system to enter a special CxSR |
| 419 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 420 | * is that several display FIFOs may get combined into a single larger |
| 421 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 422 | * system to defer memory fetches longer, and the memory will enter |
| 423 | * self refresh. |
| 424 | * |
| 425 | * Note that enabling CxSR does not guarantee that the system enter |
| 426 | * this special mode, nor does it guarantee that the system stays |
| 427 | * in that mode once entered. So this just allows/disallows the system |
| 428 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 429 | * C-states will affect when/if the system actually enters/exits the |
| 430 | * CxSR mode. |
| 431 | * |
| 432 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 433 | * and the system is free to enter/exit memory self refresh at any time |
| 434 | * even when the use of CxSR has been disallowed. |
| 435 | * |
| 436 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 437 | * control registers will not get latched on vblank. Thus in order to |
| 438 | * guarantee the system will respond to changes in the plane registers |
| 439 | * we must always disallow CxSR prior to making changes to those registers. |
| 440 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 441 | * frame start which happens after vblank start (which is when the plane |
| 442 | * registers would get latched), so we can't proceed with the plane update |
| 443 | * during the same frame where we disallowed CxSR. |
| 444 | * |
| 445 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 446 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 447 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 448 | * Disallowing just CxSR is sufficient. |
| 449 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 450 | 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] | 451 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 452 | bool ret; |
| 453 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 454 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 455 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 456 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 457 | dev_priv->wm.vlv.cxsr = enable; |
| 458 | else if (IS_G4X(dev_priv)) |
| 459 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 460 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 461 | |
| 462 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 463 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 464 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 465 | /* |
| 466 | * Latency for FIFO fetches is dependent on several factors: |
| 467 | * - memory configuration (speed, channels) |
| 468 | * - chipset |
| 469 | * - current MCH state |
| 470 | * It can be fairly high in some situations, so here we assume a fairly |
| 471 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 472 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 473 | * and power consumption (set it too low to save power and we might see |
| 474 | * FIFO underruns and display "flicker"). |
| 475 | * |
| 476 | * A value of 5us seems to be a good balance; safe for very low end |
| 477 | * platforms but not overly aggressive on lower latency configs. |
| 478 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 479 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 480 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 481 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 482 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 483 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 484 | 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] | 485 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 486 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 487 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 488 | 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] | 489 | enum pipe pipe = crtc->pipe; |
| 490 | int sprite0_start, sprite1_start; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 491 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 492 | switch (pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 493 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 494 | case PIPE_A: |
| 495 | dsparb = I915_READ(DSPARB); |
| 496 | dsparb2 = I915_READ(DSPARB2); |
| 497 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 498 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 499 | break; |
| 500 | case PIPE_B: |
| 501 | dsparb = I915_READ(DSPARB); |
| 502 | dsparb2 = I915_READ(DSPARB2); |
| 503 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 504 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 505 | break; |
| 506 | case PIPE_C: |
| 507 | dsparb2 = I915_READ(DSPARB2); |
| 508 | dsparb3 = I915_READ(DSPARB3); |
| 509 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 510 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 511 | break; |
| 512 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 513 | MISSING_CASE(pipe); |
| 514 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 517 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 518 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 519 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 520 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 521 | } |
| 522 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 523 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 524 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 525 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 526 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 527 | int size; |
| 528 | |
| 529 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 530 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 531 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 532 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 533 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 534 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 535 | |
| 536 | return size; |
| 537 | } |
| 538 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 539 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 540 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 541 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 542 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 543 | int size; |
| 544 | |
| 545 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 546 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 547 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 548 | size >>= 1; /* Convert to cachelines */ |
| 549 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 550 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 551 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 552 | |
| 553 | return size; |
| 554 | } |
| 555 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 556 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 557 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 558 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 559 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 560 | int size; |
| 561 | |
| 562 | size = dsparb & 0x7f; |
| 563 | size >>= 2; /* Convert to cachelines */ |
| 564 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 565 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 566 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 567 | |
| 568 | return size; |
| 569 | } |
| 570 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 571 | /* Pineview has different values for various configs */ |
| 572 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 573 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 574 | .max_wm = PINEVIEW_MAX_WM, |
| 575 | .default_wm = PINEVIEW_DFT_WM, |
| 576 | .guard_size = PINEVIEW_GUARD_WM, |
| 577 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 578 | }; |
| 579 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 580 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 581 | .max_wm = PINEVIEW_MAX_WM, |
| 582 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 583 | .guard_size = PINEVIEW_GUARD_WM, |
| 584 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 585 | }; |
| 586 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 587 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 588 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 589 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 590 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 591 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 592 | }; |
| 593 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 594 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 595 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 596 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 597 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 598 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 599 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 600 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 601 | .fifo_size = I965_CURSOR_FIFO, |
| 602 | .max_wm = I965_CURSOR_MAX_WM, |
| 603 | .default_wm = I965_CURSOR_DFT_WM, |
| 604 | .guard_size = 2, |
| 605 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 606 | }; |
| 607 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 608 | .fifo_size = I945_FIFO_SIZE, |
| 609 | .max_wm = I915_MAX_WM, |
| 610 | .default_wm = 1, |
| 611 | .guard_size = 2, |
| 612 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 613 | }; |
| 614 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 615 | .fifo_size = I915_FIFO_SIZE, |
| 616 | .max_wm = I915_MAX_WM, |
| 617 | .default_wm = 1, |
| 618 | .guard_size = 2, |
| 619 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 620 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 621 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 622 | .fifo_size = I855GM_FIFO_SIZE, |
| 623 | .max_wm = I915_MAX_WM, |
| 624 | .default_wm = 1, |
| 625 | .guard_size = 2, |
| 626 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 627 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 628 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 629 | .fifo_size = I855GM_FIFO_SIZE, |
| 630 | .max_wm = I915_MAX_WM/2, |
| 631 | .default_wm = 1, |
| 632 | .guard_size = 2, |
| 633 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 634 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 635 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 636 | .fifo_size = I830_FIFO_SIZE, |
| 637 | .max_wm = I915_MAX_WM, |
| 638 | .default_wm = 1, |
| 639 | .guard_size = 2, |
| 640 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 641 | }; |
| 642 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 643 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 644 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 645 | * @pixel_rate: Pipe pixel rate in kHz |
| 646 | * @cpp: Plane bytes per pixel |
| 647 | * @latency: Memory wakeup latency in 0.1us units |
| 648 | * |
| 649 | * Compute the watermark using the method 1 or "small buffer" |
| 650 | * formula. The caller may additonally add extra cachelines |
| 651 | * to account for TLB misses and clock crossings. |
| 652 | * |
| 653 | * This method is concerned with the short term drain rate |
| 654 | * of the FIFO, ie. it does not account for blanking periods |
| 655 | * which would effectively reduce the average drain rate across |
| 656 | * a longer period. The name "small" refers to the fact the |
| 657 | * FIFO is relatively small compared to the amount of data |
| 658 | * fetched. |
| 659 | * |
| 660 | * The FIFO level vs. time graph might look something like: |
| 661 | * |
| 662 | * |\ |\ |
| 663 | * | \ | \ |
| 664 | * __---__---__ (- plane active, _ blanking) |
| 665 | * -> time |
| 666 | * |
| 667 | * or perhaps like this: |
| 668 | * |
| 669 | * |\|\ |\|\ |
| 670 | * __----__----__ (- plane active, _ blanking) |
| 671 | * -> time |
| 672 | * |
| 673 | * Returns: |
| 674 | * The watermark in bytes |
| 675 | */ |
| 676 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 677 | unsigned int cpp, |
| 678 | unsigned int latency) |
| 679 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 680 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 681 | |
Ville Syrjälä | d492a29 | 2019-04-08 18:27:01 +0300 | [diff] [blame] | 682 | ret = mul_u32_u32(pixel_rate, cpp * latency); |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 683 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 684 | |
| 685 | return ret; |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 690 | * @pixel_rate: Pipe pixel rate in kHz |
| 691 | * @htotal: Pipe horizontal total |
| 692 | * @width: Plane width in pixels |
| 693 | * @cpp: Plane bytes per pixel |
| 694 | * @latency: Memory wakeup latency in 0.1us units |
| 695 | * |
| 696 | * Compute the watermark using the method 2 or "large buffer" |
| 697 | * formula. The caller may additonally add extra cachelines |
| 698 | * to account for TLB misses and clock crossings. |
| 699 | * |
| 700 | * This method is concerned with the long term drain rate |
| 701 | * of the FIFO, ie. it does account for blanking periods |
| 702 | * which effectively reduce the average drain rate across |
| 703 | * a longer period. The name "large" refers to the fact the |
| 704 | * FIFO is relatively large compared to the amount of data |
| 705 | * fetched. |
| 706 | * |
| 707 | * The FIFO level vs. time graph might look something like: |
| 708 | * |
| 709 | * |\___ |\___ |
| 710 | * | \___ | \___ |
| 711 | * | \ | \ |
| 712 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 713 | * -> time |
| 714 | * |
| 715 | * Returns: |
| 716 | * The watermark in bytes |
| 717 | */ |
| 718 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 719 | unsigned int htotal, |
| 720 | unsigned int width, |
| 721 | unsigned int cpp, |
| 722 | unsigned int latency) |
| 723 | { |
| 724 | unsigned int ret; |
| 725 | |
| 726 | /* |
| 727 | * FIXME remove once all users are computing |
| 728 | * watermarks in the correct place. |
| 729 | */ |
| 730 | if (WARN_ON_ONCE(htotal == 0)) |
| 731 | htotal = 1; |
| 732 | |
| 733 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 734 | ret = (ret + 1) * width * cpp; |
| 735 | |
| 736 | return ret; |
| 737 | } |
| 738 | |
| 739 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 740 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 741 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 742 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 743 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 744 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 745 | * @latency_ns: memory latency for the platform |
| 746 | * |
| 747 | * Calculate the watermark level (the level at which the display plane will |
| 748 | * start fetching from memory again). Each chip has a different display |
| 749 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 750 | * in the correct intel_watermark_params structure. |
| 751 | * |
| 752 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 753 | * on the pixel size. When it reaches the watermark level, it'll start |
| 754 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 755 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 756 | * will occur, and a display engine hang could result. |
| 757 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 758 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 759 | const struct intel_watermark_params *wm, |
| 760 | int fifo_size, int cpp, |
| 761 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 762 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 763 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 764 | |
| 765 | /* |
| 766 | * Note: we need to make sure we don't overflow for various clock & |
| 767 | * latency values. |
| 768 | * clocks go from a few thousand to several hundred thousand. |
| 769 | * latency is usually a few thousand |
| 770 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 771 | entries = intel_wm_method1(pixel_rate, cpp, |
| 772 | latency_ns / 100); |
| 773 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 774 | wm->guard_size; |
| 775 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 776 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 777 | wm_size = fifo_size - entries; |
| 778 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 779 | |
| 780 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 781 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 782 | wm_size = wm->max_wm; |
| 783 | if (wm_size <= 0) |
| 784 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 785 | |
| 786 | /* |
| 787 | * Bspec seems to indicate that the value shouldn't be lower than |
| 788 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 789 | * Lets go for 8 which is the burst size since certain platforms |
| 790 | * already use a hardcoded 8 (which is what the spec says should be |
| 791 | * done). |
| 792 | */ |
| 793 | if (wm_size <= 8) |
| 794 | wm_size = 8; |
| 795 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 796 | return wm_size; |
| 797 | } |
| 798 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 799 | static bool is_disabling(int old, int new, int threshold) |
| 800 | { |
| 801 | return old >= threshold && new < threshold; |
| 802 | } |
| 803 | |
| 804 | static bool is_enabling(int old, int new, int threshold) |
| 805 | { |
| 806 | return old < threshold && new >= threshold; |
| 807 | } |
| 808 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 809 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 810 | { |
| 811 | return dev_priv->wm.max_level + 1; |
| 812 | } |
| 813 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 814 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 815 | const struct intel_plane_state *plane_state) |
| 816 | { |
| 817 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 818 | |
| 819 | /* FIXME check the 'enable' instead */ |
| 820 | if (!crtc_state->base.active) |
| 821 | return false; |
| 822 | |
| 823 | /* |
| 824 | * Treat cursor with fb as always visible since cursor updates |
| 825 | * can happen faster than the vrefresh rate, and the current |
| 826 | * watermark code doesn't handle that correctly. Cursor updates |
| 827 | * which set/clear the fb or change the cursor size are going |
| 828 | * to get throttled by intel_legacy_cursor_update() to work |
| 829 | * around this problem with the watermark code. |
| 830 | */ |
| 831 | if (plane->id == PLANE_CURSOR) |
| 832 | return plane_state->base.fb != NULL; |
| 833 | else |
| 834 | return plane_state->base.visible; |
| 835 | } |
| 836 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 837 | 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] | 838 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 839 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 840 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 841 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 842 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 843 | if (enabled) |
| 844 | return NULL; |
| 845 | enabled = crtc; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | return enabled; |
| 850 | } |
| 851 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 852 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 853 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 854 | 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] | 855 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 856 | const struct cxsr_latency *latency; |
| 857 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 858 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 859 | |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 860 | latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 861 | dev_priv->is_ddr3, |
| 862 | dev_priv->fsb_freq, |
| 863 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 864 | if (!latency) { |
| 865 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 866 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 867 | return; |
| 868 | } |
| 869 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 870 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 871 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 872 | const struct drm_display_mode *adjusted_mode = |
| 873 | &crtc->config->base.adjusted_mode; |
| 874 | const struct drm_framebuffer *fb = |
| 875 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 876 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 877 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 878 | |
| 879 | /* Display SR */ |
| 880 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 881 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 882 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 883 | reg = I915_READ(DSPFW1); |
| 884 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 885 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 886 | I915_WRITE(DSPFW1, reg); |
| 887 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 888 | |
| 889 | /* cursor SR */ |
| 890 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 891 | pineview_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 892 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 893 | reg = I915_READ(DSPFW3); |
| 894 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 895 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 896 | I915_WRITE(DSPFW3, reg); |
| 897 | |
| 898 | /* Display HPLL off SR */ |
| 899 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 900 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 901 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 902 | reg = I915_READ(DSPFW3); |
| 903 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 904 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 905 | I915_WRITE(DSPFW3, reg); |
| 906 | |
| 907 | /* cursor HPLL off SR */ |
| 908 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 909 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 910 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 911 | reg = I915_READ(DSPFW3); |
| 912 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 913 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 914 | I915_WRITE(DSPFW3, reg); |
| 915 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 916 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 917 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 918 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 919 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 920 | } |
| 921 | } |
| 922 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 923 | /* |
| 924 | * Documentation says: |
| 925 | * "If the line size is small, the TLB fetches can get in the way of the |
| 926 | * data fetches, causing some lag in the pixel data return which is not |
| 927 | * accounted for in the above formulas. The following adjustment only |
| 928 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 929 | * The WM is adjusted upwards by the difference between the FIFO size |
| 930 | * and the size of 8 whole lines. This adjustment is always performed |
| 931 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 932 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 933 | 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] | 934 | { |
| 935 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 936 | |
| 937 | return max(0, tlb_miss); |
| 938 | } |
| 939 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 940 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 941 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 942 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 943 | enum pipe pipe; |
| 944 | |
| 945 | for_each_pipe(dev_priv, pipe) |
| 946 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 947 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 948 | I915_WRITE(DSPFW1, |
| 949 | FW_WM(wm->sr.plane, SR) | |
| 950 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 951 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 952 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 953 | I915_WRITE(DSPFW2, |
| 954 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 955 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 956 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 957 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 958 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 959 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 960 | I915_WRITE(DSPFW3, |
| 961 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 962 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 963 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 964 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 965 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 966 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 967 | } |
| 968 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 969 | #define FW_WM_VLV(value, plane) \ |
| 970 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 971 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 972 | 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] | 973 | const struct vlv_wm_values *wm) |
| 974 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 975 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 976 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 977 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 978 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 979 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 980 | I915_WRITE(VLV_DDL(pipe), |
| 981 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 982 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 983 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 984 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 985 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 986 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 987 | /* |
| 988 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 989 | * high order bits so that there are no out of bounds values |
| 990 | * present in the registers during the reprogramming. |
| 991 | */ |
| 992 | I915_WRITE(DSPHOWM, 0); |
| 993 | I915_WRITE(DSPHOWM1, 0); |
| 994 | I915_WRITE(DSPFW4, 0); |
| 995 | I915_WRITE(DSPFW5, 0); |
| 996 | I915_WRITE(DSPFW6, 0); |
| 997 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 998 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 999 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1000 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 1001 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 1002 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1003 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1004 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 1005 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1006 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1007 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1008 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1009 | |
| 1010 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1011 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1012 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1013 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1014 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1015 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 1016 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1017 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1018 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1019 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1020 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1021 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1022 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1023 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1024 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 1025 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1026 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1027 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1028 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1029 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1030 | 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] | 1031 | } else { |
| 1032 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1033 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1034 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1035 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1036 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1037 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1038 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1039 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1040 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1041 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1042 | 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] | 1043 | } |
| 1044 | |
| 1045 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1046 | } |
| 1047 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1048 | #undef FW_WM_VLV |
| 1049 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1050 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1051 | { |
| 1052 | /* all latencies in usec */ |
| 1053 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1054 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1055 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1056 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1057 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1061 | { |
| 1062 | /* |
| 1063 | * DSPCNTR[13] supposedly controls whether the |
| 1064 | * primary plane can use the FIFO space otherwise |
| 1065 | * reserved for the sprite plane. It's not 100% clear |
| 1066 | * what the actual FIFO size is, but it looks like we |
| 1067 | * can happily set both primary and sprite watermarks |
| 1068 | * up to 127 cachelines. So that would seem to mean |
| 1069 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1070 | * the total FIFO is >= 256 cachelines in size. Either |
| 1071 | * way, we don't seem to have to worry about this |
| 1072 | * repartitioning as the maximum watermark value the |
| 1073 | * register can hold for each plane is lower than the |
| 1074 | * minimum FIFO size. |
| 1075 | */ |
| 1076 | switch (plane_id) { |
| 1077 | case PLANE_CURSOR: |
| 1078 | return 63; |
| 1079 | case PLANE_PRIMARY: |
| 1080 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1081 | case PLANE_SPRITE0: |
| 1082 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1083 | default: |
| 1084 | MISSING_CASE(plane_id); |
| 1085 | return 0; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | static int g4x_fbc_fifo_size(int level) |
| 1090 | { |
| 1091 | switch (level) { |
| 1092 | case G4X_WM_LEVEL_SR: |
| 1093 | return 7; |
| 1094 | case G4X_WM_LEVEL_HPLL: |
| 1095 | return 15; |
| 1096 | default: |
| 1097 | MISSING_CASE(level); |
| 1098 | return 0; |
| 1099 | } |
| 1100 | } |
| 1101 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1102 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1103 | const struct intel_plane_state *plane_state, |
| 1104 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1105 | { |
| 1106 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1107 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 1108 | const struct drm_display_mode *adjusted_mode = |
| 1109 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1110 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1111 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1112 | |
| 1113 | if (latency == 0) |
| 1114 | return USHRT_MAX; |
| 1115 | |
| 1116 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1117 | return 0; |
| 1118 | |
| 1119 | /* |
| 1120 | * Not 100% sure which way ELK should go here as the |
| 1121 | * spec only says CL/CTG should assume 32bpp and BW |
| 1122 | * doesn't need to. But as these things followed the |
| 1123 | * mobile vs. desktop lines on gen3 as well, let's |
| 1124 | * assume ELK doesn't need this. |
| 1125 | * |
| 1126 | * The spec also fails to list such a restriction for |
| 1127 | * the HPLL watermark, which seems a little strange. |
| 1128 | * Let's use 32bpp for the HPLL watermark as well. |
| 1129 | */ |
| 1130 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1131 | level != G4X_WM_LEVEL_NORMAL) |
| 1132 | cpp = 4; |
| 1133 | else |
| 1134 | cpp = plane_state->base.fb->format->cpp[0]; |
| 1135 | |
| 1136 | clock = adjusted_mode->crtc_clock; |
| 1137 | htotal = adjusted_mode->crtc_htotal; |
| 1138 | |
| 1139 | if (plane->id == PLANE_CURSOR) |
| 1140 | width = plane_state->base.crtc_w; |
| 1141 | else |
| 1142 | width = drm_rect_width(&plane_state->base.dst); |
| 1143 | |
| 1144 | if (plane->id == PLANE_CURSOR) { |
| 1145 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1146 | } else if (plane->id == PLANE_PRIMARY && |
| 1147 | level == G4X_WM_LEVEL_NORMAL) { |
| 1148 | wm = intel_wm_method1(clock, cpp, latency); |
| 1149 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1150 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1151 | |
| 1152 | small = intel_wm_method1(clock, cpp, latency); |
| 1153 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1154 | |
| 1155 | wm = min(small, large); |
| 1156 | } |
| 1157 | |
| 1158 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1159 | width, cpp); |
| 1160 | |
| 1161 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1162 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1163 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1167 | int level, enum plane_id plane_id, u16 value) |
| 1168 | { |
| 1169 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1170 | bool dirty = false; |
| 1171 | |
| 1172 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1173 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1174 | |
| 1175 | dirty |= raw->plane[plane_id] != value; |
| 1176 | raw->plane[plane_id] = value; |
| 1177 | } |
| 1178 | |
| 1179 | return dirty; |
| 1180 | } |
| 1181 | |
| 1182 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1183 | int level, u16 value) |
| 1184 | { |
| 1185 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1186 | bool dirty = false; |
| 1187 | |
| 1188 | /* NORMAL level doesn't have an FBC watermark */ |
| 1189 | level = max(level, G4X_WM_LEVEL_SR); |
| 1190 | |
| 1191 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1192 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1193 | |
| 1194 | dirty |= raw->fbc != value; |
| 1195 | raw->fbc = value; |
| 1196 | } |
| 1197 | |
| 1198 | return dirty; |
| 1199 | } |
| 1200 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 1201 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 1202 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1203 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1204 | |
| 1205 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1206 | const struct intel_plane_state *plane_state) |
| 1207 | { |
| 1208 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1209 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1210 | enum plane_id plane_id = plane->id; |
| 1211 | bool dirty = false; |
| 1212 | int level; |
| 1213 | |
| 1214 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1215 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1216 | if (plane_id == PLANE_PRIMARY) |
| 1217 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1218 | goto out; |
| 1219 | } |
| 1220 | |
| 1221 | for (level = 0; level < num_levels; level++) { |
| 1222 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1223 | int wm, max_wm; |
| 1224 | |
| 1225 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1226 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1227 | |
| 1228 | if (wm > max_wm) |
| 1229 | break; |
| 1230 | |
| 1231 | dirty |= raw->plane[plane_id] != wm; |
| 1232 | raw->plane[plane_id] = wm; |
| 1233 | |
| 1234 | if (plane_id != PLANE_PRIMARY || |
| 1235 | level == G4X_WM_LEVEL_NORMAL) |
| 1236 | continue; |
| 1237 | |
| 1238 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1239 | raw->plane[plane_id]); |
| 1240 | max_wm = g4x_fbc_fifo_size(level); |
| 1241 | |
| 1242 | /* |
| 1243 | * FBC wm is not mandatory as we |
| 1244 | * can always just disable its use. |
| 1245 | */ |
| 1246 | if (wm > max_wm) |
| 1247 | wm = USHRT_MAX; |
| 1248 | |
| 1249 | dirty |= raw->fbc != wm; |
| 1250 | raw->fbc = wm; |
| 1251 | } |
| 1252 | |
| 1253 | /* mark watermarks as invalid */ |
| 1254 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1255 | |
| 1256 | if (plane_id == PLANE_PRIMARY) |
| 1257 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1258 | |
| 1259 | out: |
| 1260 | if (dirty) { |
| 1261 | DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1262 | plane->base.name, |
| 1263 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1264 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1265 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
| 1266 | |
| 1267 | if (plane_id == PLANE_PRIMARY) |
| 1268 | DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", |
| 1269 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1270 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
| 1271 | } |
| 1272 | |
| 1273 | return dirty; |
| 1274 | } |
| 1275 | |
| 1276 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1277 | enum plane_id plane_id, int level) |
| 1278 | { |
| 1279 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1280 | |
| 1281 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1282 | } |
| 1283 | |
| 1284 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1285 | int level) |
| 1286 | { |
| 1287 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1288 | |
| 1289 | if (level > dev_priv->wm.max_level) |
| 1290 | return false; |
| 1291 | |
| 1292 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1293 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1294 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1295 | } |
| 1296 | |
| 1297 | /* mark all levels starting from 'level' as invalid */ |
| 1298 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1299 | struct g4x_wm_state *wm_state, int level) |
| 1300 | { |
| 1301 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1302 | enum plane_id plane_id; |
| 1303 | |
| 1304 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1305 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1306 | } |
| 1307 | |
| 1308 | if (level <= G4X_WM_LEVEL_SR) { |
| 1309 | wm_state->cxsr = false; |
| 1310 | wm_state->sr.cursor = USHRT_MAX; |
| 1311 | wm_state->sr.plane = USHRT_MAX; |
| 1312 | wm_state->sr.fbc = USHRT_MAX; |
| 1313 | } |
| 1314 | |
| 1315 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1316 | wm_state->hpll_en = false; |
| 1317 | wm_state->hpll.cursor = USHRT_MAX; |
| 1318 | wm_state->hpll.plane = USHRT_MAX; |
| 1319 | wm_state->hpll.fbc = USHRT_MAX; |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1324 | { |
| 1325 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1326 | struct intel_atomic_state *state = |
| 1327 | to_intel_atomic_state(crtc_state->base.state); |
| 1328 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 1329 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1330 | ~BIT(PLANE_CURSOR)); |
| 1331 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1332 | const struct intel_plane_state *old_plane_state; |
| 1333 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1334 | struct intel_plane *plane; |
| 1335 | enum plane_id plane_id; |
| 1336 | int i, level; |
| 1337 | unsigned int dirty = 0; |
| 1338 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1339 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1340 | old_plane_state, |
| 1341 | new_plane_state, i) { |
| 1342 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1343 | old_plane_state->base.crtc != &crtc->base) |
| 1344 | continue; |
| 1345 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1346 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1347 | dirty |= BIT(plane->id); |
| 1348 | } |
| 1349 | |
| 1350 | if (!dirty) |
| 1351 | return 0; |
| 1352 | |
| 1353 | level = G4X_WM_LEVEL_NORMAL; |
| 1354 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1355 | goto out; |
| 1356 | |
| 1357 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1358 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1359 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1360 | |
| 1361 | level = G4X_WM_LEVEL_SR; |
| 1362 | |
| 1363 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1364 | goto out; |
| 1365 | |
| 1366 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1367 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1368 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1369 | wm_state->sr.fbc = raw->fbc; |
| 1370 | |
| 1371 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1372 | |
| 1373 | level = G4X_WM_LEVEL_HPLL; |
| 1374 | |
| 1375 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1376 | goto out; |
| 1377 | |
| 1378 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1379 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1380 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1381 | wm_state->hpll.fbc = raw->fbc; |
| 1382 | |
| 1383 | wm_state->hpll_en = wm_state->cxsr; |
| 1384 | |
| 1385 | level++; |
| 1386 | |
| 1387 | out: |
| 1388 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1389 | return -EINVAL; |
| 1390 | |
| 1391 | /* invalidate the higher levels */ |
| 1392 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1393 | |
| 1394 | /* |
| 1395 | * Determine if the FBC watermark(s) can be used. IF |
| 1396 | * this isn't the case we prefer to disable the FBC |
| 1397 | ( watermark(s) rather than disable the SR/HPLL |
| 1398 | * level(s) entirely. |
| 1399 | */ |
| 1400 | wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL; |
| 1401 | |
| 1402 | if (level >= G4X_WM_LEVEL_SR && |
| 1403 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1404 | wm_state->fbc_en = false; |
| 1405 | else if (level >= G4X_WM_LEVEL_HPLL && |
| 1406 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1407 | wm_state->fbc_en = false; |
| 1408 | |
| 1409 | return 0; |
| 1410 | } |
| 1411 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1412 | 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] | 1413 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1414 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1415 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1416 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
| 1417 | struct intel_atomic_state *intel_state = |
| 1418 | to_intel_atomic_state(new_crtc_state->base.state); |
| 1419 | const struct intel_crtc_state *old_crtc_state = |
| 1420 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 1421 | 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] | 1422 | enum plane_id plane_id; |
| 1423 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1424 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 1425 | *intermediate = *optimal; |
| 1426 | |
| 1427 | intermediate->cxsr = false; |
| 1428 | intermediate->hpll_en = false; |
| 1429 | goto out; |
| 1430 | } |
| 1431 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1432 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1433 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1434 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1435 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1436 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1437 | |
| 1438 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1439 | intermediate->wm.plane[plane_id] = |
| 1440 | max(optimal->wm.plane[plane_id], |
| 1441 | active->wm.plane[plane_id]); |
| 1442 | |
| 1443 | WARN_ON(intermediate->wm.plane[plane_id] > |
| 1444 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
| 1445 | } |
| 1446 | |
| 1447 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1448 | active->sr.plane); |
| 1449 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1450 | active->sr.cursor); |
| 1451 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1452 | active->sr.fbc); |
| 1453 | |
| 1454 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1455 | active->hpll.plane); |
| 1456 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1457 | active->hpll.cursor); |
| 1458 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1459 | active->hpll.fbc); |
| 1460 | |
| 1461 | WARN_ON((intermediate->sr.plane > |
| 1462 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1463 | intermediate->sr.cursor > |
| 1464 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1465 | intermediate->cxsr); |
| 1466 | WARN_ON((intermediate->sr.plane > |
| 1467 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1468 | intermediate->sr.cursor > |
| 1469 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1470 | intermediate->hpll_en); |
| 1471 | |
| 1472 | WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1473 | intermediate->fbc_en && intermediate->cxsr); |
| 1474 | WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1475 | intermediate->fbc_en && intermediate->hpll_en); |
| 1476 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1477 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1478 | /* |
| 1479 | * If our intermediate WM are identical to the final WM, then we can |
| 1480 | * omit the post-vblank programming; only update if it's different. |
| 1481 | */ |
| 1482 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1483 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1484 | |
| 1485 | return 0; |
| 1486 | } |
| 1487 | |
| 1488 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1489 | struct g4x_wm_values *wm) |
| 1490 | { |
| 1491 | struct intel_crtc *crtc; |
| 1492 | int num_active_crtcs = 0; |
| 1493 | |
| 1494 | wm->cxsr = true; |
| 1495 | wm->hpll_en = true; |
| 1496 | wm->fbc_en = true; |
| 1497 | |
| 1498 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1499 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1500 | |
| 1501 | if (!crtc->active) |
| 1502 | continue; |
| 1503 | |
| 1504 | if (!wm_state->cxsr) |
| 1505 | wm->cxsr = false; |
| 1506 | if (!wm_state->hpll_en) |
| 1507 | wm->hpll_en = false; |
| 1508 | if (!wm_state->fbc_en) |
| 1509 | wm->fbc_en = false; |
| 1510 | |
| 1511 | num_active_crtcs++; |
| 1512 | } |
| 1513 | |
| 1514 | if (num_active_crtcs != 1) { |
| 1515 | wm->cxsr = false; |
| 1516 | wm->hpll_en = false; |
| 1517 | wm->fbc_en = false; |
| 1518 | } |
| 1519 | |
| 1520 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1521 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1522 | enum pipe pipe = crtc->pipe; |
| 1523 | |
| 1524 | wm->pipe[pipe] = wm_state->wm; |
| 1525 | if (crtc->active && wm->cxsr) |
| 1526 | wm->sr = wm_state->sr; |
| 1527 | if (crtc->active && wm->hpll_en) |
| 1528 | wm->hpll = wm_state->hpll; |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1533 | { |
| 1534 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1535 | struct g4x_wm_values new_wm = {}; |
| 1536 | |
| 1537 | g4x_merge_wm(dev_priv, &new_wm); |
| 1538 | |
| 1539 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1540 | return; |
| 1541 | |
| 1542 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1543 | _intel_set_memory_cxsr(dev_priv, false); |
| 1544 | |
| 1545 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1546 | |
| 1547 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1548 | _intel_set_memory_cxsr(dev_priv, true); |
| 1549 | |
| 1550 | *old_wm = new_wm; |
| 1551 | } |
| 1552 | |
| 1553 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
| 1554 | struct intel_crtc_state *crtc_state) |
| 1555 | { |
| 1556 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1557 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1558 | |
| 1559 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1560 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1561 | g4x_program_watermarks(dev_priv); |
| 1562 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1563 | } |
| 1564 | |
| 1565 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
| 1566 | struct intel_crtc_state *crtc_state) |
| 1567 | { |
| 1568 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1569 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1570 | |
| 1571 | if (!crtc_state->wm.need_postvbl_update) |
| 1572 | return; |
| 1573 | |
| 1574 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1575 | intel_crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 1576 | g4x_program_watermarks(dev_priv); |
| 1577 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1578 | } |
| 1579 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1580 | /* latency must be in 0.1us units. */ |
| 1581 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1582 | unsigned int htotal, |
| 1583 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1584 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1585 | unsigned int latency) |
| 1586 | { |
| 1587 | unsigned int ret; |
| 1588 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1589 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1590 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1591 | ret = DIV_ROUND_UP(ret, 64); |
| 1592 | |
| 1593 | return ret; |
| 1594 | } |
| 1595 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1596 | 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] | 1597 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1598 | /* all latencies in usec */ |
| 1599 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1600 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1601 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1602 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1603 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1604 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1605 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1606 | |
| 1607 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1611 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1612 | const struct intel_plane_state *plane_state, |
| 1613 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1614 | { |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1615 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1616 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1617 | const struct drm_display_mode *adjusted_mode = |
| 1618 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1619 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1620 | |
| 1621 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1622 | return USHRT_MAX; |
| 1623 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1624 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1625 | return 0; |
| 1626 | |
Daniel Vetter | ef426c1 | 2017-01-04 11:41:10 +0100 | [diff] [blame] | 1627 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1628 | clock = adjusted_mode->crtc_clock; |
| 1629 | htotal = adjusted_mode->crtc_htotal; |
| 1630 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1631 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1632 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1633 | /* |
| 1634 | * FIXME the formula gives values that are |
| 1635 | * too big for the cursor FIFO, and hence we |
| 1636 | * would never be able to use cursors. For |
| 1637 | * now just hardcode the watermark. |
| 1638 | */ |
| 1639 | wm = 63; |
| 1640 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1641 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1642 | dev_priv->wm.pri_latency[level] * 10); |
| 1643 | } |
| 1644 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1645 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1646 | } |
| 1647 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1648 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1649 | { |
| 1650 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1651 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1652 | } |
| 1653 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1654 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1655 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1656 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1657 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1658 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1659 | 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] | 1660 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1661 | int num_active_planes = hweight32(active_planes); |
| 1662 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1663 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1664 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1665 | unsigned int total_rate; |
| 1666 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1667 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1668 | /* |
| 1669 | * When enabling sprite0 after sprite1 has already been enabled |
| 1670 | * we tend to get an underrun unless sprite0 already has some |
| 1671 | * FIFO space allcoated. Hence we always allocate at least one |
| 1672 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1673 | * |
| 1674 | * All other plane enable sequences appear immune to this problem. |
| 1675 | */ |
| 1676 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1677 | sprite0_fifo_extra = 1; |
| 1678 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1679 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1680 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1681 | raw->plane[PLANE_SPRITE1] + |
| 1682 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1683 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1684 | if (total_rate > fifo_size) |
| 1685 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1686 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1687 | if (total_rate == 0) |
| 1688 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1689 | |
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 | unsigned int rate; |
| 1692 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1693 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1694 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1695 | continue; |
| 1696 | } |
| 1697 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1698 | rate = raw->plane[plane_id]; |
| 1699 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1700 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1701 | } |
| 1702 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1703 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1704 | fifo_left -= sprite0_fifo_extra; |
| 1705 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1706 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1707 | |
| 1708 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1709 | |
| 1710 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1711 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1712 | int plane_extra; |
| 1713 | |
| 1714 | if (fifo_left == 0) |
| 1715 | break; |
| 1716 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1717 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1718 | continue; |
| 1719 | |
| 1720 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1721 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1722 | fifo_left -= plane_extra; |
| 1723 | } |
| 1724 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1725 | WARN_ON(active_planes != 0 && fifo_left != 0); |
| 1726 | |
| 1727 | /* give it all to the first plane if none are active */ |
| 1728 | if (active_planes == 0) { |
| 1729 | WARN_ON(fifo_left != fifo_size); |
| 1730 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1731 | } |
| 1732 | |
| 1733 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1734 | } |
| 1735 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1736 | /* mark all levels starting from 'level' as invalid */ |
| 1737 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1738 | struct vlv_wm_state *wm_state, int level) |
| 1739 | { |
| 1740 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1741 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1742 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1743 | enum plane_id plane_id; |
| 1744 | |
| 1745 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1746 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1747 | |
| 1748 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1749 | wm_state->sr[level].plane = USHRT_MAX; |
| 1750 | } |
| 1751 | } |
| 1752 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1753 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1754 | { |
| 1755 | if (wm > fifo_size) |
| 1756 | return USHRT_MAX; |
| 1757 | else |
| 1758 | return fifo_size - wm; |
| 1759 | } |
| 1760 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1761 | /* |
| 1762 | * Starting from 'level' set all higher |
| 1763 | * levels to 'value' in the "raw" watermarks. |
| 1764 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1765 | 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] | 1766 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1767 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1768 | 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] | 1769 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1770 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1771 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1772 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1773 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1774 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1775 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1776 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1777 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1778 | |
| 1779 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1780 | } |
| 1781 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1782 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1783 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1784 | { |
| 1785 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1786 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1787 | 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] | 1788 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1789 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1790 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1791 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1792 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1793 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1797 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1798 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1799 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1800 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1801 | if (wm > max_wm) |
| 1802 | break; |
| 1803 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1804 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1805 | raw->plane[plane_id] = wm; |
| 1806 | } |
| 1807 | |
| 1808 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1809 | 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] | 1810 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1811 | out: |
| 1812 | if (dirty) |
Ville Syrjälä | 57a6528 | 2017-04-21 21:14:22 +0300 | [diff] [blame] | 1813 | 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] | 1814 | plane->base.name, |
| 1815 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1816 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1817 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
| 1818 | |
| 1819 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1820 | } |
| 1821 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1822 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1823 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1824 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1825 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1826 | &crtc_state->wm.vlv.raw[level]; |
| 1827 | const struct vlv_fifo_state *fifo_state = |
| 1828 | &crtc_state->wm.vlv.fifo_state; |
| 1829 | |
| 1830 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1831 | } |
| 1832 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1833 | 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] | 1834 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1835 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1836 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1837 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1838 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | 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] | 1842 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1843 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1844 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1845 | struct intel_atomic_state *state = |
| 1846 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1847 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1848 | const struct vlv_fifo_state *fifo_state = |
| 1849 | &crtc_state->wm.vlv.fifo_state; |
| 1850 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1851 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1852 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->base); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1853 | const struct intel_plane_state *old_plane_state; |
| 1854 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1855 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1856 | enum plane_id plane_id; |
| 1857 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1858 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1859 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1860 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1861 | old_plane_state, |
| 1862 | new_plane_state, i) { |
| 1863 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1864 | old_plane_state->base.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1865 | continue; |
| 1866 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1867 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1868 | dirty |= BIT(plane->id); |
| 1869 | } |
| 1870 | |
| 1871 | /* |
| 1872 | * DSPARB registers may have been reset due to the |
| 1873 | * power well being turned off. Make sure we restore |
| 1874 | * them to a consistent state even if no primary/sprite |
| 1875 | * planes are initially active. |
| 1876 | */ |
| 1877 | if (needs_modeset) |
| 1878 | crtc_state->fifo_changed = true; |
| 1879 | |
| 1880 | if (!dirty) |
| 1881 | return 0; |
| 1882 | |
| 1883 | /* cursor changes don't warrant a FIFO recompute */ |
| 1884 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1885 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1886 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1887 | const struct vlv_fifo_state *old_fifo_state = |
| 1888 | &old_crtc_state->wm.vlv.fifo_state; |
| 1889 | |
| 1890 | ret = vlv_compute_fifo(crtc_state); |
| 1891 | if (ret) |
| 1892 | return ret; |
| 1893 | |
| 1894 | if (needs_modeset || |
| 1895 | memcmp(old_fifo_state, fifo_state, |
| 1896 | sizeof(*fifo_state)) != 0) |
| 1897 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1898 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1899 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1900 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1901 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1902 | /* |
| 1903 | * Note that enabling cxsr with no primary/sprite planes |
| 1904 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1905 | * with exactly one enabled primary/sprite plane. |
| 1906 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1907 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1908 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1909 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1910 | const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1911 | const int sr_fifo_size = INTEL_INFO(dev_priv)->num_pipes * 512 - 1; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1912 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1913 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1914 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1915 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1916 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1917 | wm_state->wm[level].plane[plane_id] = |
| 1918 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1919 | fifo_state->plane[plane_id]); |
| 1920 | } |
| 1921 | |
| 1922 | wm_state->sr[level].plane = |
| 1923 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1924 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1925 | raw->plane[PLANE_SPRITE1]), |
| 1926 | sr_fifo_size); |
| 1927 | |
| 1928 | wm_state->sr[level].cursor = |
| 1929 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1930 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1931 | } |
| 1932 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1933 | if (level == 0) |
| 1934 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1935 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1936 | /* limit to only levels we can actually handle */ |
| 1937 | wm_state->num_levels = level; |
| 1938 | |
| 1939 | /* invalidate the higher levels */ |
| 1940 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1941 | |
| 1942 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1943 | } |
| 1944 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1945 | #define VLV_FIFO(plane, value) \ |
| 1946 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1947 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1948 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
| 1949 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1950 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1951 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1952 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1953 | struct intel_uncore *uncore = &dev_priv->uncore; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1954 | const struct vlv_fifo_state *fifo_state = |
| 1955 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1956 | int sprite0_start, sprite1_start, fifo_size; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1957 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1958 | if (!crtc_state->fifo_changed) |
| 1959 | return; |
| 1960 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1961 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 1962 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 1963 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1964 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1965 | WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63); |
| 1966 | WARN_ON(fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1967 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1968 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 1969 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1970 | /* |
| 1971 | * uncore.lock serves a double purpose here. It allows us to |
| 1972 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 1973 | * it protects the DSPARB registers from getting clobbered by |
| 1974 | * parallel updates from multiple pipes. |
| 1975 | * |
| 1976 | * intel_pipe_update_start() has already disabled interrupts |
| 1977 | * for us, so a plain spin_lock() is sufficient here. |
| 1978 | */ |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1979 | spin_lock(&uncore->lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1980 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1981 | switch (crtc->pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1982 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1983 | case PIPE_A: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1984 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 1985 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1986 | |
| 1987 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1988 | VLV_FIFO(SPRITEB, 0xff)); |
| 1989 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1990 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1991 | |
| 1992 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1993 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1994 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1995 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1996 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 1997 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 1998 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1999 | break; |
| 2000 | case PIPE_B: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2001 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2002 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2003 | |
| 2004 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 2005 | VLV_FIFO(SPRITED, 0xff)); |
| 2006 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 2007 | VLV_FIFO(SPRITED, sprite1_start)); |
| 2008 | |
| 2009 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 2010 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 2011 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 2012 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 2013 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2014 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2015 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2016 | break; |
| 2017 | case PIPE_C: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2018 | dsparb3 = intel_uncore_read_fw(uncore, DSPARB3); |
| 2019 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2020 | |
| 2021 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2022 | VLV_FIFO(SPRITEF, 0xff)); |
| 2023 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2024 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2025 | |
| 2026 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2027 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2028 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2029 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2030 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2031 | intel_uncore_write_fw(uncore, DSPARB3, dsparb3); |
| 2032 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2033 | break; |
| 2034 | default: |
| 2035 | break; |
| 2036 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2037 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2038 | intel_uncore_posting_read_fw(uncore, DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2039 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2040 | spin_unlock(&uncore->lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | #undef VLV_FIFO |
| 2044 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2045 | 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] | 2046 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2047 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2048 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2049 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
| 2050 | struct intel_atomic_state *intel_state = |
| 2051 | to_intel_atomic_state(new_crtc_state->base.state); |
| 2052 | const struct intel_crtc_state *old_crtc_state = |
| 2053 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 2054 | 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] | 2055 | int level; |
| 2056 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2057 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 2058 | *intermediate = *optimal; |
| 2059 | |
| 2060 | intermediate->cxsr = false; |
| 2061 | goto out; |
| 2062 | } |
| 2063 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2064 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2065 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2066 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2067 | |
| 2068 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2069 | enum plane_id plane_id; |
| 2070 | |
| 2071 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2072 | intermediate->wm[level].plane[plane_id] = |
| 2073 | min(optimal->wm[level].plane[plane_id], |
| 2074 | active->wm[level].plane[plane_id]); |
| 2075 | } |
| 2076 | |
| 2077 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2078 | active->sr[level].plane); |
| 2079 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2080 | active->sr[level].cursor); |
| 2081 | } |
| 2082 | |
| 2083 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2084 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2085 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2086 | /* |
| 2087 | * If our intermediate WM are identical to the final WM, then we can |
| 2088 | * omit the post-vblank programming; only update if it's different. |
| 2089 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2090 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2091 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2092 | |
| 2093 | return 0; |
| 2094 | } |
| 2095 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2096 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2097 | struct vlv_wm_values *wm) |
| 2098 | { |
| 2099 | struct intel_crtc *crtc; |
| 2100 | int num_active_crtcs = 0; |
| 2101 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2102 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2103 | wm->cxsr = true; |
| 2104 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2105 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2106 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2107 | |
| 2108 | if (!crtc->active) |
| 2109 | continue; |
| 2110 | |
| 2111 | if (!wm_state->cxsr) |
| 2112 | wm->cxsr = false; |
| 2113 | |
| 2114 | num_active_crtcs++; |
| 2115 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2116 | } |
| 2117 | |
| 2118 | if (num_active_crtcs != 1) |
| 2119 | wm->cxsr = false; |
| 2120 | |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2121 | if (num_active_crtcs > 1) |
| 2122 | wm->level = VLV_WM_LEVEL_PM2; |
| 2123 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2124 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2125 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2126 | enum pipe pipe = crtc->pipe; |
| 2127 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2128 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2129 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2130 | wm->sr = wm_state->sr[wm->level]; |
| 2131 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2132 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2133 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2134 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2135 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2139 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2140 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2141 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2142 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2143 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2144 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2145 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2146 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2147 | return; |
| 2148 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2149 | 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] | 2150 | chv_set_memory_dvfs(dev_priv, false); |
| 2151 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2152 | 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] | 2153 | chv_set_memory_pm5(dev_priv, false); |
| 2154 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2155 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2156 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2157 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2158 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2159 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2160 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2161 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2162 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2163 | 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] | 2164 | chv_set_memory_pm5(dev_priv, true); |
| 2165 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2166 | 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] | 2167 | chv_set_memory_dvfs(dev_priv, true); |
| 2168 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2169 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2170 | } |
| 2171 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2172 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
| 2173 | struct intel_crtc_state *crtc_state) |
| 2174 | { |
| 2175 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2176 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2177 | |
| 2178 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2179 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2180 | vlv_program_watermarks(dev_priv); |
| 2181 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2182 | } |
| 2183 | |
| 2184 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
| 2185 | struct intel_crtc_state *crtc_state) |
| 2186 | { |
| 2187 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2188 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2189 | |
| 2190 | if (!crtc_state->wm.need_postvbl_update) |
| 2191 | return; |
| 2192 | |
| 2193 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 2194 | intel_crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2195 | vlv_program_watermarks(dev_priv); |
| 2196 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2197 | } |
| 2198 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2199 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2200 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2201 | 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] | 2202 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2203 | int srwm = 1; |
| 2204 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2205 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2206 | |
| 2207 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2208 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2209 | if (crtc) { |
| 2210 | /* self-refresh has much higher latency */ |
| 2211 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2212 | const struct drm_display_mode *adjusted_mode = |
| 2213 | &crtc->config->base.adjusted_mode; |
| 2214 | const struct drm_framebuffer *fb = |
| 2215 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2216 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2217 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2218 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2219 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2220 | int entries; |
| 2221 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2222 | entries = intel_wm_method2(clock, htotal, |
| 2223 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2224 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2225 | srwm = I965_FIFO_SIZE - entries; |
| 2226 | if (srwm < 0) |
| 2227 | srwm = 1; |
| 2228 | srwm &= 0x1ff; |
| 2229 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 2230 | entries, srwm); |
| 2231 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2232 | entries = intel_wm_method2(clock, htotal, |
| 2233 | crtc->base.cursor->state->crtc_w, 4, |
| 2234 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2235 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2236 | i965_cursor_wm_info.cacheline_size) + |
| 2237 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2238 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2239 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2240 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2241 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2242 | |
| 2243 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 2244 | "cursor %d\n", srwm, cursor_sr); |
| 2245 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2246 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2247 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2248 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2249 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2250 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2254 | srwm); |
| 2255 | |
| 2256 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2257 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2258 | FW_WM(8, CURSORB) | |
| 2259 | FW_WM(8, PLANEB) | |
| 2260 | FW_WM(8, PLANEA)); |
| 2261 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2262 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2263 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2264 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2265 | |
| 2266 | if (cxsr_enabled) |
| 2267 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2268 | } |
| 2269 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2270 | #undef FW_WM |
| 2271 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2272 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2273 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2274 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2275 | const struct intel_watermark_params *wm_info; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2276 | u32 fwater_lo; |
| 2277 | u32 fwater_hi; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2278 | int cwm, srwm = 1; |
| 2279 | int fifo_size; |
| 2280 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2281 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2282 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2283 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2284 | wm_info = &i945_wm_info; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2285 | else if (!IS_GEN(dev_priv, 2)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2286 | wm_info = &i915_wm_info; |
| 2287 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2288 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2289 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2290 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_A); |
| 2291 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2292 | if (intel_crtc_active(crtc)) { |
| 2293 | const struct drm_display_mode *adjusted_mode = |
| 2294 | &crtc->config->base.adjusted_mode; |
| 2295 | const struct drm_framebuffer *fb = |
| 2296 | crtc->base.primary->state->fb; |
| 2297 | int cpp; |
| 2298 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2299 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2300 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2301 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2302 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2303 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2304 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2305 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2306 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2307 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2308 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2309 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2310 | if (planea_wm > (long)wm_info->max_wm) |
| 2311 | planea_wm = wm_info->max_wm; |
| 2312 | } |
| 2313 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2314 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2315 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2316 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2317 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_B); |
| 2318 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2319 | if (intel_crtc_active(crtc)) { |
| 2320 | const struct drm_display_mode *adjusted_mode = |
| 2321 | &crtc->config->base.adjusted_mode; |
| 2322 | const struct drm_framebuffer *fb = |
| 2323 | crtc->base.primary->state->fb; |
| 2324 | int cpp; |
| 2325 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2326 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2327 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2328 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2329 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2330 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2331 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2332 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2333 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2334 | if (enabled == NULL) |
| 2335 | enabled = crtc; |
| 2336 | else |
| 2337 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2338 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2339 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2340 | if (planeb_wm > (long)wm_info->max_wm) |
| 2341 | planeb_wm = wm_info->max_wm; |
| 2342 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2343 | |
| 2344 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2345 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2346 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2347 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2348 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2349 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2350 | |
| 2351 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2352 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2353 | enabled = NULL; |
| 2354 | } |
| 2355 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2356 | /* |
| 2357 | * Overlay gets an aggressive default since video jitter is bad. |
| 2358 | */ |
| 2359 | cwm = 2; |
| 2360 | |
| 2361 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2362 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2363 | |
| 2364 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2365 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2366 | /* self-refresh has much higher latency */ |
| 2367 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2368 | const struct drm_display_mode *adjusted_mode = |
| 2369 | &enabled->config->base.adjusted_mode; |
| 2370 | const struct drm_framebuffer *fb = |
| 2371 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2372 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2373 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2374 | int hdisplay = enabled->config->pipe_src_w; |
| 2375 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2376 | int entries; |
| 2377 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2378 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2379 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2380 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2381 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2382 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2383 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2384 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2385 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 2386 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 2387 | srwm = wm_info->fifo_size - entries; |
| 2388 | if (srwm < 0) |
| 2389 | srwm = 1; |
| 2390 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2391 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2392 | I915_WRITE(FW_BLC_SELF, |
| 2393 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2394 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2395 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2396 | } |
| 2397 | |
| 2398 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2399 | planea_wm, planeb_wm, cwm, srwm); |
| 2400 | |
| 2401 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2402 | fwater_hi = (cwm & 0x1f); |
| 2403 | |
| 2404 | /* Set request length to 8 cachelines per fetch */ |
| 2405 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2406 | fwater_hi = fwater_hi | (1 << 8); |
| 2407 | |
| 2408 | I915_WRITE(FW_BLC, fwater_lo); |
| 2409 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2410 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2411 | if (enabled) |
| 2412 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2413 | } |
| 2414 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2415 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2416 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2417 | 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] | 2418 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2419 | const struct drm_display_mode *adjusted_mode; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2420 | u32 fwater_lo; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2421 | int planea_wm; |
| 2422 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2423 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2424 | if (crtc == NULL) |
| 2425 | return; |
| 2426 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2427 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2428 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2429 | &i845_wm_info, |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2430 | dev_priv->display.get_fifo_size(dev_priv, PLANE_A), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2431 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2432 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2433 | fwater_lo |= (3<<8) | planea_wm; |
| 2434 | |
| 2435 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 2436 | |
| 2437 | I915_WRITE(FW_BLC, fwater_lo); |
| 2438 | } |
| 2439 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2440 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2441 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2442 | unsigned int cpp, |
| 2443 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2444 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2445 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2446 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2447 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2448 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2449 | |
| 2450 | return ret; |
| 2451 | } |
| 2452 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2453 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2454 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2455 | unsigned int htotal, |
| 2456 | unsigned int width, |
| 2457 | unsigned int cpp, |
| 2458 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2459 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2460 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2461 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2462 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2463 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2464 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2465 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2466 | return ret; |
| 2467 | } |
| 2468 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2469 | 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] | 2470 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2471 | /* |
| 2472 | * Neither of these should be possible since this function shouldn't be |
| 2473 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2474 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2475 | * elsewhere in the driver. |
| 2476 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2477 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2478 | return 0; |
| 2479 | if (WARN_ON(!horiz_pixels)) |
| 2480 | return 0; |
| 2481 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2482 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2483 | } |
| 2484 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2485 | struct ilk_wm_maximums { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2486 | u16 pri; |
| 2487 | u16 spr; |
| 2488 | u16 cur; |
| 2489 | u16 fbc; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2490 | }; |
| 2491 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2492 | /* |
| 2493 | * For both WM_PIPE and WM_LP. |
| 2494 | * mem_value must be in 0.1us units. |
| 2495 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2496 | static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state, |
| 2497 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2498 | u32 mem_value, bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2499 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2500 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2501 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2502 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2503 | if (mem_value == 0) |
| 2504 | return U32_MAX; |
| 2505 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2506 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2507 | return 0; |
| 2508 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2509 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2510 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2511 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2512 | |
| 2513 | if (!is_lp) |
| 2514 | return method1; |
| 2515 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2516 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
| 2517 | crtc_state->base.adjusted_mode.crtc_htotal, |
| 2518 | drm_rect_width(&plane_state->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2519 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2520 | |
| 2521 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2522 | } |
| 2523 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2524 | /* |
| 2525 | * For both WM_PIPE and WM_LP. |
| 2526 | * mem_value must be in 0.1us units. |
| 2527 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2528 | static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state, |
| 2529 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2530 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2531 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2532 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2533 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2534 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2535 | if (mem_value == 0) |
| 2536 | return U32_MAX; |
| 2537 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2538 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2539 | return 0; |
| 2540 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2541 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2542 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2543 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
| 2544 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
| 2545 | crtc_state->base.adjusted_mode.crtc_htotal, |
| 2546 | drm_rect_width(&plane_state->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2547 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2548 | return min(method1, method2); |
| 2549 | } |
| 2550 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2551 | /* |
| 2552 | * For both WM_PIPE and WM_LP. |
| 2553 | * mem_value must be in 0.1us units. |
| 2554 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2555 | static u32 ilk_compute_cur_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 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2558 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2559 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2560 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2561 | if (mem_value == 0) |
| 2562 | return U32_MAX; |
| 2563 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2564 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2565 | return 0; |
| 2566 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2567 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2568 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2569 | return ilk_wm_method2(crtc_state->pixel_rate, |
| 2570 | crtc_state->base.adjusted_mode.crtc_htotal, |
| 2571 | plane_state->base.crtc_w, cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2572 | } |
| 2573 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2574 | /* Only for WM_LP. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2575 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 2576 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2577 | u32 pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2578 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2579 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2580 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2581 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2582 | return 0; |
| 2583 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2584 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2585 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2586 | 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] | 2587 | } |
| 2588 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2589 | static unsigned int |
| 2590 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2591 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2592 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2593 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2594 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2595 | return 768; |
| 2596 | else |
| 2597 | return 512; |
| 2598 | } |
| 2599 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2600 | static unsigned int |
| 2601 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2602 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2603 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2604 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2605 | /* BDW primary/sprite plane watermarks */ |
| 2606 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2607 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2608 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2609 | return level == 0 ? 127 : 1023; |
| 2610 | else if (!is_sprite) |
| 2611 | /* ILK/SNB primary plane watermarks */ |
| 2612 | return level == 0 ? 127 : 511; |
| 2613 | else |
| 2614 | /* ILK/SNB sprite plane watermarks */ |
| 2615 | return level == 0 ? 63 : 255; |
| 2616 | } |
| 2617 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2618 | static unsigned int |
| 2619 | 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] | 2620 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2621 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2622 | return level == 0 ? 63 : 255; |
| 2623 | else |
| 2624 | return level == 0 ? 31 : 63; |
| 2625 | } |
| 2626 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2627 | 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] | 2628 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2629 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2630 | return 31; |
| 2631 | else |
| 2632 | return 15; |
| 2633 | } |
| 2634 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2635 | /* Calculate the maximum primary/sprite plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2636 | 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] | 2637 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2638 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2639 | enum intel_ddb_partitioning ddb_partitioning, |
| 2640 | bool is_sprite) |
| 2641 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2642 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2643 | |
| 2644 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2645 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2646 | return 0; |
| 2647 | |
| 2648 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2649 | if (level == 0 || config->num_pipes_active > 1) { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2650 | fifo_size /= INTEL_INFO(dev_priv)->num_pipes; |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2651 | |
| 2652 | /* |
| 2653 | * For some reason the non self refresh |
| 2654 | * FIFO size is only half of the self |
| 2655 | * refresh FIFO size on ILK/SNB. |
| 2656 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2657 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2658 | fifo_size /= 2; |
| 2659 | } |
| 2660 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2661 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2662 | /* level 0 is always calculated with 1:1 split */ |
| 2663 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2664 | if (is_sprite) |
| 2665 | fifo_size *= 5; |
| 2666 | fifo_size /= 6; |
| 2667 | } else { |
| 2668 | fifo_size /= 2; |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2673 | 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] | 2674 | } |
| 2675 | |
| 2676 | /* Calculate the maximum cursor plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2677 | 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] | 2678 | int level, |
| 2679 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2680 | { |
| 2681 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2682 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2683 | return 64; |
| 2684 | |
| 2685 | /* otherwise just report max that registers can hold */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2686 | return ilk_cursor_wm_reg_max(dev_priv, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2687 | } |
| 2688 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2689 | 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] | 2690 | int level, |
| 2691 | const struct intel_wm_config *config, |
| 2692 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2693 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2694 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2695 | max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false); |
| 2696 | max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true); |
| 2697 | max->cur = ilk_cursor_wm_max(dev_priv, level, config); |
| 2698 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2699 | } |
| 2700 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2701 | 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] | 2702 | int level, |
| 2703 | struct ilk_wm_maximums *max) |
| 2704 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2705 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2706 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2707 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2708 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2709 | } |
| 2710 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2711 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2712 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2713 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2714 | { |
| 2715 | bool ret; |
| 2716 | |
| 2717 | /* already determined to be invalid? */ |
| 2718 | if (!result->enable) |
| 2719 | return false; |
| 2720 | |
| 2721 | result->enable = result->pri_val <= max->pri && |
| 2722 | result->spr_val <= max->spr && |
| 2723 | result->cur_val <= max->cur; |
| 2724 | |
| 2725 | ret = result->enable; |
| 2726 | |
| 2727 | /* |
| 2728 | * HACK until we can pre-compute everything, |
| 2729 | * and thus fail gracefully if LP0 watermarks |
| 2730 | * are exceeded... |
| 2731 | */ |
| 2732 | if (level == 0 && !result->enable) { |
| 2733 | if (result->pri_val > max->pri) |
| 2734 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2735 | level, result->pri_val, max->pri); |
| 2736 | if (result->spr_val > max->spr) |
| 2737 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2738 | level, result->spr_val, max->spr); |
| 2739 | if (result->cur_val > max->cur) |
| 2740 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2741 | level, result->cur_val, max->cur); |
| 2742 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2743 | result->pri_val = min_t(u32, result->pri_val, max->pri); |
| 2744 | result->spr_val = min_t(u32, result->spr_val, max->spr); |
| 2745 | result->cur_val = min_t(u32, result->cur_val, max->cur); |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2746 | result->enable = true; |
| 2747 | } |
| 2748 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2749 | return ret; |
| 2750 | } |
| 2751 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2752 | 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] | 2753 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2754 | int level, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2755 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2756 | const struct intel_plane_state *pristate, |
| 2757 | const struct intel_plane_state *sprstate, |
| 2758 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2759 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2760 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2761 | u16 pri_latency = dev_priv->wm.pri_latency[level]; |
| 2762 | u16 spr_latency = dev_priv->wm.spr_latency[level]; |
| 2763 | u16 cur_latency = dev_priv->wm.cur_latency[level]; |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2764 | |
| 2765 | /* WM1+ latency values stored in 0.5us units */ |
| 2766 | if (level > 0) { |
| 2767 | pri_latency *= 5; |
| 2768 | spr_latency *= 5; |
| 2769 | cur_latency *= 5; |
| 2770 | } |
| 2771 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2772 | if (pristate) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2773 | result->pri_val = ilk_compute_pri_wm(crtc_state, pristate, |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2774 | pri_latency, level); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2775 | 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] | 2776 | } |
| 2777 | |
| 2778 | if (sprstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2779 | result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2780 | |
| 2781 | if (curstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2782 | result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2783 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2784 | result->enable = true; |
| 2785 | } |
| 2786 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2787 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2788 | hsw_compute_linetime_wm(const struct intel_crtc_state *crtc_state) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2789 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2790 | const struct intel_atomic_state *intel_state = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2791 | to_intel_atomic_state(crtc_state->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2792 | const struct drm_display_mode *adjusted_mode = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2793 | &crtc_state->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2794 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2795 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 2796 | if (!crtc_state->base.active) |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2797 | return 0; |
| 2798 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2799 | return 0; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2800 | if (WARN_ON(intel_state->cdclk.logical.cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2801 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2802 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2803 | /* The WM are computed with base on how long it takes to fill a single |
| 2804 | * row at the given clock rate, multiplied by 8. |
| 2805 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2806 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2807 | adjusted_mode->crtc_clock); |
| 2808 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2809 | intel_state->cdclk.logical.cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2810 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2811 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2812 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2813 | } |
| 2814 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2815 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2816 | u16 wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2817 | { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2818 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 2819 | |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2820 | if (INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2821 | u32 val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2822 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2823 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2824 | |
| 2825 | /* read the first set of memory latencies[0:3] */ |
| 2826 | val = 0; /* data0 to be programmed to 0 for first set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2827 | ret = sandybridge_pcode_read(dev_priv, |
| 2828 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2829 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2830 | |
| 2831 | if (ret) { |
| 2832 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2833 | return; |
| 2834 | } |
| 2835 | |
| 2836 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2837 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2838 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2839 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2840 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2841 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2842 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2843 | |
| 2844 | /* read the second set of memory latencies[4:7] */ |
| 2845 | val = 1; /* data0 to be programmed to 1 for second set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2846 | ret = sandybridge_pcode_read(dev_priv, |
| 2847 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2848 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2849 | if (ret) { |
| 2850 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2851 | return; |
| 2852 | } |
| 2853 | |
| 2854 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2855 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2856 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2857 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2858 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2859 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2860 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2861 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2862 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2863 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2864 | * need to be disabled. We make sure to sanitize the values out |
| 2865 | * of the punit to satisfy this requirement. |
| 2866 | */ |
| 2867 | for (level = 1; level <= max_level; level++) { |
| 2868 | if (wm[level] == 0) { |
| 2869 | for (i = level + 1; i <= max_level; i++) |
| 2870 | wm[i] = 0; |
| 2871 | break; |
| 2872 | } |
| 2873 | } |
| 2874 | |
| 2875 | /* |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2876 | * WaWmMemoryReadLatency:skl+,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2877 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2878 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2879 | * to add 2us to the various latency levels we retrieve from the |
| 2880 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2881 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2882 | if (wm[0] == 0) { |
| 2883 | wm[0] += 2; |
| 2884 | for (level = 1; level <= max_level; level++) { |
| 2885 | if (wm[level] == 0) |
| 2886 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2887 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2888 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2889 | } |
| 2890 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2891 | /* |
| 2892 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2893 | * If we could not get dimm info enable this WA to prevent from |
| 2894 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2895 | * to avoid any underrun. |
| 2896 | */ |
Ville Syrjälä | 5d6f36b | 2018-10-23 21:21:02 +0300 | [diff] [blame] | 2897 | if (dev_priv->dram_info.is_16gb_dimm) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2898 | wm[0] += 1; |
| 2899 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2900 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2901 | u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2902 | |
| 2903 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2904 | if (wm[0] == 0) |
| 2905 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2906 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2907 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2908 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2909 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2910 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2911 | u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2912 | |
| 2913 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2914 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2915 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2916 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2917 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2918 | u32 mltr = intel_uncore_read(uncore, MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2919 | |
| 2920 | /* ILK primary LP0 latency is 700 ns */ |
| 2921 | wm[0] = 7; |
| 2922 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2923 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2924 | } else { |
| 2925 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2929 | 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] | 2930 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2931 | { |
| 2932 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2933 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2934 | wm[0] = 13; |
| 2935 | } |
| 2936 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2937 | 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] | 2938 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2939 | { |
| 2940 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2941 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2942 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2943 | } |
| 2944 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2945 | 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] | 2946 | { |
| 2947 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2948 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2949 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2950 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2951 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2952 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2953 | return 3; |
| 2954 | else |
| 2955 | return 2; |
| 2956 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2957 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2958 | 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] | 2959 | const char *name, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2960 | const u16 wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2961 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2962 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2963 | |
| 2964 | for (level = 0; level <= max_level; level++) { |
| 2965 | unsigned int latency = wm[level]; |
| 2966 | |
| 2967 | if (latency == 0) { |
Chris Wilson | 86c1c87 | 2018-07-26 17:15:27 +0100 | [diff] [blame] | 2968 | DRM_DEBUG_KMS("%s WM%d latency not provided\n", |
| 2969 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2970 | continue; |
| 2971 | } |
| 2972 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2973 | /* |
| 2974 | * - latencies are in us on gen9. |
| 2975 | * - before then, WM1+ latency values are in 0.5us units |
| 2976 | */ |
Paulo Zanoni | dfc267a | 2017-08-09 13:52:46 -0700 | [diff] [blame] | 2977 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2978 | latency *= 10; |
| 2979 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2980 | latency *= 5; |
| 2981 | |
| 2982 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2983 | name, level, wm[level], |
| 2984 | latency / 10, latency % 10); |
| 2985 | } |
| 2986 | } |
| 2987 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2988 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2989 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2990 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2991 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2992 | |
| 2993 | if (wm[0] >= min) |
| 2994 | return false; |
| 2995 | |
| 2996 | wm[0] = max(wm[0], min); |
| 2997 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2998 | 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] | 2999 | |
| 3000 | return true; |
| 3001 | } |
| 3002 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3003 | 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] | 3004 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3005 | bool changed; |
| 3006 | |
| 3007 | /* |
| 3008 | * The BIOS provided WM memory latency values are often |
| 3009 | * inadequate for high resolution displays. Adjust them. |
| 3010 | */ |
| 3011 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 3012 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 3013 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 3014 | |
| 3015 | if (!changed) |
| 3016 | return; |
| 3017 | |
| 3018 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3019 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3020 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3021 | 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] | 3022 | } |
| 3023 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3024 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 3025 | { |
| 3026 | /* |
| 3027 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 3028 | * LP3 usage can cause vblank interrupts to be lost. |
| 3029 | * The DEIIR bit will go high but it looks like the CPU |
| 3030 | * never gets interrupted. |
| 3031 | * |
| 3032 | * It's not clear whether other interrupt source could |
| 3033 | * be affected or if this is somehow limited to vblank |
| 3034 | * interrupts only. To play it safe we disable LP3 |
| 3035 | * watermarks entirely. |
| 3036 | */ |
| 3037 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3038 | dev_priv->wm.spr_latency[3] == 0 && |
| 3039 | dev_priv->wm.cur_latency[3] == 0) |
| 3040 | return; |
| 3041 | |
| 3042 | dev_priv->wm.pri_latency[3] = 0; |
| 3043 | dev_priv->wm.spr_latency[3] = 0; |
| 3044 | dev_priv->wm.cur_latency[3] = 0; |
| 3045 | |
| 3046 | DRM_DEBUG_KMS("LP3 watermarks disabled due to potential for lost interrupts\n"); |
| 3047 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3048 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3049 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3050 | } |
| 3051 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3052 | 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] | 3053 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3054 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3055 | |
| 3056 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3057 | sizeof(dev_priv->wm.pri_latency)); |
| 3058 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3059 | sizeof(dev_priv->wm.pri_latency)); |
| 3060 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3061 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3062 | 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] | 3063 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3064 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3065 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3066 | 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] | 3067 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3068 | if (IS_GEN(dev_priv, 6)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3069 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3070 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3071 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3072 | } |
| 3073 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3074 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3075 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3076 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3077 | 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] | 3078 | } |
| 3079 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3080 | 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] | 3081 | struct intel_pipe_wm *pipe_wm) |
| 3082 | { |
| 3083 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3084 | const struct intel_wm_config config = { |
| 3085 | .num_pipes_active = 1, |
| 3086 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3087 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3088 | }; |
| 3089 | struct ilk_wm_maximums max; |
| 3090 | |
| 3091 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3092 | 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] | 3093 | |
| 3094 | /* At least LP0 must be valid */ |
| 3095 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 3096 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 3097 | return false; |
| 3098 | } |
| 3099 | |
| 3100 | return true; |
| 3101 | } |
| 3102 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3103 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3104 | static int ilk_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3105 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3106 | struct drm_atomic_state *state = crtc_state->base.state; |
| 3107 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3108 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3109 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3110 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3111 | struct drm_plane *plane; |
| 3112 | const struct drm_plane_state *plane_state; |
| 3113 | const struct intel_plane_state *pristate = NULL; |
| 3114 | const struct intel_plane_state *sprstate = NULL; |
| 3115 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3116 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3117 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3118 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3119 | pipe_wm = &crtc_state->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3120 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3121 | drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, &crtc_state->base) { |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3122 | const struct intel_plane_state *ps = to_intel_plane_state(plane_state); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3123 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3124 | if (plane->type == DRM_PLANE_TYPE_PRIMARY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3125 | pristate = ps; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3126 | else if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3127 | sprstate = ps; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3128 | else if (plane->type == DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3129 | curstate = ps; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3132 | pipe_wm->pipe_enabled = crtc_state->base.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3133 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3134 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 3135 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 3136 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 3137 | 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] | 3138 | } |
| 3139 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3140 | usable_level = max_level; |
| 3141 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3142 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3143 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3144 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3145 | |
| 3146 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3147 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3148 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3149 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3150 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3151 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3152 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3153 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3154 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3155 | pipe_wm->linetime = hsw_compute_linetime_wm(crtc_state); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3156 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3157 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3158 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3159 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3160 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3161 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3162 | for (level = 1; level <= usable_level; level++) { |
| 3163 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3164 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3165 | ilk_compute_wm_level(dev_priv, intel_crtc, level, crtc_state, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3166 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3167 | |
| 3168 | /* |
| 3169 | * Disable any watermark level that exceeds the |
| 3170 | * register maximums since such watermarks are |
| 3171 | * always invalid. |
| 3172 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3173 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3174 | memset(wm, 0, sizeof(*wm)); |
| 3175 | break; |
| 3176 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3177 | } |
| 3178 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3179 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3183 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3184 | * state and the new state. These can be programmed to the hardware |
| 3185 | * immediately. |
| 3186 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3187 | static int ilk_compute_intermediate_wm(struct intel_crtc_state *newstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3188 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3189 | struct intel_crtc *intel_crtc = to_intel_crtc(newstate->base.crtc); |
| 3190 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3191 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3192 | struct intel_atomic_state *intel_state = |
| 3193 | to_intel_atomic_state(newstate->base.state); |
| 3194 | const struct intel_crtc_state *oldstate = |
| 3195 | intel_atomic_get_old_crtc_state(intel_state, intel_crtc); |
| 3196 | const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3197 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3198 | |
| 3199 | /* |
| 3200 | * Start with the final, target watermarks, then combine with the |
| 3201 | * currently active watermarks to get values that are safe both before |
| 3202 | * and after the vblank. |
| 3203 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3204 | *a = newstate->wm.ilk.optimal; |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 3205 | if (!newstate->base.active || drm_atomic_crtc_needs_modeset(&newstate->base) || |
| 3206 | intel_state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3207 | return 0; |
| 3208 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3209 | a->pipe_enabled |= b->pipe_enabled; |
| 3210 | a->sprites_enabled |= b->sprites_enabled; |
| 3211 | a->sprites_scaled |= b->sprites_scaled; |
| 3212 | |
| 3213 | for (level = 0; level <= max_level; level++) { |
| 3214 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3215 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3216 | |
| 3217 | a_wm->enable &= b_wm->enable; |
| 3218 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3219 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3220 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3221 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3222 | } |
| 3223 | |
| 3224 | /* |
| 3225 | * We need to make sure that these merged watermark values are |
| 3226 | * actually a valid configuration themselves. If they're not, |
| 3227 | * there's no safe way to transition from the old state to |
| 3228 | * the new state, so we need to fail the atomic transaction. |
| 3229 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3230 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3231 | return -EINVAL; |
| 3232 | |
| 3233 | /* |
| 3234 | * If our intermediate WM are identical to the final WM, then we can |
| 3235 | * omit the post-vblank programming; only update if it's different. |
| 3236 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3237 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3238 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3239 | |
| 3240 | return 0; |
| 3241 | } |
| 3242 | |
| 3243 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3244 | * Merge the watermarks from all active pipes for a specific level. |
| 3245 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3246 | 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] | 3247 | int level, |
| 3248 | struct intel_wm_level *ret_wm) |
| 3249 | { |
| 3250 | const struct intel_crtc *intel_crtc; |
| 3251 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3252 | ret_wm->enable = true; |
| 3253 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3254 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3255 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3256 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3257 | |
| 3258 | if (!active->pipe_enabled) |
| 3259 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3260 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3261 | /* |
| 3262 | * The watermark values may have been used in the past, |
| 3263 | * so we must maintain them in the registers for some |
| 3264 | * time even if the level is now disabled. |
| 3265 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3266 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3267 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3268 | |
| 3269 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3270 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3271 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3272 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3273 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | /* |
| 3277 | * Merge all low power watermarks for all active pipes. |
| 3278 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3279 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3280 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3281 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3282 | struct intel_pipe_wm *merged) |
| 3283 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3284 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3285 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3286 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3287 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3288 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3289 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3290 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3291 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3292 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3293 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3294 | |
| 3295 | /* merge each WM1+ level */ |
| 3296 | for (level = 1; level <= max_level; level++) { |
| 3297 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3298 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3299 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3300 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3301 | if (level > last_enabled_level) |
| 3302 | wm->enable = false; |
| 3303 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3304 | /* make sure all following levels get disabled */ |
| 3305 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3306 | |
| 3307 | /* |
| 3308 | * The spec says it is preferred to disable |
| 3309 | * FBC WMs instead of disabling a WM level. |
| 3310 | */ |
| 3311 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3312 | if (wm->enable) |
| 3313 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3314 | wm->fbc_val = 0; |
| 3315 | } |
| 3316 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3317 | |
| 3318 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3319 | /* |
| 3320 | * FIXME this is racy. FBC might get enabled later. |
| 3321 | * What we should check here is whether FBC can be |
| 3322 | * enabled sometime later. |
| 3323 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3324 | if (IS_GEN(dev_priv, 5) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3325 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3326 | for (level = 2; level <= max_level; level++) { |
| 3327 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3328 | |
| 3329 | wm->enable = false; |
| 3330 | } |
| 3331 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3332 | } |
| 3333 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3334 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3335 | { |
| 3336 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3337 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3338 | } |
| 3339 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3340 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3341 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3342 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3343 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3344 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3345 | return 2 * level; |
| 3346 | else |
| 3347 | return dev_priv->wm.pri_latency[level]; |
| 3348 | } |
| 3349 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3350 | 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] | 3351 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3352 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3353 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3354 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3355 | struct intel_crtc *intel_crtc; |
| 3356 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3357 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3358 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3359 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3360 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3361 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3362 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3363 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3364 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3365 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3366 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3367 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3368 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3369 | /* |
| 3370 | * Maintain the watermark values even if the level is |
| 3371 | * disabled. Doing otherwise could cause underruns. |
| 3372 | */ |
| 3373 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3374 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3375 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3376 | r->cur_val; |
| 3377 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3378 | if (r->enable) |
| 3379 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3380 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3381 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3382 | results->wm_lp[wm_lp - 1] |= |
| 3383 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3384 | else |
| 3385 | results->wm_lp[wm_lp - 1] |= |
| 3386 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3387 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3388 | /* |
| 3389 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3390 | * level is disabled. Doing otherwise could cause underruns. |
| 3391 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3392 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3393 | WARN_ON(wm_lp != 1); |
| 3394 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3395 | } else |
| 3396 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3397 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3398 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3399 | /* LP0 register values */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3400 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3401 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3402 | const struct intel_wm_level *r = |
| 3403 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3404 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3405 | if (WARN_ON(!r->enable)) |
| 3406 | continue; |
| 3407 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3408 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3409 | |
| 3410 | results->wm_pipe[pipe] = |
| 3411 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3412 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3413 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3414 | } |
| 3415 | } |
| 3416 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3417 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3418 | * 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] | 3419 | static struct intel_pipe_wm * |
| 3420 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3421 | struct intel_pipe_wm *r1, |
| 3422 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3423 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3424 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3425 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3426 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3427 | for (level = 1; level <= max_level; level++) { |
| 3428 | if (r1->wm[level].enable) |
| 3429 | level1 = level; |
| 3430 | if (r2->wm[level].enable) |
| 3431 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3432 | } |
| 3433 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3434 | if (level1 == level2) { |
| 3435 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3436 | return r2; |
| 3437 | else |
| 3438 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3439 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3440 | return r1; |
| 3441 | } else { |
| 3442 | return r2; |
| 3443 | } |
| 3444 | } |
| 3445 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3446 | /* dirty bits used to track which watermarks need changes */ |
| 3447 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 3448 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 3449 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3450 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3451 | #define WM_DIRTY_FBC (1 << 24) |
| 3452 | #define WM_DIRTY_DDB (1 << 25) |
| 3453 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3454 | 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] | 3455 | const struct ilk_wm_values *old, |
| 3456 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3457 | { |
| 3458 | unsigned int dirty = 0; |
| 3459 | enum pipe pipe; |
| 3460 | int wm_lp; |
| 3461 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3462 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3463 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 3464 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 3465 | /* Must disable LP1+ watermarks too */ |
| 3466 | dirty |= WM_DIRTY_LP_ALL; |
| 3467 | } |
| 3468 | |
| 3469 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3470 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3471 | /* Must disable LP1+ watermarks too */ |
| 3472 | dirty |= WM_DIRTY_LP_ALL; |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3477 | dirty |= WM_DIRTY_FBC; |
| 3478 | /* Must disable LP1+ watermarks too */ |
| 3479 | dirty |= WM_DIRTY_LP_ALL; |
| 3480 | } |
| 3481 | |
| 3482 | if (old->partitioning != new->partitioning) { |
| 3483 | dirty |= WM_DIRTY_DDB; |
| 3484 | /* Must disable LP1+ watermarks too */ |
| 3485 | dirty |= WM_DIRTY_LP_ALL; |
| 3486 | } |
| 3487 | |
| 3488 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3489 | if (dirty & WM_DIRTY_LP_ALL) |
| 3490 | return dirty; |
| 3491 | |
| 3492 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3493 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3494 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3495 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3496 | break; |
| 3497 | } |
| 3498 | |
| 3499 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3500 | for (; wm_lp <= 3; wm_lp++) |
| 3501 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3502 | |
| 3503 | return dirty; |
| 3504 | } |
| 3505 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3506 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3507 | unsigned int dirty) |
| 3508 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3509 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3510 | bool changed = false; |
| 3511 | |
| 3512 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3513 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3514 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3515 | changed = true; |
| 3516 | } |
| 3517 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3518 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3519 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3520 | changed = true; |
| 3521 | } |
| 3522 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3523 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3524 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3525 | changed = true; |
| 3526 | } |
| 3527 | |
| 3528 | /* |
| 3529 | * Don't touch WM1S_LP_EN here. |
| 3530 | * Doing so could cause underruns. |
| 3531 | */ |
| 3532 | |
| 3533 | return changed; |
| 3534 | } |
| 3535 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3536 | /* |
| 3537 | * The spec says we shouldn't write when we don't need, because every write |
| 3538 | * causes WMs to be re-evaluated, expending some power. |
| 3539 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3540 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3541 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3542 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3543 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3544 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3545 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3546 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3547 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3548 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3549 | return; |
| 3550 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3551 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3552 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3553 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3554 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3555 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3556 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3557 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3558 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 3559 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3560 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3561 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3562 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3563 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3564 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3565 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 3566 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3567 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3568 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3569 | val = I915_READ(WM_MISC); |
| 3570 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3571 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3572 | else |
| 3573 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3574 | I915_WRITE(WM_MISC, val); |
| 3575 | } else { |
| 3576 | val = I915_READ(DISP_ARB_CTL2); |
| 3577 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3578 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3579 | else |
| 3580 | val |= DISP_DATA_PARTITION_5_6; |
| 3581 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3582 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3583 | } |
| 3584 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3585 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3586 | val = I915_READ(DISP_ARB_CTL); |
| 3587 | if (results->enable_fbc_wm) |
| 3588 | val &= ~DISP_FBC_WM_DIS; |
| 3589 | else |
| 3590 | val |= DISP_FBC_WM_DIS; |
| 3591 | I915_WRITE(DISP_ARB_CTL, val); |
| 3592 | } |
| 3593 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3594 | if (dirty & WM_DIRTY_LP(1) && |
| 3595 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3596 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3597 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3598 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3599 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3600 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3601 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3602 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3603 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3604 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3605 | 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] | 3606 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3607 | 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] | 3608 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3609 | 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] | 3610 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3611 | |
| 3612 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3613 | } |
| 3614 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3615 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3616 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3617 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3618 | |
| 3619 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3620 | } |
| 3621 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3622 | static u8 intel_enabled_dbuf_slices_num(struct drm_i915_private *dev_priv) |
| 3623 | { |
| 3624 | u8 enabled_slices; |
| 3625 | |
| 3626 | /* Slice 1 will always be enabled */ |
| 3627 | enabled_slices = 1; |
| 3628 | |
| 3629 | /* Gen prior to GEN11 have only one DBuf slice */ |
| 3630 | if (INTEL_GEN(dev_priv) < 11) |
| 3631 | return enabled_slices; |
| 3632 | |
Imre Deak | 209d735 | 2019-03-07 12:32:35 +0200 | [diff] [blame] | 3633 | /* |
| 3634 | * FIXME: for now we'll only ever use 1 slice; pretend that we have |
| 3635 | * only that 1 slice enabled until we have a proper way for on-demand |
| 3636 | * toggling of the second slice. |
| 3637 | */ |
| 3638 | if (0 && I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3639 | enabled_slices++; |
| 3640 | |
| 3641 | return enabled_slices; |
| 3642 | } |
| 3643 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3644 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3645 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3646 | * so assume we'll always need it in order to avoid underruns. |
| 3647 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3648 | 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] | 3649 | { |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3650 | return IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3651 | } |
| 3652 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3653 | static bool |
| 3654 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3655 | { |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3656 | return (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) && |
| 3657 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3658 | } |
| 3659 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3660 | /* |
| 3661 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3662 | * depending on power and performance requirements. The display engine access |
| 3663 | * to system memory is blocked during the adjustment time. Because of the |
| 3664 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3665 | * underruns if we don't meet all of the following requirements: |
| 3666 | * |
| 3667 | * - <= 1 pipe enabled |
| 3668 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3669 | * - We're not using an interlaced display configuration |
| 3670 | */ |
| 3671 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3672 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3673 | { |
| 3674 | int ret; |
| 3675 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3676 | if (!intel_has_sagv(dev_priv)) |
| 3677 | return 0; |
| 3678 | |
| 3679 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3680 | return 0; |
| 3681 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3682 | DRM_DEBUG_KMS("Enabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3683 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3684 | GEN9_SAGV_ENABLE); |
| 3685 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3686 | /* We don't need to wait for SAGV when enabling */ |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3687 | |
| 3688 | /* |
| 3689 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3690 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3691 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3692 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3693 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3694 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3695 | return 0; |
| 3696 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3697 | DRM_ERROR("Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3698 | return ret; |
| 3699 | } |
| 3700 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3701 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3702 | return 0; |
| 3703 | } |
| 3704 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3705 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3706 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3707 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3708 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3709 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3710 | if (!intel_has_sagv(dev_priv)) |
| 3711 | return 0; |
| 3712 | |
| 3713 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3714 | return 0; |
| 3715 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3716 | DRM_DEBUG_KMS("Disabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3717 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3718 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3719 | GEN9_SAGV_DISABLE, |
| 3720 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3721 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3722 | /* |
| 3723 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3724 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3725 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3726 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3727 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3728 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3729 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3730 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3731 | DRM_ERROR("Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3732 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3733 | } |
| 3734 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3735 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3736 | return 0; |
| 3737 | } |
| 3738 | |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3739 | bool intel_can_enable_sagv(struct intel_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3740 | { |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3741 | struct drm_device *dev = state->base.dev; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3742 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3743 | struct intel_crtc *crtc; |
| 3744 | struct intel_plane *plane; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3745 | struct intel_crtc_state *crtc_state; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3746 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3747 | int level, latency; |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3748 | int sagv_block_time_us; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3749 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3750 | if (!intel_has_sagv(dev_priv)) |
| 3751 | return false; |
| 3752 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3753 | if (IS_GEN(dev_priv, 9)) |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3754 | sagv_block_time_us = 30; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3755 | else if (IS_GEN(dev_priv, 10)) |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3756 | sagv_block_time_us = 20; |
| 3757 | else |
| 3758 | sagv_block_time_us = 10; |
| 3759 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3760 | /* |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3761 | * If there are no active CRTCs, no additional checks need be performed |
| 3762 | */ |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3763 | if (hweight32(state->active_crtcs) == 0) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3764 | return true; |
Lucas De Marchi | da17223 | 2019-04-04 16:04:26 -0700 | [diff] [blame] | 3765 | |
| 3766 | /* |
| 3767 | * SKL+ workaround: bspec recommends we disable SAGV when we have |
| 3768 | * more then one pipe enabled |
| 3769 | */ |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3770 | if (hweight32(state->active_crtcs) > 1) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3771 | return false; |
| 3772 | |
| 3773 | /* Since we're now guaranteed to only have one active CRTC... */ |
Maarten Lankhorst | 855e0d6 | 2019-06-28 10:55:13 +0200 | [diff] [blame] | 3774 | pipe = ffs(state->active_crtcs) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 3775 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3776 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3777 | |
Paulo Zanoni | c89cadd | 2016-10-10 17:30:59 -0300 | [diff] [blame] | 3778 | if (crtc->base.state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3779 | return false; |
| 3780 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3781 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3782 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3783 | &crtc_state->wm.skl.optimal.planes[plane->id]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3784 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3785 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3786 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3787 | continue; |
| 3788 | |
| 3789 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3790 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3791 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3792 | { } |
| 3793 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3794 | latency = dev_priv->wm.skl_latency[level]; |
| 3795 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3796 | if (skl_needs_memory_bw_wa(dev_priv) && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3797 | plane->base.state->fb->modifier == |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3798 | I915_FORMAT_MOD_X_TILED) |
| 3799 | latency += 15; |
| 3800 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3801 | /* |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3802 | * If any of the planes on this pipe don't enable wm levels that |
| 3803 | * incur memory latencies higher than sagv_block_time_us we |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3804 | * can't enable SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3805 | */ |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3806 | if (latency < sagv_block_time_us) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3807 | return false; |
| 3808 | } |
| 3809 | |
| 3810 | return true; |
| 3811 | } |
| 3812 | |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3813 | static u16 intel_get_ddb_size(struct drm_i915_private *dev_priv, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3814 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3815 | const u64 total_data_rate, |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3816 | const int num_active, |
| 3817 | struct skl_ddb_allocation *ddb) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3818 | { |
| 3819 | const struct drm_display_mode *adjusted_mode; |
| 3820 | u64 total_data_bw; |
| 3821 | u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3822 | |
| 3823 | WARN_ON(ddb_size == 0); |
| 3824 | |
| 3825 | if (INTEL_GEN(dev_priv) < 11) |
| 3826 | return ddb_size - 4; /* 4 blocks for bypass path allocation */ |
| 3827 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3828 | adjusted_mode = &crtc_state->base.adjusted_mode; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3829 | total_data_bw = total_data_rate * drm_mode_vrefresh(adjusted_mode); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3830 | |
| 3831 | /* |
| 3832 | * 12GB/s is maximum BW supported by single DBuf slice. |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3833 | * |
| 3834 | * FIXME dbuf slice code is broken: |
| 3835 | * - must wait for planes to stop using the slice before powering it off |
| 3836 | * - plane straddling both slices is illegal in multi-pipe scenarios |
| 3837 | * - should validate we stay within the hw bandwidth limits |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3838 | */ |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3839 | if (0 && (num_active > 1 || total_data_bw >= GBps(12))) { |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3840 | ddb->enabled_slices = 2; |
| 3841 | } else { |
| 3842 | ddb->enabled_slices = 1; |
| 3843 | ddb_size /= 2; |
| 3844 | } |
| 3845 | |
| 3846 | return ddb_size; |
| 3847 | } |
| 3848 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3849 | static void |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 3850 | skl_ddb_get_pipe_allocation_limits(struct drm_i915_private *dev_priv, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3851 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3852 | const u64 total_data_rate, |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3853 | struct skl_ddb_allocation *ddb, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3854 | struct skl_ddb_entry *alloc, /* out */ |
| 3855 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3856 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3857 | struct drm_atomic_state *state = crtc_state->base.state; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3858 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3859 | struct drm_crtc *for_crtc = crtc_state->base.crtc; |
| 3860 | const struct intel_crtc *crtc; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3861 | u32 pipe_width = 0, total_width = 0, width_before_pipe = 0; |
| 3862 | enum pipe for_pipe = to_intel_crtc(for_crtc)->pipe; |
| 3863 | u16 ddb_size; |
| 3864 | u32 i; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3865 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3866 | if (WARN_ON(!state) || !crtc_state->base.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3867 | alloc->start = 0; |
| 3868 | alloc->end = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3869 | *num_active = hweight32(dev_priv->active_crtcs); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3870 | return; |
| 3871 | } |
| 3872 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3873 | if (intel_state->active_pipe_changes) |
| 3874 | *num_active = hweight32(intel_state->active_crtcs); |
| 3875 | else |
| 3876 | *num_active = hweight32(dev_priv->active_crtcs); |
| 3877 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3878 | 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] | 3879 | *num_active, ddb); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3880 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3881 | /* |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3882 | * If the state doesn't change the active CRTC's or there is no |
| 3883 | * modeset request, then there's no need to recalculate; |
| 3884 | * the existing pipe allocation limits should remain unchanged. |
| 3885 | * Note that we're safe from racing commits since any racing commit |
| 3886 | * that changes the active CRTC list or do modeset would need to |
| 3887 | * grab _all_ crtc locks, including the one we currently hold. |
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 (!intel_state->active_pipe_changes && !intel_state->modeset) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 3890 | /* |
| 3891 | * alloc may be cleared by clear_intel_crtc_state, |
| 3892 | * copy from old state to be sure |
| 3893 | */ |
| 3894 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3895 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3896 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3897 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3898 | /* |
| 3899 | * Watermark/ddb requirement highly depends upon width of the |
| 3900 | * framebuffer, So instead of allocating DDB equally among pipes |
| 3901 | * distribute DDB based on resolution/width of the display. |
| 3902 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3903 | for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) { |
| 3904 | const struct drm_display_mode *adjusted_mode = |
| 3905 | &crtc_state->base.adjusted_mode; |
| 3906 | enum pipe pipe = crtc->pipe; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3907 | int hdisplay, vdisplay; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3908 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3909 | if (!crtc_state->base.enable) |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3910 | continue; |
| 3911 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3912 | drm_mode_get_hv_timing(adjusted_mode, &hdisplay, &vdisplay); |
| 3913 | total_width += hdisplay; |
| 3914 | |
| 3915 | if (pipe < for_pipe) |
| 3916 | width_before_pipe += hdisplay; |
| 3917 | else if (pipe == for_pipe) |
| 3918 | pipe_width = hdisplay; |
| 3919 | } |
| 3920 | |
| 3921 | alloc->start = ddb_size * width_before_pipe / total_width; |
| 3922 | alloc->end = ddb_size * (width_before_pipe + pipe_width) / total_width; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3923 | } |
| 3924 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3925 | static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 3926 | int width, const struct drm_format_info *format, |
| 3927 | u64 modifier, unsigned int rotation, |
| 3928 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 3929 | int color_plane); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 3930 | 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] | 3931 | int level, |
| 3932 | const struct skl_wm_params *wp, |
| 3933 | const struct skl_wm_level *result_prev, |
| 3934 | struct skl_wm_level *result /* out */); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3935 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3936 | static unsigned int |
| 3937 | skl_cursor_allocation(const struct intel_crtc_state *crtc_state, |
| 3938 | int num_active) |
| 3939 | { |
| 3940 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 3941 | int level, max_level = ilk_wm_max_level(dev_priv); |
| 3942 | struct skl_wm_level wm = {}; |
| 3943 | int ret, min_ddb_alloc = 0; |
| 3944 | struct skl_wm_params wp; |
| 3945 | |
| 3946 | ret = skl_compute_wm_params(crtc_state, 256, |
| 3947 | drm_format_info(DRM_FORMAT_ARGB8888), |
| 3948 | DRM_FORMAT_MOD_LINEAR, |
| 3949 | DRM_MODE_ROTATE_0, |
| 3950 | crtc_state->pixel_rate, &wp, 0); |
| 3951 | WARN_ON(ret); |
| 3952 | |
| 3953 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | 6086e47 | 2019-03-21 19:51:28 +0200 | [diff] [blame] | 3954 | skl_compute_plane_wm(crtc_state, level, &wp, &wm, &wm); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3955 | if (wm.min_ddb_alloc == U16_MAX) |
| 3956 | break; |
| 3957 | |
| 3958 | min_ddb_alloc = wm.min_ddb_alloc; |
| 3959 | } |
| 3960 | |
| 3961 | return max(num_active == 1 ? 32 : 8, min_ddb_alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3962 | } |
| 3963 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3964 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 3965 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3966 | { |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3967 | |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 3968 | entry->start = reg & DDB_ENTRY_MASK; |
| 3969 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3970 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3971 | if (entry->end) |
| 3972 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3973 | } |
| 3974 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3975 | static void |
| 3976 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 3977 | const enum pipe pipe, |
| 3978 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3979 | struct skl_ddb_entry *ddb_y, |
| 3980 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3981 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3982 | u32 val, val2; |
| 3983 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3984 | |
| 3985 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 3986 | if (plane_id == PLANE_CURSOR) { |
| 3987 | val = I915_READ(CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3988 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3989 | return; |
| 3990 | } |
| 3991 | |
| 3992 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
| 3993 | |
| 3994 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3995 | if (val & PLANE_CTL_ENABLE) |
| 3996 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 3997 | val & PLANE_CTL_ORDER_RGBX, |
| 3998 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3999 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4000 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4001 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 4002 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4003 | } else { |
| 4004 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
Paulo Zanoni | 12a6c93 | 2018-07-31 17:46:14 -0700 | [diff] [blame] | 4005 | val2 = I915_READ(PLANE_NV12_BUF_CFG(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4006 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4007 | if (is_planar_yuv_format(fourcc)) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4008 | swap(val, val2); |
| 4009 | |
| 4010 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4011 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4012 | } |
| 4013 | } |
| 4014 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4015 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 4016 | struct skl_ddb_entry *ddb_y, |
| 4017 | struct skl_ddb_entry *ddb_uv) |
| 4018 | { |
| 4019 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4020 | enum intel_display_power_domain power_domain; |
| 4021 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4022 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4023 | enum plane_id plane_id; |
| 4024 | |
| 4025 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4026 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 4027 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4028 | return; |
| 4029 | |
| 4030 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4031 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4032 | plane_id, |
| 4033 | &ddb_y[plane_id], |
| 4034 | &ddb_uv[plane_id]); |
| 4035 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4036 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4037 | } |
| 4038 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 4039 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 4040 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4041 | { |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 4042 | ddb->enabled_slices = intel_enabled_dbuf_slices_num(dev_priv); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4045 | /* |
| 4046 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4047 | * The bspec defines downscale amount as: |
| 4048 | * |
| 4049 | * """ |
| 4050 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4051 | * Horizontal destination size] |
| 4052 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4053 | * Vertical destination size] |
| 4054 | * Total down scale amount = Horizontal down scale amount * |
| 4055 | * Vertical down scale amount |
| 4056 | * """ |
| 4057 | * |
| 4058 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4059 | * Caller should take care of dividing & rounding off the value. |
| 4060 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4061 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4062 | skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state, |
| 4063 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4064 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4065 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4066 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4067 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4068 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4069 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4070 | if (WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4071 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4072 | |
| 4073 | /* n.b., src is 16.16 fixed point, dst is whole integer */ |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4074 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4075 | /* |
| 4076 | * Cursors only support 0/180 degree rotation, |
| 4077 | * hence no need to account for rotation here. |
| 4078 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4079 | src_w = plane_state->base.src_w >> 16; |
| 4080 | src_h = plane_state->base.src_h >> 16; |
| 4081 | dst_w = plane_state->base.crtc_w; |
| 4082 | dst_h = plane_state->base.crtc_h; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4083 | } else { |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4084 | /* |
| 4085 | * Src coordinates are already rotated by 270 degrees for |
| 4086 | * the 90/270 degree plane rotation cases (to match the |
| 4087 | * GTT mapping), hence no need to account for rotation here. |
| 4088 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4089 | src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 4090 | src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 4091 | dst_w = drm_rect_width(&plane_state->base.dst); |
| 4092 | dst_h = drm_rect_height(&plane_state->base.dst); |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4093 | } |
| 4094 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4095 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4096 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4097 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4098 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4099 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4100 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4103 | static uint_fixed_16_16_t |
| 4104 | skl_pipe_downscale_amount(const struct intel_crtc_state *crtc_state) |
| 4105 | { |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4106 | uint_fixed_16_16_t pipe_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4107 | |
| 4108 | if (!crtc_state->base.enable) |
| 4109 | return pipe_downscale; |
| 4110 | |
| 4111 | if (crtc_state->pch_pfit.enabled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4112 | u32 src_w, src_h, dst_w, dst_h; |
| 4113 | u32 pfit_size = crtc_state->pch_pfit.size; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4114 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4115 | uint_fixed_16_16_t downscale_h, downscale_w; |
| 4116 | |
| 4117 | src_w = crtc_state->pipe_src_w; |
| 4118 | src_h = crtc_state->pipe_src_h; |
| 4119 | dst_w = pfit_size >> 16; |
| 4120 | dst_h = pfit_size & 0xffff; |
| 4121 | |
| 4122 | if (!dst_w || !dst_h) |
| 4123 | return pipe_downscale; |
| 4124 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4125 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4126 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4127 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4128 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4129 | |
| 4130 | pipe_downscale = mul_fixed16(downscale_w, downscale_h); |
| 4131 | } |
| 4132 | |
| 4133 | return pipe_downscale; |
| 4134 | } |
| 4135 | |
| 4136 | int skl_check_pipe_max_pixel_rate(struct intel_crtc *intel_crtc, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4137 | struct intel_crtc_state *crtc_state) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4138 | { |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 4139 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4140 | struct drm_atomic_state *state = crtc_state->base.state; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4141 | struct drm_plane *plane; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4142 | const struct drm_plane_state *drm_plane_state; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4143 | int crtc_clock, dotclk; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4144 | u32 pipe_max_pixel_rate; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4145 | uint_fixed_16_16_t pipe_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4146 | uint_fixed_16_16_t max_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4147 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4148 | if (!crtc_state->base.enable) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4149 | return 0; |
| 4150 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4151 | drm_atomic_crtc_state_for_each_plane_state(plane, drm_plane_state, &crtc_state->base) { |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4152 | uint_fixed_16_16_t plane_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4153 | 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] | 4154 | int bpp; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4155 | const struct intel_plane_state *plane_state = |
| 4156 | to_intel_plane_state(drm_plane_state); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4157 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4158 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4159 | continue; |
| 4160 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4161 | if (WARN_ON(!plane_state->base.fb)) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4162 | return -EINVAL; |
| 4163 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4164 | plane_downscale = skl_plane_downscale_amount(crtc_state, plane_state); |
| 4165 | bpp = plane_state->base.fb->format->cpp[0] * 8; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4166 | if (bpp == 64) |
| 4167 | plane_downscale = mul_fixed16(plane_downscale, |
| 4168 | fp_9_div_8); |
| 4169 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4170 | max_downscale = max_fixed16(plane_downscale, max_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4171 | } |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4172 | pipe_downscale = skl_pipe_downscale_amount(crtc_state); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4173 | |
| 4174 | pipe_downscale = mul_fixed16(pipe_downscale, max_downscale); |
| 4175 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4176 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4177 | dotclk = to_intel_atomic_state(state)->cdclk.logical.cdclk; |
| 4178 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 4179 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4180 | dotclk *= 2; |
| 4181 | |
| 4182 | pipe_max_pixel_rate = div_round_up_u32_fixed16(dotclk, pipe_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4183 | |
| 4184 | if (pipe_max_pixel_rate < crtc_clock) { |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4185 | DRM_DEBUG_KMS("Max supported pixel clock with scaling exceeded\n"); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4186 | return -EINVAL; |
| 4187 | } |
| 4188 | |
| 4189 | return 0; |
| 4190 | } |
| 4191 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4192 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4193 | skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state, |
| 4194 | const struct intel_plane_state *plane_state, |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4195 | const int plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4196 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4197 | struct intel_plane *intel_plane = to_intel_plane(plane_state->base.plane); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4198 | u32 data_rate; |
| 4199 | u32 width = 0, height = 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4200 | struct drm_framebuffer *fb; |
| 4201 | u32 format; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4202 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4203 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4204 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4205 | if (!plane_state->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4206 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4207 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4208 | fb = plane_state->base.fb; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4209 | format = fb->format->format; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4210 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4211 | if (intel_plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4212 | return 0; |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4213 | if (plane == 1 && !is_planar_yuv_format(format)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4214 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4215 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4216 | /* |
| 4217 | * Src coordinates are already rotated by 270 degrees for |
| 4218 | * the 90/270 degree plane rotation cases (to match the |
| 4219 | * GTT mapping), hence no need to account for rotation here. |
| 4220 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4221 | width = drm_rect_width(&plane_state->base.src) >> 16; |
| 4222 | height = drm_rect_height(&plane_state->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4223 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4224 | /* UV plane does 1/2 pixel sub-sampling */ |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4225 | if (plane == 1 && is_planar_yuv_format(format)) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4226 | width /= 2; |
| 4227 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4230 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4231 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4232 | down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4233 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4234 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4235 | |
| 4236 | rate *= fb->format->cpp[plane]; |
| 4237 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4240 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4241 | skl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4242 | u64 *plane_data_rate, |
| 4243 | u64 *uv_plane_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4244 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4245 | struct drm_atomic_state *state = crtc_state->base.state; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4246 | struct drm_plane *plane; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4247 | const struct drm_plane_state *drm_plane_state; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4248 | u64 total_data_rate = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4249 | |
| 4250 | if (WARN_ON(!state)) |
| 4251 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4252 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4253 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4254 | drm_atomic_crtc_state_for_each_plane_state(plane, drm_plane_state, &crtc_state->base) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4255 | enum plane_id plane_id = to_intel_plane(plane)->id; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4256 | const struct intel_plane_state *plane_state = |
| 4257 | to_intel_plane_state(drm_plane_state); |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4258 | u64 rate; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4259 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4260 | /* packed/y */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4261 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4262 | plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4263 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4264 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4265 | /* uv-plane */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4266 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4267 | uv_plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4268 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | return total_data_rate; |
| 4272 | } |
| 4273 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4274 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4275 | icl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4276 | u64 *plane_data_rate) |
| 4277 | { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4278 | struct drm_plane *plane; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4279 | const struct drm_plane_state *drm_plane_state; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4280 | u64 total_data_rate = 0; |
| 4281 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4282 | if (WARN_ON(!crtc_state->base.state)) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4283 | return 0; |
| 4284 | |
| 4285 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4286 | drm_atomic_crtc_state_for_each_plane_state(plane, drm_plane_state, &crtc_state->base) { |
| 4287 | const struct intel_plane_state *plane_state = |
| 4288 | to_intel_plane_state(drm_plane_state); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4289 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 4290 | u64 rate; |
| 4291 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4292 | if (!plane_state->linked_plane) { |
| 4293 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4294 | plane_data_rate[plane_id] = rate; |
| 4295 | total_data_rate += rate; |
| 4296 | } else { |
| 4297 | enum plane_id y_plane_id; |
| 4298 | |
| 4299 | /* |
| 4300 | * The slave plane might not iterate in |
| 4301 | * drm_atomic_crtc_state_for_each_plane_state(), |
| 4302 | * and needs the master plane state which may be |
| 4303 | * NULL if we try get_new_plane_state(), so we |
| 4304 | * always calculate from the master. |
| 4305 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4306 | if (plane_state->slave) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4307 | continue; |
| 4308 | |
| 4309 | /* Y plane rate is calculated on the slave */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4310 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
| 4311 | y_plane_id = plane_state->linked_plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4312 | plane_data_rate[y_plane_id] = rate; |
| 4313 | total_data_rate += rate; |
| 4314 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4315 | rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4316 | plane_data_rate[plane_id] = rate; |
| 4317 | total_data_rate += rate; |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | return total_data_rate; |
| 4322 | } |
| 4323 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4324 | static int |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4325 | skl_allocate_pipe_ddb(struct intel_crtc_state *crtc_state, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4326 | struct skl_ddb_allocation *ddb /* out */) |
| 4327 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4328 | struct drm_atomic_state *state = crtc_state->base.state; |
| 4329 | struct drm_crtc *crtc = crtc_state->base.crtc; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4330 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4331 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4332 | struct skl_ddb_entry *alloc = &crtc_state->wm.skl.ddb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4333 | u16 alloc_size, start = 0; |
| 4334 | u16 total[I915_MAX_PLANES] = {}; |
| 4335 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4336 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4337 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4338 | int num_active; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4339 | u64 plane_data_rate[I915_MAX_PLANES] = {}; |
| 4340 | u64 uv_plane_data_rate[I915_MAX_PLANES] = {}; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4341 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4342 | int level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4343 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4344 | /* Clear the partitioning for disabled planes. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4345 | memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y)); |
| 4346 | 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] | 4347 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4348 | if (WARN_ON(!state)) |
| 4349 | return 0; |
| 4350 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4351 | if (!crtc_state->base.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4352 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4353 | return 0; |
| 4354 | } |
| 4355 | |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4356 | if (INTEL_GEN(dev_priv) >= 11) |
| 4357 | total_data_rate = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4358 | icl_get_total_relative_data_rate(crtc_state, |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4359 | plane_data_rate); |
| 4360 | else |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4361 | total_data_rate = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4362 | skl_get_total_relative_data_rate(crtc_state, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4363 | plane_data_rate, |
| 4364 | uv_plane_data_rate); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4365 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4366 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4367 | 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] | 4368 | ddb, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4369 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 4370 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4371 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4372 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4373 | /* Allocate fixed number of blocks for cursor. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4374 | total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4375 | alloc_size -= total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4376 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4377 | alloc->end - total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4378 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4379 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4380 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4381 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4382 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4383 | /* |
| 4384 | * Find the highest watermark level for which we can satisfy the block |
| 4385 | * requirement of active planes. |
| 4386 | */ |
| 4387 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 4388 | blocks = 0; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4389 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4390 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4391 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 4392 | |
| 4393 | if (plane_id == PLANE_CURSOR) { |
| 4394 | if (WARN_ON(wm->wm[level].min_ddb_alloc > |
| 4395 | total[PLANE_CURSOR])) { |
| 4396 | blocks = U32_MAX; |
| 4397 | break; |
| 4398 | } |
| 4399 | continue; |
| 4400 | } |
| 4401 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4402 | blocks += wm->wm[level].min_ddb_alloc; |
| 4403 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4404 | } |
| 4405 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame] | 4406 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4407 | alloc_size -= blocks; |
| 4408 | break; |
| 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | if (level < 0) { |
| 4413 | DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); |
| 4414 | DRM_DEBUG_KMS("minimum required %d/%d\n", blocks, |
| 4415 | alloc_size); |
| 4416 | return -EINVAL; |
| 4417 | } |
| 4418 | |
| 4419 | /* |
| 4420 | * Grant each plane the blocks it requires at the highest achievable |
| 4421 | * watermark level, plus an extra share of the leftover blocks |
| 4422 | * proportional to its relative data rate. |
| 4423 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4424 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4425 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4426 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4427 | u64 rate; |
| 4428 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4429 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4430 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4431 | continue; |
| 4432 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4433 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4434 | * We've accounted for all active planes; remaining planes are |
| 4435 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4436 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4437 | if (total_data_rate == 0) |
| 4438 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4439 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4440 | rate = 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 | total[plane_id] = wm->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; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4447 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4448 | if (total_data_rate == 0) |
| 4449 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4450 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4451 | rate = uv_plane_data_rate[plane_id]; |
| 4452 | extra = min_t(u16, alloc_size, |
| 4453 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4454 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4455 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4456 | alloc_size -= extra; |
| 4457 | total_data_rate -= rate; |
| 4458 | } |
| 4459 | WARN_ON(alloc_size != 0 || total_data_rate != 0); |
| 4460 | |
| 4461 | /* Set the actual DDB start/end points for each plane */ |
| 4462 | start = alloc->start; |
| 4463 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4464 | struct skl_ddb_entry *plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4465 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4466 | struct skl_ddb_entry *uv_plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4467 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4468 | |
| 4469 | if (plane_id == PLANE_CURSOR) |
| 4470 | continue; |
| 4471 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4472 | /* Gen11+ uses a separate plane for UV watermarks */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4473 | WARN_ON(INTEL_GEN(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4474 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4475 | /* Leave disabled planes at (0,0) */ |
| 4476 | if (total[plane_id]) { |
| 4477 | plane_alloc->start = start; |
| 4478 | start += total[plane_id]; |
| 4479 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4480 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4481 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4482 | if (uv_total[plane_id]) { |
| 4483 | uv_plane_alloc->start = start; |
| 4484 | start += uv_total[plane_id]; |
| 4485 | uv_plane_alloc->end = start; |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | /* |
| 4490 | * When we calculated watermark values we didn't know how high |
| 4491 | * of a level we'd actually be able to hit, so we just marked |
| 4492 | * all levels as "enabled." Go back now and disable the ones |
| 4493 | * that aren't actually possible. |
| 4494 | */ |
| 4495 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
| 4496 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4497 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4498 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | a301cb0 | 2019-03-12 22:58:41 +0200 | [diff] [blame] | 4499 | |
| 4500 | /* |
| 4501 | * We only disable the watermarks for each plane if |
| 4502 | * they exceed the ddb allocation of said plane. This |
| 4503 | * is done so that we don't end up touching cursor |
| 4504 | * watermarks needlessly when some other plane reduces |
| 4505 | * our max possible watermark level. |
| 4506 | * |
| 4507 | * Bspec has this to say about the PLANE_WM enable bit: |
| 4508 | * "All the watermarks at this level for all enabled |
| 4509 | * planes must be enabled before the level will be used." |
| 4510 | * So this is actually safe to do. |
| 4511 | */ |
| 4512 | if (wm->wm[level].min_ddb_alloc > total[plane_id] || |
| 4513 | wm->uv_wm[level].min_ddb_alloc > uv_total[plane_id]) |
| 4514 | memset(&wm->wm[level], 0, sizeof(wm->wm[level])); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4515 | |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4516 | /* |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 4517 | * Wa_1408961008:icl, ehl |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4518 | * Underruns with WM1+ disabled |
| 4519 | */ |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 4520 | if (IS_GEN(dev_priv, 11) && |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4521 | level == 1 && wm->wm[0].plane_en) { |
| 4522 | 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] | 4523 | wm->wm[level].plane_res_l = wm->wm[0].plane_res_l; |
| 4524 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4525 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | /* |
| 4530 | * Go back and disable the transition watermark if it turns out we |
| 4531 | * don't have enough DDB blocks for it. |
| 4532 | */ |
| 4533 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4534 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4535 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4536 | |
Ville Syrjälä | b19c9bc | 2018-12-21 19:14:31 +0200 | [diff] [blame] | 4537 | if (wm->trans_wm.plane_res_b >= total[plane_id]) |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4538 | memset(&wm->trans_wm, 0, sizeof(wm->trans_wm)); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4539 | } |
| 4540 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4541 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4542 | } |
| 4543 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4544 | /* |
| 4545 | * 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] | 4546 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4547 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 4548 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 4549 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4550 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4551 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 4552 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4553 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4554 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4555 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4556 | |
| 4557 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4558 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4559 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4560 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4561 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4562 | |
| 4563 | if (INTEL_GEN(dev_priv) >= 10) |
| 4564 | ret = add_fixed16_u32(ret, 1); |
| 4565 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4566 | return ret; |
| 4567 | } |
| 4568 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4569 | static uint_fixed_16_16_t |
| 4570 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 4571 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4572 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4573 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4574 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4575 | |
| 4576 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4577 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4578 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4579 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4580 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 4581 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4582 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4583 | return ret; |
| 4584 | } |
| 4585 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4586 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4587 | intel_get_linetime_us(const struct intel_crtc_state *crtc_state) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4588 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4589 | u32 pixel_rate; |
| 4590 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4591 | uint_fixed_16_16_t linetime_us; |
| 4592 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4593 | if (!crtc_state->base.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4594 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4595 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4596 | pixel_rate = crtc_state->pixel_rate; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4597 | |
| 4598 | if (WARN_ON(pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4599 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4600 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4601 | crtc_htotal = crtc_state->base.adjusted_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4602 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4603 | |
| 4604 | return linetime_us; |
| 4605 | } |
| 4606 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4607 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4608 | skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *crtc_state, |
| 4609 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4610 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4611 | u64 adjusted_pixel_rate; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4612 | uint_fixed_16_16_t downscale_amount; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4613 | |
| 4614 | /* Shouldn't reach here on disabled planes... */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4615 | if (WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4616 | return 0; |
| 4617 | |
| 4618 | /* |
| 4619 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 4620 | * with additional adjustments for plane-specific scaling. |
| 4621 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4622 | adjusted_pixel_rate = crtc_state->pixel_rate; |
| 4623 | downscale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4624 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4625 | return mul_round_up_u32_fixed16(adjusted_pixel_rate, |
| 4626 | downscale_amount); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4629 | static int |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4630 | skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 4631 | int width, const struct drm_format_info *format, |
| 4632 | u64 modifier, unsigned int rotation, |
| 4633 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 4634 | int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4635 | { |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4636 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4637 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4638 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4639 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4640 | /* only planar format has two planes */ |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4641 | if (color_plane == 1 && !is_planar_yuv_format(format->format)) { |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4642 | DRM_DEBUG_KMS("Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4643 | return -EINVAL; |
| 4644 | } |
| 4645 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4646 | wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED || |
| 4647 | modifier == I915_FORMAT_MOD_Yf_TILED || |
| 4648 | modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4649 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4650 | wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED; |
| 4651 | wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4652 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4653 | wp->is_planar = is_planar_yuv_format(format->format); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4654 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4655 | wp->width = width; |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 4656 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4657 | wp->width /= 2; |
| 4658 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4659 | wp->cpp = format->cpp[color_plane]; |
| 4660 | wp->plane_pixel_rate = plane_pixel_rate; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4661 | |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4662 | if (INTEL_GEN(dev_priv) >= 11 && |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4663 | modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4664 | wp->dbuf_block_size = 256; |
| 4665 | else |
| 4666 | wp->dbuf_block_size = 512; |
| 4667 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4668 | if (drm_rotation_90_or_270(rotation)) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4669 | switch (wp->cpp) { |
| 4670 | case 1: |
| 4671 | wp->y_min_scanlines = 16; |
| 4672 | break; |
| 4673 | case 2: |
| 4674 | wp->y_min_scanlines = 8; |
| 4675 | break; |
| 4676 | case 4: |
| 4677 | wp->y_min_scanlines = 4; |
| 4678 | break; |
| 4679 | default: |
| 4680 | MISSING_CASE(wp->cpp); |
| 4681 | return -EINVAL; |
| 4682 | } |
| 4683 | } else { |
| 4684 | wp->y_min_scanlines = 4; |
| 4685 | } |
| 4686 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4687 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4688 | wp->y_min_scanlines *= 2; |
| 4689 | |
| 4690 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 4691 | if (wp->y_tiled) { |
| 4692 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4693 | wp->y_min_scanlines, |
| 4694 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4695 | |
| 4696 | if (INTEL_GEN(dev_priv) >= 10) |
| 4697 | interm_pbpl++; |
| 4698 | |
| 4699 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 4700 | wp->y_min_scanlines); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4701 | } else if (wp->x_tiled && IS_GEN(dev_priv, 9)) { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4702 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4703 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4704 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4705 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4706 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4707 | wp->dbuf_block_size) + 1; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4708 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4709 | } |
| 4710 | |
| 4711 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 4712 | wp->plane_blocks_per_line); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4713 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4714 | wp->linetime_us = fixed16_to_u32_round_up( |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4715 | intel_get_linetime_us(crtc_state)); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4716 | |
| 4717 | return 0; |
| 4718 | } |
| 4719 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4720 | static int |
| 4721 | skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state, |
| 4722 | const struct intel_plane_state *plane_state, |
| 4723 | struct skl_wm_params *wp, int color_plane) |
| 4724 | { |
| 4725 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 4726 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 4727 | int width; |
| 4728 | |
| 4729 | if (plane->id == PLANE_CURSOR) { |
| 4730 | width = plane_state->base.crtc_w; |
| 4731 | } else { |
| 4732 | /* |
| 4733 | * Src coordinates are already rotated by 270 degrees for |
| 4734 | * the 90/270 degree plane rotation cases (to match the |
| 4735 | * GTT mapping), hence no need to account for rotation here. |
| 4736 | */ |
| 4737 | width = drm_rect_width(&plane_state->base.src) >> 16; |
| 4738 | } |
| 4739 | |
| 4740 | return skl_compute_wm_params(crtc_state, width, |
| 4741 | fb->format, fb->modifier, |
| 4742 | plane_state->base.rotation, |
| 4743 | skl_adjusted_plane_pixel_rate(crtc_state, plane_state), |
| 4744 | wp, color_plane); |
| 4745 | } |
| 4746 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4747 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 4748 | { |
| 4749 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 4750 | return true; |
| 4751 | |
| 4752 | /* The number of lines are ignored for the level 0 watermark. */ |
| 4753 | return level > 0; |
| 4754 | } |
| 4755 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4756 | 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] | 4757 | int level, |
| 4758 | const struct skl_wm_params *wp, |
| 4759 | const struct skl_wm_level *result_prev, |
| 4760 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4761 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4762 | 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] | 4763 | u32 latency = dev_priv->wm.skl_latency[level]; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4764 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4765 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4766 | u32 res_blocks, res_lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 4767 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4768 | if (latency == 0) { |
| 4769 | /* reject it */ |
| 4770 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4771 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4772 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4773 | |
Ville Syrjälä | 25312ef | 2019-05-03 20:38:05 +0300 | [diff] [blame] | 4774 | /* |
| 4775 | * WaIncreaseLatencyIPCEnabled: kbl,cfl |
| 4776 | * Display WA #1141: kbl,cfl |
| 4777 | */ |
Ville Syrjälä | 5a7d202 | 2019-05-03 20:38:06 +0300 | [diff] [blame] | 4778 | if ((IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) || |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4779 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 4780 | latency += 4; |
| 4781 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4782 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4783 | latency += 15; |
| 4784 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4785 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4786 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4787 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4788 | crtc_state->base.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4789 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4790 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4791 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4792 | if (wp->y_tiled) { |
| 4793 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4794 | } else { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4795 | if ((wp->cpp * crtc_state->base.adjusted_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4796 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4797 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 4798 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4799 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4800 | if (IS_GEN(dev_priv, 9) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4801 | !IS_GEMINILAKE(dev_priv)) |
| 4802 | selected_result = min_fixed16(method1, method2); |
| 4803 | else |
| 4804 | selected_result = method2; |
| 4805 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4806 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4807 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4808 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4809 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4810 | res_blocks = fixed16_to_u32_round_up(selected_result) + 1; |
Kumar, Mahesh | d273ecc | 2017-05-17 17:28:22 +0530 | [diff] [blame] | 4811 | res_lines = div_round_up_fixed16(selected_result, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4812 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4813 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4814 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) { |
| 4815 | /* Display WA #1125: skl,bxt,kbl */ |
| 4816 | if (level == 0 && wp->rc_surface) |
| 4817 | res_blocks += |
| 4818 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 4819 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4820 | /* Display WA #1126: skl,bxt,kbl */ |
| 4821 | if (level >= 1 && level <= 7) { |
| 4822 | if (wp->y_tiled) { |
| 4823 | res_blocks += |
| 4824 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 4825 | res_lines += wp->y_min_scanlines; |
| 4826 | } else { |
| 4827 | res_blocks++; |
| 4828 | } |
| 4829 | |
| 4830 | /* |
| 4831 | * Make sure result blocks for higher latency levels are |
| 4832 | * atleast as high as level below the current level. |
| 4833 | * Assumption in DDB algorithm optimization for special |
| 4834 | * cases. Also covers Display WA #1125 for RC. |
| 4835 | */ |
| 4836 | if (result_prev->plane_res_b > res_blocks) |
| 4837 | res_blocks = result_prev->plane_res_b; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4838 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4839 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4840 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4841 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4842 | if (wp->y_tiled) { |
| 4843 | int extra_lines; |
| 4844 | |
| 4845 | if (res_lines % wp->y_min_scanlines == 0) |
| 4846 | extra_lines = wp->y_min_scanlines; |
| 4847 | else |
| 4848 | extra_lines = wp->y_min_scanlines * 2 - |
| 4849 | res_lines % wp->y_min_scanlines; |
| 4850 | |
| 4851 | min_ddb_alloc = mul_round_up_u32_fixed16(res_lines + extra_lines, |
| 4852 | wp->plane_blocks_per_line); |
| 4853 | } else { |
| 4854 | min_ddb_alloc = res_blocks + |
| 4855 | DIV_ROUND_UP(res_blocks, 10); |
| 4856 | } |
| 4857 | } |
| 4858 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4859 | if (!skl_wm_has_lines(dev_priv, level)) |
| 4860 | res_lines = 0; |
| 4861 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4862 | if (res_lines > 31) { |
| 4863 | /* reject it */ |
| 4864 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4865 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4866 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4867 | |
| 4868 | /* |
| 4869 | * If res_lines is valid, assume we can use this watermark level |
| 4870 | * for now. We'll come back and disable it after we calculate the |
| 4871 | * DDB allocation if it turns out we don't actually have enough |
| 4872 | * blocks to satisfy it. |
| 4873 | */ |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4874 | result->plane_res_b = res_blocks; |
| 4875 | result->plane_res_l = res_lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4876 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
| 4877 | result->min_ddb_alloc = max(min_ddb_alloc, res_blocks) + 1; |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4878 | result->plane_en = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4879 | } |
| 4880 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4881 | static void |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4882 | skl_compute_wm_levels(const struct intel_crtc_state *crtc_state, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4883 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4884 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4885 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4886 | 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] | 4887 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4888 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4889 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4890 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4891 | struct skl_wm_level *result = &levels[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4892 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4893 | skl_compute_plane_wm(crtc_state, level, wm_params, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4894 | result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4895 | |
| 4896 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4897 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4900 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4901 | skl_compute_linetime_wm(const struct intel_crtc_state *crtc_state) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4902 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4903 | struct drm_atomic_state *state = crtc_state->base.state; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4904 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4905 | uint_fixed_16_16_t linetime_us; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4906 | u32 linetime_wm; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4907 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4908 | linetime_us = intel_get_linetime_us(crtc_state); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4909 | 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] | 4910 | |
Ville Syrjälä | 717671c | 2018-12-21 19:14:36 +0200 | [diff] [blame] | 4911 | /* Display WA #1135: BXT:ALL GLK:ALL */ |
| 4912 | if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled) |
Kumar, Mahesh | 446e850 | 2017-08-17 19:15:25 +0530 | [diff] [blame] | 4913 | linetime_wm /= 2; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4914 | |
| 4915 | return linetime_wm; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4918 | 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] | 4919 | const struct skl_wm_params *wp, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4920 | struct skl_plane_wm *wm) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4921 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 4922 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4923 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4924 | u16 trans_min, trans_y_tile_min; |
| 4925 | const u16 trans_amount = 10; /* This is configurable amount */ |
| 4926 | u16 wm0_sel_res_b, trans_offset_b, res_blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4927 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4928 | /* Transition WM are not recommended by HW team for GEN9 */ |
| 4929 | if (INTEL_GEN(dev_priv) <= 9) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4930 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4931 | |
| 4932 | /* Transition WM don't make any sense if ipc is disabled */ |
| 4933 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4934 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4935 | |
Paulo Zanoni | 91961a8 | 2018-10-04 16:15:56 -0700 | [diff] [blame] | 4936 | trans_min = 14; |
| 4937 | if (INTEL_GEN(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4938 | trans_min = 4; |
| 4939 | |
| 4940 | trans_offset_b = trans_min + trans_amount; |
| 4941 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4942 | /* |
| 4943 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 4944 | * not Result Blocks (the integer value). Pay attention to the capital |
| 4945 | * letters. The value wm_l0->plane_res_b is actually Result Blocks, but |
| 4946 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 4947 | * and since we later will have to get the ceiling of the sum in the |
| 4948 | * transition watermarks calculation, we can just pretend Selected |
| 4949 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 4950 | * current platforms. |
| 4951 | */ |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 4952 | wm0_sel_res_b = wm->wm[0].plane_res_b - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4953 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4954 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4955 | trans_y_tile_min = |
| 4956 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4957 | res_blocks = max(wm0_sel_res_b, trans_y_tile_min) + |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4958 | trans_offset_b; |
| 4959 | } else { |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4960 | res_blocks = wm0_sel_res_b + trans_offset_b; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4961 | |
| 4962 | /* WA BUG:1938466 add one block for non y-tile planes */ |
| 4963 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_A0)) |
| 4964 | res_blocks += 1; |
| 4965 | |
| 4966 | } |
| 4967 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4968 | /* |
| 4969 | * Just assume we can enable the transition watermark. After |
| 4970 | * computing the DDB we'll come back and disable it if that |
| 4971 | * assumption turns out to be false. |
| 4972 | */ |
| 4973 | wm->trans_wm.plane_res_b = res_blocks + 1; |
| 4974 | wm->trans_wm.plane_en = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4975 | } |
| 4976 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4977 | 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] | 4978 | const struct intel_plane_state *plane_state, |
| 4979 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4980 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4981 | 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] | 4982 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4983 | int ret; |
| 4984 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4985 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4986 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4987 | if (ret) |
| 4988 | return ret; |
| 4989 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4990 | skl_compute_wm_levels(crtc_state, &wm_params, wm->wm); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4991 | skl_compute_transition_wm(crtc_state, &wm_params, wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4992 | |
| 4993 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4994 | } |
| 4995 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4996 | 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] | 4997 | const struct intel_plane_state *plane_state, |
| 4998 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4999 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5000 | struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5001 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5002 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5003 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5004 | wm->is_planar = true; |
| 5005 | |
| 5006 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5007 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5008 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5009 | if (ret) |
| 5010 | return ret; |
| 5011 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5012 | skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5013 | |
| 5014 | return 0; |
| 5015 | } |
| 5016 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5017 | 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] | 5018 | const struct intel_plane_state *plane_state) |
| 5019 | { |
| 5020 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 5021 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 5022 | enum plane_id plane_id = plane->id; |
| 5023 | int ret; |
| 5024 | |
| 5025 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 5026 | return 0; |
| 5027 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5028 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5029 | plane_id, 0); |
| 5030 | if (ret) |
| 5031 | return ret; |
| 5032 | |
| 5033 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5034 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5035 | plane_id); |
| 5036 | if (ret) |
| 5037 | return ret; |
| 5038 | } |
| 5039 | |
| 5040 | return 0; |
| 5041 | } |
| 5042 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5043 | 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] | 5044 | const struct intel_plane_state *plane_state) |
| 5045 | { |
| 5046 | enum plane_id plane_id = to_intel_plane(plane_state->base.plane)->id; |
| 5047 | int ret; |
| 5048 | |
| 5049 | /* Watermarks calculated in master */ |
| 5050 | if (plane_state->slave) |
| 5051 | return 0; |
| 5052 | |
| 5053 | if (plane_state->linked_plane) { |
| 5054 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 5055 | enum plane_id y_plane_id = plane_state->linked_plane->id; |
| 5056 | |
| 5057 | WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state)); |
| 5058 | WARN_ON(!fb->format->is_yuv || |
| 5059 | fb->format->num_planes == 1); |
| 5060 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5061 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5062 | y_plane_id, 0); |
| 5063 | if (ret) |
| 5064 | return ret; |
| 5065 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5066 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5067 | plane_id, 1); |
| 5068 | if (ret) |
| 5069 | return ret; |
| 5070 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5071 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5072 | plane_id, 0); |
| 5073 | if (ret) |
| 5074 | return ret; |
| 5075 | } |
| 5076 | |
| 5077 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5078 | } |
| 5079 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5080 | static int skl_build_pipe_wm(struct intel_crtc_state *crtc_state) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5081 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5082 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 5083 | struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5084 | struct drm_plane *plane; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5085 | const struct drm_plane_state *drm_plane_state; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5086 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5087 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 5088 | /* |
| 5089 | * We'll only calculate watermarks for planes that are actually |
| 5090 | * enabled, so make sure all other planes are set as disabled. |
| 5091 | */ |
| 5092 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 5093 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5094 | drm_atomic_crtc_state_for_each_plane_state(plane, drm_plane_state, |
| 5095 | &crtc_state->base) { |
| 5096 | const struct intel_plane_state *plane_state = |
| 5097 | to_intel_plane_state(drm_plane_state); |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5098 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5099 | if (INTEL_GEN(dev_priv) >= 11) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5100 | ret = icl_build_plane_wm(crtc_state, plane_state); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5101 | else |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5102 | ret = skl_build_plane_wm(crtc_state, plane_state); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5103 | if (ret) |
| 5104 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5105 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5106 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5107 | pipe_wm->linetime = skl_compute_linetime_wm(crtc_state); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5108 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5109 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5110 | } |
| 5111 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5112 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 5113 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5114 | const struct skl_ddb_entry *entry) |
| 5115 | { |
| 5116 | if (entry->end) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5117 | I915_WRITE_FW(reg, (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5118 | else |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5119 | I915_WRITE_FW(reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5120 | } |
| 5121 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5122 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5123 | i915_reg_t reg, |
| 5124 | const struct skl_wm_level *level) |
| 5125 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5126 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5127 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5128 | if (level->plane_en) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5129 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5130 | if (level->ignore_lines) |
| 5131 | val |= PLANE_WM_IGNORE_LINES; |
| 5132 | val |= level->plane_res_b; |
| 5133 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5134 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5135 | I915_WRITE_FW(reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5136 | } |
| 5137 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5138 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5139 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5140 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5141 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5142 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5143 | enum plane_id plane_id = plane->id; |
| 5144 | enum pipe pipe = plane->pipe; |
| 5145 | const struct skl_plane_wm *wm = |
| 5146 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5147 | const struct skl_ddb_entry *ddb_y = |
| 5148 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5149 | const struct skl_ddb_entry *ddb_uv = |
| 5150 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5151 | |
| 5152 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5153 | 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] | 5154 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5155 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5156 | 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] | 5157 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5158 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5159 | if (INTEL_GEN(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5160 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5161 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5162 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5163 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5164 | |
| 5165 | if (wm->is_planar) |
| 5166 | swap(ddb_y, ddb_uv); |
| 5167 | |
| 5168 | skl_ddb_entry_write(dev_priv, |
| 5169 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5170 | skl_ddb_entry_write(dev_priv, |
| 5171 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5172 | } |
| 5173 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5174 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5175 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5176 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5177 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5178 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5179 | enum plane_id plane_id = plane->id; |
| 5180 | enum pipe pipe = plane->pipe; |
| 5181 | const struct skl_plane_wm *wm = |
| 5182 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5183 | const struct skl_ddb_entry *ddb = |
| 5184 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5185 | |
| 5186 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5187 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 5188 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5189 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5190 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5191 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5192 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5193 | } |
| 5194 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5195 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5196 | const struct skl_wm_level *l2) |
| 5197 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5198 | return l1->plane_en == l2->plane_en && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5199 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5200 | l1->plane_res_l == l2->plane_res_l && |
| 5201 | l1->plane_res_b == l2->plane_res_b; |
| 5202 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5203 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5204 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5205 | const struct skl_plane_wm *wm1, |
| 5206 | const struct skl_plane_wm *wm2) |
| 5207 | { |
| 5208 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5209 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5210 | for (level = 0; level <= max_level; level++) { |
| 5211 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level]) || |
| 5212 | !skl_wm_level_equals(&wm1->uv_wm[level], &wm2->uv_wm[level])) |
| 5213 | return false; |
| 5214 | } |
| 5215 | |
| 5216 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5217 | } |
| 5218 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5219 | static bool skl_pipe_wm_equals(struct intel_crtc *crtc, |
| 5220 | const struct skl_pipe_wm *wm1, |
| 5221 | const struct skl_pipe_wm *wm2) |
| 5222 | { |
| 5223 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5224 | enum plane_id plane_id; |
| 5225 | |
| 5226 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5227 | if (!skl_plane_wm_equals(dev_priv, |
| 5228 | &wm1->planes[plane_id], |
| 5229 | &wm2->planes[plane_id])) |
| 5230 | return false; |
| 5231 | } |
| 5232 | |
| 5233 | return wm1->linetime == wm2->linetime; |
| 5234 | } |
| 5235 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5236 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 5237 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5238 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5239 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5240 | } |
| 5241 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5242 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 5243 | const struct skl_ddb_entry *entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5244 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5245 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5246 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5247 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5248 | for (i = 0; i < num_entries; i++) { |
| 5249 | if (i != ignore_idx && |
| 5250 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5251 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 5252 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5253 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5254 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5255 | } |
| 5256 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5257 | static u32 |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5258 | pipes_modified(struct intel_atomic_state *state) |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5259 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5260 | struct intel_crtc *crtc; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5261 | struct intel_crtc_state *crtc_state; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5262 | u32 i, ret = 0; |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5263 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5264 | for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5265 | ret |= drm_crtc_mask(&crtc->base); |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5266 | |
| 5267 | return ret; |
| 5268 | } |
| 5269 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 5270 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5271 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 5272 | struct intel_crtc_state *new_crtc_state) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5273 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5274 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->base.state); |
| 5275 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5276 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5277 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5278 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5279 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5280 | struct intel_plane_state *plane_state; |
| 5281 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5282 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5283 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 5284 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 5285 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 5286 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5287 | continue; |
| 5288 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5289 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5290 | if (IS_ERR(plane_state)) |
| 5291 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 5292 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5293 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | return 0; |
| 5297 | } |
| 5298 | |
| 5299 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5300 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5301 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5302 | const struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5303 | struct skl_ddb_allocation *ddb = &state->wm_results.ddb; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5304 | struct intel_crtc_state *old_crtc_state; |
| 5305 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5306 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5307 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5308 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 5309 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 5310 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5311 | 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] | 5312 | new_crtc_state, i) { |
| 5313 | ret = skl_allocate_pipe_ddb(new_crtc_state, ddb); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5314 | if (ret) |
| 5315 | return ret; |
| 5316 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5317 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 5318 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5319 | if (ret) |
| 5320 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | return 0; |
| 5324 | } |
| 5325 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5326 | static char enast(bool enable) |
| 5327 | { |
| 5328 | return enable ? '*' : ' '; |
| 5329 | } |
| 5330 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 5331 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5332 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5333 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5334 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5335 | const struct intel_crtc_state *old_crtc_state; |
| 5336 | const struct intel_crtc_state *new_crtc_state; |
| 5337 | struct intel_plane *plane; |
| 5338 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5339 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5340 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5341 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 5342 | return; |
| 5343 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5344 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 5345 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5346 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 5347 | |
| 5348 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 5349 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 5350 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5351 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5352 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5353 | const struct skl_ddb_entry *old, *new; |
| 5354 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5355 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5356 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5357 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5358 | if (skl_ddb_entry_equal(old, new)) |
| 5359 | continue; |
| 5360 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5361 | 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] | 5362 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5363 | old->start, old->end, new->start, new->end, |
| 5364 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
| 5365 | } |
| 5366 | |
| 5367 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5368 | enum plane_id plane_id = plane->id; |
| 5369 | const struct skl_plane_wm *old_wm, *new_wm; |
| 5370 | |
| 5371 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 5372 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 5373 | |
| 5374 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 5375 | continue; |
| 5376 | |
| 5377 | DRM_DEBUG_KMS("[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm" |
| 5378 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm\n", |
| 5379 | plane->base.base.id, plane->base.name, |
| 5380 | enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en), |
| 5381 | enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en), |
| 5382 | enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en), |
| 5383 | enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en), |
| 5384 | enast(old_wm->trans_wm.plane_en), |
| 5385 | enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en), |
| 5386 | enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en), |
| 5387 | enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en), |
| 5388 | enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en), |
| 5389 | enast(new_wm->trans_wm.plane_en)); |
| 5390 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5391 | 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" |
| 5392 | " -> %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] | 5393 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5394 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l, |
| 5395 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l, |
| 5396 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l, |
| 5397 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l, |
| 5398 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l, |
| 5399 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l, |
| 5400 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l, |
| 5401 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l, |
| 5402 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l, |
| 5403 | |
| 5404 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l, |
| 5405 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l, |
| 5406 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l, |
| 5407 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l, |
| 5408 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l, |
| 5409 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l, |
| 5410 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l, |
| 5411 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l, |
| 5412 | 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] | 5413 | |
| 5414 | DRM_DEBUG_KMS("[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5415 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5416 | plane->base.base.id, plane->base.name, |
| 5417 | old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b, |
| 5418 | old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b, |
| 5419 | old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b, |
| 5420 | old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b, |
| 5421 | old_wm->trans_wm.plane_res_b, |
| 5422 | new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b, |
| 5423 | new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b, |
| 5424 | new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b, |
| 5425 | new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b, |
| 5426 | new_wm->trans_wm.plane_res_b); |
| 5427 | |
| 5428 | DRM_DEBUG_KMS("[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5429 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5430 | plane->base.base.id, plane->base.name, |
| 5431 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 5432 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 5433 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 5434 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 5435 | old_wm->trans_wm.min_ddb_alloc, |
| 5436 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 5437 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 5438 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 5439 | new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc, |
| 5440 | new_wm->trans_wm.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5441 | } |
| 5442 | } |
| 5443 | } |
| 5444 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5445 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5446 | skl_ddb_add_affected_pipes(struct intel_atomic_state *state, bool *changed) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5447 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5448 | struct drm_device *dev = state->base.dev; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5449 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5450 | struct intel_crtc *crtc; |
| 5451 | struct intel_crtc_state *crtc_state; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5452 | u32 realloc_pipes = pipes_modified(state); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5453 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5454 | |
| 5455 | /* |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5456 | * When we distrust bios wm we always need to recompute to set the |
| 5457 | * expected DDB allocations for each CRTC. |
| 5458 | */ |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5459 | if (dev_priv->wm.distrust_bios_wm) |
| 5460 | (*changed) = true; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5461 | |
| 5462 | /* |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5463 | * If this transaction isn't actually touching any CRTC's, don't |
| 5464 | * bother with watermark calculation. Note that if we pass this |
| 5465 | * test, we're guaranteed to hold at least one CRTC state mutex, |
| 5466 | * which means we can safely use values like dev_priv->active_crtcs |
| 5467 | * since any racing commits that want to update them would need to |
| 5468 | * hold _all_ CRTC state mutexes. |
| 5469 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5470 | for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5471 | (*changed) = true; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5472 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5473 | if (!*changed) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5474 | return 0; |
| 5475 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5476 | /* |
| 5477 | * If this is our first atomic update following hardware readout, |
| 5478 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 5479 | * pretend that all pipes switched active status so that we'll |
| 5480 | * ensure a full DDB recompute. |
| 5481 | */ |
| 5482 | if (dev_priv->wm.distrust_bios_wm) { |
| 5483 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5484 | state->base.acquire_ctx); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5485 | if (ret) |
| 5486 | return ret; |
| 5487 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5488 | state->active_pipe_changes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5489 | |
| 5490 | /* |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5491 | * We usually only initialize state->active_crtcs if we |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5492 | * we're doing a modeset; make sure this field is always |
| 5493 | * initialized during the sanitization process that happens |
| 5494 | * on the first commit too. |
| 5495 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5496 | if (!state->modeset) |
| 5497 | state->active_crtcs = dev_priv->active_crtcs; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | /* |
| 5501 | * If the modeset changes which CRTC's are active, we need to |
| 5502 | * recompute the DDB allocation for *all* active pipes, even |
| 5503 | * those that weren't otherwise being modified in any way by this |
| 5504 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 5505 | * when new active CRTC's are added, it's possible for a pipe that |
| 5506 | * we were already using and aren't changing at all here to suddenly |
| 5507 | * become invalid if its DDB needs exceeds its new allocation. |
| 5508 | * |
| 5509 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 5510 | * any other display updates race with this transaction, so we need |
| 5511 | * to grab the lock on *all* CRTC's. |
| 5512 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5513 | if (state->active_pipe_changes || state->modeset) { |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5514 | realloc_pipes = ~0; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5515 | state->wm_results.dirty_pipes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | /* |
| 5519 | * We're not recomputing for the pipes not included in the commit, so |
| 5520 | * make sure we start with the current state. |
| 5521 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5522 | for_each_intel_crtc_mask(dev, crtc, realloc_pipes) { |
| 5523 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 5524 | if (IS_ERR(crtc_state)) |
| 5525 | return PTR_ERR(crtc_state); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | return 0; |
| 5529 | } |
| 5530 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5531 | /* |
| 5532 | * To make sure the cursor watermark registers are always consistent |
| 5533 | * with our computed state the following scenario needs special |
| 5534 | * treatment: |
| 5535 | * |
| 5536 | * 1. enable cursor |
| 5537 | * 2. move cursor entirely offscreen |
| 5538 | * 3. disable cursor |
| 5539 | * |
| 5540 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 5541 | * (since we consider an offscreen cursor still active for the purposes |
| 5542 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 5543 | * because the actual plane visibility isn't changing, and we don't |
| 5544 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 5545 | * force step 3. to call .disable_plane() to update the watermark |
| 5546 | * registers properly. |
| 5547 | * |
| 5548 | * Other planes do not suffer from this issues as their watermarks are |
| 5549 | * calculated based on the actual plane visibility. The only time this |
| 5550 | * can trigger for the other planes is during the initial readout as the |
| 5551 | * default value of the watermarks registers is not zero. |
| 5552 | */ |
| 5553 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 5554 | struct intel_crtc *crtc) |
| 5555 | { |
| 5556 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5557 | const struct intel_crtc_state *old_crtc_state = |
| 5558 | intel_atomic_get_old_crtc_state(state, crtc); |
| 5559 | struct intel_crtc_state *new_crtc_state = |
| 5560 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5561 | struct intel_plane *plane; |
| 5562 | |
| 5563 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5564 | struct intel_plane_state *plane_state; |
| 5565 | enum plane_id plane_id = plane->id; |
| 5566 | |
| 5567 | /* |
| 5568 | * Force a full wm update for every plane on modeset. |
| 5569 | * Required because the reset value of the wm registers |
| 5570 | * is non-zero, whereas we want all disabled planes to |
| 5571 | * have zero watermarks. So if we turn off the relevant |
| 5572 | * power well the hardware state will go out of sync |
| 5573 | * with the software state. |
| 5574 | */ |
| 5575 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->base) && |
| 5576 | skl_plane_wm_equals(dev_priv, |
| 5577 | &old_crtc_state->wm.skl.optimal.planes[plane_id], |
| 5578 | &new_crtc_state->wm.skl.optimal.planes[plane_id])) |
| 5579 | continue; |
| 5580 | |
| 5581 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 5582 | if (IS_ERR(plane_state)) |
| 5583 | return PTR_ERR(plane_state); |
| 5584 | |
| 5585 | new_crtc_state->update_planes |= BIT(plane_id); |
| 5586 | } |
| 5587 | |
| 5588 | return 0; |
| 5589 | } |
| 5590 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5591 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5592 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5593 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5594 | struct intel_crtc *crtc; |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5595 | struct intel_crtc_state *new_crtc_state; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5596 | struct intel_crtc_state *old_crtc_state; |
| 5597 | struct skl_ddb_values *results = &state->wm_results; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5598 | bool changed = false; |
| 5599 | int ret, i; |
| 5600 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5601 | /* Clear all dirty flags */ |
| 5602 | results->dirty_pipes = 0; |
| 5603 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5604 | ret = skl_ddb_add_affected_pipes(state, &changed); |
| 5605 | if (ret || !changed) |
| 5606 | return ret; |
| 5607 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5608 | /* |
| 5609 | * Calculate WM's for all pipes that are part of this transaction. |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5610 | * 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] | 5611 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 5612 | * pipe allocations had to change. |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5613 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5614 | 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] | 5615 | new_crtc_state, i) { |
| 5616 | ret = skl_build_pipe_wm(new_crtc_state); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5617 | if (ret) |
| 5618 | return ret; |
| 5619 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5620 | ret = skl_wm_add_affected_planes(state, crtc); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5621 | if (ret) |
| 5622 | return ret; |
| 5623 | |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5624 | if (!skl_pipe_wm_equals(crtc, |
| 5625 | &old_crtc_state->wm.skl.optimal, |
| 5626 | &new_crtc_state->wm.skl.optimal)) |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5627 | results->dirty_pipes |= drm_crtc_mask(&crtc->base); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5628 | } |
| 5629 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5630 | ret = skl_compute_ddb(state); |
| 5631 | if (ret) |
| 5632 | return ret; |
| 5633 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5634 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5635 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5636 | return 0; |
| 5637 | } |
| 5638 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5639 | static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5640 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5641 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5642 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5643 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5644 | struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5645 | enum pipe pipe = crtc->pipe; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5646 | |
| 5647 | if (!(state->wm_results.dirty_pipes & drm_crtc_mask(&crtc->base))) |
| 5648 | return; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5649 | |
| 5650 | I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime); |
| 5651 | } |
| 5652 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5653 | static void skl_initial_wm(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5654 | struct intel_crtc_state *crtc_state) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5655 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5656 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5657 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5658 | struct drm_i915_private *dev_priv = to_i915(dev); |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5659 | struct skl_ddb_values *results = &state->wm_results; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 5660 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5661 | if ((results->dirty_pipes & drm_crtc_mask(&intel_crtc->base)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5662 | return; |
| 5663 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5664 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5665 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5666 | if (crtc_state->base.active_changed) |
| 5667 | skl_atomic_update_crtc_wm(state, crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5668 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5669 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5670 | } |
| 5671 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5672 | 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] | 5673 | struct intel_wm_config *config) |
| 5674 | { |
| 5675 | struct intel_crtc *crtc; |
| 5676 | |
| 5677 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5678 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5679 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 5680 | |
| 5681 | if (!wm->pipe_enabled) |
| 5682 | continue; |
| 5683 | |
| 5684 | config->sprites_enabled |= wm->sprites_enabled; |
| 5685 | config->sprites_scaled |= wm->sprites_scaled; |
| 5686 | config->num_pipes_active++; |
| 5687 | } |
| 5688 | } |
| 5689 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5690 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 5691 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5692 | 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] | 5693 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5694 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5695 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5696 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 5697 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5698 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5699 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5700 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 5701 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 5702 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5703 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5704 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5705 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5706 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 5707 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5708 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5709 | 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] | 5710 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5711 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5712 | } |
| 5713 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5714 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5715 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5716 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5717 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 5718 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5719 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 5720 | } |
| 5721 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5722 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5723 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5724 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5725 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 5726 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5727 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5728 | mutex_lock(&dev_priv->wm.wm_mutex); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5729 | intel_crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5730 | ilk_program_watermarks(dev_priv); |
| 5731 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5732 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5733 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5734 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5735 | struct intel_crtc_state *crtc_state) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5736 | { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5737 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 5738 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5739 | |
| 5740 | mutex_lock(&dev_priv->wm.wm_mutex); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5741 | if (crtc_state->wm.need_postvbl_update) { |
| 5742 | intel_crtc->wm.active.ilk = crtc_state->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5743 | ilk_program_watermarks(dev_priv); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5744 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5745 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5746 | } |
| 5747 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5748 | static inline void skl_wm_level_from_reg_val(u32 val, |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5749 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5750 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5751 | level->plane_en = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5752 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5753 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 5754 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 5755 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5756 | } |
| 5757 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5758 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5759 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5760 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5761 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5762 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5763 | int level, max_level; |
| 5764 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5765 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5766 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5767 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5768 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5769 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5770 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5771 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5772 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5773 | if (plane_id != PLANE_CURSOR) |
| 5774 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5775 | else |
| 5776 | val = I915_READ(CUR_WM(pipe, level)); |
| 5777 | |
| 5778 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 5779 | } |
| 5780 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5781 | if (plane_id != PLANE_CURSOR) |
| 5782 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5783 | else |
| 5784 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 5785 | |
| 5786 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 5787 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5788 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5789 | if (!crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5790 | return; |
| 5791 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5792 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5793 | } |
| 5794 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5795 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5796 | { |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5797 | struct skl_ddb_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5798 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5799 | struct intel_crtc *crtc; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5800 | struct intel_crtc_state *crtc_state; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5801 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5802 | skl_ddb_get_hw_state(dev_priv, ddb); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5803 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5804 | crtc_state = to_intel_crtc_state(crtc->base.state); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5805 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5806 | 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] | 5807 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5808 | if (crtc->active) |
| 5809 | hw->dirty_pipes |= drm_crtc_mask(&crtc->base); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5810 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5811 | |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5812 | if (dev_priv->active_crtcs) { |
| 5813 | /* Fully recompute DDB on first atomic commit */ |
| 5814 | dev_priv->wm.distrust_bios_wm = true; |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5815 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5816 | } |
| 5817 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5818 | 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] | 5819 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5820 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5821 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5822 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 5823 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 5824 | struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5825 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5826 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5827 | [PIPE_A] = WM0_PIPEA_ILK, |
| 5828 | [PIPE_B] = WM0_PIPEB_ILK, |
| 5829 | [PIPE_C] = WM0_PIPEC_IVB, |
| 5830 | }; |
| 5831 | |
| 5832 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5833 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 5834 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5835 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 5836 | memset(active, 0, sizeof(*active)); |
| 5837 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5838 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 5839 | |
| 5840 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5841 | u32 tmp = hw->wm_pipe[pipe]; |
| 5842 | |
| 5843 | /* |
| 5844 | * For active pipes LP0 watermark is marked as |
| 5845 | * enabled, and LP1+ watermaks as disabled since |
| 5846 | * we can't really reverse compute them in case |
| 5847 | * multiple pipes are active. |
| 5848 | */ |
| 5849 | active->wm[0].enable = true; |
| 5850 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 5851 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 5852 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 5853 | active->linetime = hw->wm_linetime[pipe]; |
| 5854 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5855 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5856 | |
| 5857 | /* |
| 5858 | * For inactive pipes, all watermark levels |
| 5859 | * should be marked as enabled but zeroed, |
| 5860 | * which is what we'd compute them to. |
| 5861 | */ |
| 5862 | for (level = 0; level <= max_level; level++) |
| 5863 | active->wm[level].enable = true; |
| 5864 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5865 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5866 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5867 | } |
| 5868 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5869 | #define _FW_WM(value, plane) \ |
| 5870 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 5871 | #define _FW_WM_VLV(value, plane) \ |
| 5872 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 5873 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5874 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 5875 | struct g4x_wm_values *wm) |
| 5876 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5877 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5878 | |
| 5879 | tmp = I915_READ(DSPFW1); |
| 5880 | wm->sr.plane = _FW_WM(tmp, SR); |
| 5881 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5882 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 5883 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 5884 | |
| 5885 | tmp = I915_READ(DSPFW2); |
| 5886 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 5887 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 5888 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 5889 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 5890 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5891 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 5892 | |
| 5893 | tmp = I915_READ(DSPFW3); |
| 5894 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 5895 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5896 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 5897 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 5898 | } |
| 5899 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5900 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 5901 | struct vlv_wm_values *wm) |
| 5902 | { |
| 5903 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5904 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5905 | |
| 5906 | for_each_pipe(dev_priv, pipe) { |
| 5907 | tmp = I915_READ(VLV_DDL(pipe)); |
| 5908 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5909 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5910 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5911 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5912 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5913 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5914 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5915 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5916 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 5917 | } |
| 5918 | |
| 5919 | tmp = I915_READ(DSPFW1); |
| 5920 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5921 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5922 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 5923 | 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] | 5924 | |
| 5925 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5926 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 5927 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5928 | 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] | 5929 | |
| 5930 | tmp = I915_READ(DSPFW3); |
| 5931 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5932 | |
| 5933 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5934 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5935 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5936 | 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] | 5937 | |
| 5938 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5939 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 5940 | 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] | 5941 | |
| 5942 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5943 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 5944 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5945 | |
| 5946 | tmp = I915_READ(DSPHOWM); |
| 5947 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5948 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 5949 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 5950 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 5951 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5952 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5953 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5954 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5955 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5956 | 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] | 5957 | } else { |
| 5958 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5959 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5960 | 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] | 5961 | |
| 5962 | tmp = I915_READ(DSPHOWM); |
| 5963 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5964 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5965 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5966 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5967 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5968 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5969 | 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] | 5970 | } |
| 5971 | } |
| 5972 | |
| 5973 | #undef _FW_WM |
| 5974 | #undef _FW_WM_VLV |
| 5975 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5976 | 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] | 5977 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5978 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 5979 | struct intel_crtc *crtc; |
| 5980 | |
| 5981 | g4x_read_wm_values(dev_priv, wm); |
| 5982 | |
| 5983 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 5984 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5985 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5986 | struct intel_crtc_state *crtc_state = |
| 5987 | to_intel_crtc_state(crtc->base.state); |
| 5988 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 5989 | struct g4x_pipe_wm *raw; |
| 5990 | enum pipe pipe = crtc->pipe; |
| 5991 | enum plane_id plane_id; |
| 5992 | int level, max_level; |
| 5993 | |
| 5994 | active->cxsr = wm->cxsr; |
| 5995 | active->hpll_en = wm->hpll_en; |
| 5996 | active->fbc_en = wm->fbc_en; |
| 5997 | |
| 5998 | active->sr = wm->sr; |
| 5999 | active->hpll = wm->hpll; |
| 6000 | |
| 6001 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6002 | active->wm.plane[plane_id] = |
| 6003 | wm->pipe[pipe].plane[plane_id]; |
| 6004 | } |
| 6005 | |
| 6006 | if (wm->cxsr && wm->hpll_en) |
| 6007 | max_level = G4X_WM_LEVEL_HPLL; |
| 6008 | else if (wm->cxsr) |
| 6009 | max_level = G4X_WM_LEVEL_SR; |
| 6010 | else |
| 6011 | max_level = G4X_WM_LEVEL_NORMAL; |
| 6012 | |
| 6013 | level = G4X_WM_LEVEL_NORMAL; |
| 6014 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6015 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6016 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 6017 | |
| 6018 | if (++level > max_level) |
| 6019 | goto out; |
| 6020 | |
| 6021 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6022 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 6023 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 6024 | raw->plane[PLANE_SPRITE0] = 0; |
| 6025 | raw->fbc = active->sr.fbc; |
| 6026 | |
| 6027 | if (++level > max_level) |
| 6028 | goto out; |
| 6029 | |
| 6030 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6031 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 6032 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 6033 | raw->plane[PLANE_SPRITE0] = 0; |
| 6034 | raw->fbc = active->hpll.fbc; |
| 6035 | |
| 6036 | out: |
| 6037 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6038 | g4x_raw_plane_wm_set(crtc_state, level, |
| 6039 | plane_id, USHRT_MAX); |
| 6040 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 6041 | |
| 6042 | crtc_state->wm.g4x.optimal = *active; |
| 6043 | crtc_state->wm.g4x.intermediate = *active; |
| 6044 | |
| 6045 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 6046 | pipe_name(pipe), |
| 6047 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6048 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6049 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
| 6050 | } |
| 6051 | |
| 6052 | DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 6053 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 6054 | DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 6055 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 6056 | DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", |
| 6057 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
| 6058 | } |
| 6059 | |
| 6060 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6061 | { |
| 6062 | struct intel_plane *plane; |
| 6063 | struct intel_crtc *crtc; |
| 6064 | |
| 6065 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6066 | |
| 6067 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6068 | struct intel_crtc *crtc = |
| 6069 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6070 | struct intel_crtc_state *crtc_state = |
| 6071 | to_intel_crtc_state(crtc->base.state); |
| 6072 | struct intel_plane_state *plane_state = |
| 6073 | to_intel_plane_state(plane->base.state); |
| 6074 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 6075 | enum plane_id plane_id = plane->id; |
| 6076 | int level; |
| 6077 | |
| 6078 | if (plane_state->base.visible) |
| 6079 | continue; |
| 6080 | |
| 6081 | for (level = 0; level < 3; level++) { |
| 6082 | struct g4x_pipe_wm *raw = |
| 6083 | &crtc_state->wm.g4x.raw[level]; |
| 6084 | |
| 6085 | raw->plane[plane_id] = 0; |
| 6086 | wm_state->wm.plane[plane_id] = 0; |
| 6087 | } |
| 6088 | |
| 6089 | if (plane_id == PLANE_PRIMARY) { |
| 6090 | for (level = 0; level < 3; level++) { |
| 6091 | struct g4x_pipe_wm *raw = |
| 6092 | &crtc_state->wm.g4x.raw[level]; |
| 6093 | raw->fbc = 0; |
| 6094 | } |
| 6095 | |
| 6096 | wm_state->sr.fbc = 0; |
| 6097 | wm_state->hpll.fbc = 0; |
| 6098 | wm_state->fbc_en = false; |
| 6099 | } |
| 6100 | } |
| 6101 | |
| 6102 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6103 | struct intel_crtc_state *crtc_state = |
| 6104 | to_intel_crtc_state(crtc->base.state); |
| 6105 | |
| 6106 | crtc_state->wm.g4x.intermediate = |
| 6107 | crtc_state->wm.g4x.optimal; |
| 6108 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 6109 | } |
| 6110 | |
| 6111 | g4x_program_watermarks(dev_priv); |
| 6112 | |
| 6113 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6114 | } |
| 6115 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6116 | 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] | 6117 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6118 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 6119 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6120 | u32 val; |
| 6121 | |
| 6122 | vlv_read_wm_values(dev_priv, wm); |
| 6123 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6124 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 6125 | wm->level = VLV_WM_LEVEL_PM2; |
| 6126 | |
| 6127 | if (IS_CHERRYVIEW(dev_priv)) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6128 | vlv_punit_get(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6129 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 6130 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6131 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 6132 | wm->level = VLV_WM_LEVEL_PM5; |
| 6133 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6134 | /* |
| 6135 | * If DDR DVFS is disabled in the BIOS, Punit |
| 6136 | * will never ack the request. So if that happens |
| 6137 | * assume we don't have to enable/disable DDR DVFS |
| 6138 | * dynamically. To test that just set the REQ_ACK |
| 6139 | * bit to poke the Punit, but don't change the |
| 6140 | * HIGH/LOW bits so that we don't actually change |
| 6141 | * the current state. |
| 6142 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6143 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6144 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 6145 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 6146 | |
| 6147 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 6148 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 6149 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 6150 | "assuming DDR DVFS is disabled\n"); |
| 6151 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 6152 | } else { |
| 6153 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 6154 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 6155 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 6156 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6157 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6158 | vlv_punit_put(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6159 | } |
| 6160 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6161 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6162 | struct intel_crtc_state *crtc_state = |
| 6163 | to_intel_crtc_state(crtc->base.state); |
| 6164 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 6165 | const struct vlv_fifo_state *fifo_state = |
| 6166 | &crtc_state->wm.vlv.fifo_state; |
| 6167 | enum pipe pipe = crtc->pipe; |
| 6168 | enum plane_id plane_id; |
| 6169 | int level; |
| 6170 | |
| 6171 | vlv_get_fifo_size(crtc_state); |
| 6172 | |
| 6173 | active->num_levels = wm->level + 1; |
| 6174 | active->cxsr = wm->cxsr; |
| 6175 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6176 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6177 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6178 | &crtc_state->wm.vlv.raw[level]; |
| 6179 | |
| 6180 | active->sr[level].plane = wm->sr.plane; |
| 6181 | active->sr[level].cursor = wm->sr.cursor; |
| 6182 | |
| 6183 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6184 | active->wm[level].plane[plane_id] = |
| 6185 | wm->pipe[pipe].plane[plane_id]; |
| 6186 | |
| 6187 | raw->plane[plane_id] = |
| 6188 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 6189 | fifo_state->plane[plane_id]); |
| 6190 | } |
| 6191 | } |
| 6192 | |
| 6193 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6194 | vlv_raw_plane_wm_set(crtc_state, level, |
| 6195 | plane_id, USHRT_MAX); |
| 6196 | vlv_invalidate_wms(crtc, active, level); |
| 6197 | |
| 6198 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 6199 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6200 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6201 | 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] | 6202 | pipe_name(pipe), |
| 6203 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6204 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6205 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 6206 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6207 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6208 | |
| 6209 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 6210 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 6211 | } |
| 6212 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6213 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6214 | { |
| 6215 | struct intel_plane *plane; |
| 6216 | struct intel_crtc *crtc; |
| 6217 | |
| 6218 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6219 | |
| 6220 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6221 | struct intel_crtc *crtc = |
| 6222 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6223 | struct intel_crtc_state *crtc_state = |
| 6224 | to_intel_crtc_state(crtc->base.state); |
| 6225 | struct intel_plane_state *plane_state = |
| 6226 | to_intel_plane_state(plane->base.state); |
| 6227 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 6228 | const struct vlv_fifo_state *fifo_state = |
| 6229 | &crtc_state->wm.vlv.fifo_state; |
| 6230 | enum plane_id plane_id = plane->id; |
| 6231 | int level; |
| 6232 | |
| 6233 | if (plane_state->base.visible) |
| 6234 | continue; |
| 6235 | |
| 6236 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6237 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6238 | &crtc_state->wm.vlv.raw[level]; |
| 6239 | |
| 6240 | raw->plane[plane_id] = 0; |
| 6241 | |
| 6242 | wm_state->wm[level].plane[plane_id] = |
| 6243 | vlv_invert_wm_value(raw->plane[plane_id], |
| 6244 | fifo_state->plane[plane_id]); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6249 | struct intel_crtc_state *crtc_state = |
| 6250 | to_intel_crtc_state(crtc->base.state); |
| 6251 | |
| 6252 | crtc_state->wm.vlv.intermediate = |
| 6253 | crtc_state->wm.vlv.optimal; |
| 6254 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 6255 | } |
| 6256 | |
| 6257 | vlv_program_watermarks(dev_priv); |
| 6258 | |
| 6259 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6260 | } |
| 6261 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6262 | /* |
| 6263 | * FIXME should probably kill this and improve |
| 6264 | * the real watermark readout/sanitation instead |
| 6265 | */ |
| 6266 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 6267 | { |
| 6268 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 6269 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 6270 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 6271 | |
| 6272 | /* |
| 6273 | * Don't touch WM1S_LP_EN here. |
| 6274 | * Doing so could cause underruns. |
| 6275 | */ |
| 6276 | } |
| 6277 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6278 | 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] | 6279 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6280 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6281 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6282 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6283 | ilk_init_lp_watermarks(dev_priv); |
| 6284 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6285 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6286 | ilk_pipe_wm_get_hw_state(crtc); |
| 6287 | |
| 6288 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 6289 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 6290 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 6291 | |
| 6292 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 6293 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 6294 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 6295 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 6296 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6297 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6298 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6299 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 6300 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 6301 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6302 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 6303 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6304 | |
| 6305 | hw->enable_fbc_wm = |
| 6306 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 6307 | } |
| 6308 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6309 | /** |
| 6310 | * intel_update_watermarks - update FIFO watermark values based on current modes |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 6311 | * @crtc: the #intel_crtc on which to compute the WM |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6312 | * |
| 6313 | * Calculate watermark values for the various WM regs based on current mode |
| 6314 | * and plane configuration. |
| 6315 | * |
| 6316 | * There are several cases to deal with here: |
| 6317 | * - normal (i.e. non-self-refresh) |
| 6318 | * - self-refresh (SR) mode |
| 6319 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 6320 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 6321 | * lines), so need to account for TLB latency |
| 6322 | * |
| 6323 | * The normal calculation is: |
| 6324 | * watermark = dotclock * bytes per pixel * latency |
| 6325 | * where latency is platform & configuration dependent (we assume pessimal |
| 6326 | * values here). |
| 6327 | * |
| 6328 | * The SR calculation is: |
| 6329 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 6330 | * bytes per pixel |
| 6331 | * where |
| 6332 | * line time = htotal / dotclock |
| 6333 | * surface width = hdisplay for normal plane and 64 for cursor |
| 6334 | * and latency is assumed to be high, as above. |
| 6335 | * |
| 6336 | * The final value programmed to the register should always be rounded up, |
| 6337 | * and include an extra 2 entries to account for clock crossings. |
| 6338 | * |
| 6339 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 6340 | * to set the non-SR watermarks to 8. |
| 6341 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6342 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6343 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6344 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6345 | |
| 6346 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 6347 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6348 | } |
| 6349 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6350 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 6351 | { |
| 6352 | u32 val; |
| 6353 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 6354 | if (!HAS_IPC(dev_priv)) |
| 6355 | return; |
| 6356 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6357 | val = I915_READ(DISP_ARB_CTL2); |
| 6358 | |
| 6359 | if (dev_priv->ipc_enabled) |
| 6360 | val |= DISP_IPC_ENABLE; |
| 6361 | else |
| 6362 | val &= ~DISP_IPC_ENABLE; |
| 6363 | |
| 6364 | I915_WRITE(DISP_ARB_CTL2, val); |
| 6365 | } |
| 6366 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6367 | static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv) |
| 6368 | { |
| 6369 | /* Display WA #0477 WaDisableIPC: skl */ |
| 6370 | if (IS_SKYLAKE(dev_priv)) |
| 6371 | return false; |
| 6372 | |
| 6373 | /* Display WA #1141: SKL:all KBL:all CFL */ |
| 6374 | if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) |
| 6375 | return dev_priv->dram_info.symmetric_memory; |
| 6376 | |
| 6377 | return true; |
| 6378 | } |
| 6379 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6380 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 6381 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6382 | if (!HAS_IPC(dev_priv)) |
| 6383 | return; |
| 6384 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6385 | dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv); |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 6386 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6387 | intel_enable_ipc(dev_priv); |
| 6388 | } |
| 6389 | |
Jani Nikula | e282891 | 2016-01-18 09:19:47 +0200 | [diff] [blame] | 6390 | /* |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6391 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6392 | */ |
| 6393 | DEFINE_SPINLOCK(mchdev_lock); |
| 6394 | |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6395 | bool ironlake_set_drps(struct drm_i915_private *i915, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6396 | { |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6397 | struct intel_uncore *uncore = &i915->uncore; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6398 | u16 rgvswctl; |
| 6399 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 6400 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6401 | |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6402 | rgvswctl = intel_uncore_read16(uncore, MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6403 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 6404 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 6405 | return false; /* still busy with another command */ |
| 6406 | } |
| 6407 | |
| 6408 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 6409 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6410 | intel_uncore_write16(uncore, MEMSWCTL, rgvswctl); |
| 6411 | intel_uncore_posting_read16(uncore, MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6412 | |
| 6413 | rgvswctl |= MEMCTL_CMD_STS; |
Tvrtko Ursulin | e44d62d | 2019-06-11 11:45:45 +0100 | [diff] [blame] | 6414 | intel_uncore_write16(uncore, MEMSWCTL, rgvswctl); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6415 | |
| 6416 | return true; |
| 6417 | } |
| 6418 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6419 | static void ironlake_enable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6420 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6421 | struct intel_uncore *uncore = &dev_priv->uncore; |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 6422 | u32 rgvmodectl; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6423 | u8 fmax, fmin, fstart, vstart; |
| 6424 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6425 | spin_lock_irq(&mchdev_lock); |
| 6426 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6427 | rgvmodectl = intel_uncore_read(uncore, MEMMODECTL); |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 6428 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6429 | /* Enable temp reporting */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6430 | intel_uncore_write16(uncore, PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 6431 | intel_uncore_write16(uncore, TSC1, I915_READ(TSC1) | TSE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6432 | |
| 6433 | /* 100ms RC evaluation intervals */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6434 | intel_uncore_write(uncore, RCUPEI, 100000); |
| 6435 | intel_uncore_write(uncore, RCDNEI, 100000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6436 | |
| 6437 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6438 | intel_uncore_write(uncore, RCBMAXAVG, 90000); |
| 6439 | intel_uncore_write(uncore, RCBMINAVG, 80000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6440 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6441 | intel_uncore_write(uncore, MEMIHYST, 1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6442 | |
| 6443 | /* Set up min, max, and cur for interrupt handling */ |
| 6444 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 6445 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 6446 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 6447 | MEMMODE_FSTART_SHIFT; |
| 6448 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6449 | vstart = (intel_uncore_read(uncore, PXVFREQ(fstart)) & |
| 6450 | PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6451 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6452 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 6453 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6454 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6455 | dev_priv->ips.max_delay = fstart; |
| 6456 | dev_priv->ips.min_delay = fmin; |
| 6457 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6458 | |
| 6459 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 6460 | fmax, fmin, fstart); |
| 6461 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6462 | intel_uncore_write(uncore, |
| 6463 | MEMINTREN, |
| 6464 | MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6465 | |
| 6466 | /* |
| 6467 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 6468 | */ |
| 6469 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6470 | intel_uncore_write(uncore, VIDSTART, vstart); |
| 6471 | intel_uncore_posting_read(uncore, VIDSTART); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6472 | |
| 6473 | rgvmodectl |= MEMMODE_SWMODE_EN; |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6474 | intel_uncore_write(uncore, MEMMODECTL, rgvmodectl); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6475 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6476 | if (wait_for_atomic((intel_uncore_read(uncore, MEMSWCTL) & |
| 6477 | MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6478 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6479 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6480 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6481 | ironlake_set_drps(dev_priv, fstart); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6482 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6483 | dev_priv->ips.last_count1 = |
| 6484 | intel_uncore_read(uncore, DMIEC) + |
| 6485 | intel_uncore_read(uncore, DDREC) + |
| 6486 | intel_uncore_read(uncore, CSIEC); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6487 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6488 | dev_priv->ips.last_count2 = intel_uncore_read(uncore, GFXEC); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 6489 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6490 | |
| 6491 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6492 | } |
| 6493 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6494 | static void ironlake_disable_drps(struct drm_i915_private *i915) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6495 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6496 | struct intel_uncore *uncore = &i915->uncore; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6497 | u16 rgvswctl; |
| 6498 | |
| 6499 | spin_lock_irq(&mchdev_lock); |
| 6500 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6501 | rgvswctl = intel_uncore_read16(uncore, MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6502 | |
| 6503 | /* Ack interrupts, disable EFC interrupt */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6504 | intel_uncore_write(uncore, |
| 6505 | MEMINTREN, |
| 6506 | intel_uncore_read(uncore, MEMINTREN) & |
| 6507 | ~MEMINT_EVAL_CHG_EN); |
| 6508 | intel_uncore_write(uncore, MEMINTRSTS, MEMINT_EVAL_CHG); |
| 6509 | intel_uncore_write(uncore, |
| 6510 | DEIER, |
| 6511 | intel_uncore_read(uncore, DEIER) & ~DE_PCU_EVENT); |
| 6512 | intel_uncore_write(uncore, DEIIR, DE_PCU_EVENT); |
| 6513 | intel_uncore_write(uncore, |
| 6514 | DEIMR, |
| 6515 | intel_uncore_read(uncore, DEIMR) | DE_PCU_EVENT); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6516 | |
| 6517 | /* Go back to the starting frequency */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6518 | ironlake_set_drps(i915, i915->ips.fstart); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6519 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6520 | rgvswctl |= MEMCTL_CMD_STS; |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 6521 | intel_uncore_write(uncore, MEMSWCTL, rgvswctl); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6522 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6523 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6524 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6525 | } |
| 6526 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 6527 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 6528 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 6529 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 6530 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 6531 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6532 | 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] | 6533 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6534 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6535 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6536 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6537 | /* Only set the down limit when we've reached the lowest level to avoid |
| 6538 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 6539 | * race in the hw when coming out of rc6: There's a tiny window where |
| 6540 | * the hw runs at the minimal clock before selecting the desired |
| 6541 | * frequency, if the down threshold expires in that window we will not |
| 6542 | * receive a down interrupt. */ |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6543 | if (INTEL_GEN(dev_priv) >= 9) { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6544 | limits = (rps->max_freq_softlimit) << 23; |
| 6545 | if (val <= rps->min_freq_softlimit) |
| 6546 | limits |= (rps->min_freq_softlimit) << 14; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6547 | } else { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6548 | limits = rps->max_freq_softlimit << 24; |
| 6549 | if (val <= rps->min_freq_softlimit) |
| 6550 | limits |= rps->min_freq_softlimit << 16; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6551 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6552 | |
| 6553 | return limits; |
| 6554 | } |
| 6555 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6556 | 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] | 6557 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6558 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6559 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 6560 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6561 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6562 | lockdep_assert_held(&rps->power.mutex); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6563 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6564 | if (new_power == rps->power.mode) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6565 | return; |
| 6566 | |
| 6567 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 6568 | switch (new_power) { |
| 6569 | case LOW_POWER: |
| 6570 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6571 | ei_up = 16000; |
| 6572 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6573 | |
| 6574 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6575 | ei_down = 32000; |
| 6576 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6577 | break; |
| 6578 | |
| 6579 | case BETWEEN: |
| 6580 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6581 | ei_up = 13000; |
| 6582 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6583 | |
| 6584 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6585 | ei_down = 32000; |
| 6586 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6587 | break; |
| 6588 | |
| 6589 | case HIGH_POWER: |
| 6590 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6591 | ei_up = 10000; |
| 6592 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6593 | |
| 6594 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6595 | ei_down = 32000; |
| 6596 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6597 | break; |
| 6598 | } |
| 6599 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6600 | /* When byt can survive without system hang with dynamic |
| 6601 | * sw freq adjustments, this restriction can be lifted. |
| 6602 | */ |
| 6603 | if (IS_VALLEYVIEW(dev_priv)) |
| 6604 | goto skip_hw_write; |
| 6605 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6606 | I915_WRITE(GEN6_RP_UP_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6607 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6608 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6609 | GT_INTERVAL_FROM_US(dev_priv, |
| 6610 | ei_up * threshold_up / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6611 | |
| 6612 | I915_WRITE(GEN6_RP_DOWN_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6613 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6614 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6615 | GT_INTERVAL_FROM_US(dev_priv, |
| 6616 | ei_down * threshold_down / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6617 | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6618 | I915_WRITE(GEN6_RP_CONTROL, |
Mika Kuoppala | 1071d0f | 2019-04-10 16:24:36 +0300 | [diff] [blame] | 6619 | (INTEL_GEN(dev_priv) > 9 ? 0 : GEN6_RP_MEDIA_TURBO) | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6620 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6621 | GEN6_RP_MEDIA_IS_GFX | |
| 6622 | GEN6_RP_ENABLE | |
| 6623 | GEN6_RP_UP_BUSY_AVG | |
| 6624 | GEN6_RP_DOWN_IDLE_AVG); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6625 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6626 | skip_hw_write: |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6627 | rps->power.mode = new_power; |
| 6628 | rps->power.up_threshold = threshold_up; |
| 6629 | rps->power.down_threshold = threshold_down; |
| 6630 | } |
| 6631 | |
| 6632 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 6633 | { |
| 6634 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6635 | int new_power; |
| 6636 | |
| 6637 | new_power = rps->power.mode; |
| 6638 | switch (rps->power.mode) { |
| 6639 | case LOW_POWER: |
| 6640 | if (val > rps->efficient_freq + 1 && |
| 6641 | val > rps->cur_freq) |
| 6642 | new_power = BETWEEN; |
| 6643 | break; |
| 6644 | |
| 6645 | case BETWEEN: |
| 6646 | if (val <= rps->efficient_freq && |
| 6647 | val < rps->cur_freq) |
| 6648 | new_power = LOW_POWER; |
| 6649 | else if (val >= rps->rp0_freq && |
| 6650 | val > rps->cur_freq) |
| 6651 | new_power = HIGH_POWER; |
| 6652 | break; |
| 6653 | |
| 6654 | case HIGH_POWER: |
| 6655 | if (val < (rps->rp1_freq + rps->rp0_freq) >> 1 && |
| 6656 | val < rps->cur_freq) |
| 6657 | new_power = BETWEEN; |
| 6658 | break; |
| 6659 | } |
| 6660 | /* Max/min bins are special */ |
| 6661 | if (val <= rps->min_freq_softlimit) |
| 6662 | new_power = LOW_POWER; |
| 6663 | if (val >= rps->max_freq_softlimit) |
| 6664 | new_power = HIGH_POWER; |
| 6665 | |
| 6666 | mutex_lock(&rps->power.mutex); |
| 6667 | if (rps->power.interactive) |
| 6668 | new_power = HIGH_POWER; |
| 6669 | rps_set_power(dev_priv, new_power); |
| 6670 | mutex_unlock(&rps->power.mutex); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6671 | } |
| 6672 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6673 | void intel_rps_mark_interactive(struct drm_i915_private *i915, bool interactive) |
| 6674 | { |
| 6675 | struct intel_rps *rps = &i915->gt_pm.rps; |
| 6676 | |
| 6677 | if (INTEL_GEN(i915) < 6) |
| 6678 | return; |
| 6679 | |
| 6680 | mutex_lock(&rps->power.mutex); |
| 6681 | if (interactive) { |
| 6682 | if (!rps->power.interactive++ && READ_ONCE(i915->gt.awake)) |
| 6683 | rps_set_power(i915, HIGH_POWER); |
| 6684 | } else { |
| 6685 | GEM_BUG_ON(!rps->power.interactive); |
| 6686 | rps->power.interactive--; |
| 6687 | } |
| 6688 | mutex_unlock(&rps->power.mutex); |
| 6689 | } |
| 6690 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6691 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 6692 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6693 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6694 | u32 mask = 0; |
| 6695 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6696 | /* 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] | 6697 | if (val > rps->min_freq_softlimit) |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6698 | 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] | 6699 | if (val < rps->max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 6700 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6701 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 6702 | mask &= dev_priv->pm_rps_events; |
| 6703 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 6704 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6705 | } |
| 6706 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6707 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 6708 | * called when the range (min_delay and max_delay) is modified so that we can |
| 6709 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6710 | 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] | 6711 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6712 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6713 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6714 | /* min/max delay may still have been modified so be sure to |
| 6715 | * write the limits value. |
| 6716 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6717 | if (val != rps->cur_freq) { |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6718 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6719 | |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6720 | if (INTEL_GEN(dev_priv) >= 9) |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 6721 | I915_WRITE(GEN6_RPNSWREQ, |
| 6722 | GEN9_FREQUENCY(val)); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6723 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6724 | I915_WRITE(GEN6_RPNSWREQ, |
| 6725 | HSW_FREQUENCY(val)); |
| 6726 | else |
| 6727 | I915_WRITE(GEN6_RPNSWREQ, |
| 6728 | GEN6_FREQUENCY(val) | |
| 6729 | GEN6_OFFSET(0) | |
| 6730 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6731 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6732 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6733 | /* Make sure we continue to get interrupts |
| 6734 | * until we hit the minimum or maximum frequencies. |
| 6735 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6736 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6737 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6738 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6739 | rps->cur_freq = val; |
Mika Kuoppala | 0f94592 | 2015-11-17 18:14:26 +0200 | [diff] [blame] | 6740 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6741 | |
| 6742 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6743 | } |
| 6744 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6745 | 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] | 6746 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6747 | int err; |
| 6748 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6749 | if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1), |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6750 | "Odd GPU freq value\n")) |
| 6751 | val &= ~1; |
| 6752 | |
Deepak S | cd25dd5 | 2015-07-10 18:31:40 +0530 | [diff] [blame] | 6753 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 6754 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6755 | if (val != dev_priv->gt_pm.rps.cur_freq) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6756 | vlv_punit_get(dev_priv); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6757 | err = vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6758 | vlv_punit_put(dev_priv); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6759 | if (err) |
| 6760 | return err; |
| 6761 | |
Chris Wilson | db4c5e0 | 2017-02-10 15:03:46 +0000 | [diff] [blame] | 6762 | gen6_set_rps_thresholds(dev_priv, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 6763 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6764 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6765 | dev_priv->gt_pm.rps.cur_freq = val; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6766 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6767 | |
| 6768 | return 0; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6769 | } |
| 6770 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6771 | /* 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] | 6772 | * |
| 6773 | * * If Gfx is Idle, then |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6774 | * 1. Forcewake Media well. |
| 6775 | * 2. Request idle freq. |
| 6776 | * 3. Release Forcewake of Media well. |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6777 | */ |
| 6778 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 6779 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6780 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6781 | u32 val = rps->idle_freq; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6782 | int err; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 6783 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6784 | if (rps->cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6785 | return; |
| 6786 | |
Chris Wilson | c9efef7 | 2017-01-02 15:28:45 +0000 | [diff] [blame] | 6787 | /* The punit delays the write of the frequency and voltage until it |
| 6788 | * determines the GPU is awake. During normal usage we don't want to |
| 6789 | * waste power changing the frequency if the GPU is sleeping (rc6). |
| 6790 | * However, the GPU and driver is now idle and we do not want to delay |
| 6791 | * switching to minimum voltage (reducing power whilst idle) as we do |
| 6792 | * not expect to be woken in the near future and so must flush the |
| 6793 | * change by waking the device. |
| 6794 | * |
| 6795 | * We choose to take the media powerwell (either would do to trick the |
| 6796 | * punit into committing the voltage change) as that takes a lot less |
| 6797 | * power than the render powerwell. |
| 6798 | */ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6799 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6800 | err = valleyview_set_rps(dev_priv, val); |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6801 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6802 | |
| 6803 | if (err) |
| 6804 | DRM_ERROR("Failed to set RPS for idle\n"); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6805 | } |
| 6806 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6807 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 6808 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6809 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6810 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6811 | mutex_lock(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6812 | if (rps->enabled) { |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6813 | u8 freq; |
| 6814 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6815 | if (dev_priv->pm_rps_events & GEN6_PM_RP_UP_EI_EXPIRED) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6816 | gen6_rps_reset_ei(dev_priv); |
| 6817 | I915_WRITE(GEN6_PMINTRMSK, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6818 | gen6_rps_pm_mask(dev_priv, rps->cur_freq)); |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 6819 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6820 | gen6_enable_rps_interrupts(dev_priv); |
| 6821 | |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6822 | /* Use the user's desired frequency as a guide, but for better |
| 6823 | * performance, jump directly to RPe as our starting frequency. |
| 6824 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6825 | freq = max(rps->cur_freq, |
| 6826 | rps->efficient_freq); |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6827 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6828 | if (intel_set_rps(dev_priv, |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6829 | clamp(freq, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6830 | rps->min_freq_softlimit, |
| 6831 | rps->max_freq_softlimit))) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6832 | DRM_DEBUG_DRIVER("Failed to set idle frequency\n"); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6833 | } |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6834 | mutex_unlock(&rps->lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6835 | } |
| 6836 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6837 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 6838 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6839 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6840 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6841 | /* Flush our bottom-half so that it does not race with us |
| 6842 | * setting the idle frequency and so that it is bounded by |
| 6843 | * our rpm wakeref. And then disable the interrupts to stop any |
| 6844 | * futher RPS reclocking whilst we are asleep. |
| 6845 | */ |
| 6846 | gen6_disable_rps_interrupts(dev_priv); |
| 6847 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6848 | mutex_lock(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6849 | if (rps->enabled) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6850 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6851 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6852 | else |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6853 | gen6_set_rps(dev_priv, rps->idle_freq); |
| 6854 | rps->last_adj = 0; |
Ville Syrjälä | 12c100b | 2016-05-23 17:42:48 +0300 | [diff] [blame] | 6855 | I915_WRITE(GEN6_PMINTRMSK, |
| 6856 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6857 | } |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6858 | mutex_unlock(&rps->lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6859 | } |
| 6860 | |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 6861 | void gen6_rps_boost(struct i915_request *rq) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6862 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6863 | struct intel_rps *rps = &rq->i915->gt_pm.rps; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6864 | unsigned long flags; |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6865 | bool boost; |
| 6866 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6867 | /* This is intentionally racy! We peek at the state here, then |
| 6868 | * validate inside the RPS worker. |
| 6869 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6870 | if (!rps->enabled) |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6871 | return; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6872 | |
Chris Wilson | 0e21834 | 2019-01-21 22:21:02 +0000 | [diff] [blame] | 6873 | if (i915_request_signaled(rq)) |
Chris Wilson | 253a281 | 2018-02-06 14:31:37 +0000 | [diff] [blame] | 6874 | return; |
| 6875 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 6876 | /* Serializes with i915_request_retire() */ |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6877 | boost = false; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6878 | spin_lock_irqsave(&rq->lock, flags); |
Chris Wilson | 253a281 | 2018-02-06 14:31:37 +0000 | [diff] [blame] | 6879 | if (!rq->waitboost && !dma_fence_is_signaled_locked(&rq->fence)) { |
| 6880 | boost = !atomic_fetch_inc(&rps->num_waiters); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6881 | rq->waitboost = true; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6882 | } |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6883 | spin_unlock_irqrestore(&rq->lock, flags); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6884 | if (!boost) |
| 6885 | return; |
| 6886 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6887 | if (READ_ONCE(rps->cur_freq) < rps->boost_freq) |
| 6888 | schedule_work(&rps->work); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6889 | |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 6890 | atomic_inc(&rps->boosts); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6891 | } |
| 6892 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6893 | int intel_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6894 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6895 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6896 | int err; |
| 6897 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6898 | lockdep_assert_held(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6899 | GEM_BUG_ON(val > rps->max_freq); |
| 6900 | GEM_BUG_ON(val < rps->min_freq); |
Chris Wilson | cfd1c48 | 2017-02-20 09:47:07 +0000 | [diff] [blame] | 6901 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6902 | if (!rps->enabled) { |
| 6903 | rps->cur_freq = val; |
Chris Wilson | 76e4e4b | 2017-02-20 09:47:08 +0000 | [diff] [blame] | 6904 | return 0; |
| 6905 | } |
| 6906 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6907 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6908 | err = valleyview_set_rps(dev_priv, val); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6909 | else |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6910 | err = gen6_set_rps(dev_priv, val); |
| 6911 | |
| 6912 | return err; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6913 | } |
| 6914 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6915 | static void gen9_disable_rc6(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6916 | { |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6917 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6918 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6919 | } |
| 6920 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6921 | static void gen9_disable_rps(struct drm_i915_private *dev_priv) |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6922 | { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6923 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6924 | } |
| 6925 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6926 | static void gen6_disable_rc6(struct drm_i915_private *dev_priv) |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6927 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6928 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | static void gen6_disable_rps(struct drm_i915_private *dev_priv) |
| 6932 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6933 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6934 | I915_WRITE(GEN6_RP_CONTROL, 0); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6935 | } |
| 6936 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6937 | static void cherryview_disable_rc6(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6938 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6939 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6940 | } |
| 6941 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6942 | static void cherryview_disable_rps(struct drm_i915_private *dev_priv) |
| 6943 | { |
| 6944 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6945 | } |
| 6946 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6947 | static void valleyview_disable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6948 | { |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6949 | /* We're doing forcewake before Disabling RC6, |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6950 | * This what the BIOS expects when going into suspend */ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6951 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6952 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6953 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6954 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6955 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6956 | } |
| 6957 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6958 | static void valleyview_disable_rps(struct drm_i915_private *dev_priv) |
| 6959 | { |
| 6960 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6961 | } |
| 6962 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6963 | static bool bxt_check_bios_rc6_setup(struct drm_i915_private *dev_priv) |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6964 | { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6965 | bool enable_rc6 = true; |
| 6966 | unsigned long rc6_ctx_base; |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6967 | u32 rc_ctl; |
| 6968 | int rc_sw_target; |
| 6969 | |
| 6970 | rc_ctl = I915_READ(GEN6_RC_CONTROL); |
| 6971 | rc_sw_target = (I915_READ(GEN6_RC_STATE) & RC_SW_TARGET_STATE_MASK) >> |
| 6972 | RC_SW_TARGET_STATE_SHIFT; |
| 6973 | DRM_DEBUG_DRIVER("BIOS enabled RC states: " |
| 6974 | "HW_CTRL %s HW_RC6 %s SW_TARGET_STATE %x\n", |
| 6975 | onoff(rc_ctl & GEN6_RC_CTL_HW_ENABLE), |
| 6976 | onoff(rc_ctl & GEN6_RC_CTL_RC6_ENABLE), |
| 6977 | rc_sw_target); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6978 | |
| 6979 | if (!(I915_READ(RC6_LOCATION) & RC6_CTX_IN_DRAM)) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6980 | DRM_DEBUG_DRIVER("RC6 Base location not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6981 | enable_rc6 = false; |
| 6982 | } |
| 6983 | |
| 6984 | /* |
| 6985 | * The exact context size is not known for BXT, so assume a page size |
| 6986 | * for this check. |
| 6987 | */ |
| 6988 | rc6_ctx_base = I915_READ(RC6_CTX_BASE) & RC6_CTX_BASE_MASK; |
Matthew Auld | 17a0534 | 2017-12-11 15:18:19 +0000 | [diff] [blame] | 6989 | if (!((rc6_ctx_base >= dev_priv->dsm_reserved.start) && |
| 6990 | (rc6_ctx_base + PAGE_SIZE < dev_priv->dsm_reserved.end))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6991 | DRM_DEBUG_DRIVER("RC6 Base address not as expected.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6992 | enable_rc6 = false; |
| 6993 | } |
| 6994 | |
| 6995 | if (!(((I915_READ(PWRCTX_MAXCNT_RCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6996 | ((I915_READ(PWRCTX_MAXCNT_VCSUNIT0) & IDLE_TIME_MASK) > 1) && |
| 6997 | ((I915_READ(PWRCTX_MAXCNT_BCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6998 | ((I915_READ(PWRCTX_MAXCNT_VECSUNIT) & IDLE_TIME_MASK) > 1))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6999 | DRM_DEBUG_DRIVER("Engine Idle wait time not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7000 | enable_rc6 = false; |
| 7001 | } |
| 7002 | |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 7003 | if (!I915_READ(GEN8_PUSHBUS_CONTROL) || |
| 7004 | !I915_READ(GEN8_PUSHBUS_ENABLE) || |
| 7005 | !I915_READ(GEN8_PUSHBUS_SHIFT)) { |
| 7006 | DRM_DEBUG_DRIVER("Pushbus not setup properly.\n"); |
| 7007 | enable_rc6 = false; |
| 7008 | } |
| 7009 | |
| 7010 | if (!I915_READ(GEN6_GFXPAUSE)) { |
| 7011 | DRM_DEBUG_DRIVER("GFX pause not setup properly.\n"); |
| 7012 | enable_rc6 = false; |
| 7013 | } |
| 7014 | |
| 7015 | if (!I915_READ(GEN8_MISC_CTRL0)) { |
| 7016 | DRM_DEBUG_DRIVER("GPM control not setup properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7017 | enable_rc6 = false; |
| 7018 | } |
| 7019 | |
| 7020 | return enable_rc6; |
| 7021 | } |
| 7022 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7023 | static bool sanitize_rc6(struct drm_i915_private *i915) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7024 | { |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7025 | struct intel_device_info *info = mkwrite_device_info(i915); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7026 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7027 | /* Powersaving is controlled by the host when inside a VM */ |
Chris Wilson | 91cbdb8 | 2019-04-19 14:48:36 +0100 | [diff] [blame] | 7028 | if (intel_vgpu_active(i915)) { |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7029 | info->has_rc6 = 0; |
Chris Wilson | 91cbdb8 | 2019-04-19 14:48:36 +0100 | [diff] [blame] | 7030 | info->has_rps = false; |
| 7031 | } |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7032 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7033 | if (info->has_rc6 && |
| 7034 | IS_GEN9_LP(i915) && !bxt_check_bios_rc6_setup(i915)) { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7035 | DRM_INFO("RC6 disabled by BIOS\n"); |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7036 | info->has_rc6 = 0; |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7037 | } |
| 7038 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7039 | /* |
| 7040 | * We assume that we do not have any deep rc6 levels if we don't have |
| 7041 | * have the previous rc6 level supported, i.e. we use HAS_RC6() |
| 7042 | * as the initial coarse check for rc6 in general, moving on to |
| 7043 | * progressively finer/deeper levels. |
| 7044 | */ |
| 7045 | if (!info->has_rc6 && info->has_rc6p) |
| 7046 | info->has_rc6p = 0; |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7047 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7048 | return info->has_rc6; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7049 | } |
| 7050 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7051 | static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7052 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7053 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7054 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7055 | /* All of these values are in units of 50MHz */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7056 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 7057 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 7058 | if (IS_GEN9_LP(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7059 | u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7060 | rps->rp0_freq = (rp_state_cap >> 16) & 0xff; |
| 7061 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 7062 | rps->min_freq = (rp_state_cap >> 0) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 7063 | } else { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7064 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7065 | rps->rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 7066 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 7067 | rps->min_freq = (rp_state_cap >> 16) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 7068 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7069 | /* hw_max = RP0 until we check for overclocking */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7070 | rps->max_freq = rps->rp0_freq; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7071 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7072 | rps->efficient_freq = rps->rp1_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7073 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) || |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7074 | IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7075 | u32 ddcc_status = 0; |
| 7076 | |
| 7077 | if (sandybridge_pcode_read(dev_priv, |
| 7078 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 7079 | &ddcc_status, NULL) == 0) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7080 | rps->efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 7081 | clamp_t(u8, |
| 7082 | ((ddcc_status >> 8) & 0xff), |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7083 | rps->min_freq, |
| 7084 | rps->max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 7085 | } |
| 7086 | |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7087 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 7088 | /* Store the frequency values in 16.66 MHZ units, which is |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7089 | * the natural hardware unit for SKL |
| 7090 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7091 | rps->rp0_freq *= GEN9_FREQ_SCALER; |
| 7092 | rps->rp1_freq *= GEN9_FREQ_SCALER; |
| 7093 | rps->min_freq *= GEN9_FREQ_SCALER; |
| 7094 | rps->max_freq *= GEN9_FREQ_SCALER; |
| 7095 | rps->efficient_freq *= GEN9_FREQ_SCALER; |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 7096 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7097 | } |
| 7098 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7099 | static void reset_rps(struct drm_i915_private *dev_priv, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 7100 | int (*set)(struct drm_i915_private *, u8)) |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7101 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7102 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7103 | u8 freq = rps->cur_freq; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7104 | |
| 7105 | /* force a reset */ |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 7106 | rps->power.mode = -1; |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7107 | rps->cur_freq = -1; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7108 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 7109 | if (set(dev_priv, freq)) |
| 7110 | DRM_ERROR("Failed to reset RPS to initial values\n"); |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7111 | } |
| 7112 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7113 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7114 | static void gen9_enable_rps(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7115 | { |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7116 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7117 | |
David Weinehall | 36fe778 | 2017-11-17 10:01:46 +0200 | [diff] [blame] | 7118 | /* Program defaults and thresholds for RPS */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7119 | if (IS_GEN(dev_priv, 9)) |
David Weinehall | 36fe778 | 2017-11-17 10:01:46 +0200 | [diff] [blame] | 7120 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 7121 | GEN9_FREQUENCY(dev_priv->gt_pm.rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7122 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 7123 | /* 1 second timeout*/ |
| 7124 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 7125 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 7126 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7127 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7128 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 7129 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 7130 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 7131 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7132 | reset_rps(dev_priv, gen6_set_rps); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7133 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7134 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7135 | } |
| 7136 | |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7137 | static void gen11_enable_rc6(struct drm_i915_private *dev_priv) |
| 7138 | { |
| 7139 | struct intel_engine_cs *engine; |
| 7140 | enum intel_engine_id id; |
| 7141 | |
| 7142 | /* 1a: Software RC state - RC0 */ |
| 7143 | I915_WRITE(GEN6_RC_STATE, 0); |
| 7144 | |
| 7145 | /* |
| 7146 | * 1b: Get forcewake during program sequence. Although the driver |
| 7147 | * hasn't enabled a state yet where we need forcewake, BIOS may have. |
| 7148 | */ |
| 7149 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
| 7150 | |
| 7151 | /* 2a: Disable RC states. */ |
| 7152 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7153 | |
| 7154 | /* 2b: Program RC6 thresholds.*/ |
| 7155 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16 | 85); |
| 7156 | I915_WRITE(GEN10_MEDIA_WAKE_RATE_LIMIT, 150); |
| 7157 | |
| 7158 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7159 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 7160 | for_each_engine(engine, dev_priv, id) |
| 7161 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
| 7162 | |
| 7163 | if (HAS_GUC(dev_priv)) |
| 7164 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 7165 | |
| 7166 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7167 | |
Mika Kuoppala | d105e9a | 2019-04-10 13:59:18 +0300 | [diff] [blame] | 7168 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 7169 | |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7170 | /* |
| 7171 | * 2c: Program Coarse Power Gating Policies. |
| 7172 | * |
| 7173 | * Bspec's guidance is to use 25us (really 25 * 1280ns) here. What we |
| 7174 | * use instead is a more conservative estimate for the maximum time |
| 7175 | * it takes us to service a CS interrupt and submit a new ELSP - that |
| 7176 | * is the time which the GPU is idle waiting for the CPU to select the |
| 7177 | * next request to execute. If the idle hysteresis is less than that |
| 7178 | * interrupt service latency, the hardware will automatically gate |
| 7179 | * the power well and we will then incur the wake up cost on top of |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 7180 | * the service latency. A similar guide from plane_state is that we |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7181 | * do not want the enable hysteresis to less than the wakeup latency. |
| 7182 | * |
| 7183 | * igt/gem_exec_nop/sequential provides a rough estimate for the |
| 7184 | * service latency, and puts it around 10us for Broadwell (and other |
| 7185 | * big core) and around 40us for Broxton (and other low power cores). |
| 7186 | * [Note that for legacy ringbuffer submission, this is less than 1us!] |
| 7187 | * However, the wakeup latency on Broxton is closer to 100us. To be |
| 7188 | * conservative, we have to factor in a context switch on top (due |
| 7189 | * to ksoftirqd). |
| 7190 | */ |
| 7191 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 250); |
| 7192 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 250); |
| 7193 | |
| 7194 | /* 3a: Enable RC6 */ |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7195 | I915_WRITE(GEN6_RC_CONTROL, |
| 7196 | GEN6_RC_CTL_HW_ENABLE | |
| 7197 | GEN6_RC_CTL_RC6_ENABLE | |
| 7198 | GEN6_RC_CTL_EI_MODE(1)); |
| 7199 | |
| 7200 | /* 3b: Enable Coarse Power Gating only when RC6 is enabled. */ |
| 7201 | I915_WRITE(GEN9_PG_ENABLE, |
Mika Kuoppala | 2ea7414 | 2019-04-10 13:59:19 +0300 | [diff] [blame] | 7202 | GEN9_RENDER_PG_ENABLE | |
| 7203 | GEN9_MEDIA_PG_ENABLE | |
| 7204 | GEN11_MEDIA_SAMPLER_PG_ENABLE); |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7205 | |
| 7206 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
| 7207 | } |
| 7208 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7209 | static void gen9_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7210 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7211 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7212 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7213 | u32 rc6_mode; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7214 | |
| 7215 | /* 1a: Software RC state - RC0 */ |
| 7216 | I915_WRITE(GEN6_RC_STATE, 0); |
| 7217 | |
| 7218 | /* 1b: Get forcewake during program sequence. Although the driver |
| 7219 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7220 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7221 | |
| 7222 | /* 2a: Disable RC states. */ |
| 7223 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7224 | |
| 7225 | /* 2b: Program RC6 thresholds.*/ |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7226 | if (INTEL_GEN(dev_priv) >= 10) { |
| 7227 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16 | 85); |
| 7228 | I915_WRITE(GEN10_MEDIA_WAKE_RATE_LIMIT, 150); |
| 7229 | } else if (IS_SKYLAKE(dev_priv)) { |
| 7230 | /* |
| 7231 | * WaRsDoubleRc6WrlWithCoarsePowerGating:skl Doubling WRL only |
| 7232 | * when CPG is enabled |
| 7233 | */ |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 7234 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 108 << 16); |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7235 | } else { |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 7236 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7237 | } |
| 7238 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7239 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7240 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7241 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7242 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 7243 | |
Dave Gordon | 1a3d189 | 2016-05-13 15:36:30 +0100 | [diff] [blame] | 7244 | if (HAS_GUC(dev_priv)) |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 7245 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 7246 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7247 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7248 | |
Chris Wilson | c1beabc | 2018-01-22 13:55:41 +0000 | [diff] [blame] | 7249 | /* |
| 7250 | * 2c: Program Coarse Power Gating Policies. |
| 7251 | * |
| 7252 | * Bspec's guidance is to use 25us (really 25 * 1280ns) here. What we |
| 7253 | * use instead is a more conservative estimate for the maximum time |
| 7254 | * it takes us to service a CS interrupt and submit a new ELSP - that |
| 7255 | * is the time which the GPU is idle waiting for the CPU to select the |
| 7256 | * next request to execute. If the idle hysteresis is less than that |
| 7257 | * interrupt service latency, the hardware will automatically gate |
| 7258 | * the power well and we will then incur the wake up cost on top of |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame^] | 7259 | * the service latency. A similar guide from plane_state is that we |
Chris Wilson | c1beabc | 2018-01-22 13:55:41 +0000 | [diff] [blame] | 7260 | * do not want the enable hysteresis to less than the wakeup latency. |
| 7261 | * |
| 7262 | * igt/gem_exec_nop/sequential provides a rough estimate for the |
| 7263 | * service latency, and puts it around 10us for Broadwell (and other |
| 7264 | * big core) and around 40us for Broxton (and other low power cores). |
| 7265 | * [Note that for legacy ringbuffer submission, this is less than 1us!] |
| 7266 | * However, the wakeup latency on Broxton is closer to 100us. To be |
| 7267 | * conservative, we have to factor in a context switch on top (due |
| 7268 | * to ksoftirqd). |
| 7269 | */ |
| 7270 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 250); |
| 7271 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 250); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 7272 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7273 | /* 3a: Enable RC6 */ |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 7274 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
Rodrigo Vivi | e4ffc83 | 2017-08-22 16:58:28 -0700 | [diff] [blame] | 7275 | |
| 7276 | /* WaRsUseTimeoutMode:cnl (pre-prod) */ |
| 7277 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_C0)) |
| 7278 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
| 7279 | else |
| 7280 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 7281 | |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 7282 | I915_WRITE(GEN6_RC_CONTROL, |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7283 | GEN6_RC_CTL_HW_ENABLE | |
| 7284 | GEN6_RC_CTL_RC6_ENABLE | |
| 7285 | rc6_mode); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7286 | |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 7287 | /* |
| 7288 | * 3b: Enable Coarse Power Gating only when RC6 is enabled. |
Rodrigo Vivi | d66047e4 | 2018-02-22 12:05:35 -0800 | [diff] [blame] | 7289 | * WaRsDisableCoarsePowerGating:skl,cnl - Render/Media PG need to be disabled with RC6. |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 7290 | */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7291 | if (NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 7292 | I915_WRITE(GEN9_PG_ENABLE, 0); |
| 7293 | else |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7294 | I915_WRITE(GEN9_PG_ENABLE, |
| 7295 | GEN9_RENDER_PG_ENABLE | GEN9_MEDIA_PG_ENABLE); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 7296 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7297 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7298 | } |
| 7299 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7300 | static void gen8_enable_rc6(struct drm_i915_private *dev_priv) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7301 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7302 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7303 | enum intel_engine_id id; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7304 | |
| 7305 | /* 1a: Software RC state - RC0 */ |
| 7306 | I915_WRITE(GEN6_RC_STATE, 0); |
| 7307 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7308 | /* 1b: Get forcewake during program sequence. Although the driver |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7309 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7310 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7311 | |
| 7312 | /* 2a: Disable RC states. */ |
| 7313 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7314 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7315 | /* 2b: Program RC6 thresholds.*/ |
| 7316 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 7317 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7318 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7319 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7320 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7321 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Sagar Arun Kamble | 415544d | 2017-10-10 22:30:00 +0100 | [diff] [blame] | 7322 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7323 | |
| 7324 | /* 3: Enable RC6 */ |
Sagar Arun Kamble | 415544d | 2017-10-10 22:30:00 +0100 | [diff] [blame] | 7325 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7326 | I915_WRITE(GEN6_RC_CONTROL, |
| 7327 | GEN6_RC_CTL_HW_ENABLE | |
| 7328 | GEN7_RC_CTL_TO_MODE | |
| 7329 | GEN6_RC_CTL_RC6_ENABLE); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7330 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7331 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | static void gen8_enable_rps(struct drm_i915_private *dev_priv) |
| 7335 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7336 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7337 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7338 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7339 | |
| 7340 | /* 1 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 7341 | I915_WRITE(GEN6_RPNSWREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7342 | HSW_FREQUENCY(rps->rp1_freq)); |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 7343 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7344 | HSW_FREQUENCY(rps->rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7345 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 7346 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7347 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7348 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 7349 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7350 | rps->max_freq_softlimit << 24 | |
| 7351 | rps->min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7352 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7353 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 7354 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 7355 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 7356 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7357 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7358 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7359 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7360 | /* 2: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7361 | I915_WRITE(GEN6_RP_CONTROL, |
| 7362 | GEN6_RP_MEDIA_TURBO | |
| 7363 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7364 | GEN6_RP_MEDIA_IS_GFX | |
| 7365 | GEN6_RP_ENABLE | |
| 7366 | GEN6_RP_UP_BUSY_AVG | |
| 7367 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7368 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7369 | reset_rps(dev_priv, gen6_set_rps); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7370 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7371 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7372 | } |
| 7373 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7374 | static void gen6_enable_rc6(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7375 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7376 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7377 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7378 | u32 rc6vids, rc6_mask; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7379 | u32 gtfifodbg; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 7380 | int ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7381 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7382 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7383 | |
| 7384 | /* Clear the DBG now so we don't confuse earlier errors */ |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7385 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7386 | if (gtfifodbg) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7387 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 7388 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7389 | } |
| 7390 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7391 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7392 | |
| 7393 | /* disable the counters and set deterministic thresholds */ |
| 7394 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7395 | |
| 7396 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 7397 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 7398 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 7399 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 7400 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 7401 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7402 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7403 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7404 | |
| 7405 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7406 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7407 | if (IS_IVYBRIDGE(dev_priv)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 7408 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 7409 | else |
| 7410 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 7411 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7412 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 7413 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 7414 | /* We don't use those on Haswell */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7415 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 7416 | if (HAS_RC6p(dev_priv)) |
| 7417 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
| 7418 | if (HAS_RC6pp(dev_priv)) |
| 7419 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7420 | I915_WRITE(GEN6_RC_CONTROL, |
| 7421 | rc6_mask | |
| 7422 | GEN6_RC_CTL_EI_MODE(1) | |
| 7423 | GEN6_RC_CTL_HW_ENABLE); |
| 7424 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 7425 | rc6vids = 0; |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 7426 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, |
| 7427 | &rc6vids, NULL); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7428 | if (IS_GEN(dev_priv, 6) && ret) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 7429 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7430 | } else if (IS_GEN(dev_priv, 6) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 7431 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 7432 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 7433 | rc6vids &= 0xffff00; |
| 7434 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 7435 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 7436 | if (ret) |
| 7437 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 7438 | } |
| 7439 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7440 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7441 | } |
| 7442 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7443 | static void gen6_enable_rps(struct drm_i915_private *dev_priv) |
| 7444 | { |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7445 | /* Here begins a magic sequence of register writes to enable |
| 7446 | * auto-downclocking. |
| 7447 | * |
| 7448 | * Perhaps there might be some value in exposing these to |
| 7449 | * userspace... |
| 7450 | */ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7451 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7452 | |
| 7453 | /* Power down if completely idle for over 50ms */ |
| 7454 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
| 7455 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7456 | |
| 7457 | reset_rps(dev_priv, gen6_set_rps); |
| 7458 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7459 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7460 | } |
| 7461 | |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7462 | static void gen6_update_ring_freq(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7463 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7464 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Mika Kuoppala | 66c1f77 | 2018-03-20 17:17:33 +0200 | [diff] [blame] | 7465 | const int min_freq = 15; |
| 7466 | const int scaling_factor = 180; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7467 | unsigned int gpu_freq; |
| 7468 | unsigned int max_ia_freq, min_ring_freq; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7469 | unsigned int max_gpu_freq, min_gpu_freq; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7470 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7471 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 7472 | lockdep_assert_held(&rps->lock); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 7473 | |
Mika Kuoppala | 66c1f77 | 2018-03-20 17:17:33 +0200 | [diff] [blame] | 7474 | if (rps->max_freq <= rps->min_freq) |
| 7475 | return; |
| 7476 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7477 | policy = cpufreq_cpu_get(0); |
| 7478 | if (policy) { |
| 7479 | max_ia_freq = policy->cpuinfo.max_freq; |
| 7480 | cpufreq_cpu_put(policy); |
| 7481 | } else { |
| 7482 | /* |
| 7483 | * Default to measured freq if none found, PCU will ensure we |
| 7484 | * don't go over |
| 7485 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7486 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7487 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7488 | |
| 7489 | /* Convert from kHz to MHz */ |
| 7490 | max_ia_freq /= 1000; |
| 7491 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 7492 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 7493 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 7494 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7495 | |
Chris Wilson | d586b5f | 2018-03-08 14:26:48 +0000 | [diff] [blame] | 7496 | min_gpu_freq = rps->min_freq; |
| 7497 | max_gpu_freq = rps->max_freq; |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7498 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7499 | /* Convert GT frequency to 50 HZ units */ |
Chris Wilson | d586b5f | 2018-03-08 14:26:48 +0000 | [diff] [blame] | 7500 | min_gpu_freq /= GEN9_FREQ_SCALER; |
| 7501 | max_gpu_freq /= GEN9_FREQ_SCALER; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7502 | } |
| 7503 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7504 | /* |
| 7505 | * For each potential GPU frequency, load a ring frequency we'd like |
| 7506 | * to use for memory access. We do this by specifying the IA frequency |
| 7507 | * the PCU should use as a reference to determine the ring frequency. |
| 7508 | */ |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7509 | for (gpu_freq = max_gpu_freq; gpu_freq >= min_gpu_freq; gpu_freq--) { |
Mika Kuoppala | 66c1f77 | 2018-03-20 17:17:33 +0200 | [diff] [blame] | 7510 | const int diff = max_gpu_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7511 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7512 | |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7513 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7514 | /* |
| 7515 | * ring_freq = 2 * GT. ring_freq is in 100MHz units |
| 7516 | * No floor required for ring frequency on SKL. |
| 7517 | */ |
| 7518 | ring_freq = gpu_freq; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 7519 | } else if (INTEL_GEN(dev_priv) >= 8) { |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 7520 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 7521 | ring_freq = max(min_ring_freq, gpu_freq); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7522 | } else if (IS_HASWELL(dev_priv)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 7523 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7524 | ring_freq = max(min_ring_freq, ring_freq); |
| 7525 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 7526 | } else { |
| 7527 | /* On older processors, there is no separate ring |
| 7528 | * clock domain, so in order to boost the bandwidth |
| 7529 | * of the ring, we need to upclock the CPU (ia_freq). |
| 7530 | * |
| 7531 | * For GPU frequencies less than 750MHz, |
| 7532 | * just use the lowest ring freq. |
| 7533 | */ |
| 7534 | if (gpu_freq < min_freq) |
| 7535 | ia_freq = 800; |
| 7536 | else |
| 7537 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 7538 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 7539 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7540 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7541 | sandybridge_pcode_write(dev_priv, |
| 7542 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7543 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 7544 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 7545 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7546 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7547 | } |
| 7548 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7549 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7550 | { |
| 7551 | u32 val, rp0; |
| 7552 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7553 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7554 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 7555 | switch (RUNTIME_INFO(dev_priv)->sseu.eu_total) { |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7556 | case 8: |
| 7557 | /* (2 * 4) config */ |
| 7558 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 7559 | break; |
| 7560 | case 12: |
| 7561 | /* (2 * 6) config */ |
| 7562 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 7563 | break; |
| 7564 | case 16: |
| 7565 | /* (2 * 8) config */ |
| 7566 | default: |
| 7567 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 7568 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 7569 | break; |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 7570 | } |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7571 | |
| 7572 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 7573 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7574 | return rp0; |
| 7575 | } |
| 7576 | |
| 7577 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7578 | { |
| 7579 | u32 val, rpe; |
| 7580 | |
| 7581 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 7582 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 7583 | |
| 7584 | return rpe; |
| 7585 | } |
| 7586 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7587 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7588 | { |
| 7589 | u32 val, rp1; |
| 7590 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7591 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 7592 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 7593 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7594 | return rp1; |
| 7595 | } |
| 7596 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 7597 | static u32 cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 7598 | { |
| 7599 | u32 val, rpn; |
| 7600 | |
| 7601 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 7602 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 7603 | FB_GFX_FREQ_FUSE_MASK); |
| 7604 | |
| 7605 | return rpn; |
| 7606 | } |
| 7607 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7608 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7609 | { |
| 7610 | u32 val, rp1; |
| 7611 | |
| 7612 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 7613 | |
| 7614 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 7615 | |
| 7616 | return rp1; |
| 7617 | } |
| 7618 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7619 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7620 | { |
| 7621 | u32 val, rp0; |
| 7622 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7623 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7624 | |
| 7625 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 7626 | /* Clamp to max */ |
| 7627 | rp0 = min_t(u32, rp0, 0xea); |
| 7628 | |
| 7629 | return rp0; |
| 7630 | } |
| 7631 | |
| 7632 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7633 | { |
| 7634 | u32 val, rpe; |
| 7635 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7636 | 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] | 7637 | 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] | 7638 | 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] | 7639 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 7640 | |
| 7641 | return rpe; |
| 7642 | } |
| 7643 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7644 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7645 | { |
Imre Deak | 3614603 | 2014-12-04 18:39:35 +0200 | [diff] [blame] | 7646 | u32 val; |
| 7647 | |
| 7648 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
| 7649 | /* |
| 7650 | * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value |
| 7651 | * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on |
| 7652 | * a BYT-M B0 the above register contains 0xbf. Moreover when setting |
| 7653 | * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0 |
| 7654 | * to make sure it matches what Punit accepts. |
| 7655 | */ |
| 7656 | return max_t(u32, val, 0xc0); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7657 | } |
| 7658 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7659 | /* Check that the pctx buffer wasn't move under us. */ |
| 7660 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 7661 | { |
| 7662 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 7663 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7664 | WARN_ON(pctx_addr != dev_priv->dsm.start + |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7665 | dev_priv->vlv_pctx->stolen->start); |
| 7666 | } |
| 7667 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7668 | |
| 7669 | /* Check that the pcbr address is not empty. */ |
| 7670 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 7671 | { |
| 7672 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 7673 | |
| 7674 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 7675 | } |
| 7676 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7677 | static void cherryview_setup_pctx(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7678 | { |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7679 | resource_size_t pctx_paddr, paddr; |
| 7680 | resource_size_t pctx_size = 32*1024; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7681 | u32 pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7682 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7683 | pcbr = I915_READ(VLV_PCBR); |
| 7684 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7685 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7686 | paddr = dev_priv->dsm.end + 1 - pctx_size; |
| 7687 | GEM_BUG_ON(paddr > U32_MAX); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7688 | |
| 7689 | pctx_paddr = (paddr & (~4095)); |
| 7690 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 7691 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7692 | |
| 7693 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7694 | } |
| 7695 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7696 | static void valleyview_setup_pctx(struct drm_i915_private *dev_priv) |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7697 | { |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7698 | struct drm_i915_gem_object *pctx; |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7699 | resource_size_t pctx_paddr; |
| 7700 | resource_size_t pctx_size = 24*1024; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7701 | u32 pcbr; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7702 | |
| 7703 | pcbr = I915_READ(VLV_PCBR); |
| 7704 | if (pcbr) { |
| 7705 | /* BIOS set it up already, grab the pre-alloc'd space */ |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7706 | resource_size_t pcbr_offset; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7707 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7708 | pcbr_offset = (pcbr & (~4095)) - dev_priv->dsm.start; |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 7709 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7710 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 7711 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7712 | pctx_size); |
| 7713 | goto out; |
| 7714 | } |
| 7715 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7716 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 7717 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7718 | /* |
| 7719 | * From the Gunit register HAS: |
| 7720 | * The Gfx driver is expected to program this register and ensure |
| 7721 | * proper allocation within Gfx stolen memory. For example, this |
| 7722 | * register should be programmed such than the PCBR range does not |
| 7723 | * overlap with other ranges, such as the frame buffer, protected |
| 7724 | * memory, or any other relevant ranges. |
| 7725 | */ |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 7726 | pctx = i915_gem_object_create_stolen(dev_priv, pctx_size); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7727 | if (!pctx) { |
| 7728 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
Tvrtko Ursulin | ee50489 | 2016-02-11 10:27:30 +0000 | [diff] [blame] | 7729 | goto out; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7730 | } |
| 7731 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7732 | GEM_BUG_ON(range_overflows_t(u64, |
| 7733 | dev_priv->dsm.start, |
| 7734 | pctx->stolen->start, |
| 7735 | U32_MAX)); |
| 7736 | pctx_paddr = dev_priv->dsm.start + pctx->stolen->start; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7737 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 7738 | |
| 7739 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7740 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7741 | dev_priv->vlv_pctx = pctx; |
| 7742 | } |
| 7743 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7744 | static void valleyview_cleanup_pctx(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7745 | { |
Chris Wilson | 818fed4 | 2018-07-12 11:54:54 +0100 | [diff] [blame] | 7746 | struct drm_i915_gem_object *pctx; |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7747 | |
Chris Wilson | 818fed4 | 2018-07-12 11:54:54 +0100 | [diff] [blame] | 7748 | pctx = fetch_and_zero(&dev_priv->vlv_pctx); |
| 7749 | if (pctx) |
| 7750 | i915_gem_object_put(pctx); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7751 | } |
| 7752 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7753 | static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv) |
| 7754 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7755 | dev_priv->gt_pm.rps.gpll_ref_freq = |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7756 | vlv_get_cck_clock(dev_priv, "GPLL ref", |
| 7757 | CCK_GPLL_CLOCK_CONTROL, |
| 7758 | dev_priv->czclk_freq); |
| 7759 | |
| 7760 | DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7761 | dev_priv->gt_pm.rps.gpll_ref_freq); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7762 | } |
| 7763 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7764 | static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7765 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7766 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7767 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7768 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7769 | valleyview_setup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7770 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7771 | vlv_iosf_sb_get(dev_priv, |
| 7772 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7773 | BIT(VLV_IOSF_SB_NC) | |
| 7774 | BIT(VLV_IOSF_SB_CCK)); |
| 7775 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7776 | vlv_init_gpll_ref_freq(dev_priv); |
| 7777 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7778 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7779 | switch ((val >> 6) & 3) { |
| 7780 | case 0: |
| 7781 | case 1: |
| 7782 | dev_priv->mem_freq = 800; |
| 7783 | break; |
| 7784 | case 2: |
| 7785 | dev_priv->mem_freq = 1066; |
| 7786 | break; |
| 7787 | case 3: |
| 7788 | dev_priv->mem_freq = 1333; |
| 7789 | break; |
| 7790 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7791 | 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] | 7792 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7793 | rps->max_freq = valleyview_rps_max_freq(dev_priv); |
| 7794 | rps->rp0_freq = rps->max_freq; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7795 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7796 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7797 | rps->max_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7798 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7799 | rps->efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7800 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7801 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7802 | rps->efficient_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7803 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7804 | rps->rp1_freq = valleyview_rps_guar_freq(dev_priv); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7805 | 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] | 7806 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7807 | rps->rp1_freq); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7808 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7809 | rps->min_freq = valleyview_rps_min_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7810 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7811 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7812 | rps->min_freq); |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7813 | |
| 7814 | vlv_iosf_sb_put(dev_priv, |
| 7815 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7816 | BIT(VLV_IOSF_SB_NC) | |
| 7817 | BIT(VLV_IOSF_SB_CCK)); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7818 | } |
| 7819 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7820 | static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7821 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7822 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7823 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7824 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7825 | cherryview_setup_pctx(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7826 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7827 | vlv_iosf_sb_get(dev_priv, |
| 7828 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7829 | BIT(VLV_IOSF_SB_NC) | |
| 7830 | BIT(VLV_IOSF_SB_CCK)); |
| 7831 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7832 | vlv_init_gpll_ref_freq(dev_priv); |
| 7833 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7834 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7835 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7836 | switch ((val >> 2) & 0x7) { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7837 | case 3: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7838 | dev_priv->mem_freq = 2000; |
| 7839 | break; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 7840 | default: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7841 | dev_priv->mem_freq = 1600; |
| 7842 | break; |
| 7843 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7844 | 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] | 7845 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7846 | rps->max_freq = cherryview_rps_max_freq(dev_priv); |
| 7847 | rps->rp0_freq = rps->max_freq; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7848 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7849 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7850 | rps->max_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7851 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7852 | rps->efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7853 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7854 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7855 | rps->efficient_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7856 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7857 | rps->rp1_freq = cherryview_rps_guar_freq(dev_priv); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7858 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7859 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7860 | rps->rp1_freq); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7861 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7862 | rps->min_freq = cherryview_rps_min_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7863 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7864 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7865 | rps->min_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7866 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7867 | vlv_iosf_sb_put(dev_priv, |
| 7868 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7869 | BIT(VLV_IOSF_SB_NC) | |
| 7870 | BIT(VLV_IOSF_SB_CCK)); |
| 7871 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7872 | WARN_ONCE((rps->max_freq | rps->efficient_freq | rps->rp1_freq | |
| 7873 | rps->min_freq) & 1, |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7874 | "Odd GPU freq values\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7875 | } |
| 7876 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7877 | static void valleyview_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7878 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7879 | valleyview_cleanup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7880 | } |
| 7881 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7882 | static void cherryview_enable_rc6(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7883 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7884 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7885 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7886 | u32 gtfifodbg, rc6_mode, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7887 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7888 | gtfifodbg = I915_READ(GTFIFODBG) & ~(GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV | |
| 7889 | GT_FIFO_FREE_ENTRIES_CHV); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7890 | if (gtfifodbg) { |
| 7891 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7892 | gtfifodbg); |
| 7893 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7894 | } |
| 7895 | |
| 7896 | cherryview_check_pctx(dev_priv); |
| 7897 | |
| 7898 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 7899 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7900 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7901 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7902 | /* Disable RC states. */ |
| 7903 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7904 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7905 | /* 2a: Program RC6 thresholds.*/ |
| 7906 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 7907 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7908 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 7909 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7910 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7911 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7912 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7913 | |
Deepak S | f4f71c7 | 2015-03-28 15:23:35 +0530 | [diff] [blame] | 7914 | /* TO threshold set to 500 us ( 0x186 * 1.28 us) */ |
| 7915 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x186); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7916 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7917 | /* Allows RC6 residency counter to work */ |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7918 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 7919 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7920 | VLV_MEDIA_RC6_COUNT_EN | |
| 7921 | VLV_RENDER_RC6_COUNT_EN)); |
| 7922 | |
| 7923 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 7924 | pcbr = I915_READ(VLV_PCBR); |
| 7925 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7926 | /* 3: Enable RC6 */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7927 | rc6_mode = 0; |
| 7928 | if (pcbr >> VLV_PCBR_ADDR_SHIFT) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 7929 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7930 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 7931 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7932 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7933 | } |
| 7934 | |
| 7935 | static void cherryview_enable_rps(struct drm_i915_private *dev_priv) |
| 7936 | { |
| 7937 | u32 val; |
| 7938 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7939 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7940 | |
| 7941 | /* 1: Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 7942 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7943 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7944 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7945 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7946 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7947 | |
| 7948 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7949 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7950 | /* 2: Enable RPS */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7951 | I915_WRITE(GEN6_RP_CONTROL, |
| 7952 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 7953 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7954 | GEN6_RP_ENABLE | |
| 7955 | GEN6_RP_UP_BUSY_AVG | |
| 7956 | GEN6_RP_DOWN_IDLE_AVG); |
| 7957 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7958 | /* Setting Fixed Bias */ |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7959 | vlv_punit_get(dev_priv); |
| 7960 | |
| 7961 | 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] | 7962 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7963 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7964 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7965 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7966 | vlv_punit_put(dev_priv); |
| 7967 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7968 | /* RPS code assumes GPLL is used */ |
| 7969 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7970 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7971 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7972 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7973 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7974 | reset_rps(dev_priv, valleyview_set_rps); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7975 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7976 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7977 | } |
| 7978 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7979 | static void valleyview_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7980 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7981 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7982 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7983 | u32 gtfifodbg; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7984 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7985 | valleyview_check_pctx(dev_priv); |
| 7986 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7987 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7988 | if (gtfifodbg) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 7989 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7990 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7991 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7992 | } |
| 7993 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7994 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7995 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7996 | /* Disable RC states. */ |
| 7997 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7998 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7999 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 8000 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 8001 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 8002 | |
| 8003 | for_each_engine(engine, dev_priv, id) |
| 8004 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
| 8005 | |
| 8006 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
| 8007 | |
| 8008 | /* Allows RC6 residency counter to work */ |
| 8009 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 8010 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 8011 | VLV_MEDIA_RC0_COUNT_EN | |
| 8012 | VLV_RENDER_RC0_COUNT_EN | |
| 8013 | VLV_MEDIA_RC6_COUNT_EN | |
| 8014 | VLV_RENDER_RC6_COUNT_EN)); |
| 8015 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8016 | I915_WRITE(GEN6_RC_CONTROL, |
| 8017 | GEN7_RC_CTL_TO_MODE | VLV_RC_CTL_CTX_RST_PARALLEL); |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 8018 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 8019 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 8020 | } |
| 8021 | |
| 8022 | static void valleyview_enable_rps(struct drm_i915_private *dev_priv) |
| 8023 | { |
| 8024 | u32 val; |
| 8025 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 8026 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 8027 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 8028 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8029 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 8030 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 8031 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 8032 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 8033 | |
| 8034 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 8035 | |
| 8036 | I915_WRITE(GEN6_RP_CONTROL, |
| 8037 | GEN6_RP_MEDIA_TURBO | |
| 8038 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 8039 | GEN6_RP_MEDIA_IS_GFX | |
| 8040 | GEN6_RP_ENABLE | |
| 8041 | GEN6_RP_UP_BUSY_AVG | |
| 8042 | GEN6_RP_DOWN_IDLE_CONT); |
| 8043 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 8044 | vlv_punit_get(dev_priv); |
| 8045 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 8046 | /* Setting Fixed Bias */ |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 8047 | 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] | 8048 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 8049 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 8050 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8051 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 8052 | vlv_punit_put(dev_priv); |
| 8053 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 8054 | /* RPS code assumes GPLL is used */ |
| 8055 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 8056 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 8057 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8058 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 8059 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 8060 | reset_rps(dev_priv, valleyview_set_rps); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8061 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 8062 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8063 | } |
| 8064 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8065 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 8066 | { |
| 8067 | unsigned long freq; |
| 8068 | int div = (vidfreq & 0x3f0000) >> 16; |
| 8069 | int post = (vidfreq & 0x3000) >> 12; |
| 8070 | int pre = (vidfreq & 0x7); |
| 8071 | |
| 8072 | if (!pre) |
| 8073 | return 0; |
| 8074 | |
| 8075 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 8076 | |
| 8077 | return freq; |
| 8078 | } |
| 8079 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8080 | static const struct cparams { |
| 8081 | u16 i; |
| 8082 | u16 t; |
| 8083 | u16 m; |
| 8084 | u16 c; |
| 8085 | } cparams[] = { |
| 8086 | { 1, 1333, 301, 28664 }, |
| 8087 | { 1, 1066, 294, 24460 }, |
| 8088 | { 1, 800, 294, 25192 }, |
| 8089 | { 0, 1333, 276, 27605 }, |
| 8090 | { 0, 1066, 276, 27605 }, |
| 8091 | { 0, 800, 231, 23784 }, |
| 8092 | }; |
| 8093 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8094 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8095 | { |
| 8096 | u64 total_count, diff, ret; |
| 8097 | u32 count1, count2, count3, m = 0, c = 0; |
| 8098 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 8099 | int i; |
| 8100 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 8101 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8102 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8103 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8104 | |
| 8105 | /* Prevent division-by-zero if we are asking too fast. |
| 8106 | * Also, we don't get interesting results if we are polling |
| 8107 | * faster than once in 10ms, so just return the saved value |
| 8108 | * in such cases. |
| 8109 | */ |
| 8110 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8111 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8112 | |
| 8113 | count1 = I915_READ(DMIEC); |
| 8114 | count2 = I915_READ(DDREC); |
| 8115 | count3 = I915_READ(CSIEC); |
| 8116 | |
| 8117 | total_count = count1 + count2 + count3; |
| 8118 | |
| 8119 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8120 | if (total_count < dev_priv->ips.last_count1) { |
| 8121 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8122 | diff += total_count; |
| 8123 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8124 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8125 | } |
| 8126 | |
| 8127 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8128 | if (cparams[i].i == dev_priv->ips.c_m && |
| 8129 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8130 | m = cparams[i].m; |
| 8131 | c = cparams[i].c; |
| 8132 | break; |
| 8133 | } |
| 8134 | } |
| 8135 | |
| 8136 | diff = div_u64(diff, diff1); |
| 8137 | ret = ((m * diff) + c); |
| 8138 | ret = div_u64(ret, 10); |
| 8139 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8140 | dev_priv->ips.last_count1 = total_count; |
| 8141 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8142 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8143 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8144 | |
| 8145 | return ret; |
| 8146 | } |
| 8147 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8148 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 8149 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8150 | intel_wakeref_t wakeref; |
| 8151 | unsigned long val = 0; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8152 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8153 | if (!IS_GEN(dev_priv, 5)) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8154 | return 0; |
| 8155 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 8156 | with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8157 | spin_lock_irq(&mchdev_lock); |
| 8158 | val = __i915_chipset_val(dev_priv); |
| 8159 | spin_unlock_irq(&mchdev_lock); |
| 8160 | } |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8161 | |
| 8162 | return val; |
| 8163 | } |
| 8164 | |
Tvrtko Ursulin | c54f0ba | 2019-06-11 11:45:43 +0100 | [diff] [blame] | 8165 | unsigned long i915_mch_val(struct drm_i915_private *i915) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8166 | { |
| 8167 | unsigned long m, x, b; |
| 8168 | u32 tsfs; |
| 8169 | |
Tvrtko Ursulin | c54f0ba | 2019-06-11 11:45:43 +0100 | [diff] [blame] | 8170 | tsfs = intel_uncore_read(&i915->uncore, TSFS); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8171 | |
| 8172 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
Tvrtko Ursulin | c54f0ba | 2019-06-11 11:45:43 +0100 | [diff] [blame] | 8173 | x = intel_uncore_read8(&i915->uncore, TR1); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8174 | |
| 8175 | b = tsfs & TSFS_INTR_MASK; |
| 8176 | |
| 8177 | return ((m * x) / 127) - b; |
| 8178 | } |
| 8179 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8180 | static int _pxvid_to_vd(u8 pxvid) |
| 8181 | { |
| 8182 | if (pxvid == 0) |
| 8183 | return 0; |
| 8184 | |
| 8185 | if (pxvid >= 8 && pxvid < 31) |
| 8186 | pxvid = 31; |
| 8187 | |
| 8188 | return (pxvid + 2) * 125; |
| 8189 | } |
| 8190 | |
| 8191 | 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] | 8192 | { |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8193 | const int vd = _pxvid_to_vd(pxvid); |
| 8194 | const int vm = vd - 1125; |
| 8195 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8196 | if (INTEL_INFO(dev_priv)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8197 | return vm > 0 ? vm : 0; |
| 8198 | |
| 8199 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8200 | } |
| 8201 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8202 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8203 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 8204 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8205 | u32 count; |
| 8206 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 8207 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8208 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 8209 | now = ktime_get_raw_ns(); |
| 8210 | diffms = now - dev_priv->ips.last_time2; |
| 8211 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8212 | |
| 8213 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8214 | if (!diffms) |
| 8215 | return; |
| 8216 | |
| 8217 | count = I915_READ(GFXEC); |
| 8218 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8219 | if (count < dev_priv->ips.last_count2) { |
| 8220 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8221 | diff += count; |
| 8222 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8223 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8224 | } |
| 8225 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8226 | dev_priv->ips.last_count2 = count; |
| 8227 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8228 | |
| 8229 | /* More magic constants... */ |
| 8230 | diff = diff * 1181; |
| 8231 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8232 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8233 | } |
| 8234 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8235 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 8236 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8237 | intel_wakeref_t wakeref; |
| 8238 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8239 | if (!IS_GEN(dev_priv, 5)) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8240 | return; |
| 8241 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 8242 | with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8243 | spin_lock_irq(&mchdev_lock); |
| 8244 | __i915_update_gfx_val(dev_priv); |
| 8245 | spin_unlock_irq(&mchdev_lock); |
| 8246 | } |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8247 | } |
| 8248 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8249 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8250 | { |
| 8251 | unsigned long t, corr, state1, corr2, state2; |
| 8252 | u32 pxvid, ext_v; |
| 8253 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 8254 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8255 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8256 | pxvid = I915_READ(PXVFREQ(dev_priv->gt_pm.rps.cur_freq)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8257 | pxvid = (pxvid >> 24) & 0x7f; |
| 8258 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 8259 | |
| 8260 | state1 = ext_v; |
| 8261 | |
| 8262 | t = i915_mch_val(dev_priv); |
| 8263 | |
| 8264 | /* Revel in the empirically derived constants */ |
| 8265 | |
| 8266 | /* Correction factor in 1/100000 units */ |
| 8267 | if (t > 80) |
| 8268 | corr = ((t * 2349) + 135940); |
| 8269 | else if (t >= 50) |
| 8270 | corr = ((t * 964) + 29317); |
| 8271 | else /* < 50 */ |
| 8272 | corr = ((t * 301) + 1004); |
| 8273 | |
| 8274 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 8275 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8276 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8277 | |
| 8278 | state2 = (corr2 * state1) / 10000; |
| 8279 | state2 /= 100; /* convert to mW */ |
| 8280 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8281 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8282 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8283 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8284 | } |
| 8285 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8286 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 8287 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8288 | intel_wakeref_t wakeref; |
| 8289 | unsigned long val = 0; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8290 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8291 | if (!IS_GEN(dev_priv, 5)) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8292 | return 0; |
| 8293 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 8294 | with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8295 | spin_lock_irq(&mchdev_lock); |
| 8296 | val = __i915_gfx_val(dev_priv); |
| 8297 | spin_unlock_irq(&mchdev_lock); |
| 8298 | } |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8299 | |
| 8300 | return val; |
| 8301 | } |
| 8302 | |
Chris Wilson | adc674c | 2019-04-12 09:53:22 +0100 | [diff] [blame] | 8303 | static struct drm_i915_private __rcu *i915_mch_dev; |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8304 | |
| 8305 | static struct drm_i915_private *mchdev_get(void) |
| 8306 | { |
| 8307 | struct drm_i915_private *i915; |
| 8308 | |
| 8309 | rcu_read_lock(); |
Chris Wilson | adc674c | 2019-04-12 09:53:22 +0100 | [diff] [blame] | 8310 | i915 = rcu_dereference(i915_mch_dev); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8311 | if (!kref_get_unless_zero(&i915->drm.ref)) |
| 8312 | i915 = NULL; |
| 8313 | rcu_read_unlock(); |
| 8314 | |
| 8315 | return i915; |
| 8316 | } |
| 8317 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8318 | /** |
| 8319 | * i915_read_mch_val - return value for IPS use |
| 8320 | * |
| 8321 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 8322 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 8323 | */ |
| 8324 | unsigned long i915_read_mch_val(void) |
| 8325 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8326 | struct drm_i915_private *i915; |
| 8327 | unsigned long chipset_val = 0; |
| 8328 | unsigned long graphics_val = 0; |
| 8329 | intel_wakeref_t wakeref; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8330 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8331 | i915 = mchdev_get(); |
| 8332 | if (!i915) |
| 8333 | return 0; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8334 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 8335 | with_intel_runtime_pm(&i915->runtime_pm, wakeref) { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8336 | spin_lock_irq(&mchdev_lock); |
| 8337 | chipset_val = __i915_chipset_val(i915); |
| 8338 | graphics_val = __i915_gfx_val(i915); |
| 8339 | spin_unlock_irq(&mchdev_lock); |
| 8340 | } |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8341 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8342 | drm_dev_put(&i915->drm); |
| 8343 | return chipset_val + graphics_val; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8344 | } |
| 8345 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 8346 | |
| 8347 | /** |
| 8348 | * i915_gpu_raise - raise GPU frequency limit |
| 8349 | * |
| 8350 | * Raise the limit; IPS indicates we have thermal headroom. |
| 8351 | */ |
| 8352 | bool i915_gpu_raise(void) |
| 8353 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8354 | struct drm_i915_private *i915; |
| 8355 | |
| 8356 | i915 = mchdev_get(); |
| 8357 | if (!i915) |
| 8358 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8359 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8360 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8361 | if (i915->ips.max_delay > i915->ips.fmax) |
| 8362 | i915->ips.max_delay--; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8363 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8364 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8365 | drm_dev_put(&i915->drm); |
| 8366 | return true; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8367 | } |
| 8368 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 8369 | |
| 8370 | /** |
| 8371 | * i915_gpu_lower - lower GPU frequency limit |
| 8372 | * |
| 8373 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 8374 | * frequency maximum. |
| 8375 | */ |
| 8376 | bool i915_gpu_lower(void) |
| 8377 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8378 | struct drm_i915_private *i915; |
| 8379 | |
| 8380 | i915 = mchdev_get(); |
| 8381 | if (!i915) |
| 8382 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8383 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8384 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8385 | if (i915->ips.max_delay < i915->ips.min_delay) |
| 8386 | i915->ips.max_delay++; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8387 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8388 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8389 | drm_dev_put(&i915->drm); |
| 8390 | return true; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8391 | } |
| 8392 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 8393 | |
| 8394 | /** |
| 8395 | * i915_gpu_busy - indicate GPU business to IPS |
| 8396 | * |
| 8397 | * Tell the IPS driver whether or not the GPU is busy. |
| 8398 | */ |
| 8399 | bool i915_gpu_busy(void) |
| 8400 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8401 | struct drm_i915_private *i915; |
| 8402 | bool ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8403 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8404 | i915 = mchdev_get(); |
| 8405 | if (!i915) |
| 8406 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8407 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8408 | ret = i915->gt.awake; |
| 8409 | |
| 8410 | drm_dev_put(&i915->drm); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8411 | return ret; |
| 8412 | } |
| 8413 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 8414 | |
| 8415 | /** |
| 8416 | * i915_gpu_turbo_disable - disable graphics turbo |
| 8417 | * |
| 8418 | * Disable graphics turbo by resetting the max frequency and setting the |
| 8419 | * current frequency to the default. |
| 8420 | */ |
| 8421 | bool i915_gpu_turbo_disable(void) |
| 8422 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8423 | struct drm_i915_private *i915; |
| 8424 | bool ret; |
| 8425 | |
| 8426 | i915 = mchdev_get(); |
| 8427 | if (!i915) |
| 8428 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8429 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8430 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8431 | i915->ips.max_delay = i915->ips.fstart; |
| 8432 | ret = ironlake_set_drps(i915, i915->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8433 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8434 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8435 | drm_dev_put(&i915->drm); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8436 | return ret; |
| 8437 | } |
| 8438 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 8439 | |
| 8440 | /** |
| 8441 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 8442 | * IPS got loaded first. |
| 8443 | * |
| 8444 | * This awkward dance is so that neither module has to depend on the |
| 8445 | * other in order for IPS to do the appropriate communication of |
| 8446 | * GPU turbo limits to i915. |
| 8447 | */ |
| 8448 | static void |
| 8449 | ips_ping_for_i915_load(void) |
| 8450 | { |
| 8451 | void (*link)(void); |
| 8452 | |
| 8453 | link = symbol_get(ips_link_to_i915_driver); |
| 8454 | if (link) { |
| 8455 | link(); |
| 8456 | symbol_put(ips_link_to_i915_driver); |
| 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 8461 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8462 | /* We only register the i915 ips part with intel-ips once everything is |
| 8463 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8464 | rcu_assign_pointer(i915_mch_dev, dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8465 | |
| 8466 | ips_ping_for_i915_load(); |
| 8467 | } |
| 8468 | |
| 8469 | void intel_gpu_ips_teardown(void) |
| 8470 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8471 | rcu_assign_pointer(i915_mch_dev, NULL); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8472 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 8473 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8474 | static void intel_init_emon(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8475 | { |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8476 | u32 lcfuse; |
| 8477 | u8 pxw[16]; |
| 8478 | int i; |
| 8479 | |
| 8480 | /* Disable to program */ |
| 8481 | I915_WRITE(ECR, 0); |
| 8482 | POSTING_READ(ECR); |
| 8483 | |
| 8484 | /* Program energy weights for various events */ |
| 8485 | I915_WRITE(SDEW, 0x15040d00); |
| 8486 | I915_WRITE(CSIEW0, 0x007f0000); |
| 8487 | I915_WRITE(CSIEW1, 0x1e220004); |
| 8488 | I915_WRITE(CSIEW2, 0x04000004); |
| 8489 | |
| 8490 | for (i = 0; i < 5; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8491 | I915_WRITE(PEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8492 | for (i = 0; i < 3; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8493 | I915_WRITE(DEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8494 | |
| 8495 | /* Program P-state weights to account for frequency power adjustment */ |
| 8496 | for (i = 0; i < 16; i++) { |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8497 | u32 pxvidfreq = I915_READ(PXVFREQ(i)); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8498 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 8499 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 8500 | PXVFREQ_PX_SHIFT; |
| 8501 | unsigned long val; |
| 8502 | |
| 8503 | val = vid * vid; |
| 8504 | val *= (freq / 1000); |
| 8505 | val *= 255; |
| 8506 | val /= (127*127*900); |
| 8507 | if (val > 0xff) |
| 8508 | DRM_ERROR("bad pxval: %ld\n", val); |
| 8509 | pxw[i] = val; |
| 8510 | } |
| 8511 | /* Render standby states get 0 weight */ |
| 8512 | pxw[14] = 0; |
| 8513 | pxw[15] = 0; |
| 8514 | |
| 8515 | for (i = 0; i < 4; i++) { |
| 8516 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 8517 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8518 | I915_WRITE(PXW(i), val); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8519 | } |
| 8520 | |
| 8521 | /* Adjust magic regs to magic values (more experimental results) */ |
| 8522 | I915_WRITE(OGW0, 0); |
| 8523 | I915_WRITE(OGW1, 0); |
| 8524 | I915_WRITE(EG0, 0x00007f00); |
| 8525 | I915_WRITE(EG1, 0x0000000e); |
| 8526 | I915_WRITE(EG2, 0x000e0000); |
| 8527 | I915_WRITE(EG3, 0x68000300); |
| 8528 | I915_WRITE(EG4, 0x42000000); |
| 8529 | I915_WRITE(EG5, 0x00140031); |
| 8530 | I915_WRITE(EG6, 0); |
| 8531 | I915_WRITE(EG7, 0); |
| 8532 | |
| 8533 | for (i = 0; i < 8; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8534 | I915_WRITE(PXWL(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8535 | |
| 8536 | /* Enable PMON + select events */ |
| 8537 | I915_WRITE(ECR, 0x80000019); |
| 8538 | |
| 8539 | lcfuse = I915_READ(LCFUSE02); |
| 8540 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8541 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8542 | } |
| 8543 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8544 | void intel_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8545 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8546 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8547 | |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8548 | /* |
| 8549 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 8550 | * requirement. |
| 8551 | */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8552 | if (!sanitize_rc6(dev_priv)) { |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8553 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 8554 | pm_runtime_get(&dev_priv->drm.pdev->dev); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8555 | } |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 8556 | |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8557 | /* Initialize RPS limits (for userspace) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8558 | if (IS_CHERRYVIEW(dev_priv)) |
| 8559 | cherryview_init_gt_powersave(dev_priv); |
| 8560 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8561 | valleyview_init_gt_powersave(dev_priv); |
Chris Wilson | 2a13ae7 | 2016-08-02 11:15:27 +0100 | [diff] [blame] | 8562 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8563 | gen6_init_rps_frequencies(dev_priv); |
| 8564 | |
| 8565 | /* Derive initial user preferences/limits from the hardware limits */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8566 | rps->max_freq_softlimit = rps->max_freq; |
| 8567 | rps->min_freq_softlimit = rps->min_freq; |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8568 | |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8569 | /* After setting max-softlimit, find the overclock max freq */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8570 | if (IS_GEN(dev_priv, 6) || |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8571 | IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
| 8572 | u32 params = 0; |
| 8573 | |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 8574 | sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, |
| 8575 | ¶ms, NULL); |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8576 | if (params & BIT(31)) { /* OC supported */ |
| 8577 | DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8578 | (rps->max_freq & 0xff) * 50, |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8579 | (params & 0xff) * 50); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8580 | rps->max_freq = params & 0xff; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8581 | } |
| 8582 | } |
| 8583 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 8584 | /* Finally allow us to boost to max by default */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8585 | rps->boost_freq = rps->max_freq; |
Chris Wilson | 844e331 | 2019-04-18 21:53:58 +0100 | [diff] [blame] | 8586 | rps->idle_freq = rps->min_freq; |
| 8587 | rps->cur_freq = rps->idle_freq; |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8588 | } |
| 8589 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8590 | void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8591 | { |
Ville Syrjälä | 8dac1e1 | 2016-08-02 14:07:33 +0300 | [diff] [blame] | 8592 | if (IS_VALLEYVIEW(dev_priv)) |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8593 | valleyview_cleanup_gt_powersave(dev_priv); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8594 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8595 | if (!HAS_RC6(dev_priv)) |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 8596 | pm_runtime_put(&dev_priv->drm.pdev->dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8597 | } |
| 8598 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8599 | void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv) |
| 8600 | { |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8601 | dev_priv->gt_pm.rps.enabled = true; /* force RPS disabling */ |
| 8602 | dev_priv->gt_pm.rc6.enabled = true; /* force RC6 disabling */ |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8603 | intel_disable_gt_powersave(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 8604 | |
Oscar Mateo | d02b98b | 2018-04-05 17:00:50 +0300 | [diff] [blame] | 8605 | if (INTEL_GEN(dev_priv) >= 11) |
| 8606 | gen11_reset_rps_interrupts(dev_priv); |
Chris Wilson | 61e1e37 | 2018-08-12 23:36:30 +0100 | [diff] [blame] | 8607 | else if (INTEL_GEN(dev_priv) >= 6) |
Oscar Mateo | d02b98b | 2018-04-05 17:00:50 +0300 | [diff] [blame] | 8608 | gen6_reset_rps_interrupts(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 8609 | } |
| 8610 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8611 | static inline void intel_disable_llc_pstate(struct drm_i915_private *i915) |
| 8612 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8613 | lockdep_assert_held(&i915->gt_pm.rps.lock); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8614 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8615 | if (!i915->gt_pm.llc_pstate.enabled) |
| 8616 | return; |
| 8617 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8618 | /* Currently there is no HW configuration to be done to disable. */ |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8619 | |
| 8620 | i915->gt_pm.llc_pstate.enabled = false; |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8621 | } |
| 8622 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8623 | static void intel_disable_rc6(struct drm_i915_private *dev_priv) |
| 8624 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8625 | lockdep_assert_held(&dev_priv->gt_pm.rps.lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8626 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8627 | if (!dev_priv->gt_pm.rc6.enabled) |
| 8628 | return; |
| 8629 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8630 | if (INTEL_GEN(dev_priv) >= 9) |
| 8631 | gen9_disable_rc6(dev_priv); |
| 8632 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8633 | cherryview_disable_rc6(dev_priv); |
| 8634 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8635 | valleyview_disable_rc6(dev_priv); |
| 8636 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8637 | gen6_disable_rc6(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8638 | |
| 8639 | dev_priv->gt_pm.rc6.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8640 | } |
| 8641 | |
| 8642 | static void intel_disable_rps(struct drm_i915_private *dev_priv) |
| 8643 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8644 | lockdep_assert_held(&dev_priv->gt_pm.rps.lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8645 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8646 | if (!dev_priv->gt_pm.rps.enabled) |
| 8647 | return; |
| 8648 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8649 | if (INTEL_GEN(dev_priv) >= 9) |
| 8650 | gen9_disable_rps(dev_priv); |
| 8651 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8652 | cherryview_disable_rps(dev_priv); |
| 8653 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8654 | valleyview_disable_rps(dev_priv); |
| 8655 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8656 | gen6_disable_rps(dev_priv); |
| 8657 | else if (IS_IRONLAKE_M(dev_priv)) |
| 8658 | ironlake_disable_drps(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8659 | |
| 8660 | dev_priv->gt_pm.rps.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8661 | } |
| 8662 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8663 | void intel_disable_gt_powersave(struct drm_i915_private *dev_priv) |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 8664 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8665 | mutex_lock(&dev_priv->gt_pm.rps.lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8666 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8667 | intel_disable_rc6(dev_priv); |
| 8668 | intel_disable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8669 | if (HAS_LLC(dev_priv)) |
| 8670 | intel_disable_llc_pstate(dev_priv); |
| 8671 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8672 | mutex_unlock(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8673 | } |
| 8674 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8675 | static inline void intel_enable_llc_pstate(struct drm_i915_private *i915) |
| 8676 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8677 | lockdep_assert_held(&i915->gt_pm.rps.lock); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8678 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8679 | if (i915->gt_pm.llc_pstate.enabled) |
| 8680 | return; |
| 8681 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8682 | gen6_update_ring_freq(i915); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8683 | |
| 8684 | i915->gt_pm.llc_pstate.enabled = true; |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8685 | } |
| 8686 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8687 | static void intel_enable_rc6(struct drm_i915_private *dev_priv) |
| 8688 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8689 | lockdep_assert_held(&dev_priv->gt_pm.rps.lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8690 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8691 | if (dev_priv->gt_pm.rc6.enabled) |
| 8692 | return; |
| 8693 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8694 | if (IS_CHERRYVIEW(dev_priv)) |
| 8695 | cherryview_enable_rc6(dev_priv); |
| 8696 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8697 | valleyview_enable_rc6(dev_priv); |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 8698 | else if (INTEL_GEN(dev_priv) >= 11) |
| 8699 | gen11_enable_rc6(dev_priv); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8700 | else if (INTEL_GEN(dev_priv) >= 9) |
| 8701 | gen9_enable_rc6(dev_priv); |
| 8702 | else if (IS_BROADWELL(dev_priv)) |
| 8703 | gen8_enable_rc6(dev_priv); |
| 8704 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8705 | gen6_enable_rc6(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8706 | |
| 8707 | dev_priv->gt_pm.rc6.enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8708 | } |
| 8709 | |
| 8710 | static void intel_enable_rps(struct drm_i915_private *dev_priv) |
| 8711 | { |
| 8712 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8713 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8714 | lockdep_assert_held(&rps->lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8715 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8716 | if (rps->enabled) |
| 8717 | return; |
| 8718 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8719 | if (IS_CHERRYVIEW(dev_priv)) { |
| 8720 | cherryview_enable_rps(dev_priv); |
| 8721 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 8722 | valleyview_enable_rps(dev_priv); |
| 8723 | } else if (INTEL_GEN(dev_priv) >= 9) { |
| 8724 | gen9_enable_rps(dev_priv); |
| 8725 | } else if (IS_BROADWELL(dev_priv)) { |
| 8726 | gen8_enable_rps(dev_priv); |
| 8727 | } else if (INTEL_GEN(dev_priv) >= 6) { |
| 8728 | gen6_enable_rps(dev_priv); |
| 8729 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 8730 | ironlake_enable_drps(dev_priv); |
| 8731 | intel_init_emon(dev_priv); |
| 8732 | } |
| 8733 | |
| 8734 | WARN_ON(rps->max_freq < rps->min_freq); |
| 8735 | WARN_ON(rps->idle_freq > rps->max_freq); |
| 8736 | |
| 8737 | WARN_ON(rps->efficient_freq < rps->min_freq); |
| 8738 | WARN_ON(rps->efficient_freq > rps->max_freq); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8739 | |
| 8740 | rps->enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8741 | } |
| 8742 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8743 | void intel_enable_gt_powersave(struct drm_i915_private *dev_priv) |
| 8744 | { |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8745 | /* Powersaving is controlled by the host when inside a VM */ |
| 8746 | if (intel_vgpu_active(dev_priv)) |
| 8747 | return; |
| 8748 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8749 | mutex_lock(&dev_priv->gt_pm.rps.lock); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 8750 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8751 | if (HAS_RC6(dev_priv)) |
| 8752 | intel_enable_rc6(dev_priv); |
Chris Wilson | 91cbdb8 | 2019-04-19 14:48:36 +0100 | [diff] [blame] | 8753 | if (HAS_RPS(dev_priv)) |
| 8754 | intel_enable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8755 | if (HAS_LLC(dev_priv)) |
| 8756 | intel_enable_llc_pstate(dev_priv); |
| 8757 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8758 | mutex_unlock(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8759 | } |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 8760 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8761 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8762 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8763 | /* |
| 8764 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8765 | * gating for the panel power sequencer or it will fail to |
| 8766 | * start up when no ports are active. |
| 8767 | */ |
| 8768 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 8769 | } |
| 8770 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8771 | 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] | 8772 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 8773 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8774 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8775 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8776 | I915_WRITE(DSPCNTR(pipe), |
| 8777 | I915_READ(DSPCNTR(pipe)) | |
| 8778 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 8779 | |
| 8780 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 8781 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8782 | } |
| 8783 | } |
| 8784 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8785 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8786 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8787 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8788 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 8789 | /* |
| 8790 | * Required for FBC |
| 8791 | * WaFbcDisableDpfcClockGating:ilk |
| 8792 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8793 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 8794 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 8795 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8796 | |
| 8797 | I915_WRITE(PCH_3DCGDIS0, |
| 8798 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 8799 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 8800 | I915_WRITE(PCH_3DCGDIS1, |
| 8801 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 8802 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8803 | /* |
| 8804 | * According to the spec the following bits should be set in |
| 8805 | * order to enable memory self-refresh |
| 8806 | * The bit 22/21 of 0x42004 |
| 8807 | * The bit 5 of 0x42020 |
| 8808 | * The bit 15 of 0x45000 |
| 8809 | */ |
| 8810 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8811 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8812 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8813 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8814 | I915_WRITE(DISP_ARB_CTL, |
| 8815 | (I915_READ(DISP_ARB_CTL) | |
| 8816 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 8817 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8818 | /* |
| 8819 | * Based on the document from hardware guys the following bits |
| 8820 | * should be set unconditionally in order to enable FBC. |
| 8821 | * The bit 22 of 0x42000 |
| 8822 | * The bit 22 of 0x42004 |
| 8823 | * The bit 7,8,9 of 0x42020. |
| 8824 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8825 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8826 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8827 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8828 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8829 | ILK_FBCQ_DIS); |
| 8830 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8831 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8832 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8833 | } |
| 8834 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8835 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 8836 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8837 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8838 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8839 | ILK_ELPIN_409_SELECT); |
| 8840 | I915_WRITE(_3D_CHICKEN2, |
| 8841 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 8842 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8843 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8844 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8845 | I915_WRITE(CACHE_MODE_0, |
| 8846 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8847 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8848 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 8849 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8850 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8851 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 8852 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8853 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8854 | } |
| 8855 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8856 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8857 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8858 | int pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8859 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8860 | |
| 8861 | /* |
| 8862 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8863 | * gating for the panel power sequencer or it will fail to |
| 8864 | * start up when no ports are active. |
| 8865 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 8866 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 8867 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 8868 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8869 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 8870 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 8871 | /* The below fixes the weird display corruption, a few pixels shifted |
| 8872 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 8873 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8874 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8875 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 8876 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 8877 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8878 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8879 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8880 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 8881 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 8882 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8883 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 8884 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8885 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8886 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8887 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 8888 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 8889 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8890 | } |
| 8891 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8892 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8893 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8894 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8895 | |
| 8896 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 8897 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 8898 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 8899 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8900 | } |
| 8901 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8902 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8903 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8904 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8905 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8906 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8907 | |
| 8908 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8909 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8910 | ILK_ELPIN_409_SELECT); |
| 8911 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8912 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 8913 | I915_WRITE(_3D_CHICKEN, |
| 8914 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 8915 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8916 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 8917 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8918 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8919 | /* |
| 8920 | * BSpec recoomends 8x4 when MSAA is used, |
| 8921 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8922 | * |
| 8923 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8924 | * disable bit, which we don't touch here, but it's good |
| 8925 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8926 | */ |
| 8927 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8928 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8929 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8930 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 8931 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8932 | |
| 8933 | I915_WRITE(GEN6_UCGCTL1, |
| 8934 | I915_READ(GEN6_UCGCTL1) | |
| 8935 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 8936 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 8937 | |
| 8938 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 8939 | * gating disable must be set. Failure to set it results in |
| 8940 | * flickering pixels due to Z write ordering failures after |
| 8941 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 8942 | * Sanctuary and Tropics, and apparently anything else with |
| 8943 | * alpha test or pixel discard. |
| 8944 | * |
| 8945 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 8946 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8947 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 8948 | * WaDisableRCCUnitClockGating:snb |
| 8949 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8950 | */ |
| 8951 | I915_WRITE(GEN6_UCGCTL2, |
| 8952 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 8953 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 8954 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 8955 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 8956 | I915_WRITE(_3D_CHICKEN3, |
| 8957 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8958 | |
| 8959 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 8960 | * Bspec says: |
| 8961 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 8962 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 8963 | */ |
| 8964 | I915_WRITE(_3D_CHICKEN3, |
| 8965 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 8966 | |
| 8967 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8968 | * According to the spec the following bits should be |
| 8969 | * set in order to enable memory self-refresh and fbc: |
| 8970 | * The bit21 and bit22 of 0x42000 |
| 8971 | * The bit21 and bit22 of 0x42004 |
| 8972 | * The bit5 and bit7 of 0x42020 |
| 8973 | * The bit14 of 0x70180 |
| 8974 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8975 | * |
| 8976 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8977 | */ |
| 8978 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8979 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8980 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 8981 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8982 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8983 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8984 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 8985 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 8986 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 8987 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8988 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8989 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 8990 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8991 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8992 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8993 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8994 | } |
| 8995 | |
| 8996 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 8997 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8998 | u32 reg = I915_READ(GEN7_FF_THREAD_MODE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8999 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 9000 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 9001 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 9002 | * |
| 9003 | * This actually overrides the dispatch |
| 9004 | * mode for all thread types. |
| 9005 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9006 | reg &= ~GEN7_FF_SCHED_MASK; |
| 9007 | reg |= GEN7_FF_TS_SCHED_HW; |
| 9008 | reg |= GEN7_FF_VS_SCHED_HW; |
| 9009 | reg |= GEN7_FF_DS_SCHED_HW; |
| 9010 | |
| 9011 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 9012 | } |
| 9013 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9014 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 9015 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 9016 | /* |
| 9017 | * TODO: this bit should only be enabled when really needed, then |
| 9018 | * disabled when not needed anymore in order to save power. |
| 9019 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9020 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 9021 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 9022 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 9023 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 9024 | |
| 9025 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 9026 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 9027 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 9028 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 9029 | } |
| 9030 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 9031 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9032 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9033 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9034 | u32 val = I915_READ(SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9035 | |
| 9036 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9037 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9038 | } |
| 9039 | } |
| 9040 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9041 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 9042 | int general_prio_credits, |
| 9043 | int high_prio_credits) |
| 9044 | { |
| 9045 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 9046 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9047 | |
| 9048 | /* WaTempDisableDOPClkGating:bdw */ |
| 9049 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 9050 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 9051 | |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 9052 | val = I915_READ(GEN8_L3SQCREG1); |
| 9053 | val &= ~L3_PRIO_CREDITS_MASK; |
| 9054 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 9055 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
| 9056 | I915_WRITE(GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9057 | |
| 9058 | /* |
| 9059 | * Wait at least 100 clocks before re-enabling clock gating. |
| 9060 | * See the definition of L3SQCREG1 in BSpec. |
| 9061 | */ |
| 9062 | POSTING_READ(GEN8_L3SQCREG1); |
| 9063 | udelay(1); |
| 9064 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 9065 | } |
| 9066 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 9067 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 9068 | { |
| 9069 | /* This is not an Wa. Enable to reduce Sampler power */ |
| 9070 | I915_WRITE(GEN10_DFR_RATIO_EN_AND_CHICKEN, |
| 9071 | I915_READ(GEN10_DFR_RATIO_EN_AND_CHICKEN) & ~DFR_DISABLE); |
Radhakrishna Sripada | 622b3f6 | 2018-10-30 01:45:01 -0700 | [diff] [blame] | 9072 | |
| 9073 | /* WaEnable32PlaneMode:icl */ |
| 9074 | I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, |
| 9075 | _MASKED_BIT_ENABLE(GEN11_ENABLE_32_PLANE_MODE)); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 9076 | } |
| 9077 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9078 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 9079 | { |
| 9080 | if (!HAS_PCH_CNP(dev_priv)) |
| 9081 | return; |
| 9082 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 9083 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Rodrigo Vivi | 4cc6feb | 2017-09-08 16:45:33 -0700 | [diff] [blame] | 9084 | I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 9085 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9086 | } |
| 9087 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9088 | static void cnl_init_clock_gating(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9089 | { |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 9090 | u32 val; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9091 | cnp_init_clock_gating(dev_priv); |
| 9092 | |
Rodrigo Vivi | 1a25db6 | 2017-08-15 16:16:51 -0700 | [diff] [blame] | 9093 | /* This is not an Wa. Enable for better image quality */ |
| 9094 | I915_WRITE(_3D_CHICKEN3, |
| 9095 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE)); |
| 9096 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9097 | /* WaEnableChickenDCPR:cnl */ |
| 9098 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 9099 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
| 9100 | |
| 9101 | /* WaFbcWakeMemOn:cnl */ |
| 9102 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 9103 | DISP_FBC_MEMORY_WAKE); |
| 9104 | |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 9105 | val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE); |
| 9106 | /* ReadHitWriteOnlyDisable:cnl */ |
| 9107 | val |= RCCUNIT_CLKGATE_DIS; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9108 | /* WaSarbUnitClockGatingDisable:cnl (pre-prod) */ |
| 9109 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 9110 | val |= SARBUNIT_CLKGATE_DIS; |
| 9111 | I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val); |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 9112 | |
Rodrigo Vivi | a4713c5 | 2018-03-07 14:09:12 -0800 | [diff] [blame] | 9113 | /* Wa_2201832410:cnl */ |
| 9114 | val = I915_READ(SUBSLICE_UNIT_LEVEL_CLKGATE); |
| 9115 | val |= GWUNIT_CLKGATE_DIS; |
| 9116 | I915_WRITE(SUBSLICE_UNIT_LEVEL_CLKGATE, val); |
| 9117 | |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 9118 | /* WaDisableVFclkgate:cnl */ |
Rodrigo Vivi | 14941b6 | 2018-03-05 17:20:00 -0800 | [diff] [blame] | 9119 | /* WaVFUnitClockGatingDisable:cnl */ |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 9120 | val = I915_READ(UNSLICE_UNIT_LEVEL_CLKGATE); |
| 9121 | val |= VFUNIT_CLKGATE_DIS; |
| 9122 | I915_WRITE(UNSLICE_UNIT_LEVEL_CLKGATE, val); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9123 | } |
| 9124 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9125 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 9126 | { |
| 9127 | cnp_init_clock_gating(dev_priv); |
| 9128 | gen9_init_clock_gating(dev_priv); |
| 9129 | |
| 9130 | /* WaFbcNukeOnHostModify:cfl */ |
| 9131 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 9132 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 9133 | } |
| 9134 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9135 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9136 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9137 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9138 | |
| 9139 | /* WaDisableSDEUnitClockGating:kbl */ |
| 9140 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 9141 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9142 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 9143 | |
| 9144 | /* WaDisableGamClockGating:kbl */ |
| 9145 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 9146 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 9147 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9148 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9149 | /* WaFbcNukeOnHostModify:kbl */ |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9150 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 9151 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9152 | } |
| 9153 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9154 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 9155 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9156 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 9157 | |
| 9158 | /* WAC6entrylatency:skl */ |
| 9159 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 9160 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9161 | |
| 9162 | /* WaFbcNukeOnHostModify:skl */ |
| 9163 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 9164 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 9165 | } |
| 9166 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9167 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9168 | { |
Matthew Auld | 8cb0983 | 2017-10-06 23:18:23 +0100 | [diff] [blame] | 9169 | /* The GTT cache must be disabled if the system is using 2M pages. */ |
| 9170 | bool can_use_gtt_cache = !HAS_PAGE_SIZES(dev_priv, |
| 9171 | I915_GTT_PAGE_SIZE_2M); |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 9172 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9173 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9174 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 9175 | 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] | 9176 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9177 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 9178 | I915_WRITE(CHICKEN_PAR1_1, |
| 9179 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 9180 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9181 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 9182 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 9183 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 9184 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 9185 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 9186 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 9187 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9188 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 9189 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 9190 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9191 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 9192 | ~(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] | 9193 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 9194 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 9195 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 9196 | |
| 9197 | /* WaDisableSDEUnitClockGating:bdw */ |
| 9198 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9199 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 9200 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9201 | /* WaProgramL3SqcReg1Default:bdw */ |
| 9202 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 9203 | |
Matthew Auld | 8cb0983 | 2017-10-06 23:18:23 +0100 | [diff] [blame] | 9204 | /* WaGttCachingOffByDefault:bdw */ |
| 9205 | I915_WRITE(HSW_GTT_CACHE_EN, can_use_gtt_cache ? GTT_CACHE_EN_ALL : 0); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 9206 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 9207 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 9208 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 9209 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 9210 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9211 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 9212 | |
| 9213 | /* WaDisableDopClockGating:bdw |
| 9214 | * |
| 9215 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 9216 | * clock gating. |
| 9217 | */ |
| 9218 | I915_WRITE(GEN6_UCGCTL1, |
| 9219 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9220 | } |
| 9221 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9222 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9223 | { |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 9224 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 9225 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 9226 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 9227 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 9228 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9229 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9230 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9231 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9232 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9233 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 9234 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 9235 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9236 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9237 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9238 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 9239 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9240 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 9241 | /* enable HiZ Raw Stall Optimization */ |
| 9242 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 9243 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 9244 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9245 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9246 | I915_WRITE(CACHE_MODE_1, |
| 9247 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 9248 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9249 | /* |
| 9250 | * BSpec recommends 8x4 when MSAA is used, |
| 9251 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 9252 | * |
| 9253 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9254 | * disable bit, which we don't touch here, but it's good |
| 9255 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9256 | */ |
| 9257 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 9258 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9259 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 9260 | /* WaSampleCChickenBitEnable:hsw */ |
| 9261 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 9262 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 9263 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9264 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 9265 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 9266 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9267 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9268 | } |
| 9269 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9270 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9271 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9272 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9273 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 9274 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9275 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9276 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 9277 | I915_WRITE(_3D_CHICKEN3, |
| 9278 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 9279 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9280 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9281 | I915_WRITE(IVB_CHICKEN3, |
| 9282 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 9283 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 9284 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9285 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9286 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9287 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 9288 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9289 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9290 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 9291 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9292 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9293 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9294 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 9295 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 9296 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9297 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9298 | I915_WRITE(GEN7_L3CNTLREG1, |
| 9299 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 9300 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9301 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9302 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9303 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9304 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 9305 | else { |
| 9306 | /* must write both registers */ |
| 9307 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9308 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9309 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 9310 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 9311 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9312 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9313 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 9314 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 9315 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 9316 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 9317 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9318 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9319 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9320 | */ |
| 9321 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 9322 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9323 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9324 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9325 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9326 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9327 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9328 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9329 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9330 | |
| 9331 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 9332 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 9333 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 9334 | /* enable HiZ Raw Stall Optimization */ |
| 9335 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 9336 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 9337 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 9338 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9339 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 9340 | I915_WRITE(CACHE_MODE_1, |
| 9341 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 9342 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9343 | /* |
| 9344 | * BSpec recommends 8x4 when MSAA is used, |
| 9345 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 9346 | * |
| 9347 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9348 | * disable bit, which we don't touch here, but it's good |
| 9349 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9350 | */ |
| 9351 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 9352 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9353 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 9354 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 9355 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 9356 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 9357 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 9358 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9359 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9360 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 9361 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9362 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9363 | } |
| 9364 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9365 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9366 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9367 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 9368 | I915_WRITE(_3D_CHICKEN3, |
| 9369 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 9370 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9371 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9372 | I915_WRITE(IVB_CHICKEN3, |
| 9373 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 9374 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 9375 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 9376 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9377 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9378 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 9379 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 9380 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9381 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9382 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 9383 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9384 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9385 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 9386 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 9387 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 9388 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9389 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9390 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9391 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 9392 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9393 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9394 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9395 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9396 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9397 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 9398 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 9399 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 9400 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9401 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9402 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9403 | */ |
| 9404 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 9405 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9406 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 9407 | /* WaDisableL3Bank2xClockGate:vlv |
| 9408 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 9409 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 9410 | I915_WRITE(GEN7_UCGCTL4, |
| 9411 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 9412 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 9413 | /* |
| 9414 | * BSpec says this must be set, even though |
| 9415 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 9416 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 9417 | I915_WRITE(CACHE_MODE_1, |
| 9418 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 9419 | |
| 9420 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 9421 | * BSpec recommends 8x4 when MSAA is used, |
| 9422 | * however in practice 16x4 seems fastest. |
| 9423 | * |
| 9424 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9425 | * disable bit, which we don't touch here, but it's good |
| 9426 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 9427 | */ |
| 9428 | I915_WRITE(GEN7_GT_MODE, |
| 9429 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 9430 | |
| 9431 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 9432 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 9433 | * This is the hardware default actually. |
| 9434 | */ |
| 9435 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 9436 | |
| 9437 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9438 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 9439 | * Disable clock gating on th GCFG unit to prevent a delay |
| 9440 | * in the reporting of vblank events. |
| 9441 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 9442 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9443 | } |
| 9444 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9445 | 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] | 9446 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 9447 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 9448 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 9449 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9450 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 9451 | ~(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] | 9452 | |
| 9453 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 9454 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 9455 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 9456 | |
| 9457 | /* WaDisableCSUnitClockGating:chv */ |
| 9458 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 9459 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 9460 | |
| 9461 | /* WaDisableSDEUnitClockGating:chv */ |
| 9462 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9463 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 9464 | |
| 9465 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9466 | * WaProgramL3SqcReg1Default:chv |
| 9467 | * See gfxspecs/Related Documents/Performance Guide/ |
| 9468 | * LSQC Setting Recommendations. |
| 9469 | */ |
| 9470 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
| 9471 | |
| 9472 | /* |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 9473 | * GTT cache may not work with big pages, so if those |
| 9474 | * are ever enabled GTT cache may need to be disabled. |
| 9475 | */ |
| 9476 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 9477 | } |
| 9478 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9479 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9480 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9481 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9482 | |
| 9483 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 9484 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 9485 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 9486 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 9487 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 9488 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 9489 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 9490 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9491 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9492 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 9493 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 9494 | |
| 9495 | /* WaDisableRenderCachePipelinedFlush */ |
| 9496 | I915_WRITE(CACHE_MODE_0, |
| 9497 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 9498 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9499 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 9500 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9501 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9502 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9503 | } |
| 9504 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9505 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9506 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 9507 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 9508 | |
| 9509 | intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 9510 | intel_uncore_write(uncore, RENCLK_GATE_D2, 0); |
| 9511 | intel_uncore_write(uncore, DSPCLK_GATE_D, 0); |
| 9512 | intel_uncore_write(uncore, RAMCLK_GATE_D, 0); |
| 9513 | intel_uncore_write16(uncore, DEUC, 0); |
| 9514 | intel_uncore_write(uncore, |
| 9515 | MI_ARB_STATE, |
| 9516 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9517 | |
| 9518 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 9519 | intel_uncore_write(uncore, |
| 9520 | CACHE_MODE_0, |
| 9521 | _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9522 | } |
| 9523 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9524 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9525 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9526 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 9527 | I965_RCC_CLOCK_GATE_DISABLE | |
| 9528 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 9529 | I965_ISC_CLOCK_GATE_DISABLE | |
| 9530 | I965_FBC_CLOCK_GATE_DISABLE); |
| 9531 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 9532 | I915_WRITE(MI_ARB_STATE, |
| 9533 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9534 | |
| 9535 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 9536 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9537 | } |
| 9538 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9539 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9540 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9541 | u32 dstate = I915_READ(D_STATE); |
| 9542 | |
| 9543 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 9544 | DSTATE_DOT_CLOCK_GATING; |
| 9545 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 9546 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9547 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 9548 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 9549 | |
| 9550 | /* IIR "flip pending" means done if this bit is set */ |
| 9551 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 9552 | |
| 9553 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 9554 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 9555 | |
| 9556 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 9557 | 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] | 9558 | |
| 9559 | I915_WRITE(MI_ARB_STATE, |
| 9560 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9561 | } |
| 9562 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9563 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9564 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9565 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 9566 | |
| 9567 | /* interrupts should cause a wake up from C3 */ |
| 9568 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 9569 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 9570 | |
| 9571 | I915_WRITE(MEM_MODE, |
| 9572 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9573 | } |
| 9574 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9575 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9576 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 9577 | I915_WRITE(MEM_MODE, |
| 9578 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 9579 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9580 | } |
| 9581 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9582 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9583 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9584 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9585 | } |
| 9586 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 9587 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9588 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 9589 | if (HAS_PCH_LPT(dev_priv)) |
| 9590 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9591 | } |
| 9592 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9593 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9594 | { |
| 9595 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 9596 | } |
| 9597 | |
| 9598 | /** |
| 9599 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 9600 | * @dev_priv: device private |
| 9601 | * |
| 9602 | * Setup the hooks that configure which clocks of a given platform can be |
| 9603 | * gated and also apply various GT and display specific workarounds for these |
| 9604 | * platforms. Note that some GT specific workarounds are applied separately |
| 9605 | * when GPU contexts or batchbuffers start their execution. |
| 9606 | */ |
| 9607 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 9608 | { |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 9609 | if (IS_GEN(dev_priv, 11)) |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 9610 | dev_priv->display.init_clock_gating = icl_init_clock_gating; |
Oscar Mateo | cc38cae | 2018-05-08 14:29:23 -0700 | [diff] [blame] | 9611 | else if (IS_CANNONLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9612 | dev_priv->display.init_clock_gating = cnl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9613 | else if (IS_COFFEELAKE(dev_priv)) |
| 9614 | dev_priv->display.init_clock_gating = cfl_init_clock_gating; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9615 | else if (IS_SKYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9616 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9617 | else if (IS_KABYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9618 | dev_priv->display.init_clock_gating = kbl_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 9619 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9620 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 9621 | else if (IS_GEMINILAKE(dev_priv)) |
| 9622 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9623 | else if (IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9624 | dev_priv->display.init_clock_gating = bdw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9625 | else if (IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9626 | dev_priv->display.init_clock_gating = chv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9627 | else if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9628 | dev_priv->display.init_clock_gating = hsw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9629 | else if (IS_IVYBRIDGE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9630 | dev_priv->display.init_clock_gating = ivb_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9631 | else if (IS_VALLEYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9632 | dev_priv->display.init_clock_gating = vlv_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9633 | else if (IS_GEN(dev_priv, 6)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9634 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9635 | else if (IS_GEN(dev_priv, 5)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9636 | dev_priv->display.init_clock_gating = ilk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9637 | else if (IS_G4X(dev_priv)) |
| 9638 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 9639 | else if (IS_I965GM(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9640 | dev_priv->display.init_clock_gating = i965gm_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 9641 | else if (IS_I965G(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9642 | dev_priv->display.init_clock_gating = i965g_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9643 | else if (IS_GEN(dev_priv, 3)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9644 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 9645 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 9646 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9647 | else if (IS_GEN(dev_priv, 2)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9648 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 9649 | else { |
| 9650 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 9651 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 9652 | } |
| 9653 | } |
| 9654 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9655 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9656 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9657 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 9658 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9659 | if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 9660 | i915_pineview_get_mem_freq(dev_priv); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9661 | else if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 9662 | i915_ironlake_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 9663 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9664 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9665 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9666 | skl_setup_wm_latency(dev_priv); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 9667 | dev_priv->display.initial_watermarks = skl_initial_wm; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 9668 | dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 9669 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9670 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9671 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 9672 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9673 | 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] | 9674 | 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] | 9675 | (!IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9676 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 9677 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 9678 | dev_priv->display.compute_intermediate_wm = |
| 9679 | ilk_compute_intermediate_wm; |
| 9680 | dev_priv->display.initial_watermarks = |
| 9681 | ilk_initial_watermarks; |
| 9682 | dev_priv->display.optimize_watermarks = |
| 9683 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9684 | } else { |
| 9685 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 9686 | "Disable CxSR\n"); |
| 9687 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 9688 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9689 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9690 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 9691 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9692 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 9693 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9694 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 9695 | } else if (IS_G4X(dev_priv)) { |
| 9696 | g4x_setup_wm_latency(dev_priv); |
| 9697 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 9698 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 9699 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 9700 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9701 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 9702 | if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9703 | dev_priv->is_ddr3, |
| 9704 | dev_priv->fsb_freq, |
| 9705 | dev_priv->mem_freq)) { |
| 9706 | DRM_INFO("failed to find known CxSR latency " |
| 9707 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 9708 | "disabling CxSR\n", |
| 9709 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 9710 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 9711 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 9712 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9713 | dev_priv->display.update_wm = NULL; |
| 9714 | } else |
| 9715 | dev_priv->display.update_wm = pineview_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9716 | } else if (IS_GEN(dev_priv, 4)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9717 | dev_priv->display.update_wm = i965_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9718 | } else if (IS_GEN(dev_priv, 3)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9719 | dev_priv->display.update_wm = i9xx_update_wm; |
| 9720 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9721 | } else if (IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9722 | if (INTEL_INFO(dev_priv)->num_pipes == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9723 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9724 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9725 | } else { |
| 9726 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9727 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9728 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9729 | } else { |
| 9730 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9731 | } |
| 9732 | } |
| 9733 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 9734 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9735 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9736 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9737 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9738 | /* |
| 9739 | * N = val - 0xb7 |
| 9740 | * Slow = Fast = GPLL ref * N |
| 9741 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9742 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * (val - 0xb7), 1000); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 9743 | } |
| 9744 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9745 | 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] | 9746 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9747 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9748 | |
| 9749 | return DIV_ROUND_CLOSEST(1000 * val, rps->gpll_ref_freq) + 0xb7; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 9750 | } |
| 9751 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9752 | 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] | 9753 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9754 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9755 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9756 | /* |
| 9757 | * N = val / 2 |
| 9758 | * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2 |
| 9759 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9760 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * val, 2 * 2 * 1000); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9761 | } |
| 9762 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9763 | 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] | 9764 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9765 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9766 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 9767 | /* CHV needs even values */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9768 | return DIV_ROUND_CLOSEST(2 * 1000 * val, rps->gpll_ref_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9769 | } |
| 9770 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9771 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9772 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 9773 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9774 | return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, |
| 9775 | GEN9_FREQ_SCALER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9776 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9777 | return chv_gpu_freq(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9778 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9779 | return byt_gpu_freq(dev_priv, val); |
| 9780 | else |
| 9781 | return val * GT_FREQUENCY_MULTIPLIER; |
| 9782 | } |
| 9783 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9784 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 9785 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 9786 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9787 | return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, |
| 9788 | GT_FREQUENCY_MULTIPLIER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9789 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9790 | return chv_freq_opcode(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9791 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9792 | return byt_freq_opcode(dev_priv, val); |
| 9793 | else |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9794 | return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9795 | } |
| 9796 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 9797 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9798 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 9799 | mutex_init(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 9800 | mutex_init(&dev_priv->gt_pm.rps.power.mutex); |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9801 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9802 | atomic_set(&dev_priv->gt_pm.rps.num_waiters, 0); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 9803 | |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 9804 | dev_priv->runtime_pm.suspended = false; |
| 9805 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9806 | } |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9807 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9808 | static u64 vlv_residency_raw(struct drm_i915_private *dev_priv, |
| 9809 | const i915_reg_t reg) |
| 9810 | { |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9811 | u32 lower, upper, tmp; |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9812 | int loop = 2; |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9813 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9814 | /* |
| 9815 | * The register accessed do not need forcewake. We borrow |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9816 | * uncore lock to prevent concurrent access to range reg. |
| 9817 | */ |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9818 | lockdep_assert_held(&dev_priv->uncore.lock); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9819 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9820 | /* |
| 9821 | * vlv and chv residency counters are 40 bits in width. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9822 | * With a control bit, we can choose between upper or lower |
| 9823 | * 32bit window into this counter. |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9824 | * |
| 9825 | * Although we always use the counter in high-range mode elsewhere, |
| 9826 | * userspace may attempt to read the value before rc6 is initialised, |
| 9827 | * before we have set the default VLV_COUNTER_CONTROL value. So always |
| 9828 | * set the high bit to be safe. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9829 | */ |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9830 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9831 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9832 | upper = I915_READ_FW(reg); |
| 9833 | do { |
| 9834 | tmp = upper; |
| 9835 | |
| 9836 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9837 | _MASKED_BIT_DISABLE(VLV_COUNT_RANGE_HIGH)); |
| 9838 | lower = I915_READ_FW(reg); |
| 9839 | |
| 9840 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9841 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
| 9842 | upper = I915_READ_FW(reg); |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9843 | } while (upper != tmp && --loop); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9844 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9845 | /* |
| 9846 | * Everywhere else we always use VLV_COUNTER_CONTROL with the |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9847 | * VLV_COUNT_RANGE_HIGH bit set - so it is safe to leave it set |
| 9848 | * now. |
| 9849 | */ |
| 9850 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9851 | return lower | (u64)upper << 8; |
| 9852 | } |
| 9853 | |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9854 | u64 intel_rc6_residency_ns(struct drm_i915_private *dev_priv, |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9855 | const i915_reg_t reg) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9856 | { |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9857 | struct intel_uncore *uncore = &dev_priv->uncore; |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9858 | u64 time_hw, prev_hw, overflow_hw; |
| 9859 | unsigned int fw_domains; |
| 9860 | unsigned long flags; |
| 9861 | unsigned int i; |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9862 | u32 mul, div; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9863 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 9864 | if (!HAS_RC6(dev_priv)) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9865 | return 0; |
| 9866 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9867 | /* |
| 9868 | * Store previous hw counter values for counter wrap-around handling. |
| 9869 | * |
| 9870 | * There are only four interesting registers and they live next to each |
| 9871 | * other so we can use the relative address, compared to the smallest |
| 9872 | * one as the index into driver storage. |
| 9873 | */ |
| 9874 | i = (i915_mmio_reg_offset(reg) - |
| 9875 | i915_mmio_reg_offset(GEN6_GT_GFX_RC6_LOCKED)) / sizeof(u32); |
| 9876 | if (WARN_ON_ONCE(i >= ARRAY_SIZE(dev_priv->gt_pm.rc6.cur_residency))) |
| 9877 | return 0; |
| 9878 | |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9879 | fw_domains = intel_uncore_forcewake_for_reg(uncore, reg, FW_REG_READ); |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9880 | |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9881 | spin_lock_irqsave(&uncore->lock, flags); |
| 9882 | intel_uncore_forcewake_get__locked(uncore, fw_domains); |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9883 | |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9884 | /* On VLV and CHV, residency time is in CZ units rather than 1.28us */ |
| 9885 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9886 | mul = 1000000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9887 | div = dev_priv->czclk_freq; |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9888 | overflow_hw = BIT_ULL(40); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9889 | time_hw = vlv_residency_raw(dev_priv, reg); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9890 | } else { |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9891 | /* 833.33ns units on Gen9LP, 1.28us elsewhere. */ |
| 9892 | if (IS_GEN9_LP(dev_priv)) { |
| 9893 | mul = 10000; |
| 9894 | div = 12; |
| 9895 | } else { |
| 9896 | mul = 1280; |
| 9897 | div = 1; |
| 9898 | } |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9899 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9900 | overflow_hw = BIT_ULL(32); |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9901 | time_hw = intel_uncore_read_fw(uncore, reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9902 | } |
| 9903 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9904 | /* |
| 9905 | * Counter wrap handling. |
| 9906 | * |
| 9907 | * But relying on a sufficient frequency of queries otherwise counters |
| 9908 | * can still wrap. |
| 9909 | */ |
| 9910 | prev_hw = dev_priv->gt_pm.rc6.prev_hw_residency[i]; |
| 9911 | dev_priv->gt_pm.rc6.prev_hw_residency[i] = time_hw; |
| 9912 | |
| 9913 | /* RC6 delta from last sample. */ |
| 9914 | if (time_hw >= prev_hw) |
| 9915 | time_hw -= prev_hw; |
| 9916 | else |
| 9917 | time_hw += overflow_hw - prev_hw; |
| 9918 | |
| 9919 | /* Add delta to RC6 extended raw driver copy. */ |
| 9920 | time_hw += dev_priv->gt_pm.rc6.cur_residency[i]; |
| 9921 | dev_priv->gt_pm.rc6.cur_residency[i] = time_hw; |
| 9922 | |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9923 | intel_uncore_forcewake_put__locked(uncore, fw_domains); |
| 9924 | spin_unlock_irqrestore(&uncore->lock, flags); |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9925 | |
| 9926 | return mul_u64_u32_div(time_hw, mul, div); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9927 | } |
Tvrtko Ursulin | c84b270 | 2017-11-21 18:18:44 +0000 | [diff] [blame] | 9928 | |
Jani Nikula | ecbb5fb | 2019-04-29 15:29:37 +0300 | [diff] [blame] | 9929 | u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv, |
| 9930 | i915_reg_t reg) |
| 9931 | { |
| 9932 | return DIV_ROUND_UP_ULL(intel_rc6_residency_ns(dev_priv, reg), 1000); |
| 9933 | } |
| 9934 | |
Tvrtko Ursulin | c84b270 | 2017-11-21 18:18:44 +0000 | [diff] [blame] | 9935 | u32 intel_get_cagf(struct drm_i915_private *dev_priv, u32 rpstat) |
| 9936 | { |
| 9937 | u32 cagf; |
| 9938 | |
| 9939 | if (INTEL_GEN(dev_priv) >= 9) |
| 9940 | cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT; |
| 9941 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 9942 | cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT; |
| 9943 | else |
| 9944 | cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT; |
| 9945 | |
| 9946 | return cagf; |
| 9947 | } |