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 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 36 | #include "i915_drv.h" |
Jani Nikula | 440e2b3 | 2019-04-29 15:29:27 +0300 | [diff] [blame] | 37 | #include "i915_irq.h" |
Jani Nikula | 12392a7 | 2019-04-29 15:53:31 +0300 | [diff] [blame] | 38 | #include "intel_atomic.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 39 | #include "intel_drv.h" |
Jani Nikula | 98afa31 | 2019-04-05 14:00:08 +0300 | [diff] [blame] | 40 | #include "intel_fbc.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 41 | #include "intel_pm.h" |
Jani Nikula | f9a79f9 | 2019-04-05 14:00:24 +0300 | [diff] [blame] | 42 | #include "intel_sprite.h" |
Chris Wilson | 56c5098 | 2019-04-26 09:17:22 +0100 | [diff] [blame] | 43 | #include "intel_sideband.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 44 | #include "../../../platform/x86/intel_ips.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 45 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 46 | /** |
Jani Nikula | 18afd44 | 2016-01-18 09:19:48 +0200 | [diff] [blame] | 47 | * DOC: RC6 |
| 48 | * |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 49 | * RC6 is a special power stage which allows the GPU to enter an very |
| 50 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 51 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 52 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 53 | * |
| 54 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 55 | * among each other with the latency required to enter and leave RC6 and |
| 56 | * voltage consumed by the GPU in different states. |
| 57 | * |
| 58 | * The combination of the following flags define which states GPU is allowed |
| 59 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 60 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 61 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 62 | * which brings the most power savings; deeper states save more power, but |
| 63 | * require higher latency to switch to and wake up. |
| 64 | */ |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 65 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 66 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 67 | { |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 68 | if (HAS_LLC(dev_priv)) { |
| 69 | /* |
| 70 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
Lucas De Marchi | e0403cb | 2017-12-05 11:01:17 -0800 | [diff] [blame] | 71 | * Display WA #0390: skl,kbl |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 72 | * |
| 73 | * Must match Sampler, Pixel Back End, and Media. See |
| 74 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 75 | */ |
| 76 | I915_WRITE(CHICKEN_PAR1_1, |
| 77 | I915_READ(CHICKEN_PAR1_1) | |
| 78 | SKL_DE_COMPRESSED_HASH_MODE); |
| 79 | } |
| 80 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 81 | /* 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] | 82 | I915_WRITE(CHICKEN_PAR1_1, |
| 83 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 84 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 85 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 86 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 87 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 88 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 89 | /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl,cfl */ |
| 90 | /* WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 91 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 92 | DISP_FBC_WM_DIS | |
| 93 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 94 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 95 | /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl,cfl */ |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 96 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 97 | ILK_DPFC_DISABLE_DUMMY0); |
Praveen Paneri | 32087d1 | 2017-08-03 23:02:10 +0530 | [diff] [blame] | 98 | |
| 99 | if (IS_SKYLAKE(dev_priv)) { |
| 100 | /* WaDisableDopClockGating */ |
| 101 | I915_WRITE(GEN7_MISCCPCTL, I915_READ(GEN7_MISCCPCTL) |
| 102 | & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 103 | } |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 104 | } |
| 105 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 106 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 107 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 108 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 109 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 110 | /* WaDisableSDEUnitClockGating:bxt */ |
| 111 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 112 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 113 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 114 | /* |
| 115 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 116 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 117 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 118 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 119 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 123 | * to stay fully on. |
| 124 | */ |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 125 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 126 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 129 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 130 | { |
| 131 | gen9_init_clock_gating(dev_priv); |
| 132 | |
| 133 | /* |
| 134 | * WaDisablePWMClockGating:glk |
| 135 | * Backlight PWM may stop in the asserted state, causing backlight |
| 136 | * to stay fully on. |
| 137 | */ |
| 138 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 139 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Ander Conselvan de Oliveira | f4f4b59 | 2017-02-22 08:34:29 +0200 | [diff] [blame] | 140 | |
| 141 | /* WaDDIIOTimeout:glk */ |
| 142 | if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1)) { |
| 143 | u32 val = I915_READ(CHICKEN_MISC_2); |
| 144 | val &= ~(GLK_CL0_PWR_DOWN | |
| 145 | GLK_CL1_PWR_DOWN | |
| 146 | GLK_CL2_PWR_DOWN); |
| 147 | I915_WRITE(CHICKEN_MISC_2, val); |
| 148 | } |
| 149 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 152 | 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] | 153 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 154 | u32 tmp; |
| 155 | |
| 156 | tmp = I915_READ(CLKCFG); |
| 157 | |
| 158 | switch (tmp & CLKCFG_FSB_MASK) { |
| 159 | case CLKCFG_FSB_533: |
| 160 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 161 | break; |
| 162 | case CLKCFG_FSB_800: |
| 163 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 164 | break; |
| 165 | case CLKCFG_FSB_667: |
| 166 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 167 | break; |
| 168 | case CLKCFG_FSB_400: |
| 169 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | switch (tmp & CLKCFG_MEM_MASK) { |
| 174 | case CLKCFG_MEM_533: |
| 175 | dev_priv->mem_freq = 533; |
| 176 | break; |
| 177 | case CLKCFG_MEM_667: |
| 178 | dev_priv->mem_freq = 667; |
| 179 | break; |
| 180 | case CLKCFG_MEM_800: |
| 181 | dev_priv->mem_freq = 800; |
| 182 | break; |
| 183 | } |
| 184 | |
| 185 | /* detect pineview DDR3 setting */ |
| 186 | tmp = I915_READ(CSHRDDR3CTL); |
| 187 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 188 | } |
| 189 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 190 | 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] | 191 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 192 | u16 ddrpll, csipll; |
| 193 | |
| 194 | ddrpll = I915_READ16(DDRMPLL1); |
| 195 | csipll = I915_READ16(CSIPLL0); |
| 196 | |
| 197 | switch (ddrpll & 0xff) { |
| 198 | case 0xc: |
| 199 | dev_priv->mem_freq = 800; |
| 200 | break; |
| 201 | case 0x10: |
| 202 | dev_priv->mem_freq = 1066; |
| 203 | break; |
| 204 | case 0x14: |
| 205 | dev_priv->mem_freq = 1333; |
| 206 | break; |
| 207 | case 0x18: |
| 208 | dev_priv->mem_freq = 1600; |
| 209 | break; |
| 210 | default: |
| 211 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 212 | ddrpll & 0xff); |
| 213 | dev_priv->mem_freq = 0; |
| 214 | break; |
| 215 | } |
| 216 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 217 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 218 | |
| 219 | switch (csipll & 0x3ff) { |
| 220 | case 0x00c: |
| 221 | dev_priv->fsb_freq = 3200; |
| 222 | break; |
| 223 | case 0x00e: |
| 224 | dev_priv->fsb_freq = 3733; |
| 225 | break; |
| 226 | case 0x010: |
| 227 | dev_priv->fsb_freq = 4266; |
| 228 | break; |
| 229 | case 0x012: |
| 230 | dev_priv->fsb_freq = 4800; |
| 231 | break; |
| 232 | case 0x014: |
| 233 | dev_priv->fsb_freq = 5333; |
| 234 | break; |
| 235 | case 0x016: |
| 236 | dev_priv->fsb_freq = 5866; |
| 237 | break; |
| 238 | case 0x018: |
| 239 | dev_priv->fsb_freq = 6400; |
| 240 | break; |
| 241 | default: |
| 242 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 243 | csipll & 0x3ff); |
| 244 | dev_priv->fsb_freq = 0; |
| 245 | break; |
| 246 | } |
| 247 | |
| 248 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 249 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 250 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 251 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 252 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 253 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 257 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 258 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 259 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 260 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 261 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 262 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 263 | |
| 264 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 265 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 266 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 267 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 268 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 269 | |
| 270 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 271 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 272 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 273 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 274 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 275 | |
| 276 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 277 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 278 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 279 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 280 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 281 | |
| 282 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 283 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 284 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 285 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 286 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 287 | |
| 288 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 289 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 290 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 291 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 292 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 293 | }; |
| 294 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 295 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 296 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 297 | int fsb, |
| 298 | int mem) |
| 299 | { |
| 300 | const struct cxsr_latency *latency; |
| 301 | int i; |
| 302 | |
| 303 | if (fsb == 0 || mem == 0) |
| 304 | return NULL; |
| 305 | |
| 306 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 307 | latency = &cxsr_latency_table[i]; |
| 308 | if (is_desktop == latency->is_desktop && |
| 309 | is_ddr3 == latency->is_ddr3 && |
| 310 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 311 | return latency; |
| 312 | } |
| 313 | |
| 314 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 315 | |
| 316 | return NULL; |
| 317 | } |
| 318 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 319 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 320 | { |
| 321 | u32 val; |
| 322 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 323 | vlv_punit_get(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 324 | |
| 325 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 326 | if (enable) |
| 327 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 328 | else |
| 329 | val |= FORCE_DDR_HIGH_FREQ; |
| 330 | val &= ~FORCE_DDR_LOW_FREQ; |
| 331 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 332 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 333 | |
| 334 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 335 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 336 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 337 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 338 | vlv_punit_put(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 341 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 342 | { |
| 343 | u32 val; |
| 344 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 345 | vlv_punit_get(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 346 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 347 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 348 | if (enable) |
| 349 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 350 | else |
| 351 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 352 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 353 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 354 | vlv_punit_put(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 357 | #define FW_WM(value, plane) \ |
| 358 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 359 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 360 | 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] | 361 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 362 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 363 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 364 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 365 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 366 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 367 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 368 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 369 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 370 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 371 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 372 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 373 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 374 | val = I915_READ(DSPFW3); |
| 375 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 376 | if (enable) |
| 377 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 378 | else |
| 379 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 380 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 381 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 382 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 383 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 384 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 385 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 386 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 387 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 388 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 389 | /* |
| 390 | * FIXME can't find a bit like this for 915G, and |
| 391 | * and yet it does have the related watermark in |
| 392 | * FW_BLC_SELF. What's going on? |
| 393 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 394 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 395 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 396 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 397 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 398 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 399 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 400 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 401 | } |
| 402 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 403 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 404 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 405 | DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", |
| 406 | enableddisabled(enable), |
| 407 | enableddisabled(was_enabled)); |
| 408 | |
| 409 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 410 | } |
| 411 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 412 | /** |
| 413 | * intel_set_memory_cxsr - Configure CxSR state |
| 414 | * @dev_priv: i915 device |
| 415 | * @enable: Allow vs. disallow CxSR |
| 416 | * |
| 417 | * Allow or disallow the system to enter a special CxSR |
| 418 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 419 | * is that several display FIFOs may get combined into a single larger |
| 420 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 421 | * system to defer memory fetches longer, and the memory will enter |
| 422 | * self refresh. |
| 423 | * |
| 424 | * Note that enabling CxSR does not guarantee that the system enter |
| 425 | * this special mode, nor does it guarantee that the system stays |
| 426 | * in that mode once entered. So this just allows/disallows the system |
| 427 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 428 | * C-states will affect when/if the system actually enters/exits the |
| 429 | * CxSR mode. |
| 430 | * |
| 431 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 432 | * and the system is free to enter/exit memory self refresh at any time |
| 433 | * even when the use of CxSR has been disallowed. |
| 434 | * |
| 435 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 436 | * control registers will not get latched on vblank. Thus in order to |
| 437 | * guarantee the system will respond to changes in the plane registers |
| 438 | * we must always disallow CxSR prior to making changes to those registers. |
| 439 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 440 | * frame start which happens after vblank start (which is when the plane |
| 441 | * registers would get latched), so we can't proceed with the plane update |
| 442 | * during the same frame where we disallowed CxSR. |
| 443 | * |
| 444 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 445 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 446 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 447 | * Disallowing just CxSR is sufficient. |
| 448 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 449 | 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] | 450 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 451 | bool ret; |
| 452 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 453 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 454 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 455 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 456 | dev_priv->wm.vlv.cxsr = enable; |
| 457 | else if (IS_G4X(dev_priv)) |
| 458 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 459 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 460 | |
| 461 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 462 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 463 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 464 | /* |
| 465 | * Latency for FIFO fetches is dependent on several factors: |
| 466 | * - memory configuration (speed, channels) |
| 467 | * - chipset |
| 468 | * - current MCH state |
| 469 | * It can be fairly high in some situations, so here we assume a fairly |
| 470 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 471 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 472 | * and power consumption (set it too low to save power and we might see |
| 473 | * FIFO underruns and display "flicker"). |
| 474 | * |
| 475 | * A value of 5us seems to be a good balance; safe for very low end |
| 476 | * platforms but not overly aggressive on lower latency configs. |
| 477 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 478 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 479 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 480 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 481 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 482 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 483 | 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] | 484 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 485 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 486 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 487 | 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] | 488 | enum pipe pipe = crtc->pipe; |
| 489 | int sprite0_start, sprite1_start; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 490 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 491 | switch (pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 492 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 493 | case PIPE_A: |
| 494 | dsparb = I915_READ(DSPARB); |
| 495 | dsparb2 = I915_READ(DSPARB2); |
| 496 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 497 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 498 | break; |
| 499 | case PIPE_B: |
| 500 | dsparb = I915_READ(DSPARB); |
| 501 | dsparb2 = I915_READ(DSPARB2); |
| 502 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 503 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 504 | break; |
| 505 | case PIPE_C: |
| 506 | dsparb2 = I915_READ(DSPARB2); |
| 507 | dsparb3 = I915_READ(DSPARB3); |
| 508 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 509 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 510 | break; |
| 511 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 512 | MISSING_CASE(pipe); |
| 513 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 516 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 517 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 518 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 519 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 520 | } |
| 521 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 522 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 523 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 524 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 525 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 526 | int size; |
| 527 | |
| 528 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 529 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 530 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 531 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 532 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 533 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 534 | |
| 535 | return size; |
| 536 | } |
| 537 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 538 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 539 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 540 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 541 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 542 | int size; |
| 543 | |
| 544 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 545 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 546 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 547 | size >>= 1; /* Convert to cachelines */ |
| 548 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 549 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 550 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 551 | |
| 552 | return size; |
| 553 | } |
| 554 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 555 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 556 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 557 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 558 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 559 | int size; |
| 560 | |
| 561 | size = dsparb & 0x7f; |
| 562 | size >>= 2; /* Convert to cachelines */ |
| 563 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 564 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 565 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 566 | |
| 567 | return size; |
| 568 | } |
| 569 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 570 | /* Pineview has different values for various configs */ |
| 571 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 572 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 573 | .max_wm = PINEVIEW_MAX_WM, |
| 574 | .default_wm = PINEVIEW_DFT_WM, |
| 575 | .guard_size = PINEVIEW_GUARD_WM, |
| 576 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 577 | }; |
| 578 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 579 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 580 | .max_wm = PINEVIEW_MAX_WM, |
| 581 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 582 | .guard_size = PINEVIEW_GUARD_WM, |
| 583 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 584 | }; |
| 585 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 586 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 587 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 588 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 589 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 590 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 591 | }; |
| 592 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 593 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 594 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 595 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 596 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 597 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 598 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 599 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 600 | .fifo_size = I965_CURSOR_FIFO, |
| 601 | .max_wm = I965_CURSOR_MAX_WM, |
| 602 | .default_wm = I965_CURSOR_DFT_WM, |
| 603 | .guard_size = 2, |
| 604 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 605 | }; |
| 606 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 607 | .fifo_size = I945_FIFO_SIZE, |
| 608 | .max_wm = I915_MAX_WM, |
| 609 | .default_wm = 1, |
| 610 | .guard_size = 2, |
| 611 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 612 | }; |
| 613 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 614 | .fifo_size = I915_FIFO_SIZE, |
| 615 | .max_wm = I915_MAX_WM, |
| 616 | .default_wm = 1, |
| 617 | .guard_size = 2, |
| 618 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 619 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 620 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 621 | .fifo_size = I855GM_FIFO_SIZE, |
| 622 | .max_wm = I915_MAX_WM, |
| 623 | .default_wm = 1, |
| 624 | .guard_size = 2, |
| 625 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 626 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 627 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 628 | .fifo_size = I855GM_FIFO_SIZE, |
| 629 | .max_wm = I915_MAX_WM/2, |
| 630 | .default_wm = 1, |
| 631 | .guard_size = 2, |
| 632 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 633 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 634 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 635 | .fifo_size = I830_FIFO_SIZE, |
| 636 | .max_wm = I915_MAX_WM, |
| 637 | .default_wm = 1, |
| 638 | .guard_size = 2, |
| 639 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 640 | }; |
| 641 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 642 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 643 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 644 | * @pixel_rate: Pipe pixel rate in kHz |
| 645 | * @cpp: Plane bytes per pixel |
| 646 | * @latency: Memory wakeup latency in 0.1us units |
| 647 | * |
| 648 | * Compute the watermark using the method 1 or "small buffer" |
| 649 | * formula. The caller may additonally add extra cachelines |
| 650 | * to account for TLB misses and clock crossings. |
| 651 | * |
| 652 | * This method is concerned with the short term drain rate |
| 653 | * of the FIFO, ie. it does not account for blanking periods |
| 654 | * which would effectively reduce the average drain rate across |
| 655 | * a longer period. The name "small" refers to the fact the |
| 656 | * FIFO is relatively small compared to the amount of data |
| 657 | * fetched. |
| 658 | * |
| 659 | * The FIFO level vs. time graph might look something like: |
| 660 | * |
| 661 | * |\ |\ |
| 662 | * | \ | \ |
| 663 | * __---__---__ (- plane active, _ blanking) |
| 664 | * -> time |
| 665 | * |
| 666 | * or perhaps like this: |
| 667 | * |
| 668 | * |\|\ |\|\ |
| 669 | * __----__----__ (- plane active, _ blanking) |
| 670 | * -> time |
| 671 | * |
| 672 | * Returns: |
| 673 | * The watermark in bytes |
| 674 | */ |
| 675 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 676 | unsigned int cpp, |
| 677 | unsigned int latency) |
| 678 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 679 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 680 | |
Ville Syrjälä | d492a29 | 2019-04-08 18:27:01 +0300 | [diff] [blame^] | 681 | ret = mul_u32_u32(pixel_rate, cpp * latency); |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 682 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 683 | |
| 684 | return ret; |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 689 | * @pixel_rate: Pipe pixel rate in kHz |
| 690 | * @htotal: Pipe horizontal total |
| 691 | * @width: Plane width in pixels |
| 692 | * @cpp: Plane bytes per pixel |
| 693 | * @latency: Memory wakeup latency in 0.1us units |
| 694 | * |
| 695 | * Compute the watermark using the method 2 or "large buffer" |
| 696 | * formula. The caller may additonally add extra cachelines |
| 697 | * to account for TLB misses and clock crossings. |
| 698 | * |
| 699 | * This method is concerned with the long term drain rate |
| 700 | * of the FIFO, ie. it does account for blanking periods |
| 701 | * which effectively reduce the average drain rate across |
| 702 | * a longer period. The name "large" refers to the fact the |
| 703 | * FIFO is relatively large compared to the amount of data |
| 704 | * fetched. |
| 705 | * |
| 706 | * The FIFO level vs. time graph might look something like: |
| 707 | * |
| 708 | * |\___ |\___ |
| 709 | * | \___ | \___ |
| 710 | * | \ | \ |
| 711 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 712 | * -> time |
| 713 | * |
| 714 | * Returns: |
| 715 | * The watermark in bytes |
| 716 | */ |
| 717 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 718 | unsigned int htotal, |
| 719 | unsigned int width, |
| 720 | unsigned int cpp, |
| 721 | unsigned int latency) |
| 722 | { |
| 723 | unsigned int ret; |
| 724 | |
| 725 | /* |
| 726 | * FIXME remove once all users are computing |
| 727 | * watermarks in the correct place. |
| 728 | */ |
| 729 | if (WARN_ON_ONCE(htotal == 0)) |
| 730 | htotal = 1; |
| 731 | |
| 732 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 733 | ret = (ret + 1) * width * cpp; |
| 734 | |
| 735 | return ret; |
| 736 | } |
| 737 | |
| 738 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 739 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 740 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 741 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 742 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 743 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 744 | * @latency_ns: memory latency for the platform |
| 745 | * |
| 746 | * Calculate the watermark level (the level at which the display plane will |
| 747 | * start fetching from memory again). Each chip has a different display |
| 748 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 749 | * in the correct intel_watermark_params structure. |
| 750 | * |
| 751 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 752 | * on the pixel size. When it reaches the watermark level, it'll start |
| 753 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 754 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 755 | * will occur, and a display engine hang could result. |
| 756 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 757 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 758 | const struct intel_watermark_params *wm, |
| 759 | int fifo_size, int cpp, |
| 760 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 761 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 762 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 763 | |
| 764 | /* |
| 765 | * Note: we need to make sure we don't overflow for various clock & |
| 766 | * latency values. |
| 767 | * clocks go from a few thousand to several hundred thousand. |
| 768 | * latency is usually a few thousand |
| 769 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 770 | entries = intel_wm_method1(pixel_rate, cpp, |
| 771 | latency_ns / 100); |
| 772 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 773 | wm->guard_size; |
| 774 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 775 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 776 | wm_size = fifo_size - entries; |
| 777 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 778 | |
| 779 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 780 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 781 | wm_size = wm->max_wm; |
| 782 | if (wm_size <= 0) |
| 783 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 784 | |
| 785 | /* |
| 786 | * Bspec seems to indicate that the value shouldn't be lower than |
| 787 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 788 | * Lets go for 8 which is the burst size since certain platforms |
| 789 | * already use a hardcoded 8 (which is what the spec says should be |
| 790 | * done). |
| 791 | */ |
| 792 | if (wm_size <= 8) |
| 793 | wm_size = 8; |
| 794 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 795 | return wm_size; |
| 796 | } |
| 797 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 798 | static bool is_disabling(int old, int new, int threshold) |
| 799 | { |
| 800 | return old >= threshold && new < threshold; |
| 801 | } |
| 802 | |
| 803 | static bool is_enabling(int old, int new, int threshold) |
| 804 | { |
| 805 | return old < threshold && new >= threshold; |
| 806 | } |
| 807 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 808 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 809 | { |
| 810 | return dev_priv->wm.max_level + 1; |
| 811 | } |
| 812 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 813 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 814 | const struct intel_plane_state *plane_state) |
| 815 | { |
| 816 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 817 | |
| 818 | /* FIXME check the 'enable' instead */ |
| 819 | if (!crtc_state->base.active) |
| 820 | return false; |
| 821 | |
| 822 | /* |
| 823 | * Treat cursor with fb as always visible since cursor updates |
| 824 | * can happen faster than the vrefresh rate, and the current |
| 825 | * watermark code doesn't handle that correctly. Cursor updates |
| 826 | * which set/clear the fb or change the cursor size are going |
| 827 | * to get throttled by intel_legacy_cursor_update() to work |
| 828 | * around this problem with the watermark code. |
| 829 | */ |
| 830 | if (plane->id == PLANE_CURSOR) |
| 831 | return plane_state->base.fb != NULL; |
| 832 | else |
| 833 | return plane_state->base.visible; |
| 834 | } |
| 835 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 836 | 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] | 837 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 838 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 839 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 840 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 841 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 842 | if (enabled) |
| 843 | return NULL; |
| 844 | enabled = crtc; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | return enabled; |
| 849 | } |
| 850 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 851 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 852 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 853 | 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] | 854 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 855 | const struct cxsr_latency *latency; |
| 856 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 857 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 858 | |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 859 | latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 860 | dev_priv->is_ddr3, |
| 861 | dev_priv->fsb_freq, |
| 862 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 863 | if (!latency) { |
| 864 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 865 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 866 | return; |
| 867 | } |
| 868 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 869 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 870 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 871 | const struct drm_display_mode *adjusted_mode = |
| 872 | &crtc->config->base.adjusted_mode; |
| 873 | const struct drm_framebuffer *fb = |
| 874 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 875 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 876 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 877 | |
| 878 | /* Display SR */ |
| 879 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 880 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 881 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 882 | reg = I915_READ(DSPFW1); |
| 883 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 884 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 885 | I915_WRITE(DSPFW1, reg); |
| 886 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 887 | |
| 888 | /* cursor SR */ |
| 889 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 890 | pineview_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 891 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 892 | reg = I915_READ(DSPFW3); |
| 893 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 894 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 895 | I915_WRITE(DSPFW3, reg); |
| 896 | |
| 897 | /* Display HPLL off SR */ |
| 898 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 899 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 900 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 901 | reg = I915_READ(DSPFW3); |
| 902 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 903 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 904 | I915_WRITE(DSPFW3, reg); |
| 905 | |
| 906 | /* cursor HPLL off SR */ |
| 907 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 908 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 909 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 910 | reg = I915_READ(DSPFW3); |
| 911 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 912 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 913 | I915_WRITE(DSPFW3, reg); |
| 914 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 915 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 916 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 917 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 918 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 922 | /* |
| 923 | * Documentation says: |
| 924 | * "If the line size is small, the TLB fetches can get in the way of the |
| 925 | * data fetches, causing some lag in the pixel data return which is not |
| 926 | * accounted for in the above formulas. The following adjustment only |
| 927 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 928 | * The WM is adjusted upwards by the difference between the FIFO size |
| 929 | * and the size of 8 whole lines. This adjustment is always performed |
| 930 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 931 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 932 | 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] | 933 | { |
| 934 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 935 | |
| 936 | return max(0, tlb_miss); |
| 937 | } |
| 938 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 939 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 940 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 941 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 942 | enum pipe pipe; |
| 943 | |
| 944 | for_each_pipe(dev_priv, pipe) |
| 945 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 946 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 947 | I915_WRITE(DSPFW1, |
| 948 | FW_WM(wm->sr.plane, SR) | |
| 949 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 950 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 951 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 952 | I915_WRITE(DSPFW2, |
| 953 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 954 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 955 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 956 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 957 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 958 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 959 | I915_WRITE(DSPFW3, |
| 960 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 961 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 962 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 963 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 964 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 965 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 966 | } |
| 967 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 968 | #define FW_WM_VLV(value, plane) \ |
| 969 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 970 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 971 | 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] | 972 | const struct vlv_wm_values *wm) |
| 973 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 974 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 975 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 976 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 977 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 978 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 979 | I915_WRITE(VLV_DDL(pipe), |
| 980 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 981 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 982 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 983 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 984 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 985 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 986 | /* |
| 987 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 988 | * high order bits so that there are no out of bounds values |
| 989 | * present in the registers during the reprogramming. |
| 990 | */ |
| 991 | I915_WRITE(DSPHOWM, 0); |
| 992 | I915_WRITE(DSPHOWM1, 0); |
| 993 | I915_WRITE(DSPFW4, 0); |
| 994 | I915_WRITE(DSPFW5, 0); |
| 995 | I915_WRITE(DSPFW6, 0); |
| 996 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 997 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 998 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 999 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 1000 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 1001 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1002 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1003 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 1004 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1005 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1006 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1007 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1008 | |
| 1009 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1010 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1011 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1012 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1013 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1014 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 1015 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1016 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1017 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1018 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1019 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1020 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1021 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1022 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1023 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 1024 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1025 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1026 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1027 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1028 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1029 | 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] | 1030 | } else { |
| 1031 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1032 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1033 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1034 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1035 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1036 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1037 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1038 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1039 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1040 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1041 | 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] | 1042 | } |
| 1043 | |
| 1044 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1045 | } |
| 1046 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1047 | #undef FW_WM_VLV |
| 1048 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1049 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1050 | { |
| 1051 | /* all latencies in usec */ |
| 1052 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1053 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1054 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1055 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1056 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1060 | { |
| 1061 | /* |
| 1062 | * DSPCNTR[13] supposedly controls whether the |
| 1063 | * primary plane can use the FIFO space otherwise |
| 1064 | * reserved for the sprite plane. It's not 100% clear |
| 1065 | * what the actual FIFO size is, but it looks like we |
| 1066 | * can happily set both primary and sprite watermarks |
| 1067 | * up to 127 cachelines. So that would seem to mean |
| 1068 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1069 | * the total FIFO is >= 256 cachelines in size. Either |
| 1070 | * way, we don't seem to have to worry about this |
| 1071 | * repartitioning as the maximum watermark value the |
| 1072 | * register can hold for each plane is lower than the |
| 1073 | * minimum FIFO size. |
| 1074 | */ |
| 1075 | switch (plane_id) { |
| 1076 | case PLANE_CURSOR: |
| 1077 | return 63; |
| 1078 | case PLANE_PRIMARY: |
| 1079 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1080 | case PLANE_SPRITE0: |
| 1081 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1082 | default: |
| 1083 | MISSING_CASE(plane_id); |
| 1084 | return 0; |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | static int g4x_fbc_fifo_size(int level) |
| 1089 | { |
| 1090 | switch (level) { |
| 1091 | case G4X_WM_LEVEL_SR: |
| 1092 | return 7; |
| 1093 | case G4X_WM_LEVEL_HPLL: |
| 1094 | return 15; |
| 1095 | default: |
| 1096 | MISSING_CASE(level); |
| 1097 | return 0; |
| 1098 | } |
| 1099 | } |
| 1100 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1101 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1102 | const struct intel_plane_state *plane_state, |
| 1103 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1104 | { |
| 1105 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1106 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 1107 | const struct drm_display_mode *adjusted_mode = |
| 1108 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1109 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1110 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1111 | |
| 1112 | if (latency == 0) |
| 1113 | return USHRT_MAX; |
| 1114 | |
| 1115 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1116 | return 0; |
| 1117 | |
| 1118 | /* |
| 1119 | * Not 100% sure which way ELK should go here as the |
| 1120 | * spec only says CL/CTG should assume 32bpp and BW |
| 1121 | * doesn't need to. But as these things followed the |
| 1122 | * mobile vs. desktop lines on gen3 as well, let's |
| 1123 | * assume ELK doesn't need this. |
| 1124 | * |
| 1125 | * The spec also fails to list such a restriction for |
| 1126 | * the HPLL watermark, which seems a little strange. |
| 1127 | * Let's use 32bpp for the HPLL watermark as well. |
| 1128 | */ |
| 1129 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1130 | level != G4X_WM_LEVEL_NORMAL) |
| 1131 | cpp = 4; |
| 1132 | else |
| 1133 | cpp = plane_state->base.fb->format->cpp[0]; |
| 1134 | |
| 1135 | clock = adjusted_mode->crtc_clock; |
| 1136 | htotal = adjusted_mode->crtc_htotal; |
| 1137 | |
| 1138 | if (plane->id == PLANE_CURSOR) |
| 1139 | width = plane_state->base.crtc_w; |
| 1140 | else |
| 1141 | width = drm_rect_width(&plane_state->base.dst); |
| 1142 | |
| 1143 | if (plane->id == PLANE_CURSOR) { |
| 1144 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1145 | } else if (plane->id == PLANE_PRIMARY && |
| 1146 | level == G4X_WM_LEVEL_NORMAL) { |
| 1147 | wm = intel_wm_method1(clock, cpp, latency); |
| 1148 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1149 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1150 | |
| 1151 | small = intel_wm_method1(clock, cpp, latency); |
| 1152 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1153 | |
| 1154 | wm = min(small, large); |
| 1155 | } |
| 1156 | |
| 1157 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1158 | width, cpp); |
| 1159 | |
| 1160 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1161 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1162 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1166 | int level, enum plane_id plane_id, u16 value) |
| 1167 | { |
| 1168 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1169 | bool dirty = false; |
| 1170 | |
| 1171 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1172 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1173 | |
| 1174 | dirty |= raw->plane[plane_id] != value; |
| 1175 | raw->plane[plane_id] = value; |
| 1176 | } |
| 1177 | |
| 1178 | return dirty; |
| 1179 | } |
| 1180 | |
| 1181 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1182 | int level, u16 value) |
| 1183 | { |
| 1184 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1185 | bool dirty = false; |
| 1186 | |
| 1187 | /* NORMAL level doesn't have an FBC watermark */ |
| 1188 | level = max(level, G4X_WM_LEVEL_SR); |
| 1189 | |
| 1190 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1191 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1192 | |
| 1193 | dirty |= raw->fbc != value; |
| 1194 | raw->fbc = value; |
| 1195 | } |
| 1196 | |
| 1197 | return dirty; |
| 1198 | } |
| 1199 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1200 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
| 1201 | const struct intel_plane_state *pstate, |
| 1202 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1203 | |
| 1204 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1205 | const struct intel_plane_state *plane_state) |
| 1206 | { |
| 1207 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1208 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1209 | enum plane_id plane_id = plane->id; |
| 1210 | bool dirty = false; |
| 1211 | int level; |
| 1212 | |
| 1213 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1214 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1215 | if (plane_id == PLANE_PRIMARY) |
| 1216 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1217 | goto out; |
| 1218 | } |
| 1219 | |
| 1220 | for (level = 0; level < num_levels; level++) { |
| 1221 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1222 | int wm, max_wm; |
| 1223 | |
| 1224 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1225 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1226 | |
| 1227 | if (wm > max_wm) |
| 1228 | break; |
| 1229 | |
| 1230 | dirty |= raw->plane[plane_id] != wm; |
| 1231 | raw->plane[plane_id] = wm; |
| 1232 | |
| 1233 | if (plane_id != PLANE_PRIMARY || |
| 1234 | level == G4X_WM_LEVEL_NORMAL) |
| 1235 | continue; |
| 1236 | |
| 1237 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1238 | raw->plane[plane_id]); |
| 1239 | max_wm = g4x_fbc_fifo_size(level); |
| 1240 | |
| 1241 | /* |
| 1242 | * FBC wm is not mandatory as we |
| 1243 | * can always just disable its use. |
| 1244 | */ |
| 1245 | if (wm > max_wm) |
| 1246 | wm = USHRT_MAX; |
| 1247 | |
| 1248 | dirty |= raw->fbc != wm; |
| 1249 | raw->fbc = wm; |
| 1250 | } |
| 1251 | |
| 1252 | /* mark watermarks as invalid */ |
| 1253 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1254 | |
| 1255 | if (plane_id == PLANE_PRIMARY) |
| 1256 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1257 | |
| 1258 | out: |
| 1259 | if (dirty) { |
| 1260 | DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1261 | plane->base.name, |
| 1262 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1263 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1264 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
| 1265 | |
| 1266 | if (plane_id == PLANE_PRIMARY) |
| 1267 | DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", |
| 1268 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1269 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
| 1270 | } |
| 1271 | |
| 1272 | return dirty; |
| 1273 | } |
| 1274 | |
| 1275 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1276 | enum plane_id plane_id, int level) |
| 1277 | { |
| 1278 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1279 | |
| 1280 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1281 | } |
| 1282 | |
| 1283 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1284 | int level) |
| 1285 | { |
| 1286 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1287 | |
| 1288 | if (level > dev_priv->wm.max_level) |
| 1289 | return false; |
| 1290 | |
| 1291 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1292 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1293 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1294 | } |
| 1295 | |
| 1296 | /* mark all levels starting from 'level' as invalid */ |
| 1297 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1298 | struct g4x_wm_state *wm_state, int level) |
| 1299 | { |
| 1300 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1301 | enum plane_id plane_id; |
| 1302 | |
| 1303 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1304 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1305 | } |
| 1306 | |
| 1307 | if (level <= G4X_WM_LEVEL_SR) { |
| 1308 | wm_state->cxsr = false; |
| 1309 | wm_state->sr.cursor = USHRT_MAX; |
| 1310 | wm_state->sr.plane = USHRT_MAX; |
| 1311 | wm_state->sr.fbc = USHRT_MAX; |
| 1312 | } |
| 1313 | |
| 1314 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1315 | wm_state->hpll_en = false; |
| 1316 | wm_state->hpll.cursor = USHRT_MAX; |
| 1317 | wm_state->hpll.plane = USHRT_MAX; |
| 1318 | wm_state->hpll.fbc = USHRT_MAX; |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1323 | { |
| 1324 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1325 | struct intel_atomic_state *state = |
| 1326 | to_intel_atomic_state(crtc_state->base.state); |
| 1327 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 1328 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1329 | ~BIT(PLANE_CURSOR)); |
| 1330 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1331 | const struct intel_plane_state *old_plane_state; |
| 1332 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1333 | struct intel_plane *plane; |
| 1334 | enum plane_id plane_id; |
| 1335 | int i, level; |
| 1336 | unsigned int dirty = 0; |
| 1337 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1338 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1339 | old_plane_state, |
| 1340 | new_plane_state, i) { |
| 1341 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1342 | old_plane_state->base.crtc != &crtc->base) |
| 1343 | continue; |
| 1344 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1345 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1346 | dirty |= BIT(plane->id); |
| 1347 | } |
| 1348 | |
| 1349 | if (!dirty) |
| 1350 | return 0; |
| 1351 | |
| 1352 | level = G4X_WM_LEVEL_NORMAL; |
| 1353 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1354 | goto out; |
| 1355 | |
| 1356 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1357 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1358 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1359 | |
| 1360 | level = G4X_WM_LEVEL_SR; |
| 1361 | |
| 1362 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1363 | goto out; |
| 1364 | |
| 1365 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1366 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1367 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1368 | wm_state->sr.fbc = raw->fbc; |
| 1369 | |
| 1370 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1371 | |
| 1372 | level = G4X_WM_LEVEL_HPLL; |
| 1373 | |
| 1374 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1375 | goto out; |
| 1376 | |
| 1377 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1378 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1379 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1380 | wm_state->hpll.fbc = raw->fbc; |
| 1381 | |
| 1382 | wm_state->hpll_en = wm_state->cxsr; |
| 1383 | |
| 1384 | level++; |
| 1385 | |
| 1386 | out: |
| 1387 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1388 | return -EINVAL; |
| 1389 | |
| 1390 | /* invalidate the higher levels */ |
| 1391 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1392 | |
| 1393 | /* |
| 1394 | * Determine if the FBC watermark(s) can be used. IF |
| 1395 | * this isn't the case we prefer to disable the FBC |
| 1396 | ( watermark(s) rather than disable the SR/HPLL |
| 1397 | * level(s) entirely. |
| 1398 | */ |
| 1399 | wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL; |
| 1400 | |
| 1401 | if (level >= G4X_WM_LEVEL_SR && |
| 1402 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1403 | wm_state->fbc_en = false; |
| 1404 | else if (level >= G4X_WM_LEVEL_HPLL && |
| 1405 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1406 | wm_state->fbc_en = false; |
| 1407 | |
| 1408 | return 0; |
| 1409 | } |
| 1410 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1411 | 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] | 1412 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1413 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1414 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1415 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
| 1416 | struct intel_atomic_state *intel_state = |
| 1417 | to_intel_atomic_state(new_crtc_state->base.state); |
| 1418 | const struct intel_crtc_state *old_crtc_state = |
| 1419 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 1420 | 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] | 1421 | enum plane_id plane_id; |
| 1422 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1423 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 1424 | *intermediate = *optimal; |
| 1425 | |
| 1426 | intermediate->cxsr = false; |
| 1427 | intermediate->hpll_en = false; |
| 1428 | goto out; |
| 1429 | } |
| 1430 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1431 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1432 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1433 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1434 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1435 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1436 | |
| 1437 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1438 | intermediate->wm.plane[plane_id] = |
| 1439 | max(optimal->wm.plane[plane_id], |
| 1440 | active->wm.plane[plane_id]); |
| 1441 | |
| 1442 | WARN_ON(intermediate->wm.plane[plane_id] > |
| 1443 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
| 1444 | } |
| 1445 | |
| 1446 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1447 | active->sr.plane); |
| 1448 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1449 | active->sr.cursor); |
| 1450 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1451 | active->sr.fbc); |
| 1452 | |
| 1453 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1454 | active->hpll.plane); |
| 1455 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1456 | active->hpll.cursor); |
| 1457 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1458 | active->hpll.fbc); |
| 1459 | |
| 1460 | WARN_ON((intermediate->sr.plane > |
| 1461 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1462 | intermediate->sr.cursor > |
| 1463 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1464 | intermediate->cxsr); |
| 1465 | WARN_ON((intermediate->sr.plane > |
| 1466 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1467 | intermediate->sr.cursor > |
| 1468 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1469 | intermediate->hpll_en); |
| 1470 | |
| 1471 | WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1472 | intermediate->fbc_en && intermediate->cxsr); |
| 1473 | WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1474 | intermediate->fbc_en && intermediate->hpll_en); |
| 1475 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1476 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1477 | /* |
| 1478 | * If our intermediate WM are identical to the final WM, then we can |
| 1479 | * omit the post-vblank programming; only update if it's different. |
| 1480 | */ |
| 1481 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1482 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1483 | |
| 1484 | return 0; |
| 1485 | } |
| 1486 | |
| 1487 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1488 | struct g4x_wm_values *wm) |
| 1489 | { |
| 1490 | struct intel_crtc *crtc; |
| 1491 | int num_active_crtcs = 0; |
| 1492 | |
| 1493 | wm->cxsr = true; |
| 1494 | wm->hpll_en = true; |
| 1495 | wm->fbc_en = true; |
| 1496 | |
| 1497 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1498 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1499 | |
| 1500 | if (!crtc->active) |
| 1501 | continue; |
| 1502 | |
| 1503 | if (!wm_state->cxsr) |
| 1504 | wm->cxsr = false; |
| 1505 | if (!wm_state->hpll_en) |
| 1506 | wm->hpll_en = false; |
| 1507 | if (!wm_state->fbc_en) |
| 1508 | wm->fbc_en = false; |
| 1509 | |
| 1510 | num_active_crtcs++; |
| 1511 | } |
| 1512 | |
| 1513 | if (num_active_crtcs != 1) { |
| 1514 | wm->cxsr = false; |
| 1515 | wm->hpll_en = false; |
| 1516 | wm->fbc_en = false; |
| 1517 | } |
| 1518 | |
| 1519 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1520 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1521 | enum pipe pipe = crtc->pipe; |
| 1522 | |
| 1523 | wm->pipe[pipe] = wm_state->wm; |
| 1524 | if (crtc->active && wm->cxsr) |
| 1525 | wm->sr = wm_state->sr; |
| 1526 | if (crtc->active && wm->hpll_en) |
| 1527 | wm->hpll = wm_state->hpll; |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1532 | { |
| 1533 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1534 | struct g4x_wm_values new_wm = {}; |
| 1535 | |
| 1536 | g4x_merge_wm(dev_priv, &new_wm); |
| 1537 | |
| 1538 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1539 | return; |
| 1540 | |
| 1541 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1542 | _intel_set_memory_cxsr(dev_priv, false); |
| 1543 | |
| 1544 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1545 | |
| 1546 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1547 | _intel_set_memory_cxsr(dev_priv, true); |
| 1548 | |
| 1549 | *old_wm = new_wm; |
| 1550 | } |
| 1551 | |
| 1552 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
| 1553 | struct intel_crtc_state *crtc_state) |
| 1554 | { |
| 1555 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1556 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1557 | |
| 1558 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1559 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1560 | g4x_program_watermarks(dev_priv); |
| 1561 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1562 | } |
| 1563 | |
| 1564 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
| 1565 | struct intel_crtc_state *crtc_state) |
| 1566 | { |
| 1567 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1568 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1569 | |
| 1570 | if (!crtc_state->wm.need_postvbl_update) |
| 1571 | return; |
| 1572 | |
| 1573 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1574 | intel_crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 1575 | g4x_program_watermarks(dev_priv); |
| 1576 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1577 | } |
| 1578 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1579 | /* latency must be in 0.1us units. */ |
| 1580 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1581 | unsigned int htotal, |
| 1582 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1583 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1584 | unsigned int latency) |
| 1585 | { |
| 1586 | unsigned int ret; |
| 1587 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1588 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1589 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1590 | ret = DIV_ROUND_UP(ret, 64); |
| 1591 | |
| 1592 | return ret; |
| 1593 | } |
| 1594 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1595 | 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] | 1596 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1597 | /* all latencies in usec */ |
| 1598 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1599 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1600 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1601 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1602 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1603 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1604 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1605 | |
| 1606 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1610 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1611 | const struct intel_plane_state *plane_state, |
| 1612 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1613 | { |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1614 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1615 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1616 | const struct drm_display_mode *adjusted_mode = |
| 1617 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1618 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1619 | |
| 1620 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1621 | return USHRT_MAX; |
| 1622 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1623 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1624 | return 0; |
| 1625 | |
Daniel Vetter | ef426c1 | 2017-01-04 11:41:10 +0100 | [diff] [blame] | 1626 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1627 | clock = adjusted_mode->crtc_clock; |
| 1628 | htotal = adjusted_mode->crtc_htotal; |
| 1629 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1630 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1631 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1632 | /* |
| 1633 | * FIXME the formula gives values that are |
| 1634 | * too big for the cursor FIFO, and hence we |
| 1635 | * would never be able to use cursors. For |
| 1636 | * now just hardcode the watermark. |
| 1637 | */ |
| 1638 | wm = 63; |
| 1639 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1640 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1641 | dev_priv->wm.pri_latency[level] * 10); |
| 1642 | } |
| 1643 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1644 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1645 | } |
| 1646 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1647 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1648 | { |
| 1649 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1650 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1651 | } |
| 1652 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1653 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1654 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1655 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1656 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1657 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1658 | 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] | 1659 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1660 | int num_active_planes = hweight32(active_planes); |
| 1661 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1662 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1663 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1664 | unsigned int total_rate; |
| 1665 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1666 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1667 | /* |
| 1668 | * When enabling sprite0 after sprite1 has already been enabled |
| 1669 | * we tend to get an underrun unless sprite0 already has some |
| 1670 | * FIFO space allcoated. Hence we always allocate at least one |
| 1671 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1672 | * |
| 1673 | * All other plane enable sequences appear immune to this problem. |
| 1674 | */ |
| 1675 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1676 | sprite0_fifo_extra = 1; |
| 1677 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1678 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1679 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1680 | raw->plane[PLANE_SPRITE1] + |
| 1681 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1682 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1683 | if (total_rate > fifo_size) |
| 1684 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1685 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1686 | if (total_rate == 0) |
| 1687 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1688 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1689 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1690 | unsigned int rate; |
| 1691 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1692 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1693 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1694 | continue; |
| 1695 | } |
| 1696 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1697 | rate = raw->plane[plane_id]; |
| 1698 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1699 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1700 | } |
| 1701 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1702 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1703 | fifo_left -= sprite0_fifo_extra; |
| 1704 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1705 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1706 | |
| 1707 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1708 | |
| 1709 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1710 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1711 | int plane_extra; |
| 1712 | |
| 1713 | if (fifo_left == 0) |
| 1714 | break; |
| 1715 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1716 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1717 | continue; |
| 1718 | |
| 1719 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1720 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1721 | fifo_left -= plane_extra; |
| 1722 | } |
| 1723 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1724 | WARN_ON(active_planes != 0 && fifo_left != 0); |
| 1725 | |
| 1726 | /* give it all to the first plane if none are active */ |
| 1727 | if (active_planes == 0) { |
| 1728 | WARN_ON(fifo_left != fifo_size); |
| 1729 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1730 | } |
| 1731 | |
| 1732 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1733 | } |
| 1734 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1735 | /* mark all levels starting from 'level' as invalid */ |
| 1736 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1737 | struct vlv_wm_state *wm_state, int level) |
| 1738 | { |
| 1739 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1740 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1741 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1742 | enum plane_id plane_id; |
| 1743 | |
| 1744 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1745 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1746 | |
| 1747 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1748 | wm_state->sr[level].plane = USHRT_MAX; |
| 1749 | } |
| 1750 | } |
| 1751 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1752 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1753 | { |
| 1754 | if (wm > fifo_size) |
| 1755 | return USHRT_MAX; |
| 1756 | else |
| 1757 | return fifo_size - wm; |
| 1758 | } |
| 1759 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1760 | /* |
| 1761 | * Starting from 'level' set all higher |
| 1762 | * levels to 'value' in the "raw" watermarks. |
| 1763 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1764 | 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] | 1765 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1766 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1767 | 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] | 1768 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1769 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1770 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1771 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1772 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1773 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1774 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1775 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1776 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1777 | |
| 1778 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1779 | } |
| 1780 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1781 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1782 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1783 | { |
| 1784 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1785 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1786 | 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] | 1787 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1788 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1789 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1790 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1791 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1792 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1796 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1797 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1798 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1799 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1800 | if (wm > max_wm) |
| 1801 | break; |
| 1802 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1803 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1804 | raw->plane[plane_id] = wm; |
| 1805 | } |
| 1806 | |
| 1807 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1808 | 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] | 1809 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1810 | out: |
| 1811 | if (dirty) |
Ville Syrjälä | 57a6528 | 2017-04-21 21:14:22 +0300 | [diff] [blame] | 1812 | 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] | 1813 | plane->base.name, |
| 1814 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1815 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1816 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
| 1817 | |
| 1818 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1819 | } |
| 1820 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1821 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1822 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1823 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1824 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1825 | &crtc_state->wm.vlv.raw[level]; |
| 1826 | const struct vlv_fifo_state *fifo_state = |
| 1827 | &crtc_state->wm.vlv.fifo_state; |
| 1828 | |
| 1829 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1830 | } |
| 1831 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1832 | 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] | 1833 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1834 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1835 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1836 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1837 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | 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] | 1841 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1842 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1843 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1844 | struct intel_atomic_state *state = |
| 1845 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1846 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1847 | const struct vlv_fifo_state *fifo_state = |
| 1848 | &crtc_state->wm.vlv.fifo_state; |
| 1849 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1850 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1851 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->base); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1852 | const struct intel_plane_state *old_plane_state; |
| 1853 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1854 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1855 | enum plane_id plane_id; |
| 1856 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1857 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1858 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1859 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1860 | old_plane_state, |
| 1861 | new_plane_state, i) { |
| 1862 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1863 | old_plane_state->base.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1864 | continue; |
| 1865 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1866 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1867 | dirty |= BIT(plane->id); |
| 1868 | } |
| 1869 | |
| 1870 | /* |
| 1871 | * DSPARB registers may have been reset due to the |
| 1872 | * power well being turned off. Make sure we restore |
| 1873 | * them to a consistent state even if no primary/sprite |
| 1874 | * planes are initially active. |
| 1875 | */ |
| 1876 | if (needs_modeset) |
| 1877 | crtc_state->fifo_changed = true; |
| 1878 | |
| 1879 | if (!dirty) |
| 1880 | return 0; |
| 1881 | |
| 1882 | /* cursor changes don't warrant a FIFO recompute */ |
| 1883 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1884 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1885 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1886 | const struct vlv_fifo_state *old_fifo_state = |
| 1887 | &old_crtc_state->wm.vlv.fifo_state; |
| 1888 | |
| 1889 | ret = vlv_compute_fifo(crtc_state); |
| 1890 | if (ret) |
| 1891 | return ret; |
| 1892 | |
| 1893 | if (needs_modeset || |
| 1894 | memcmp(old_fifo_state, fifo_state, |
| 1895 | sizeof(*fifo_state)) != 0) |
| 1896 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1897 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1898 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1899 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1900 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1901 | /* |
| 1902 | * Note that enabling cxsr with no primary/sprite planes |
| 1903 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1904 | * with exactly one enabled primary/sprite plane. |
| 1905 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1906 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1907 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1908 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1909 | 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] | 1910 | 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] | 1911 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1912 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1913 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1914 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1915 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1916 | wm_state->wm[level].plane[plane_id] = |
| 1917 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1918 | fifo_state->plane[plane_id]); |
| 1919 | } |
| 1920 | |
| 1921 | wm_state->sr[level].plane = |
| 1922 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1923 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1924 | raw->plane[PLANE_SPRITE1]), |
| 1925 | sr_fifo_size); |
| 1926 | |
| 1927 | wm_state->sr[level].cursor = |
| 1928 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1929 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1930 | } |
| 1931 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1932 | if (level == 0) |
| 1933 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1934 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1935 | /* limit to only levels we can actually handle */ |
| 1936 | wm_state->num_levels = level; |
| 1937 | |
| 1938 | /* invalidate the higher levels */ |
| 1939 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1940 | |
| 1941 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1942 | } |
| 1943 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1944 | #define VLV_FIFO(plane, value) \ |
| 1945 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1946 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1947 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
| 1948 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1949 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1950 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1951 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1952 | const struct vlv_fifo_state *fifo_state = |
| 1953 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1954 | int sprite0_start, sprite1_start, fifo_size; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1955 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1956 | if (!crtc_state->fifo_changed) |
| 1957 | return; |
| 1958 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1959 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 1960 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 1961 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1962 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1963 | WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63); |
| 1964 | WARN_ON(fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1965 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1966 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 1967 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1968 | /* |
| 1969 | * uncore.lock serves a double purpose here. It allows us to |
| 1970 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 1971 | * it protects the DSPARB registers from getting clobbered by |
| 1972 | * parallel updates from multiple pipes. |
| 1973 | * |
| 1974 | * intel_pipe_update_start() has already disabled interrupts |
| 1975 | * for us, so a plain spin_lock() is sufficient here. |
| 1976 | */ |
| 1977 | spin_lock(&dev_priv->uncore.lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1978 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1979 | switch (crtc->pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1980 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1981 | case PIPE_A: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1982 | dsparb = I915_READ_FW(DSPARB); |
| 1983 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1984 | |
| 1985 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1986 | VLV_FIFO(SPRITEB, 0xff)); |
| 1987 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1988 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1989 | |
| 1990 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1991 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1992 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1993 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1994 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1995 | I915_WRITE_FW(DSPARB, dsparb); |
| 1996 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1997 | break; |
| 1998 | case PIPE_B: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1999 | dsparb = I915_READ_FW(DSPARB); |
| 2000 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2001 | |
| 2002 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 2003 | VLV_FIFO(SPRITED, 0xff)); |
| 2004 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 2005 | VLV_FIFO(SPRITED, sprite1_start)); |
| 2006 | |
| 2007 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 2008 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 2009 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 2010 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 2011 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2012 | I915_WRITE_FW(DSPARB, dsparb); |
| 2013 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2014 | break; |
| 2015 | case PIPE_C: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2016 | dsparb3 = I915_READ_FW(DSPARB3); |
| 2017 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2018 | |
| 2019 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2020 | VLV_FIFO(SPRITEF, 0xff)); |
| 2021 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2022 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2023 | |
| 2024 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2025 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2026 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2027 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2028 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2029 | I915_WRITE_FW(DSPARB3, dsparb3); |
| 2030 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2031 | break; |
| 2032 | default: |
| 2033 | break; |
| 2034 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2035 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2036 | POSTING_READ_FW(DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2037 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2038 | spin_unlock(&dev_priv->uncore.lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | #undef VLV_FIFO |
| 2042 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2043 | 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] | 2044 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2045 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2046 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2047 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
| 2048 | struct intel_atomic_state *intel_state = |
| 2049 | to_intel_atomic_state(new_crtc_state->base.state); |
| 2050 | const struct intel_crtc_state *old_crtc_state = |
| 2051 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 2052 | 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] | 2053 | int level; |
| 2054 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2055 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 2056 | *intermediate = *optimal; |
| 2057 | |
| 2058 | intermediate->cxsr = false; |
| 2059 | goto out; |
| 2060 | } |
| 2061 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2062 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2063 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2064 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2065 | |
| 2066 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2067 | enum plane_id plane_id; |
| 2068 | |
| 2069 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2070 | intermediate->wm[level].plane[plane_id] = |
| 2071 | min(optimal->wm[level].plane[plane_id], |
| 2072 | active->wm[level].plane[plane_id]); |
| 2073 | } |
| 2074 | |
| 2075 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2076 | active->sr[level].plane); |
| 2077 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2078 | active->sr[level].cursor); |
| 2079 | } |
| 2080 | |
| 2081 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2082 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2083 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2084 | /* |
| 2085 | * If our intermediate WM are identical to the final WM, then we can |
| 2086 | * omit the post-vblank programming; only update if it's different. |
| 2087 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2088 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2089 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2090 | |
| 2091 | return 0; |
| 2092 | } |
| 2093 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2094 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2095 | struct vlv_wm_values *wm) |
| 2096 | { |
| 2097 | struct intel_crtc *crtc; |
| 2098 | int num_active_crtcs = 0; |
| 2099 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2100 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2101 | wm->cxsr = true; |
| 2102 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2103 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2104 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2105 | |
| 2106 | if (!crtc->active) |
| 2107 | continue; |
| 2108 | |
| 2109 | if (!wm_state->cxsr) |
| 2110 | wm->cxsr = false; |
| 2111 | |
| 2112 | num_active_crtcs++; |
| 2113 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2114 | } |
| 2115 | |
| 2116 | if (num_active_crtcs != 1) |
| 2117 | wm->cxsr = false; |
| 2118 | |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2119 | if (num_active_crtcs > 1) |
| 2120 | wm->level = VLV_WM_LEVEL_PM2; |
| 2121 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2122 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2123 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2124 | enum pipe pipe = crtc->pipe; |
| 2125 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2126 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2127 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2128 | wm->sr = wm_state->sr[wm->level]; |
| 2129 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2130 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2131 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2132 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2133 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2137 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2138 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2139 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2140 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2141 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2142 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2143 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2144 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2145 | return; |
| 2146 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2147 | 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] | 2148 | chv_set_memory_dvfs(dev_priv, false); |
| 2149 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2150 | 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] | 2151 | chv_set_memory_pm5(dev_priv, false); |
| 2152 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2153 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2154 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2155 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2156 | vlv_write_wm_values(dev_priv, &new_wm); |
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 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2159 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2160 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2161 | 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] | 2162 | chv_set_memory_pm5(dev_priv, true); |
| 2163 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2164 | 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] | 2165 | chv_set_memory_dvfs(dev_priv, true); |
| 2166 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2167 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2168 | } |
| 2169 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2170 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
| 2171 | struct intel_crtc_state *crtc_state) |
| 2172 | { |
| 2173 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2174 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2175 | |
| 2176 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2177 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2178 | vlv_program_watermarks(dev_priv); |
| 2179 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2180 | } |
| 2181 | |
| 2182 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
| 2183 | struct intel_crtc_state *crtc_state) |
| 2184 | { |
| 2185 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2186 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2187 | |
| 2188 | if (!crtc_state->wm.need_postvbl_update) |
| 2189 | return; |
| 2190 | |
| 2191 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 2192 | intel_crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2193 | vlv_program_watermarks(dev_priv); |
| 2194 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2195 | } |
| 2196 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2197 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2198 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2199 | 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] | 2200 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2201 | int srwm = 1; |
| 2202 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2203 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2204 | |
| 2205 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2206 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2207 | if (crtc) { |
| 2208 | /* self-refresh has much higher latency */ |
| 2209 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2210 | const struct drm_display_mode *adjusted_mode = |
| 2211 | &crtc->config->base.adjusted_mode; |
| 2212 | const struct drm_framebuffer *fb = |
| 2213 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2214 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2215 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2216 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2217 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2218 | int entries; |
| 2219 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2220 | entries = intel_wm_method2(clock, htotal, |
| 2221 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2222 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2223 | srwm = I965_FIFO_SIZE - entries; |
| 2224 | if (srwm < 0) |
| 2225 | srwm = 1; |
| 2226 | srwm &= 0x1ff; |
| 2227 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 2228 | entries, srwm); |
| 2229 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2230 | entries = intel_wm_method2(clock, htotal, |
| 2231 | crtc->base.cursor->state->crtc_w, 4, |
| 2232 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2233 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2234 | i965_cursor_wm_info.cacheline_size) + |
| 2235 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2236 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2237 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2238 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2239 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2240 | |
| 2241 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 2242 | "cursor %d\n", srwm, cursor_sr); |
| 2243 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2244 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2245 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2246 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2247 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2248 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2252 | srwm); |
| 2253 | |
| 2254 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2255 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2256 | FW_WM(8, CURSORB) | |
| 2257 | FW_WM(8, PLANEB) | |
| 2258 | FW_WM(8, PLANEA)); |
| 2259 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2260 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2261 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2262 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2263 | |
| 2264 | if (cxsr_enabled) |
| 2265 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2266 | } |
| 2267 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2268 | #undef FW_WM |
| 2269 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2270 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2271 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2272 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2273 | const struct intel_watermark_params *wm_info; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2274 | u32 fwater_lo; |
| 2275 | u32 fwater_hi; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2276 | int cwm, srwm = 1; |
| 2277 | int fifo_size; |
| 2278 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2279 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2280 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2281 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2282 | wm_info = &i945_wm_info; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2283 | else if (!IS_GEN(dev_priv, 2)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2284 | wm_info = &i915_wm_info; |
| 2285 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2286 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2287 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2288 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_A); |
| 2289 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2290 | if (intel_crtc_active(crtc)) { |
| 2291 | const struct drm_display_mode *adjusted_mode = |
| 2292 | &crtc->config->base.adjusted_mode; |
| 2293 | const struct drm_framebuffer *fb = |
| 2294 | crtc->base.primary->state->fb; |
| 2295 | int cpp; |
| 2296 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2297 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2298 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2299 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2300 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2301 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2302 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2303 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2304 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2305 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2306 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2307 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2308 | if (planea_wm > (long)wm_info->max_wm) |
| 2309 | planea_wm = wm_info->max_wm; |
| 2310 | } |
| 2311 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2312 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2313 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2314 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2315 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_B); |
| 2316 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2317 | if (intel_crtc_active(crtc)) { |
| 2318 | const struct drm_display_mode *adjusted_mode = |
| 2319 | &crtc->config->base.adjusted_mode; |
| 2320 | const struct drm_framebuffer *fb = |
| 2321 | crtc->base.primary->state->fb; |
| 2322 | int cpp; |
| 2323 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2324 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2325 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2326 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2327 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2328 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2329 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2330 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2331 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2332 | if (enabled == NULL) |
| 2333 | enabled = crtc; |
| 2334 | else |
| 2335 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2336 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2337 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2338 | if (planeb_wm > (long)wm_info->max_wm) |
| 2339 | planeb_wm = wm_info->max_wm; |
| 2340 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2341 | |
| 2342 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2343 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2344 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2345 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2346 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2347 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2348 | |
| 2349 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2350 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2351 | enabled = NULL; |
| 2352 | } |
| 2353 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2354 | /* |
| 2355 | * Overlay gets an aggressive default since video jitter is bad. |
| 2356 | */ |
| 2357 | cwm = 2; |
| 2358 | |
| 2359 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2360 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2361 | |
| 2362 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2363 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2364 | /* self-refresh has much higher latency */ |
| 2365 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2366 | const struct drm_display_mode *adjusted_mode = |
| 2367 | &enabled->config->base.adjusted_mode; |
| 2368 | const struct drm_framebuffer *fb = |
| 2369 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2370 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2371 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2372 | int hdisplay = enabled->config->pipe_src_w; |
| 2373 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2374 | int entries; |
| 2375 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2376 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2377 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2378 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2379 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2380 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2381 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2382 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2383 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 2384 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 2385 | srwm = wm_info->fifo_size - entries; |
| 2386 | if (srwm < 0) |
| 2387 | srwm = 1; |
| 2388 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2389 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2390 | I915_WRITE(FW_BLC_SELF, |
| 2391 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2392 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2393 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2394 | } |
| 2395 | |
| 2396 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2397 | planea_wm, planeb_wm, cwm, srwm); |
| 2398 | |
| 2399 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2400 | fwater_hi = (cwm & 0x1f); |
| 2401 | |
| 2402 | /* Set request length to 8 cachelines per fetch */ |
| 2403 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2404 | fwater_hi = fwater_hi | (1 << 8); |
| 2405 | |
| 2406 | I915_WRITE(FW_BLC, fwater_lo); |
| 2407 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2408 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2409 | if (enabled) |
| 2410 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2411 | } |
| 2412 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2413 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2414 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2415 | 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] | 2416 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2417 | const struct drm_display_mode *adjusted_mode; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2418 | u32 fwater_lo; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2419 | int planea_wm; |
| 2420 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2421 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2422 | if (crtc == NULL) |
| 2423 | return; |
| 2424 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2425 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2426 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2427 | &i845_wm_info, |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2428 | dev_priv->display.get_fifo_size(dev_priv, PLANE_A), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2429 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2430 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2431 | fwater_lo |= (3<<8) | planea_wm; |
| 2432 | |
| 2433 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 2434 | |
| 2435 | I915_WRITE(FW_BLC, fwater_lo); |
| 2436 | } |
| 2437 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2438 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2439 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2440 | unsigned int cpp, |
| 2441 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2442 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2443 | unsigned int ret; |
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 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2446 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2447 | |
| 2448 | return ret; |
| 2449 | } |
| 2450 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2451 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2452 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2453 | unsigned int htotal, |
| 2454 | unsigned int width, |
| 2455 | unsigned int cpp, |
| 2456 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2457 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2458 | unsigned int ret; |
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 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2461 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2462 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2463 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2464 | return ret; |
| 2465 | } |
| 2466 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2467 | 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] | 2468 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2469 | /* |
| 2470 | * Neither of these should be possible since this function shouldn't be |
| 2471 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2472 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2473 | * elsewhere in the driver. |
| 2474 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2475 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2476 | return 0; |
| 2477 | if (WARN_ON(!horiz_pixels)) |
| 2478 | return 0; |
| 2479 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2480 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2481 | } |
| 2482 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2483 | struct ilk_wm_maximums { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2484 | u16 pri; |
| 2485 | u16 spr; |
| 2486 | u16 cur; |
| 2487 | u16 fbc; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2488 | }; |
| 2489 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2490 | /* |
| 2491 | * For both WM_PIPE and WM_LP. |
| 2492 | * mem_value must be in 0.1us units. |
| 2493 | */ |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2494 | static u32 ilk_compute_pri_wm(const struct intel_crtc_state *cstate, |
| 2495 | const struct intel_plane_state *pstate, |
| 2496 | u32 mem_value, bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2497 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2498 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2499 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2500 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2501 | if (mem_value == 0) |
| 2502 | return U32_MAX; |
| 2503 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2504 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2505 | return 0; |
| 2506 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2507 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2508 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2509 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2510 | |
| 2511 | if (!is_lp) |
| 2512 | return method1; |
| 2513 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2514 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2515 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2516 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2517 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2518 | |
| 2519 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2520 | } |
| 2521 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2522 | /* |
| 2523 | * For both WM_PIPE and WM_LP. |
| 2524 | * mem_value must be in 0.1us units. |
| 2525 | */ |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2526 | static u32 ilk_compute_spr_wm(const struct intel_crtc_state *cstate, |
| 2527 | const struct intel_plane_state *pstate, |
| 2528 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2529 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2530 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2531 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2532 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2533 | if (mem_value == 0) |
| 2534 | return U32_MAX; |
| 2535 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2536 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2537 | return 0; |
| 2538 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2539 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2540 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2541 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
| 2542 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2543 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2544 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2545 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2546 | return min(method1, method2); |
| 2547 | } |
| 2548 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2549 | /* |
| 2550 | * For both WM_PIPE and WM_LP. |
| 2551 | * mem_value must be in 0.1us units. |
| 2552 | */ |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2553 | static u32 ilk_compute_cur_wm(const struct intel_crtc_state *cstate, |
| 2554 | const struct intel_plane_state *pstate, |
| 2555 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2556 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2557 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2558 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2559 | if (mem_value == 0) |
| 2560 | return U32_MAX; |
| 2561 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2562 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2563 | return 0; |
| 2564 | |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2565 | cpp = pstate->base.fb->format->cpp[0]; |
| 2566 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2567 | return ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2568 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2569 | pstate->base.crtc_w, cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2570 | } |
| 2571 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2572 | /* Only for WM_LP. */ |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2573 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
| 2574 | const struct intel_plane_state *pstate, |
| 2575 | u32 pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2576 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2577 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2578 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2579 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2580 | return 0; |
| 2581 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2582 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2583 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2584 | return ilk_wm_fbc(pri_val, drm_rect_width(&pstate->base.dst), cpp); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2585 | } |
| 2586 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2587 | static unsigned int |
| 2588 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2589 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2590 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2591 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2592 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2593 | return 768; |
| 2594 | else |
| 2595 | return 512; |
| 2596 | } |
| 2597 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2598 | static unsigned int |
| 2599 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2600 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2601 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2602 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2603 | /* BDW primary/sprite plane watermarks */ |
| 2604 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2605 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2606 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2607 | return level == 0 ? 127 : 1023; |
| 2608 | else if (!is_sprite) |
| 2609 | /* ILK/SNB primary plane watermarks */ |
| 2610 | return level == 0 ? 127 : 511; |
| 2611 | else |
| 2612 | /* ILK/SNB sprite plane watermarks */ |
| 2613 | return level == 0 ? 63 : 255; |
| 2614 | } |
| 2615 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2616 | static unsigned int |
| 2617 | 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] | 2618 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2619 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2620 | return level == 0 ? 63 : 255; |
| 2621 | else |
| 2622 | return level == 0 ? 31 : 63; |
| 2623 | } |
| 2624 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2625 | 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] | 2626 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2627 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2628 | return 31; |
| 2629 | else |
| 2630 | return 15; |
| 2631 | } |
| 2632 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2633 | /* Calculate the maximum primary/sprite plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2634 | 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] | 2635 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2636 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2637 | enum intel_ddb_partitioning ddb_partitioning, |
| 2638 | bool is_sprite) |
| 2639 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2640 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2641 | |
| 2642 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2643 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2644 | return 0; |
| 2645 | |
| 2646 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2647 | if (level == 0 || config->num_pipes_active > 1) { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2648 | fifo_size /= INTEL_INFO(dev_priv)->num_pipes; |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2649 | |
| 2650 | /* |
| 2651 | * For some reason the non self refresh |
| 2652 | * FIFO size is only half of the self |
| 2653 | * refresh FIFO size on ILK/SNB. |
| 2654 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2655 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2656 | fifo_size /= 2; |
| 2657 | } |
| 2658 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2659 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2660 | /* level 0 is always calculated with 1:1 split */ |
| 2661 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2662 | if (is_sprite) |
| 2663 | fifo_size *= 5; |
| 2664 | fifo_size /= 6; |
| 2665 | } else { |
| 2666 | fifo_size /= 2; |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2671 | 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] | 2672 | } |
| 2673 | |
| 2674 | /* Calculate the maximum cursor plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2675 | 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] | 2676 | int level, |
| 2677 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2678 | { |
| 2679 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2680 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2681 | return 64; |
| 2682 | |
| 2683 | /* otherwise just report max that registers can hold */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2684 | return ilk_cursor_wm_reg_max(dev_priv, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2685 | } |
| 2686 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2687 | 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] | 2688 | int level, |
| 2689 | const struct intel_wm_config *config, |
| 2690 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2691 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2692 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2693 | max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false); |
| 2694 | max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true); |
| 2695 | max->cur = ilk_cursor_wm_max(dev_priv, level, config); |
| 2696 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2697 | } |
| 2698 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2699 | 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] | 2700 | int level, |
| 2701 | struct ilk_wm_maximums *max) |
| 2702 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2703 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2704 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2705 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2706 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2707 | } |
| 2708 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2709 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2710 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2711 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2712 | { |
| 2713 | bool ret; |
| 2714 | |
| 2715 | /* already determined to be invalid? */ |
| 2716 | if (!result->enable) |
| 2717 | return false; |
| 2718 | |
| 2719 | result->enable = result->pri_val <= max->pri && |
| 2720 | result->spr_val <= max->spr && |
| 2721 | result->cur_val <= max->cur; |
| 2722 | |
| 2723 | ret = result->enable; |
| 2724 | |
| 2725 | /* |
| 2726 | * HACK until we can pre-compute everything, |
| 2727 | * and thus fail gracefully if LP0 watermarks |
| 2728 | * are exceeded... |
| 2729 | */ |
| 2730 | if (level == 0 && !result->enable) { |
| 2731 | if (result->pri_val > max->pri) |
| 2732 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2733 | level, result->pri_val, max->pri); |
| 2734 | if (result->spr_val > max->spr) |
| 2735 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2736 | level, result->spr_val, max->spr); |
| 2737 | if (result->cur_val > max->cur) |
| 2738 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2739 | level, result->cur_val, max->cur); |
| 2740 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2741 | result->pri_val = min_t(u32, result->pri_val, max->pri); |
| 2742 | result->spr_val = min_t(u32, result->spr_val, max->spr); |
| 2743 | result->cur_val = min_t(u32, result->cur_val, max->cur); |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2744 | result->enable = true; |
| 2745 | } |
| 2746 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2747 | return ret; |
| 2748 | } |
| 2749 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2750 | 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] | 2751 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2752 | int level, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2753 | struct intel_crtc_state *cstate, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2754 | const struct intel_plane_state *pristate, |
| 2755 | const struct intel_plane_state *sprstate, |
| 2756 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2757 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2758 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2759 | u16 pri_latency = dev_priv->wm.pri_latency[level]; |
| 2760 | u16 spr_latency = dev_priv->wm.spr_latency[level]; |
| 2761 | u16 cur_latency = dev_priv->wm.cur_latency[level]; |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2762 | |
| 2763 | /* WM1+ latency values stored in 0.5us units */ |
| 2764 | if (level > 0) { |
| 2765 | pri_latency *= 5; |
| 2766 | spr_latency *= 5; |
| 2767 | cur_latency *= 5; |
| 2768 | } |
| 2769 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2770 | if (pristate) { |
| 2771 | result->pri_val = ilk_compute_pri_wm(cstate, pristate, |
| 2772 | pri_latency, level); |
| 2773 | result->fbc_val = ilk_compute_fbc_wm(cstate, pristate, result->pri_val); |
| 2774 | } |
| 2775 | |
| 2776 | if (sprstate) |
| 2777 | result->spr_val = ilk_compute_spr_wm(cstate, sprstate, spr_latency); |
| 2778 | |
| 2779 | if (curstate) |
| 2780 | result->cur_val = ilk_compute_cur_wm(cstate, curstate, cur_latency); |
| 2781 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2782 | result->enable = true; |
| 2783 | } |
| 2784 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2785 | static u32 |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2786 | hsw_compute_linetime_wm(const struct intel_crtc_state *cstate) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2787 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2788 | const struct intel_atomic_state *intel_state = |
| 2789 | to_intel_atomic_state(cstate->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2790 | const struct drm_display_mode *adjusted_mode = |
| 2791 | &cstate->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2792 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2793 | |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2794 | if (!cstate->base.active) |
| 2795 | return 0; |
| 2796 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2797 | return 0; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2798 | if (WARN_ON(intel_state->cdclk.logical.cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2799 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2800 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2801 | /* The WM are computed with base on how long it takes to fill a single |
| 2802 | * row at the given clock rate, multiplied by 8. |
| 2803 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2804 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2805 | adjusted_mode->crtc_clock); |
| 2806 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2807 | intel_state->cdclk.logical.cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2808 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2809 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2810 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2811 | } |
| 2812 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2813 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2814 | u16 wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2815 | { |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2816 | if (INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2817 | u32 val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2818 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2819 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2820 | |
| 2821 | /* read the first set of memory latencies[0:3] */ |
| 2822 | val = 0; /* data0 to be programmed to 0 for first set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2823 | ret = sandybridge_pcode_read(dev_priv, |
| 2824 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2825 | &val); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2826 | |
| 2827 | if (ret) { |
| 2828 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2829 | return; |
| 2830 | } |
| 2831 | |
| 2832 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2833 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2834 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2835 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2836 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2837 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2838 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2839 | |
| 2840 | /* read the second set of memory latencies[4:7] */ |
| 2841 | val = 1; /* data0 to be programmed to 1 for second set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2842 | ret = sandybridge_pcode_read(dev_priv, |
| 2843 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2844 | &val); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2845 | if (ret) { |
| 2846 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2847 | return; |
| 2848 | } |
| 2849 | |
| 2850 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2851 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2852 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2853 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2854 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2855 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2856 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2857 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2858 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2859 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2860 | * need to be disabled. We make sure to sanitize the values out |
| 2861 | * of the punit to satisfy this requirement. |
| 2862 | */ |
| 2863 | for (level = 1; level <= max_level; level++) { |
| 2864 | if (wm[level] == 0) { |
| 2865 | for (i = level + 1; i <= max_level; i++) |
| 2866 | wm[i] = 0; |
| 2867 | break; |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | /* |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2872 | * WaWmMemoryReadLatency:skl+,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2873 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2874 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2875 | * to add 2us to the various latency levels we retrieve from the |
| 2876 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2877 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2878 | if (wm[0] == 0) { |
| 2879 | wm[0] += 2; |
| 2880 | for (level = 1; level <= max_level; level++) { |
| 2881 | if (wm[level] == 0) |
| 2882 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2883 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2884 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2885 | } |
| 2886 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2887 | /* |
| 2888 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2889 | * If we could not get dimm info enable this WA to prevent from |
| 2890 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2891 | * to avoid any underrun. |
| 2892 | */ |
Ville Syrjälä | 5d6f36b | 2018-10-23 21:21:02 +0300 | [diff] [blame] | 2893 | if (dev_priv->dram_info.is_16gb_dimm) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2894 | wm[0] += 1; |
| 2895 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2896 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2897 | u64 sskpd = I915_READ64(MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2898 | |
| 2899 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2900 | if (wm[0] == 0) |
| 2901 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2902 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2903 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2904 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2905 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2906 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2907 | u32 sskpd = I915_READ(MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2908 | |
| 2909 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2910 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2911 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2912 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2913 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2914 | u32 mltr = I915_READ(MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2915 | |
| 2916 | /* ILK primary LP0 latency is 700 ns */ |
| 2917 | wm[0] = 7; |
| 2918 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2919 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2920 | } else { |
| 2921 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2922 | } |
| 2923 | } |
| 2924 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2925 | 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] | 2926 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2927 | { |
| 2928 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2929 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2930 | wm[0] = 13; |
| 2931 | } |
| 2932 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2933 | 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] | 2934 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2935 | { |
| 2936 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2937 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2938 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2939 | } |
| 2940 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2941 | 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] | 2942 | { |
| 2943 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2944 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2945 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2946 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2947 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2948 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2949 | return 3; |
| 2950 | else |
| 2951 | return 2; |
| 2952 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2953 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2954 | 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] | 2955 | const char *name, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2956 | const u16 wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2957 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2958 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2959 | |
| 2960 | for (level = 0; level <= max_level; level++) { |
| 2961 | unsigned int latency = wm[level]; |
| 2962 | |
| 2963 | if (latency == 0) { |
Chris Wilson | 86c1c87 | 2018-07-26 17:15:27 +0100 | [diff] [blame] | 2964 | DRM_DEBUG_KMS("%s WM%d latency not provided\n", |
| 2965 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2966 | continue; |
| 2967 | } |
| 2968 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2969 | /* |
| 2970 | * - latencies are in us on gen9. |
| 2971 | * - before then, WM1+ latency values are in 0.5us units |
| 2972 | */ |
Paulo Zanoni | dfc267a | 2017-08-09 13:52:46 -0700 | [diff] [blame] | 2973 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2974 | latency *= 10; |
| 2975 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2976 | latency *= 5; |
| 2977 | |
| 2978 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2979 | name, level, wm[level], |
| 2980 | latency / 10, latency % 10); |
| 2981 | } |
| 2982 | } |
| 2983 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2984 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2985 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2986 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2987 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2988 | |
| 2989 | if (wm[0] >= min) |
| 2990 | return false; |
| 2991 | |
| 2992 | wm[0] = max(wm[0], min); |
| 2993 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2994 | 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] | 2995 | |
| 2996 | return true; |
| 2997 | } |
| 2998 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2999 | 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] | 3000 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3001 | bool changed; |
| 3002 | |
| 3003 | /* |
| 3004 | * The BIOS provided WM memory latency values are often |
| 3005 | * inadequate for high resolution displays. Adjust them. |
| 3006 | */ |
| 3007 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 3008 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 3009 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 3010 | |
| 3011 | if (!changed) |
| 3012 | return; |
| 3013 | |
| 3014 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3015 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3016 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3017 | 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] | 3018 | } |
| 3019 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3020 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 3021 | { |
| 3022 | /* |
| 3023 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 3024 | * LP3 usage can cause vblank interrupts to be lost. |
| 3025 | * The DEIIR bit will go high but it looks like the CPU |
| 3026 | * never gets interrupted. |
| 3027 | * |
| 3028 | * It's not clear whether other interrupt source could |
| 3029 | * be affected or if this is somehow limited to vblank |
| 3030 | * interrupts only. To play it safe we disable LP3 |
| 3031 | * watermarks entirely. |
| 3032 | */ |
| 3033 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3034 | dev_priv->wm.spr_latency[3] == 0 && |
| 3035 | dev_priv->wm.cur_latency[3] == 0) |
| 3036 | return; |
| 3037 | |
| 3038 | dev_priv->wm.pri_latency[3] = 0; |
| 3039 | dev_priv->wm.spr_latency[3] = 0; |
| 3040 | dev_priv->wm.cur_latency[3] = 0; |
| 3041 | |
| 3042 | DRM_DEBUG_KMS("LP3 watermarks disabled due to potential for lost interrupts\n"); |
| 3043 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3044 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3045 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3046 | } |
| 3047 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3048 | 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] | 3049 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3050 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3051 | |
| 3052 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3053 | sizeof(dev_priv->wm.pri_latency)); |
| 3054 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3055 | sizeof(dev_priv->wm.pri_latency)); |
| 3056 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3057 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3058 | 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] | 3059 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3060 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3061 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3062 | 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] | 3063 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3064 | if (IS_GEN(dev_priv, 6)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3065 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3066 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3067 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3068 | } |
| 3069 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3070 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3071 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3072 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3073 | 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] | 3074 | } |
| 3075 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3076 | 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] | 3077 | struct intel_pipe_wm *pipe_wm) |
| 3078 | { |
| 3079 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3080 | const struct intel_wm_config config = { |
| 3081 | .num_pipes_active = 1, |
| 3082 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3083 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3084 | }; |
| 3085 | struct ilk_wm_maximums max; |
| 3086 | |
| 3087 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3088 | 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] | 3089 | |
| 3090 | /* At least LP0 must be valid */ |
| 3091 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 3092 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 3093 | return false; |
| 3094 | } |
| 3095 | |
| 3096 | return true; |
| 3097 | } |
| 3098 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3099 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3100 | static int ilk_compute_pipe_wm(struct intel_crtc_state *cstate) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3101 | { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3102 | struct drm_atomic_state *state = cstate->base.state; |
| 3103 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3104 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3105 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3106 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3107 | struct drm_plane *plane; |
| 3108 | const struct drm_plane_state *plane_state; |
| 3109 | const struct intel_plane_state *pristate = NULL; |
| 3110 | const struct intel_plane_state *sprstate = NULL; |
| 3111 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3112 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3113 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3114 | |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3115 | pipe_wm = &cstate->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3116 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3117 | drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, &cstate->base) { |
| 3118 | const struct intel_plane_state *ps = to_intel_plane_state(plane_state); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3119 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3120 | if (plane->type == DRM_PLANE_TYPE_PRIMARY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3121 | pristate = ps; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3122 | else if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3123 | sprstate = ps; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3124 | else if (plane->type == DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3125 | curstate = ps; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3128 | pipe_wm->pipe_enabled = cstate->base.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3129 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3130 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 3131 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 3132 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 3133 | 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] | 3134 | } |
| 3135 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3136 | usable_level = max_level; |
| 3137 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3138 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3139 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3140 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3141 | |
| 3142 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3143 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3144 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3145 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3146 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3147 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, cstate, |
| 3148 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3149 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3150 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 3151 | pipe_wm->linetime = hsw_compute_linetime_wm(cstate); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3152 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3153 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3154 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3155 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3156 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3157 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3158 | for (level = 1; level <= usable_level; level++) { |
| 3159 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3160 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3161 | ilk_compute_wm_level(dev_priv, intel_crtc, level, cstate, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3162 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3163 | |
| 3164 | /* |
| 3165 | * Disable any watermark level that exceeds the |
| 3166 | * register maximums since such watermarks are |
| 3167 | * always invalid. |
| 3168 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3169 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3170 | memset(wm, 0, sizeof(*wm)); |
| 3171 | break; |
| 3172 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3173 | } |
| 3174 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3175 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3179 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3180 | * state and the new state. These can be programmed to the hardware |
| 3181 | * immediately. |
| 3182 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3183 | static int ilk_compute_intermediate_wm(struct intel_crtc_state *newstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3184 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3185 | struct intel_crtc *intel_crtc = to_intel_crtc(newstate->base.crtc); |
| 3186 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3187 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3188 | struct intel_atomic_state *intel_state = |
| 3189 | to_intel_atomic_state(newstate->base.state); |
| 3190 | const struct intel_crtc_state *oldstate = |
| 3191 | intel_atomic_get_old_crtc_state(intel_state, intel_crtc); |
| 3192 | const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3193 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3194 | |
| 3195 | /* |
| 3196 | * Start with the final, target watermarks, then combine with the |
| 3197 | * currently active watermarks to get values that are safe both before |
| 3198 | * and after the vblank. |
| 3199 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3200 | *a = newstate->wm.ilk.optimal; |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 3201 | if (!newstate->base.active || drm_atomic_crtc_needs_modeset(&newstate->base) || |
| 3202 | intel_state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3203 | return 0; |
| 3204 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3205 | a->pipe_enabled |= b->pipe_enabled; |
| 3206 | a->sprites_enabled |= b->sprites_enabled; |
| 3207 | a->sprites_scaled |= b->sprites_scaled; |
| 3208 | |
| 3209 | for (level = 0; level <= max_level; level++) { |
| 3210 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3211 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3212 | |
| 3213 | a_wm->enable &= b_wm->enable; |
| 3214 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3215 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3216 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3217 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3218 | } |
| 3219 | |
| 3220 | /* |
| 3221 | * We need to make sure that these merged watermark values are |
| 3222 | * actually a valid configuration themselves. If they're not, |
| 3223 | * there's no safe way to transition from the old state to |
| 3224 | * the new state, so we need to fail the atomic transaction. |
| 3225 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3226 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3227 | return -EINVAL; |
| 3228 | |
| 3229 | /* |
| 3230 | * If our intermediate WM are identical to the final WM, then we can |
| 3231 | * omit the post-vblank programming; only update if it's different. |
| 3232 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3233 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3234 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3235 | |
| 3236 | return 0; |
| 3237 | } |
| 3238 | |
| 3239 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3240 | * Merge the watermarks from all active pipes for a specific level. |
| 3241 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3242 | 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] | 3243 | int level, |
| 3244 | struct intel_wm_level *ret_wm) |
| 3245 | { |
| 3246 | const struct intel_crtc *intel_crtc; |
| 3247 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3248 | ret_wm->enable = true; |
| 3249 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3250 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3251 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3252 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3253 | |
| 3254 | if (!active->pipe_enabled) |
| 3255 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3256 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3257 | /* |
| 3258 | * The watermark values may have been used in the past, |
| 3259 | * so we must maintain them in the registers for some |
| 3260 | * time even if the level is now disabled. |
| 3261 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3262 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3263 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3264 | |
| 3265 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3266 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3267 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3268 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3269 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | /* |
| 3273 | * Merge all low power watermarks for all active pipes. |
| 3274 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3275 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3276 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3277 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3278 | struct intel_pipe_wm *merged) |
| 3279 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3280 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3281 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3282 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3283 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3284 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3285 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3286 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3287 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3288 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3289 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3290 | |
| 3291 | /* merge each WM1+ level */ |
| 3292 | for (level = 1; level <= max_level; level++) { |
| 3293 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3294 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3295 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3296 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3297 | if (level > last_enabled_level) |
| 3298 | wm->enable = false; |
| 3299 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3300 | /* make sure all following levels get disabled */ |
| 3301 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3302 | |
| 3303 | /* |
| 3304 | * The spec says it is preferred to disable |
| 3305 | * FBC WMs instead of disabling a WM level. |
| 3306 | */ |
| 3307 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3308 | if (wm->enable) |
| 3309 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3310 | wm->fbc_val = 0; |
| 3311 | } |
| 3312 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3313 | |
| 3314 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3315 | /* |
| 3316 | * FIXME this is racy. FBC might get enabled later. |
| 3317 | * What we should check here is whether FBC can be |
| 3318 | * enabled sometime later. |
| 3319 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3320 | if (IS_GEN(dev_priv, 5) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3321 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3322 | for (level = 2; level <= max_level; level++) { |
| 3323 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3324 | |
| 3325 | wm->enable = false; |
| 3326 | } |
| 3327 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3328 | } |
| 3329 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3330 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3331 | { |
| 3332 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3333 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3334 | } |
| 3335 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3336 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3337 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3338 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3339 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3340 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3341 | return 2 * level; |
| 3342 | else |
| 3343 | return dev_priv->wm.pri_latency[level]; |
| 3344 | } |
| 3345 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3346 | 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] | 3347 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3348 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3349 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3350 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3351 | struct intel_crtc *intel_crtc; |
| 3352 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3353 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3354 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3355 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3356 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3357 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3358 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3359 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3360 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3361 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3362 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3363 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3364 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3365 | /* |
| 3366 | * Maintain the watermark values even if the level is |
| 3367 | * disabled. Doing otherwise could cause underruns. |
| 3368 | */ |
| 3369 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3370 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3371 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3372 | r->cur_val; |
| 3373 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3374 | if (r->enable) |
| 3375 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3376 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3377 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3378 | results->wm_lp[wm_lp - 1] |= |
| 3379 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3380 | else |
| 3381 | results->wm_lp[wm_lp - 1] |= |
| 3382 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3383 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3384 | /* |
| 3385 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3386 | * level is disabled. Doing otherwise could cause underruns. |
| 3387 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3388 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3389 | WARN_ON(wm_lp != 1); |
| 3390 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3391 | } else |
| 3392 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3393 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3394 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3395 | /* LP0 register values */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3396 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3397 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3398 | const struct intel_wm_level *r = |
| 3399 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3400 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3401 | if (WARN_ON(!r->enable)) |
| 3402 | continue; |
| 3403 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3404 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3405 | |
| 3406 | results->wm_pipe[pipe] = |
| 3407 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3408 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3409 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3410 | } |
| 3411 | } |
| 3412 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3413 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3414 | * 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] | 3415 | static struct intel_pipe_wm * |
| 3416 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3417 | struct intel_pipe_wm *r1, |
| 3418 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3419 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3420 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3421 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3422 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3423 | for (level = 1; level <= max_level; level++) { |
| 3424 | if (r1->wm[level].enable) |
| 3425 | level1 = level; |
| 3426 | if (r2->wm[level].enable) |
| 3427 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3428 | } |
| 3429 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3430 | if (level1 == level2) { |
| 3431 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3432 | return r2; |
| 3433 | else |
| 3434 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3435 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3436 | return r1; |
| 3437 | } else { |
| 3438 | return r2; |
| 3439 | } |
| 3440 | } |
| 3441 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3442 | /* dirty bits used to track which watermarks need changes */ |
| 3443 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 3444 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 3445 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3446 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3447 | #define WM_DIRTY_FBC (1 << 24) |
| 3448 | #define WM_DIRTY_DDB (1 << 25) |
| 3449 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3450 | 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] | 3451 | const struct ilk_wm_values *old, |
| 3452 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3453 | { |
| 3454 | unsigned int dirty = 0; |
| 3455 | enum pipe pipe; |
| 3456 | int wm_lp; |
| 3457 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3458 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3459 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 3460 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 3461 | /* Must disable LP1+ watermarks too */ |
| 3462 | dirty |= WM_DIRTY_LP_ALL; |
| 3463 | } |
| 3464 | |
| 3465 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3466 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3467 | /* Must disable LP1+ watermarks too */ |
| 3468 | dirty |= WM_DIRTY_LP_ALL; |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3473 | dirty |= WM_DIRTY_FBC; |
| 3474 | /* Must disable LP1+ watermarks too */ |
| 3475 | dirty |= WM_DIRTY_LP_ALL; |
| 3476 | } |
| 3477 | |
| 3478 | if (old->partitioning != new->partitioning) { |
| 3479 | dirty |= WM_DIRTY_DDB; |
| 3480 | /* Must disable LP1+ watermarks too */ |
| 3481 | dirty |= WM_DIRTY_LP_ALL; |
| 3482 | } |
| 3483 | |
| 3484 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3485 | if (dirty & WM_DIRTY_LP_ALL) |
| 3486 | return dirty; |
| 3487 | |
| 3488 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3489 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3490 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3491 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3492 | break; |
| 3493 | } |
| 3494 | |
| 3495 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3496 | for (; wm_lp <= 3; wm_lp++) |
| 3497 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3498 | |
| 3499 | return dirty; |
| 3500 | } |
| 3501 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3502 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3503 | unsigned int dirty) |
| 3504 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3505 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3506 | bool changed = false; |
| 3507 | |
| 3508 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3509 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3510 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3511 | changed = true; |
| 3512 | } |
| 3513 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3514 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3515 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3516 | changed = true; |
| 3517 | } |
| 3518 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3519 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3520 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3521 | changed = true; |
| 3522 | } |
| 3523 | |
| 3524 | /* |
| 3525 | * Don't touch WM1S_LP_EN here. |
| 3526 | * Doing so could cause underruns. |
| 3527 | */ |
| 3528 | |
| 3529 | return changed; |
| 3530 | } |
| 3531 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3532 | /* |
| 3533 | * The spec says we shouldn't write when we don't need, because every write |
| 3534 | * causes WMs to be re-evaluated, expending some power. |
| 3535 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3536 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3537 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3538 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3539 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3540 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3541 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3542 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3543 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3544 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3545 | return; |
| 3546 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3547 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3548 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3549 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3550 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3551 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3552 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3553 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3554 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 3555 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3556 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3557 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3558 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3559 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3560 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3561 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 3562 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3563 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3564 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3565 | val = I915_READ(WM_MISC); |
| 3566 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3567 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3568 | else |
| 3569 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3570 | I915_WRITE(WM_MISC, val); |
| 3571 | } else { |
| 3572 | val = I915_READ(DISP_ARB_CTL2); |
| 3573 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3574 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3575 | else |
| 3576 | val |= DISP_DATA_PARTITION_5_6; |
| 3577 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3578 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3579 | } |
| 3580 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3581 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3582 | val = I915_READ(DISP_ARB_CTL); |
| 3583 | if (results->enable_fbc_wm) |
| 3584 | val &= ~DISP_FBC_WM_DIS; |
| 3585 | else |
| 3586 | val |= DISP_FBC_WM_DIS; |
| 3587 | I915_WRITE(DISP_ARB_CTL, val); |
| 3588 | } |
| 3589 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3590 | if (dirty & WM_DIRTY_LP(1) && |
| 3591 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3592 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3593 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3594 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3595 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3596 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3597 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3598 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3599 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3600 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3601 | 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] | 3602 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3603 | 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] | 3604 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3605 | 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] | 3606 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3607 | |
| 3608 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3609 | } |
| 3610 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3611 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3612 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3613 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3614 | |
| 3615 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3616 | } |
| 3617 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3618 | static u8 intel_enabled_dbuf_slices_num(struct drm_i915_private *dev_priv) |
| 3619 | { |
| 3620 | u8 enabled_slices; |
| 3621 | |
| 3622 | /* Slice 1 will always be enabled */ |
| 3623 | enabled_slices = 1; |
| 3624 | |
| 3625 | /* Gen prior to GEN11 have only one DBuf slice */ |
| 3626 | if (INTEL_GEN(dev_priv) < 11) |
| 3627 | return enabled_slices; |
| 3628 | |
Imre Deak | 209d735 | 2019-03-07 12:32:35 +0200 | [diff] [blame] | 3629 | /* |
| 3630 | * FIXME: for now we'll only ever use 1 slice; pretend that we have |
| 3631 | * only that 1 slice enabled until we have a proper way for on-demand |
| 3632 | * toggling of the second slice. |
| 3633 | */ |
| 3634 | if (0 && I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3635 | enabled_slices++; |
| 3636 | |
| 3637 | return enabled_slices; |
| 3638 | } |
| 3639 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3640 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3641 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3642 | * so assume we'll always need it in order to avoid underruns. |
| 3643 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3644 | 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] | 3645 | { |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3646 | return IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3647 | } |
| 3648 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3649 | static bool |
| 3650 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3651 | { |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3652 | return (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) && |
| 3653 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3654 | } |
| 3655 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3656 | /* |
| 3657 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3658 | * depending on power and performance requirements. The display engine access |
| 3659 | * to system memory is blocked during the adjustment time. Because of the |
| 3660 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3661 | * underruns if we don't meet all of the following requirements: |
| 3662 | * |
| 3663 | * - <= 1 pipe enabled |
| 3664 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3665 | * - We're not using an interlaced display configuration |
| 3666 | */ |
| 3667 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3668 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3669 | { |
| 3670 | int ret; |
| 3671 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3672 | if (!intel_has_sagv(dev_priv)) |
| 3673 | return 0; |
| 3674 | |
| 3675 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3676 | return 0; |
| 3677 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3678 | DRM_DEBUG_KMS("Enabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3679 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3680 | GEN9_SAGV_ENABLE); |
| 3681 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3682 | /* We don't need to wait for SAGV when enabling */ |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3683 | |
| 3684 | /* |
| 3685 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3686 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3687 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3688 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3689 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3690 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3691 | return 0; |
| 3692 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3693 | DRM_ERROR("Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3694 | return ret; |
| 3695 | } |
| 3696 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3697 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3698 | return 0; |
| 3699 | } |
| 3700 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3701 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3702 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3703 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3704 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3705 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3706 | if (!intel_has_sagv(dev_priv)) |
| 3707 | return 0; |
| 3708 | |
| 3709 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3710 | return 0; |
| 3711 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3712 | DRM_DEBUG_KMS("Disabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3713 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3714 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3715 | GEN9_SAGV_DISABLE, |
| 3716 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3717 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3718 | /* |
| 3719 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3720 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3721 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3722 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3723 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3724 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3725 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3726 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3727 | DRM_ERROR("Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3728 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3729 | } |
| 3730 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3731 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3732 | return 0; |
| 3733 | } |
| 3734 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3735 | bool intel_can_enable_sagv(struct drm_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3736 | { |
| 3737 | struct drm_device *dev = state->dev; |
| 3738 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3739 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3740 | struct intel_crtc *crtc; |
| 3741 | struct intel_plane *plane; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3742 | struct intel_crtc_state *cstate; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3743 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3744 | int level, latency; |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3745 | int sagv_block_time_us; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3746 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3747 | if (!intel_has_sagv(dev_priv)) |
| 3748 | return false; |
| 3749 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3750 | if (IS_GEN(dev_priv, 9)) |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3751 | sagv_block_time_us = 30; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3752 | else if (IS_GEN(dev_priv, 10)) |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3753 | sagv_block_time_us = 20; |
| 3754 | else |
| 3755 | sagv_block_time_us = 10; |
| 3756 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3757 | /* |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3758 | * If there are no active CRTCs, no additional checks need be performed |
| 3759 | */ |
| 3760 | if (hweight32(intel_state->active_crtcs) == 0) |
| 3761 | return true; |
Lucas De Marchi | da17223 | 2019-04-04 16:04:26 -0700 | [diff] [blame] | 3762 | |
| 3763 | /* |
| 3764 | * SKL+ workaround: bspec recommends we disable SAGV when we have |
| 3765 | * more then one pipe enabled |
| 3766 | */ |
| 3767 | if (hweight32(intel_state->active_crtcs) > 1) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3768 | return false; |
| 3769 | |
| 3770 | /* Since we're now guaranteed to only have one active CRTC... */ |
| 3771 | pipe = ffs(intel_state->active_crtcs) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 3772 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3773 | cstate = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3774 | |
Paulo Zanoni | c89cadd | 2016-10-10 17:30:59 -0300 | [diff] [blame] | 3775 | if (crtc->base.state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3776 | return false; |
| 3777 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3778 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3779 | struct skl_plane_wm *wm = |
| 3780 | &cstate->wm.skl.optimal.planes[plane->id]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3781 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3782 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3783 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3784 | continue; |
| 3785 | |
| 3786 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3787 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3788 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3789 | { } |
| 3790 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3791 | latency = dev_priv->wm.skl_latency[level]; |
| 3792 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3793 | if (skl_needs_memory_bw_wa(dev_priv) && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3794 | plane->base.state->fb->modifier == |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3795 | I915_FORMAT_MOD_X_TILED) |
| 3796 | latency += 15; |
| 3797 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3798 | /* |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3799 | * If any of the planes on this pipe don't enable wm levels that |
| 3800 | * incur memory latencies higher than sagv_block_time_us we |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3801 | * can't enable SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3802 | */ |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3803 | if (latency < sagv_block_time_us) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3804 | return false; |
| 3805 | } |
| 3806 | |
| 3807 | return true; |
| 3808 | } |
| 3809 | |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3810 | static u16 intel_get_ddb_size(struct drm_i915_private *dev_priv, |
| 3811 | const struct intel_crtc_state *cstate, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3812 | const u64 total_data_rate, |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3813 | const int num_active, |
| 3814 | struct skl_ddb_allocation *ddb) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3815 | { |
| 3816 | const struct drm_display_mode *adjusted_mode; |
| 3817 | u64 total_data_bw; |
| 3818 | u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3819 | |
| 3820 | WARN_ON(ddb_size == 0); |
| 3821 | |
| 3822 | if (INTEL_GEN(dev_priv) < 11) |
| 3823 | return ddb_size - 4; /* 4 blocks for bypass path allocation */ |
| 3824 | |
| 3825 | adjusted_mode = &cstate->base.adjusted_mode; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3826 | total_data_bw = total_data_rate * drm_mode_vrefresh(adjusted_mode); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3827 | |
| 3828 | /* |
| 3829 | * 12GB/s is maximum BW supported by single DBuf slice. |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3830 | * |
| 3831 | * FIXME dbuf slice code is broken: |
| 3832 | * - must wait for planes to stop using the slice before powering it off |
| 3833 | * - plane straddling both slices is illegal in multi-pipe scenarios |
| 3834 | * - should validate we stay within the hw bandwidth limits |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3835 | */ |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3836 | if (0 && (num_active > 1 || total_data_bw >= GBps(12))) { |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3837 | ddb->enabled_slices = 2; |
| 3838 | } else { |
| 3839 | ddb->enabled_slices = 1; |
| 3840 | ddb_size /= 2; |
| 3841 | } |
| 3842 | |
| 3843 | return ddb_size; |
| 3844 | } |
| 3845 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3846 | static void |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 3847 | skl_ddb_get_pipe_allocation_limits(struct drm_i915_private *dev_priv, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3848 | const struct intel_crtc_state *cstate, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3849 | const u64 total_data_rate, |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3850 | struct skl_ddb_allocation *ddb, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3851 | struct skl_ddb_entry *alloc, /* out */ |
| 3852 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3853 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3854 | struct drm_atomic_state *state = cstate->base.state; |
| 3855 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3856 | struct drm_crtc *for_crtc = cstate->base.crtc; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3857 | const struct drm_crtc_state *crtc_state; |
| 3858 | const struct drm_crtc *crtc; |
| 3859 | u32 pipe_width = 0, total_width = 0, width_before_pipe = 0; |
| 3860 | enum pipe for_pipe = to_intel_crtc(for_crtc)->pipe; |
| 3861 | u16 ddb_size; |
| 3862 | u32 i; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3863 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3864 | if (WARN_ON(!state) || !cstate->base.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3865 | alloc->start = 0; |
| 3866 | alloc->end = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3867 | *num_active = hweight32(dev_priv->active_crtcs); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3868 | return; |
| 3869 | } |
| 3870 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3871 | if (intel_state->active_pipe_changes) |
| 3872 | *num_active = hweight32(intel_state->active_crtcs); |
| 3873 | else |
| 3874 | *num_active = hweight32(dev_priv->active_crtcs); |
| 3875 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3876 | ddb_size = intel_get_ddb_size(dev_priv, cstate, total_data_rate, |
| 3877 | *num_active, ddb); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3878 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3879 | /* |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3880 | * If the state doesn't change the active CRTC's or there is no |
| 3881 | * modeset request, then there's no need to recalculate; |
| 3882 | * the existing pipe allocation limits should remain unchanged. |
| 3883 | * Note that we're safe from racing commits since any racing commit |
| 3884 | * that changes the active CRTC list or do modeset would need to |
| 3885 | * grab _all_ crtc locks, including the one we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3886 | */ |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3887 | if (!intel_state->active_pipe_changes && !intel_state->modeset) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 3888 | /* |
| 3889 | * alloc may be cleared by clear_intel_crtc_state, |
| 3890 | * copy from old state to be sure |
| 3891 | */ |
| 3892 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3893 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3894 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3895 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3896 | /* |
| 3897 | * Watermark/ddb requirement highly depends upon width of the |
| 3898 | * framebuffer, So instead of allocating DDB equally among pipes |
| 3899 | * distribute DDB based on resolution/width of the display. |
| 3900 | */ |
| 3901 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
| 3902 | const struct drm_display_mode *adjusted_mode; |
| 3903 | int hdisplay, vdisplay; |
| 3904 | enum pipe pipe; |
| 3905 | |
| 3906 | if (!crtc_state->enable) |
| 3907 | continue; |
| 3908 | |
| 3909 | pipe = to_intel_crtc(crtc)->pipe; |
| 3910 | adjusted_mode = &crtc_state->adjusted_mode; |
| 3911 | drm_mode_get_hv_timing(adjusted_mode, &hdisplay, &vdisplay); |
| 3912 | total_width += hdisplay; |
| 3913 | |
| 3914 | if (pipe < for_pipe) |
| 3915 | width_before_pipe += hdisplay; |
| 3916 | else if (pipe == for_pipe) |
| 3917 | pipe_width = hdisplay; |
| 3918 | } |
| 3919 | |
| 3920 | alloc->start = ddb_size * width_before_pipe / total_width; |
| 3921 | alloc->end = ddb_size * (width_before_pipe + pipe_width) / total_width; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3922 | } |
| 3923 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3924 | static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 3925 | int width, const struct drm_format_info *format, |
| 3926 | u64 modifier, unsigned int rotation, |
| 3927 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 3928 | int color_plane); |
| 3929 | static void skl_compute_plane_wm(const struct intel_crtc_state *cstate, |
| 3930 | int level, |
| 3931 | const struct skl_wm_params *wp, |
| 3932 | const struct skl_wm_level *result_prev, |
| 3933 | struct skl_wm_level *result /* out */); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3934 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3935 | static unsigned int |
| 3936 | skl_cursor_allocation(const struct intel_crtc_state *crtc_state, |
| 3937 | int num_active) |
| 3938 | { |
| 3939 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 3940 | int level, max_level = ilk_wm_max_level(dev_priv); |
| 3941 | struct skl_wm_level wm = {}; |
| 3942 | int ret, min_ddb_alloc = 0; |
| 3943 | struct skl_wm_params wp; |
| 3944 | |
| 3945 | ret = skl_compute_wm_params(crtc_state, 256, |
| 3946 | drm_format_info(DRM_FORMAT_ARGB8888), |
| 3947 | DRM_FORMAT_MOD_LINEAR, |
| 3948 | DRM_MODE_ROTATE_0, |
| 3949 | crtc_state->pixel_rate, &wp, 0); |
| 3950 | WARN_ON(ret); |
| 3951 | |
| 3952 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | 6086e47 | 2019-03-21 19:51:28 +0200 | [diff] [blame] | 3953 | skl_compute_plane_wm(crtc_state, level, &wp, &wm, &wm); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 3954 | if (wm.min_ddb_alloc == U16_MAX) |
| 3955 | break; |
| 3956 | |
| 3957 | min_ddb_alloc = wm.min_ddb_alloc; |
| 3958 | } |
| 3959 | |
| 3960 | return max(num_active == 1 ? 32 : 8, min_ddb_alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3961 | } |
| 3962 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3963 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 3964 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3965 | { |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3966 | |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 3967 | entry->start = reg & DDB_ENTRY_MASK; |
| 3968 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3969 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3970 | if (entry->end) |
| 3971 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3972 | } |
| 3973 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3974 | static void |
| 3975 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 3976 | const enum pipe pipe, |
| 3977 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3978 | struct skl_ddb_entry *ddb_y, |
| 3979 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3980 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3981 | u32 val, val2; |
| 3982 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3983 | |
| 3984 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 3985 | if (plane_id == PLANE_CURSOR) { |
| 3986 | val = I915_READ(CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3987 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3988 | return; |
| 3989 | } |
| 3990 | |
| 3991 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
| 3992 | |
| 3993 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3994 | if (val & PLANE_CTL_ENABLE) |
| 3995 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 3996 | val & PLANE_CTL_ORDER_RGBX, |
| 3997 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3998 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3999 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4000 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 4001 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4002 | } else { |
| 4003 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
Paulo Zanoni | 12a6c93 | 2018-07-31 17:46:14 -0700 | [diff] [blame] | 4004 | val2 = I915_READ(PLANE_NV12_BUF_CFG(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4005 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4006 | if (is_planar_yuv_format(fourcc)) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4007 | swap(val, val2); |
| 4008 | |
| 4009 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4010 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4011 | } |
| 4012 | } |
| 4013 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4014 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 4015 | struct skl_ddb_entry *ddb_y, |
| 4016 | struct skl_ddb_entry *ddb_uv) |
| 4017 | { |
| 4018 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4019 | enum intel_display_power_domain power_domain; |
| 4020 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4021 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4022 | enum plane_id plane_id; |
| 4023 | |
| 4024 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4025 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 4026 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4027 | return; |
| 4028 | |
| 4029 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4030 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4031 | plane_id, |
| 4032 | &ddb_y[plane_id], |
| 4033 | &ddb_uv[plane_id]); |
| 4034 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4035 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4036 | } |
| 4037 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 4038 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 4039 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4040 | { |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 4041 | ddb->enabled_slices = intel_enabled_dbuf_slices_num(dev_priv); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4042 | } |
| 4043 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4044 | /* |
| 4045 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4046 | * The bspec defines downscale amount as: |
| 4047 | * |
| 4048 | * """ |
| 4049 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4050 | * Horizontal destination size] |
| 4051 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4052 | * Vertical destination size] |
| 4053 | * Total down scale amount = Horizontal down scale amount * |
| 4054 | * Vertical down scale amount |
| 4055 | * """ |
| 4056 | * |
| 4057 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4058 | * Caller should take care of dividing & rounding off the value. |
| 4059 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4060 | static uint_fixed_16_16_t |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4061 | skl_plane_downscale_amount(const struct intel_crtc_state *cstate, |
| 4062 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4063 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4064 | struct intel_plane *plane = to_intel_plane(pstate->base.plane); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4065 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4066 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4067 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4068 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4069 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4070 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4071 | |
| 4072 | /* 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] | 4073 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4074 | /* |
| 4075 | * Cursors only support 0/180 degree rotation, |
| 4076 | * hence no need to account for rotation here. |
| 4077 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4078 | src_w = pstate->base.src_w >> 16; |
| 4079 | src_h = pstate->base.src_h >> 16; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4080 | dst_w = pstate->base.crtc_w; |
| 4081 | dst_h = pstate->base.crtc_h; |
| 4082 | } else { |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4083 | /* |
| 4084 | * Src coordinates are already rotated by 270 degrees for |
| 4085 | * the 90/270 degree plane rotation cases (to match the |
| 4086 | * GTT mapping), hence no need to account for rotation here. |
| 4087 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4088 | src_w = drm_rect_width(&pstate->base.src) >> 16; |
| 4089 | src_h = drm_rect_height(&pstate->base.src) >> 16; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4090 | dst_w = drm_rect_width(&pstate->base.dst); |
| 4091 | dst_h = drm_rect_height(&pstate->base.dst); |
| 4092 | } |
| 4093 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4094 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4095 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4096 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4097 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4098 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4099 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4102 | static uint_fixed_16_16_t |
| 4103 | skl_pipe_downscale_amount(const struct intel_crtc_state *crtc_state) |
| 4104 | { |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4105 | uint_fixed_16_16_t pipe_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4106 | |
| 4107 | if (!crtc_state->base.enable) |
| 4108 | return pipe_downscale; |
| 4109 | |
| 4110 | if (crtc_state->pch_pfit.enabled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4111 | u32 src_w, src_h, dst_w, dst_h; |
| 4112 | u32 pfit_size = crtc_state->pch_pfit.size; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4113 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4114 | uint_fixed_16_16_t downscale_h, downscale_w; |
| 4115 | |
| 4116 | src_w = crtc_state->pipe_src_w; |
| 4117 | src_h = crtc_state->pipe_src_h; |
| 4118 | dst_w = pfit_size >> 16; |
| 4119 | dst_h = pfit_size & 0xffff; |
| 4120 | |
| 4121 | if (!dst_w || !dst_h) |
| 4122 | return pipe_downscale; |
| 4123 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4124 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4125 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4126 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4127 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4128 | |
| 4129 | pipe_downscale = mul_fixed16(downscale_w, downscale_h); |
| 4130 | } |
| 4131 | |
| 4132 | return pipe_downscale; |
| 4133 | } |
| 4134 | |
| 4135 | int skl_check_pipe_max_pixel_rate(struct intel_crtc *intel_crtc, |
| 4136 | struct intel_crtc_state *cstate) |
| 4137 | { |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 4138 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4139 | struct drm_crtc_state *crtc_state = &cstate->base; |
| 4140 | struct drm_atomic_state *state = crtc_state->state; |
| 4141 | struct drm_plane *plane; |
| 4142 | const struct drm_plane_state *pstate; |
| 4143 | struct intel_plane_state *intel_pstate; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4144 | int crtc_clock, dotclk; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4145 | u32 pipe_max_pixel_rate; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4146 | uint_fixed_16_16_t pipe_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4147 | uint_fixed_16_16_t max_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4148 | |
| 4149 | if (!cstate->base.enable) |
| 4150 | return 0; |
| 4151 | |
| 4152 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { |
| 4153 | uint_fixed_16_16_t plane_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4154 | 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] | 4155 | int bpp; |
| 4156 | |
| 4157 | if (!intel_wm_plane_visible(cstate, |
| 4158 | to_intel_plane_state(pstate))) |
| 4159 | continue; |
| 4160 | |
| 4161 | if (WARN_ON(!pstate->fb)) |
| 4162 | return -EINVAL; |
| 4163 | |
| 4164 | intel_pstate = to_intel_plane_state(pstate); |
| 4165 | plane_downscale = skl_plane_downscale_amount(cstate, |
| 4166 | intel_pstate); |
| 4167 | bpp = pstate->fb->format->cpp[0] * 8; |
| 4168 | if (bpp == 64) |
| 4169 | plane_downscale = mul_fixed16(plane_downscale, |
| 4170 | fp_9_div_8); |
| 4171 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4172 | max_downscale = max_fixed16(plane_downscale, max_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4173 | } |
| 4174 | pipe_downscale = skl_pipe_downscale_amount(cstate); |
| 4175 | |
| 4176 | pipe_downscale = mul_fixed16(pipe_downscale, max_downscale); |
| 4177 | |
| 4178 | crtc_clock = crtc_state->adjusted_mode.crtc_clock; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4179 | dotclk = to_intel_atomic_state(state)->cdclk.logical.cdclk; |
| 4180 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 4181 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4182 | dotclk *= 2; |
| 4183 | |
| 4184 | pipe_max_pixel_rate = div_round_up_u32_fixed16(dotclk, pipe_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4185 | |
| 4186 | if (pipe_max_pixel_rate < crtc_clock) { |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4187 | DRM_DEBUG_KMS("Max supported pixel clock with scaling exceeded\n"); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4188 | return -EINVAL; |
| 4189 | } |
| 4190 | |
| 4191 | return 0; |
| 4192 | } |
| 4193 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4194 | static u64 |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4195 | skl_plane_relative_data_rate(const struct intel_crtc_state *cstate, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4196 | const struct intel_plane_state *intel_pstate, |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4197 | const int plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4198 | { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4199 | struct intel_plane *intel_plane = |
| 4200 | to_intel_plane(intel_pstate->base.plane); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4201 | u32 data_rate; |
| 4202 | u32 width = 0, height = 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4203 | struct drm_framebuffer *fb; |
| 4204 | u32 format; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4205 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4206 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4207 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4208 | if (!intel_pstate->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4209 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4210 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4211 | fb = intel_pstate->base.fb; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4212 | format = fb->format->format; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4213 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4214 | if (intel_plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4215 | return 0; |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4216 | if (plane == 1 && !is_planar_yuv_format(format)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4217 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4218 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4219 | /* |
| 4220 | * Src coordinates are already rotated by 270 degrees for |
| 4221 | * the 90/270 degree plane rotation cases (to match the |
| 4222 | * GTT mapping), hence no need to account for rotation here. |
| 4223 | */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4224 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4225 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4226 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4227 | /* UV plane does 1/2 pixel sub-sampling */ |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4228 | if (plane == 1 && is_planar_yuv_format(format)) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4229 | width /= 2; |
| 4230 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4231 | } |
| 4232 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4233 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4234 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4235 | down_scale_amount = skl_plane_downscale_amount(cstate, intel_pstate); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4236 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4237 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4238 | |
| 4239 | rate *= fb->format->cpp[plane]; |
| 4240 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4241 | } |
| 4242 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4243 | static u64 |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4244 | skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4245 | u64 *plane_data_rate, |
| 4246 | u64 *uv_plane_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4247 | { |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4248 | struct drm_crtc_state *cstate = &intel_cstate->base; |
| 4249 | struct drm_atomic_state *state = cstate->state; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4250 | struct drm_plane *plane; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4251 | const struct drm_plane_state *pstate; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4252 | u64 total_data_rate = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4253 | |
| 4254 | if (WARN_ON(!state)) |
| 4255 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4256 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4257 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4258 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, cstate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4259 | enum plane_id plane_id = to_intel_plane(plane)->id; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4260 | u64 rate; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4261 | const struct intel_plane_state *intel_pstate = |
| 4262 | to_intel_plane_state(pstate); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4263 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4264 | /* packed/y */ |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4265 | rate = skl_plane_relative_data_rate(intel_cstate, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4266 | intel_pstate, 0); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4267 | plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4268 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4269 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4270 | /* uv-plane */ |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4271 | rate = skl_plane_relative_data_rate(intel_cstate, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4272 | intel_pstate, 1); |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4273 | uv_plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4274 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | return total_data_rate; |
| 4278 | } |
| 4279 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4280 | static u64 |
| 4281 | icl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate, |
| 4282 | u64 *plane_data_rate) |
| 4283 | { |
| 4284 | struct drm_crtc_state *cstate = &intel_cstate->base; |
| 4285 | struct drm_atomic_state *state = cstate->state; |
| 4286 | struct drm_plane *plane; |
| 4287 | const struct drm_plane_state *pstate; |
| 4288 | u64 total_data_rate = 0; |
| 4289 | |
| 4290 | if (WARN_ON(!state)) |
| 4291 | return 0; |
| 4292 | |
| 4293 | /* Calculate and cache data rate for each plane */ |
| 4294 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, cstate) { |
| 4295 | const struct intel_plane_state *intel_pstate = |
| 4296 | to_intel_plane_state(pstate); |
| 4297 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 4298 | u64 rate; |
| 4299 | |
| 4300 | if (!intel_pstate->linked_plane) { |
| 4301 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4302 | intel_pstate, 0); |
| 4303 | plane_data_rate[plane_id] = rate; |
| 4304 | total_data_rate += rate; |
| 4305 | } else { |
| 4306 | enum plane_id y_plane_id; |
| 4307 | |
| 4308 | /* |
| 4309 | * The slave plane might not iterate in |
| 4310 | * drm_atomic_crtc_state_for_each_plane_state(), |
| 4311 | * and needs the master plane state which may be |
| 4312 | * NULL if we try get_new_plane_state(), so we |
| 4313 | * always calculate from the master. |
| 4314 | */ |
| 4315 | if (intel_pstate->slave) |
| 4316 | continue; |
| 4317 | |
| 4318 | /* Y plane rate is calculated on the slave */ |
| 4319 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4320 | intel_pstate, 0); |
| 4321 | y_plane_id = intel_pstate->linked_plane->id; |
| 4322 | plane_data_rate[y_plane_id] = rate; |
| 4323 | total_data_rate += rate; |
| 4324 | |
| 4325 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4326 | intel_pstate, 1); |
| 4327 | plane_data_rate[plane_id] = rate; |
| 4328 | total_data_rate += rate; |
| 4329 | } |
| 4330 | } |
| 4331 | |
| 4332 | return total_data_rate; |
| 4333 | } |
| 4334 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4335 | static int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4336 | skl_allocate_pipe_ddb(struct intel_crtc_state *cstate, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4337 | struct skl_ddb_allocation *ddb /* out */) |
| 4338 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4339 | struct drm_atomic_state *state = cstate->base.state; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4340 | struct drm_crtc *crtc = cstate->base.crtc; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4341 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4342 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4343 | struct skl_ddb_entry *alloc = &cstate->wm.skl.ddb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4344 | u16 alloc_size, start = 0; |
| 4345 | u16 total[I915_MAX_PLANES] = {}; |
| 4346 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4347 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4348 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4349 | int num_active; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4350 | u64 plane_data_rate[I915_MAX_PLANES] = {}; |
| 4351 | u64 uv_plane_data_rate[I915_MAX_PLANES] = {}; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4352 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4353 | int level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4354 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4355 | /* Clear the partitioning for disabled planes. */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4356 | memset(cstate->wm.skl.plane_ddb_y, 0, sizeof(cstate->wm.skl.plane_ddb_y)); |
| 4357 | memset(cstate->wm.skl.plane_ddb_uv, 0, sizeof(cstate->wm.skl.plane_ddb_uv)); |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4358 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4359 | if (WARN_ON(!state)) |
| 4360 | return 0; |
| 4361 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4362 | if (!cstate->base.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4363 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4364 | return 0; |
| 4365 | } |
| 4366 | |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4367 | if (INTEL_GEN(dev_priv) >= 11) |
| 4368 | total_data_rate = |
| 4369 | icl_get_total_relative_data_rate(cstate, |
| 4370 | plane_data_rate); |
| 4371 | else |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4372 | total_data_rate = |
| 4373 | skl_get_total_relative_data_rate(cstate, |
| 4374 | plane_data_rate, |
| 4375 | uv_plane_data_rate); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4376 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4377 | |
| 4378 | skl_ddb_get_pipe_allocation_limits(dev_priv, cstate, total_data_rate, |
| 4379 | ddb, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4380 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 4381 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4382 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4383 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4384 | /* Allocate fixed number of blocks for cursor. */ |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4385 | total[PLANE_CURSOR] = skl_cursor_allocation(cstate, num_active); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4386 | alloc_size -= total[PLANE_CURSOR]; |
| 4387 | cstate->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
| 4388 | alloc->end - total[PLANE_CURSOR]; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4389 | cstate->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4390 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4391 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4392 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4393 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4394 | /* |
| 4395 | * Find the highest watermark level for which we can satisfy the block |
| 4396 | * requirement of active planes. |
| 4397 | */ |
| 4398 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 4399 | blocks = 0; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4400 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4401 | const struct skl_plane_wm *wm = |
| 4402 | &cstate->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 4403 | |
| 4404 | if (plane_id == PLANE_CURSOR) { |
| 4405 | if (WARN_ON(wm->wm[level].min_ddb_alloc > |
| 4406 | total[PLANE_CURSOR])) { |
| 4407 | blocks = U32_MAX; |
| 4408 | break; |
| 4409 | } |
| 4410 | continue; |
| 4411 | } |
| 4412 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4413 | blocks += wm->wm[level].min_ddb_alloc; |
| 4414 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4415 | } |
| 4416 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame] | 4417 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4418 | alloc_size -= blocks; |
| 4419 | break; |
| 4420 | } |
| 4421 | } |
| 4422 | |
| 4423 | if (level < 0) { |
| 4424 | DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); |
| 4425 | DRM_DEBUG_KMS("minimum required %d/%d\n", blocks, |
| 4426 | alloc_size); |
| 4427 | return -EINVAL; |
| 4428 | } |
| 4429 | |
| 4430 | /* |
| 4431 | * Grant each plane the blocks it requires at the highest achievable |
| 4432 | * watermark level, plus an extra share of the leftover blocks |
| 4433 | * proportional to its relative data rate. |
| 4434 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4435 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4436 | const struct skl_plane_wm *wm = |
| 4437 | &cstate->wm.skl.optimal.planes[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4438 | u64 rate; |
| 4439 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4440 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4441 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4442 | continue; |
| 4443 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4444 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4445 | * We've accounted for all active planes; remaining planes are |
| 4446 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4447 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4448 | if (total_data_rate == 0) |
| 4449 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4450 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4451 | rate = 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 | total[plane_id] = wm->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; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4458 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4459 | if (total_data_rate == 0) |
| 4460 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4461 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4462 | rate = uv_plane_data_rate[plane_id]; |
| 4463 | extra = min_t(u16, alloc_size, |
| 4464 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4465 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4466 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4467 | alloc_size -= extra; |
| 4468 | total_data_rate -= rate; |
| 4469 | } |
| 4470 | WARN_ON(alloc_size != 0 || total_data_rate != 0); |
| 4471 | |
| 4472 | /* Set the actual DDB start/end points for each plane */ |
| 4473 | start = alloc->start; |
| 4474 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4475 | struct skl_ddb_entry *plane_alloc = |
| 4476 | &cstate->wm.skl.plane_ddb_y[plane_id]; |
| 4477 | struct skl_ddb_entry *uv_plane_alloc = |
| 4478 | &cstate->wm.skl.plane_ddb_uv[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4479 | |
| 4480 | if (plane_id == PLANE_CURSOR) |
| 4481 | continue; |
| 4482 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4483 | /* Gen11+ uses a separate plane for UV watermarks */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4484 | WARN_ON(INTEL_GEN(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4485 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4486 | /* Leave disabled planes at (0,0) */ |
| 4487 | if (total[plane_id]) { |
| 4488 | plane_alloc->start = start; |
| 4489 | start += total[plane_id]; |
| 4490 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4491 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4492 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4493 | if (uv_total[plane_id]) { |
| 4494 | uv_plane_alloc->start = start; |
| 4495 | start += uv_total[plane_id]; |
| 4496 | uv_plane_alloc->end = start; |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | /* |
| 4501 | * When we calculated watermark values we didn't know how high |
| 4502 | * of a level we'd actually be able to hit, so we just marked |
| 4503 | * all levels as "enabled." Go back now and disable the ones |
| 4504 | * that aren't actually possible. |
| 4505 | */ |
| 4506 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
| 4507 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4508 | struct skl_plane_wm *wm = |
| 4509 | &cstate->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | a301cb0 | 2019-03-12 22:58:41 +0200 | [diff] [blame] | 4510 | |
| 4511 | /* |
| 4512 | * We only disable the watermarks for each plane if |
| 4513 | * they exceed the ddb allocation of said plane. This |
| 4514 | * is done so that we don't end up touching cursor |
| 4515 | * watermarks needlessly when some other plane reduces |
| 4516 | * our max possible watermark level. |
| 4517 | * |
| 4518 | * Bspec has this to say about the PLANE_WM enable bit: |
| 4519 | * "All the watermarks at this level for all enabled |
| 4520 | * planes must be enabled before the level will be used." |
| 4521 | * So this is actually safe to do. |
| 4522 | */ |
| 4523 | if (wm->wm[level].min_ddb_alloc > total[plane_id] || |
| 4524 | wm->uv_wm[level].min_ddb_alloc > uv_total[plane_id]) |
| 4525 | memset(&wm->wm[level], 0, sizeof(wm->wm[level])); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4526 | |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4527 | /* |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 4528 | * Wa_1408961008:icl, ehl |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4529 | * Underruns with WM1+ disabled |
| 4530 | */ |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 4531 | if (IS_GEN(dev_priv, 11) && |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4532 | level == 1 && wm->wm[0].plane_en) { |
| 4533 | 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] | 4534 | wm->wm[level].plane_res_l = wm->wm[0].plane_res_l; |
| 4535 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4536 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | /* |
| 4541 | * Go back and disable the transition watermark if it turns out we |
| 4542 | * don't have enough DDB blocks for it. |
| 4543 | */ |
| 4544 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4545 | struct skl_plane_wm *wm = |
| 4546 | &cstate->wm.skl.optimal.planes[plane_id]; |
| 4547 | |
Ville Syrjälä | b19c9bc | 2018-12-21 19:14:31 +0200 | [diff] [blame] | 4548 | if (wm->trans_wm.plane_res_b >= total[plane_id]) |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4549 | memset(&wm->trans_wm, 0, sizeof(wm->trans_wm)); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4550 | } |
| 4551 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4552 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4553 | } |
| 4554 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4555 | /* |
| 4556 | * 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] | 4557 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4558 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 4559 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 4560 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4561 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4562 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 4563 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4564 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4565 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4566 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4567 | |
| 4568 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4569 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4570 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4571 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4572 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4573 | |
| 4574 | if (INTEL_GEN(dev_priv) >= 10) |
| 4575 | ret = add_fixed16_u32(ret, 1); |
| 4576 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4577 | return ret; |
| 4578 | } |
| 4579 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4580 | static uint_fixed_16_16_t |
| 4581 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 4582 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4583 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4584 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4585 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4586 | |
| 4587 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4588 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4589 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4590 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4591 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 4592 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4593 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4594 | return ret; |
| 4595 | } |
| 4596 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4597 | static uint_fixed_16_16_t |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4598 | intel_get_linetime_us(const struct intel_crtc_state *cstate) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4599 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4600 | u32 pixel_rate; |
| 4601 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4602 | uint_fixed_16_16_t linetime_us; |
| 4603 | |
| 4604 | if (!cstate->base.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4605 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4606 | |
| 4607 | pixel_rate = cstate->pixel_rate; |
| 4608 | |
| 4609 | if (WARN_ON(pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4610 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4611 | |
| 4612 | crtc_htotal = cstate->base.adjusted_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4613 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4614 | |
| 4615 | return linetime_us; |
| 4616 | } |
| 4617 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4618 | static u32 |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4619 | skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *cstate, |
| 4620 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4621 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4622 | u64 adjusted_pixel_rate; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4623 | uint_fixed_16_16_t downscale_amount; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4624 | |
| 4625 | /* Shouldn't reach here on disabled planes... */ |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4626 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4627 | return 0; |
| 4628 | |
| 4629 | /* |
| 4630 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 4631 | * with additional adjustments for plane-specific scaling. |
| 4632 | */ |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 4633 | adjusted_pixel_rate = cstate->pixel_rate; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4634 | downscale_amount = skl_plane_downscale_amount(cstate, pstate); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4635 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4636 | return mul_round_up_u32_fixed16(adjusted_pixel_rate, |
| 4637 | downscale_amount); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4638 | } |
| 4639 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4640 | static int |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4641 | skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 4642 | int width, const struct drm_format_info *format, |
| 4643 | u64 modifier, unsigned int rotation, |
| 4644 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 4645 | int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4646 | { |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4647 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4648 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4649 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4650 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4651 | /* only planar format has two planes */ |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4652 | if (color_plane == 1 && !is_planar_yuv_format(format->format)) { |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4653 | DRM_DEBUG_KMS("Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4654 | return -EINVAL; |
| 4655 | } |
| 4656 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4657 | wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED || |
| 4658 | modifier == I915_FORMAT_MOD_Yf_TILED || |
| 4659 | modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4660 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4661 | wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED; |
| 4662 | wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4663 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4664 | wp->is_planar = is_planar_yuv_format(format->format); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4665 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4666 | wp->width = width; |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 4667 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4668 | wp->width /= 2; |
| 4669 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4670 | wp->cpp = format->cpp[color_plane]; |
| 4671 | wp->plane_pixel_rate = plane_pixel_rate; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4672 | |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4673 | if (INTEL_GEN(dev_priv) >= 11 && |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4674 | modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4675 | wp->dbuf_block_size = 256; |
| 4676 | else |
| 4677 | wp->dbuf_block_size = 512; |
| 4678 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4679 | if (drm_rotation_90_or_270(rotation)) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4680 | switch (wp->cpp) { |
| 4681 | case 1: |
| 4682 | wp->y_min_scanlines = 16; |
| 4683 | break; |
| 4684 | case 2: |
| 4685 | wp->y_min_scanlines = 8; |
| 4686 | break; |
| 4687 | case 4: |
| 4688 | wp->y_min_scanlines = 4; |
| 4689 | break; |
| 4690 | default: |
| 4691 | MISSING_CASE(wp->cpp); |
| 4692 | return -EINVAL; |
| 4693 | } |
| 4694 | } else { |
| 4695 | wp->y_min_scanlines = 4; |
| 4696 | } |
| 4697 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4698 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4699 | wp->y_min_scanlines *= 2; |
| 4700 | |
| 4701 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 4702 | if (wp->y_tiled) { |
| 4703 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4704 | wp->y_min_scanlines, |
| 4705 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4706 | |
| 4707 | if (INTEL_GEN(dev_priv) >= 10) |
| 4708 | interm_pbpl++; |
| 4709 | |
| 4710 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 4711 | wp->y_min_scanlines); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4712 | } else if (wp->x_tiled && IS_GEN(dev_priv, 9)) { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4713 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4714 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4715 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4716 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4717 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4718 | wp->dbuf_block_size) + 1; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4719 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4720 | } |
| 4721 | |
| 4722 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 4723 | wp->plane_blocks_per_line); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4724 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4725 | wp->linetime_us = fixed16_to_u32_round_up( |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4726 | intel_get_linetime_us(crtc_state)); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4727 | |
| 4728 | return 0; |
| 4729 | } |
| 4730 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 4731 | static int |
| 4732 | skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state, |
| 4733 | const struct intel_plane_state *plane_state, |
| 4734 | struct skl_wm_params *wp, int color_plane) |
| 4735 | { |
| 4736 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 4737 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 4738 | int width; |
| 4739 | |
| 4740 | if (plane->id == PLANE_CURSOR) { |
| 4741 | width = plane_state->base.crtc_w; |
| 4742 | } else { |
| 4743 | /* |
| 4744 | * Src coordinates are already rotated by 270 degrees for |
| 4745 | * the 90/270 degree plane rotation cases (to match the |
| 4746 | * GTT mapping), hence no need to account for rotation here. |
| 4747 | */ |
| 4748 | width = drm_rect_width(&plane_state->base.src) >> 16; |
| 4749 | } |
| 4750 | |
| 4751 | return skl_compute_wm_params(crtc_state, width, |
| 4752 | fb->format, fb->modifier, |
| 4753 | plane_state->base.rotation, |
| 4754 | skl_adjusted_plane_pixel_rate(crtc_state, plane_state), |
| 4755 | wp, color_plane); |
| 4756 | } |
| 4757 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4758 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 4759 | { |
| 4760 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 4761 | return true; |
| 4762 | |
| 4763 | /* The number of lines are ignored for the level 0 watermark. */ |
| 4764 | return level > 0; |
| 4765 | } |
| 4766 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4767 | static void skl_compute_plane_wm(const struct intel_crtc_state *cstate, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4768 | int level, |
| 4769 | const struct skl_wm_params *wp, |
| 4770 | const struct skl_wm_level *result_prev, |
| 4771 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4772 | { |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4773 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4774 | u32 latency = dev_priv->wm.skl_latency[level]; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4775 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4776 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4777 | u32 res_blocks, res_lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 4778 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4779 | if (latency == 0) { |
| 4780 | /* reject it */ |
| 4781 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4782 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4783 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4784 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4785 | /* Display WA #1141: kbl,cfl */ |
Kumar, Mahesh | d86ba62 | 2017-08-17 19:15:26 +0530 | [diff] [blame] | 4786 | if ((IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || |
| 4787 | IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) && |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4788 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 4789 | latency += 4; |
| 4790 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4791 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4792 | latency += 15; |
| 4793 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4794 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4795 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4796 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4797 | cstate->base.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4798 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4799 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4800 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4801 | if (wp->y_tiled) { |
| 4802 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4803 | } else { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4804 | if ((wp->cpp * cstate->base.adjusted_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4805 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4806 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 4807 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4808 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4809 | if (IS_GEN(dev_priv, 9) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4810 | !IS_GEMINILAKE(dev_priv)) |
| 4811 | selected_result = min_fixed16(method1, method2); |
| 4812 | else |
| 4813 | selected_result = method2; |
| 4814 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4815 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4816 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4817 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4818 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4819 | res_blocks = fixed16_to_u32_round_up(selected_result) + 1; |
Kumar, Mahesh | d273ecc | 2017-05-17 17:28:22 +0530 | [diff] [blame] | 4820 | res_lines = div_round_up_fixed16(selected_result, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4821 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4822 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4823 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) { |
| 4824 | /* Display WA #1125: skl,bxt,kbl */ |
| 4825 | if (level == 0 && wp->rc_surface) |
| 4826 | res_blocks += |
| 4827 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 4828 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4829 | /* Display WA #1126: skl,bxt,kbl */ |
| 4830 | if (level >= 1 && level <= 7) { |
| 4831 | if (wp->y_tiled) { |
| 4832 | res_blocks += |
| 4833 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 4834 | res_lines += wp->y_min_scanlines; |
| 4835 | } else { |
| 4836 | res_blocks++; |
| 4837 | } |
| 4838 | |
| 4839 | /* |
| 4840 | * Make sure result blocks for higher latency levels are |
| 4841 | * atleast as high as level below the current level. |
| 4842 | * Assumption in DDB algorithm optimization for special |
| 4843 | * cases. Also covers Display WA #1125 for RC. |
| 4844 | */ |
| 4845 | if (result_prev->plane_res_b > res_blocks) |
| 4846 | res_blocks = result_prev->plane_res_b; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4847 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4848 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4849 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4850 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4851 | if (wp->y_tiled) { |
| 4852 | int extra_lines; |
| 4853 | |
| 4854 | if (res_lines % wp->y_min_scanlines == 0) |
| 4855 | extra_lines = wp->y_min_scanlines; |
| 4856 | else |
| 4857 | extra_lines = wp->y_min_scanlines * 2 - |
| 4858 | res_lines % wp->y_min_scanlines; |
| 4859 | |
| 4860 | min_ddb_alloc = mul_round_up_u32_fixed16(res_lines + extra_lines, |
| 4861 | wp->plane_blocks_per_line); |
| 4862 | } else { |
| 4863 | min_ddb_alloc = res_blocks + |
| 4864 | DIV_ROUND_UP(res_blocks, 10); |
| 4865 | } |
| 4866 | } |
| 4867 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4868 | if (!skl_wm_has_lines(dev_priv, level)) |
| 4869 | res_lines = 0; |
| 4870 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4871 | if (res_lines > 31) { |
| 4872 | /* reject it */ |
| 4873 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4874 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4875 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4876 | |
| 4877 | /* |
| 4878 | * If res_lines is valid, assume we can use this watermark level |
| 4879 | * for now. We'll come back and disable it after we calculate the |
| 4880 | * DDB allocation if it turns out we don't actually have enough |
| 4881 | * blocks to satisfy it. |
| 4882 | */ |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4883 | result->plane_res_b = res_blocks; |
| 4884 | result->plane_res_l = res_lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4885 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
| 4886 | result->min_ddb_alloc = max(min_ddb_alloc, res_blocks) + 1; |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4887 | result->plane_en = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4888 | } |
| 4889 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4890 | static void |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4891 | skl_compute_wm_levels(const struct intel_crtc_state *cstate, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4892 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4893 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4894 | { |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4895 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4896 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4897 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4898 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4899 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4900 | struct skl_wm_level *result = &levels[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4901 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4902 | skl_compute_plane_wm(cstate, level, wm_params, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4903 | result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4904 | |
| 4905 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4906 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4907 | } |
| 4908 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4909 | static u32 |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4910 | skl_compute_linetime_wm(const struct intel_crtc_state *cstate) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4911 | { |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4912 | struct drm_atomic_state *state = cstate->base.state; |
| 4913 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4914 | uint_fixed_16_16_t linetime_us; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4915 | u32 linetime_wm; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4916 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4917 | linetime_us = intel_get_linetime_us(cstate); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4918 | 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] | 4919 | |
Ville Syrjälä | 717671c | 2018-12-21 19:14:36 +0200 | [diff] [blame] | 4920 | /* Display WA #1135: BXT:ALL GLK:ALL */ |
| 4921 | if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled) |
Kumar, Mahesh | 446e850 | 2017-08-17 19:15:25 +0530 | [diff] [blame] | 4922 | linetime_wm /= 2; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4923 | |
| 4924 | return linetime_wm; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4927 | static void skl_compute_transition_wm(const struct intel_crtc_state *cstate, |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 4928 | const struct skl_wm_params *wp, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4929 | struct skl_plane_wm *wm) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4930 | { |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4931 | struct drm_device *dev = cstate->base.crtc->dev; |
| 4932 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4933 | u16 trans_min, trans_y_tile_min; |
| 4934 | const u16 trans_amount = 10; /* This is configurable amount */ |
| 4935 | u16 wm0_sel_res_b, trans_offset_b, res_blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4936 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4937 | /* Transition WM are not recommended by HW team for GEN9 */ |
| 4938 | if (INTEL_GEN(dev_priv) <= 9) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4939 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4940 | |
| 4941 | /* Transition WM don't make any sense if ipc is disabled */ |
| 4942 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4943 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4944 | |
Paulo Zanoni | 91961a8 | 2018-10-04 16:15:56 -0700 | [diff] [blame] | 4945 | trans_min = 14; |
| 4946 | if (INTEL_GEN(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4947 | trans_min = 4; |
| 4948 | |
| 4949 | trans_offset_b = trans_min + trans_amount; |
| 4950 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4951 | /* |
| 4952 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 4953 | * not Result Blocks (the integer value). Pay attention to the capital |
| 4954 | * letters. The value wm_l0->plane_res_b is actually Result Blocks, but |
| 4955 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 4956 | * and since we later will have to get the ceiling of the sum in the |
| 4957 | * transition watermarks calculation, we can just pretend Selected |
| 4958 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 4959 | * current platforms. |
| 4960 | */ |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 4961 | wm0_sel_res_b = wm->wm[0].plane_res_b - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4962 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4963 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4964 | trans_y_tile_min = |
| 4965 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4966 | res_blocks = max(wm0_sel_res_b, trans_y_tile_min) + |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4967 | trans_offset_b; |
| 4968 | } else { |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4969 | res_blocks = wm0_sel_res_b + trans_offset_b; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4970 | |
| 4971 | /* WA BUG:1938466 add one block for non y-tile planes */ |
| 4972 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_A0)) |
| 4973 | res_blocks += 1; |
| 4974 | |
| 4975 | } |
| 4976 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4977 | /* |
| 4978 | * Just assume we can enable the transition watermark. After |
| 4979 | * computing the DDB we'll come back and disable it if that |
| 4980 | * assumption turns out to be false. |
| 4981 | */ |
| 4982 | wm->trans_wm.plane_res_b = res_blocks + 1; |
| 4983 | wm->trans_wm.plane_en = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4984 | } |
| 4985 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4986 | 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] | 4987 | const struct intel_plane_state *plane_state, |
| 4988 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4989 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4990 | 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] | 4991 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4992 | int ret; |
| 4993 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4994 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4995 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4996 | if (ret) |
| 4997 | return ret; |
| 4998 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 4999 | skl_compute_wm_levels(crtc_state, &wm_params, wm->wm); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5000 | skl_compute_transition_wm(crtc_state, &wm_params, wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5001 | |
| 5002 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5003 | } |
| 5004 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5005 | 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] | 5006 | const struct intel_plane_state *plane_state, |
| 5007 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5008 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5009 | struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5010 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5011 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5012 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5013 | wm->is_planar = true; |
| 5014 | |
| 5015 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5016 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5017 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5018 | if (ret) |
| 5019 | return ret; |
| 5020 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5021 | skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5022 | |
| 5023 | return 0; |
| 5024 | } |
| 5025 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5026 | 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] | 5027 | const struct intel_plane_state *plane_state) |
| 5028 | { |
| 5029 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 5030 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 5031 | enum plane_id plane_id = plane->id; |
| 5032 | int ret; |
| 5033 | |
| 5034 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 5035 | return 0; |
| 5036 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5037 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5038 | plane_id, 0); |
| 5039 | if (ret) |
| 5040 | return ret; |
| 5041 | |
| 5042 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5043 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5044 | plane_id); |
| 5045 | if (ret) |
| 5046 | return ret; |
| 5047 | } |
| 5048 | |
| 5049 | return 0; |
| 5050 | } |
| 5051 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5052 | 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] | 5053 | const struct intel_plane_state *plane_state) |
| 5054 | { |
| 5055 | enum plane_id plane_id = to_intel_plane(plane_state->base.plane)->id; |
| 5056 | int ret; |
| 5057 | |
| 5058 | /* Watermarks calculated in master */ |
| 5059 | if (plane_state->slave) |
| 5060 | return 0; |
| 5061 | |
| 5062 | if (plane_state->linked_plane) { |
| 5063 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 5064 | enum plane_id y_plane_id = plane_state->linked_plane->id; |
| 5065 | |
| 5066 | WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state)); |
| 5067 | WARN_ON(!fb->format->is_yuv || |
| 5068 | fb->format->num_planes == 1); |
| 5069 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5070 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5071 | y_plane_id, 0); |
| 5072 | if (ret) |
| 5073 | return ret; |
| 5074 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5075 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5076 | plane_id, 1); |
| 5077 | if (ret) |
| 5078 | return ret; |
| 5079 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5080 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5081 | plane_id, 0); |
| 5082 | if (ret) |
| 5083 | return ret; |
| 5084 | } |
| 5085 | |
| 5086 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5087 | } |
| 5088 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5089 | static int skl_build_pipe_wm(struct intel_crtc_state *cstate) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5090 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5091 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5092 | struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5093 | struct drm_crtc_state *crtc_state = &cstate->base; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5094 | struct drm_plane *plane; |
| 5095 | const struct drm_plane_state *pstate; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5096 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5097 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 5098 | /* |
| 5099 | * We'll only calculate watermarks for planes that are actually |
| 5100 | * enabled, so make sure all other planes are set as disabled. |
| 5101 | */ |
| 5102 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 5103 | |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5104 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { |
| 5105 | const struct intel_plane_state *intel_pstate = |
| 5106 | to_intel_plane_state(pstate); |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5107 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5108 | if (INTEL_GEN(dev_priv) >= 11) |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5109 | ret = icl_build_plane_wm(cstate, intel_pstate); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5110 | else |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5111 | ret = skl_build_plane_wm(cstate, intel_pstate); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5112 | if (ret) |
| 5113 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5114 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5115 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 5116 | pipe_wm->linetime = skl_compute_linetime_wm(cstate); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5117 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5118 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5121 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 5122 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5123 | const struct skl_ddb_entry *entry) |
| 5124 | { |
| 5125 | if (entry->end) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5126 | I915_WRITE_FW(reg, (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5127 | else |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5128 | I915_WRITE_FW(reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5129 | } |
| 5130 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5131 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5132 | i915_reg_t reg, |
| 5133 | const struct skl_wm_level *level) |
| 5134 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5135 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5136 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5137 | if (level->plane_en) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5138 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5139 | if (level->ignore_lines) |
| 5140 | val |= PLANE_WM_IGNORE_LINES; |
| 5141 | val |= level->plane_res_b; |
| 5142 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5143 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5144 | I915_WRITE_FW(reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5145 | } |
| 5146 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5147 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5148 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5149 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5150 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5151 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5152 | enum plane_id plane_id = plane->id; |
| 5153 | enum pipe pipe = plane->pipe; |
| 5154 | const struct skl_plane_wm *wm = |
| 5155 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5156 | const struct skl_ddb_entry *ddb_y = |
| 5157 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5158 | const struct skl_ddb_entry *ddb_uv = |
| 5159 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5160 | |
| 5161 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5162 | 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] | 5163 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5164 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5165 | 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] | 5166 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5167 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5168 | if (INTEL_GEN(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5169 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5170 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5171 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5172 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5173 | |
| 5174 | if (wm->is_planar) |
| 5175 | swap(ddb_y, ddb_uv); |
| 5176 | |
| 5177 | skl_ddb_entry_write(dev_priv, |
| 5178 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5179 | skl_ddb_entry_write(dev_priv, |
| 5180 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5181 | } |
| 5182 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5183 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5184 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5185 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5186 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5187 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5188 | enum plane_id plane_id = plane->id; |
| 5189 | enum pipe pipe = plane->pipe; |
| 5190 | const struct skl_plane_wm *wm = |
| 5191 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5192 | const struct skl_ddb_entry *ddb = |
| 5193 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5194 | |
| 5195 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5196 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 5197 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5198 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5199 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5200 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5201 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5202 | } |
| 5203 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5204 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5205 | const struct skl_wm_level *l2) |
| 5206 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5207 | return l1->plane_en == l2->plane_en && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5208 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5209 | l1->plane_res_l == l2->plane_res_l && |
| 5210 | l1->plane_res_b == l2->plane_res_b; |
| 5211 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5212 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5213 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5214 | const struct skl_plane_wm *wm1, |
| 5215 | const struct skl_plane_wm *wm2) |
| 5216 | { |
| 5217 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5218 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5219 | for (level = 0; level <= max_level; level++) { |
| 5220 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level]) || |
| 5221 | !skl_wm_level_equals(&wm1->uv_wm[level], &wm2->uv_wm[level])) |
| 5222 | return false; |
| 5223 | } |
| 5224 | |
| 5225 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5226 | } |
| 5227 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5228 | static bool skl_pipe_wm_equals(struct intel_crtc *crtc, |
| 5229 | const struct skl_pipe_wm *wm1, |
| 5230 | const struct skl_pipe_wm *wm2) |
| 5231 | { |
| 5232 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5233 | enum plane_id plane_id; |
| 5234 | |
| 5235 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5236 | if (!skl_plane_wm_equals(dev_priv, |
| 5237 | &wm1->planes[plane_id], |
| 5238 | &wm2->planes[plane_id])) |
| 5239 | return false; |
| 5240 | } |
| 5241 | |
| 5242 | return wm1->linetime == wm2->linetime; |
| 5243 | } |
| 5244 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5245 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 5246 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5247 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5248 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5251 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 5252 | const struct skl_ddb_entry *entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5253 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5254 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5255 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5256 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5257 | for (i = 0; i < num_entries; i++) { |
| 5258 | if (i != ignore_idx && |
| 5259 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5260 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 5261 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5262 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5263 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5264 | } |
| 5265 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5266 | static u32 |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5267 | pipes_modified(struct intel_atomic_state *state) |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5268 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5269 | struct intel_crtc *crtc; |
| 5270 | struct intel_crtc_state *cstate; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5271 | u32 i, ret = 0; |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5272 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5273 | for_each_new_intel_crtc_in_state(state, crtc, cstate, i) |
| 5274 | ret |= drm_crtc_mask(&crtc->base); |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5275 | |
| 5276 | return ret; |
| 5277 | } |
| 5278 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 5279 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5280 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 5281 | struct intel_crtc_state *new_crtc_state) |
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 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->base.state); |
| 5284 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5285 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5286 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5287 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5288 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5289 | struct intel_plane_state *plane_state; |
| 5290 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5291 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5292 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 5293 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 5294 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 5295 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5296 | continue; |
| 5297 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5298 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5299 | if (IS_ERR(plane_state)) |
| 5300 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 5301 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5302 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | return 0; |
| 5306 | } |
| 5307 | |
| 5308 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5309 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5310 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5311 | const struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5312 | struct skl_ddb_allocation *ddb = &state->wm_results.ddb; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5313 | struct intel_crtc_state *old_crtc_state; |
| 5314 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5315 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5316 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5317 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 5318 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 5319 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5320 | 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] | 5321 | new_crtc_state, i) { |
| 5322 | ret = skl_allocate_pipe_ddb(new_crtc_state, ddb); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5323 | if (ret) |
| 5324 | return ret; |
| 5325 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5326 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 5327 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5328 | if (ret) |
| 5329 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | return 0; |
| 5333 | } |
| 5334 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5335 | static char enast(bool enable) |
| 5336 | { |
| 5337 | return enable ? '*' : ' '; |
| 5338 | } |
| 5339 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 5340 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5341 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5342 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5343 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5344 | const struct intel_crtc_state *old_crtc_state; |
| 5345 | const struct intel_crtc_state *new_crtc_state; |
| 5346 | struct intel_plane *plane; |
| 5347 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5348 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5349 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5350 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 5351 | return; |
| 5352 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5353 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 5354 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5355 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 5356 | |
| 5357 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 5358 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 5359 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5360 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5361 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5362 | const struct skl_ddb_entry *old, *new; |
| 5363 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5364 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5365 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5366 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5367 | if (skl_ddb_entry_equal(old, new)) |
| 5368 | continue; |
| 5369 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5370 | 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] | 5371 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5372 | old->start, old->end, new->start, new->end, |
| 5373 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
| 5374 | } |
| 5375 | |
| 5376 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5377 | enum plane_id plane_id = plane->id; |
| 5378 | const struct skl_plane_wm *old_wm, *new_wm; |
| 5379 | |
| 5380 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 5381 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 5382 | |
| 5383 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 5384 | continue; |
| 5385 | |
| 5386 | DRM_DEBUG_KMS("[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm" |
| 5387 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm\n", |
| 5388 | plane->base.base.id, plane->base.name, |
| 5389 | enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en), |
| 5390 | enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en), |
| 5391 | enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en), |
| 5392 | enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en), |
| 5393 | enast(old_wm->trans_wm.plane_en), |
| 5394 | enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en), |
| 5395 | enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en), |
| 5396 | enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en), |
| 5397 | enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en), |
| 5398 | enast(new_wm->trans_wm.plane_en)); |
| 5399 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5400 | 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" |
| 5401 | " -> %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] | 5402 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5403 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l, |
| 5404 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l, |
| 5405 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l, |
| 5406 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l, |
| 5407 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l, |
| 5408 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l, |
| 5409 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l, |
| 5410 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l, |
| 5411 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l, |
| 5412 | |
| 5413 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l, |
| 5414 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l, |
| 5415 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l, |
| 5416 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l, |
| 5417 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l, |
| 5418 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l, |
| 5419 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l, |
| 5420 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l, |
| 5421 | 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] | 5422 | |
| 5423 | DRM_DEBUG_KMS("[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5424 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5425 | plane->base.base.id, plane->base.name, |
| 5426 | old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b, |
| 5427 | old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b, |
| 5428 | old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b, |
| 5429 | old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b, |
| 5430 | old_wm->trans_wm.plane_res_b, |
| 5431 | new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b, |
| 5432 | new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b, |
| 5433 | new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b, |
| 5434 | new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b, |
| 5435 | new_wm->trans_wm.plane_res_b); |
| 5436 | |
| 5437 | DRM_DEBUG_KMS("[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5438 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5439 | plane->base.base.id, plane->base.name, |
| 5440 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 5441 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 5442 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 5443 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 5444 | old_wm->trans_wm.min_ddb_alloc, |
| 5445 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 5446 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 5447 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 5448 | new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc, |
| 5449 | new_wm->trans_wm.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5450 | } |
| 5451 | } |
| 5452 | } |
| 5453 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5454 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5455 | skl_ddb_add_affected_pipes(struct intel_atomic_state *state, bool *changed) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5456 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5457 | struct drm_device *dev = state->base.dev; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5458 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5459 | struct intel_crtc *crtc; |
| 5460 | struct intel_crtc_state *crtc_state; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5461 | u32 realloc_pipes = pipes_modified(state); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5462 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5463 | |
| 5464 | /* |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5465 | * When we distrust bios wm we always need to recompute to set the |
| 5466 | * expected DDB allocations for each CRTC. |
| 5467 | */ |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5468 | if (dev_priv->wm.distrust_bios_wm) |
| 5469 | (*changed) = true; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5470 | |
| 5471 | /* |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5472 | * If this transaction isn't actually touching any CRTC's, don't |
| 5473 | * bother with watermark calculation. Note that if we pass this |
| 5474 | * test, we're guaranteed to hold at least one CRTC state mutex, |
| 5475 | * which means we can safely use values like dev_priv->active_crtcs |
| 5476 | * since any racing commits that want to update them would need to |
| 5477 | * hold _all_ CRTC state mutexes. |
| 5478 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5479 | for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5480 | (*changed) = true; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5481 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5482 | if (!*changed) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5483 | return 0; |
| 5484 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5485 | /* |
| 5486 | * If this is our first atomic update following hardware readout, |
| 5487 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 5488 | * pretend that all pipes switched active status so that we'll |
| 5489 | * ensure a full DDB recompute. |
| 5490 | */ |
| 5491 | if (dev_priv->wm.distrust_bios_wm) { |
| 5492 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5493 | state->base.acquire_ctx); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5494 | if (ret) |
| 5495 | return ret; |
| 5496 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5497 | state->active_pipe_changes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5498 | |
| 5499 | /* |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5500 | * We usually only initialize state->active_crtcs if we |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5501 | * we're doing a modeset; make sure this field is always |
| 5502 | * initialized during the sanitization process that happens |
| 5503 | * on the first commit too. |
| 5504 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5505 | if (!state->modeset) |
| 5506 | state->active_crtcs = dev_priv->active_crtcs; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | /* |
| 5510 | * If the modeset changes which CRTC's are active, we need to |
| 5511 | * recompute the DDB allocation for *all* active pipes, even |
| 5512 | * those that weren't otherwise being modified in any way by this |
| 5513 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 5514 | * when new active CRTC's are added, it's possible for a pipe that |
| 5515 | * we were already using and aren't changing at all here to suddenly |
| 5516 | * become invalid if its DDB needs exceeds its new allocation. |
| 5517 | * |
| 5518 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 5519 | * any other display updates race with this transaction, so we need |
| 5520 | * to grab the lock on *all* CRTC's. |
| 5521 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5522 | if (state->active_pipe_changes || state->modeset) { |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5523 | realloc_pipes = ~0; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5524 | state->wm_results.dirty_pipes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | /* |
| 5528 | * We're not recomputing for the pipes not included in the commit, so |
| 5529 | * make sure we start with the current state. |
| 5530 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5531 | for_each_intel_crtc_mask(dev, crtc, realloc_pipes) { |
| 5532 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 5533 | if (IS_ERR(crtc_state)) |
| 5534 | return PTR_ERR(crtc_state); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | return 0; |
| 5538 | } |
| 5539 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5540 | /* |
| 5541 | * To make sure the cursor watermark registers are always consistent |
| 5542 | * with our computed state the following scenario needs special |
| 5543 | * treatment: |
| 5544 | * |
| 5545 | * 1. enable cursor |
| 5546 | * 2. move cursor entirely offscreen |
| 5547 | * 3. disable cursor |
| 5548 | * |
| 5549 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 5550 | * (since we consider an offscreen cursor still active for the purposes |
| 5551 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 5552 | * because the actual plane visibility isn't changing, and we don't |
| 5553 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 5554 | * force step 3. to call .disable_plane() to update the watermark |
| 5555 | * registers properly. |
| 5556 | * |
| 5557 | * Other planes do not suffer from this issues as their watermarks are |
| 5558 | * calculated based on the actual plane visibility. The only time this |
| 5559 | * can trigger for the other planes is during the initial readout as the |
| 5560 | * default value of the watermarks registers is not zero. |
| 5561 | */ |
| 5562 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 5563 | struct intel_crtc *crtc) |
| 5564 | { |
| 5565 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5566 | const struct intel_crtc_state *old_crtc_state = |
| 5567 | intel_atomic_get_old_crtc_state(state, crtc); |
| 5568 | struct intel_crtc_state *new_crtc_state = |
| 5569 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5570 | struct intel_plane *plane; |
| 5571 | |
| 5572 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5573 | struct intel_plane_state *plane_state; |
| 5574 | enum plane_id plane_id = plane->id; |
| 5575 | |
| 5576 | /* |
| 5577 | * Force a full wm update for every plane on modeset. |
| 5578 | * Required because the reset value of the wm registers |
| 5579 | * is non-zero, whereas we want all disabled planes to |
| 5580 | * have zero watermarks. So if we turn off the relevant |
| 5581 | * power well the hardware state will go out of sync |
| 5582 | * with the software state. |
| 5583 | */ |
| 5584 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->base) && |
| 5585 | skl_plane_wm_equals(dev_priv, |
| 5586 | &old_crtc_state->wm.skl.optimal.planes[plane_id], |
| 5587 | &new_crtc_state->wm.skl.optimal.planes[plane_id])) |
| 5588 | continue; |
| 5589 | |
| 5590 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 5591 | if (IS_ERR(plane_state)) |
| 5592 | return PTR_ERR(plane_state); |
| 5593 | |
| 5594 | new_crtc_state->update_planes |= BIT(plane_id); |
| 5595 | } |
| 5596 | |
| 5597 | return 0; |
| 5598 | } |
| 5599 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5600 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5601 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5602 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5603 | struct intel_crtc *crtc; |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5604 | struct intel_crtc_state *new_crtc_state; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5605 | struct intel_crtc_state *old_crtc_state; |
| 5606 | struct skl_ddb_values *results = &state->wm_results; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5607 | bool changed = false; |
| 5608 | int ret, i; |
| 5609 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5610 | /* Clear all dirty flags */ |
| 5611 | results->dirty_pipes = 0; |
| 5612 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5613 | ret = skl_ddb_add_affected_pipes(state, &changed); |
| 5614 | if (ret || !changed) |
| 5615 | return ret; |
| 5616 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5617 | /* |
| 5618 | * Calculate WM's for all pipes that are part of this transaction. |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5619 | * 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] | 5620 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 5621 | * pipe allocations had to change. |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5622 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5623 | 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] | 5624 | new_crtc_state, i) { |
| 5625 | ret = skl_build_pipe_wm(new_crtc_state); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5626 | if (ret) |
| 5627 | return ret; |
| 5628 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5629 | ret = skl_wm_add_affected_planes(state, crtc); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5630 | if (ret) |
| 5631 | return ret; |
| 5632 | |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 5633 | if (!skl_pipe_wm_equals(crtc, |
| 5634 | &old_crtc_state->wm.skl.optimal, |
| 5635 | &new_crtc_state->wm.skl.optimal)) |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5636 | results->dirty_pipes |= drm_crtc_mask(&crtc->base); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5637 | } |
| 5638 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5639 | ret = skl_compute_ddb(state); |
| 5640 | if (ret) |
| 5641 | return ret; |
| 5642 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5643 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5644 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5645 | return 0; |
| 5646 | } |
| 5647 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5648 | static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state, |
| 5649 | struct intel_crtc_state *cstate) |
| 5650 | { |
| 5651 | struct intel_crtc *crtc = to_intel_crtc(cstate->base.crtc); |
| 5652 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5653 | struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal; |
| 5654 | enum pipe pipe = crtc->pipe; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5655 | |
| 5656 | if (!(state->wm_results.dirty_pipes & drm_crtc_mask(&crtc->base))) |
| 5657 | return; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5658 | |
| 5659 | I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime); |
| 5660 | } |
| 5661 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5662 | static void skl_initial_wm(struct intel_atomic_state *state, |
| 5663 | struct intel_crtc_state *cstate) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5664 | { |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5665 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5666 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5667 | struct drm_i915_private *dev_priv = to_i915(dev); |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5668 | struct skl_ddb_values *results = &state->wm_results; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 5669 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5670 | if ((results->dirty_pipes & drm_crtc_mask(&intel_crtc->base)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5671 | return; |
| 5672 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5673 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5674 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5675 | if (cstate->base.active_changed) |
| 5676 | skl_atomic_update_crtc_wm(state, cstate); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5677 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5678 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5679 | } |
| 5680 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5681 | 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] | 5682 | struct intel_wm_config *config) |
| 5683 | { |
| 5684 | struct intel_crtc *crtc; |
| 5685 | |
| 5686 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5687 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5688 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 5689 | |
| 5690 | if (!wm->pipe_enabled) |
| 5691 | continue; |
| 5692 | |
| 5693 | config->sprites_enabled |= wm->sprites_enabled; |
| 5694 | config->sprites_scaled |= wm->sprites_scaled; |
| 5695 | config->num_pipes_active++; |
| 5696 | } |
| 5697 | } |
| 5698 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5699 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 5700 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5701 | 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] | 5702 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5703 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5704 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5705 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 5706 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5707 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5708 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5709 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 5710 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 5711 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5712 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5713 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5714 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5715 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 5716 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5717 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5718 | 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] | 5719 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5720 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5721 | } |
| 5722 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5723 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5724 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5725 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5726 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 5727 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5728 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 5729 | } |
| 5730 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5731 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
| 5732 | struct intel_crtc_state *cstate) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5733 | { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5734 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 5735 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5736 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5737 | mutex_lock(&dev_priv->wm.wm_mutex); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5738 | intel_crtc->wm.active.ilk = cstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5739 | ilk_program_watermarks(dev_priv); |
| 5740 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5741 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5742 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5743 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
| 5744 | struct intel_crtc_state *cstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5745 | { |
| 5746 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 5747 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
| 5748 | |
| 5749 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5750 | if (cstate->wm.need_postvbl_update) { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5751 | intel_crtc->wm.active.ilk = cstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5752 | ilk_program_watermarks(dev_priv); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5753 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5754 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5755 | } |
| 5756 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5757 | static inline void skl_wm_level_from_reg_val(u32 val, |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5758 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5759 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5760 | level->plane_en = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5761 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5762 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 5763 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 5764 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5765 | } |
| 5766 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5767 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5768 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5769 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5770 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5771 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5772 | int level, max_level; |
| 5773 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5774 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5775 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5776 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5777 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5778 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5779 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5780 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5781 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5782 | if (plane_id != PLANE_CURSOR) |
| 5783 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5784 | else |
| 5785 | val = I915_READ(CUR_WM(pipe, level)); |
| 5786 | |
| 5787 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 5788 | } |
| 5789 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5790 | if (plane_id != PLANE_CURSOR) |
| 5791 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5792 | else |
| 5793 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 5794 | |
| 5795 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 5796 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5797 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5798 | if (!crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5799 | return; |
| 5800 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5801 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5802 | } |
| 5803 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5804 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5805 | { |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5806 | struct skl_ddb_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5807 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5808 | struct intel_crtc *crtc; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5809 | struct intel_crtc_state *cstate; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5810 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5811 | skl_ddb_get_hw_state(dev_priv, ddb); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5812 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5813 | cstate = to_intel_crtc_state(crtc->base.state); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5814 | |
| 5815 | skl_pipe_wm_get_hw_state(crtc, &cstate->wm.skl.optimal); |
| 5816 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5817 | if (crtc->active) |
| 5818 | hw->dirty_pipes |= drm_crtc_mask(&crtc->base); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5819 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5820 | |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5821 | if (dev_priv->active_crtcs) { |
| 5822 | /* Fully recompute DDB on first atomic commit */ |
| 5823 | dev_priv->wm.distrust_bios_wm = true; |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5824 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5825 | } |
| 5826 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5827 | 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] | 5828 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5829 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5830 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5831 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5832 | struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->base.state); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5833 | struct intel_pipe_wm *active = &cstate->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5834 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5835 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5836 | [PIPE_A] = WM0_PIPEA_ILK, |
| 5837 | [PIPE_B] = WM0_PIPEB_ILK, |
| 5838 | [PIPE_C] = WM0_PIPEC_IVB, |
| 5839 | }; |
| 5840 | |
| 5841 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5842 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 5843 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5844 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 5845 | memset(active, 0, sizeof(*active)); |
| 5846 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5847 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 5848 | |
| 5849 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5850 | u32 tmp = hw->wm_pipe[pipe]; |
| 5851 | |
| 5852 | /* |
| 5853 | * For active pipes LP0 watermark is marked as |
| 5854 | * enabled, and LP1+ watermaks as disabled since |
| 5855 | * we can't really reverse compute them in case |
| 5856 | * multiple pipes are active. |
| 5857 | */ |
| 5858 | active->wm[0].enable = true; |
| 5859 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 5860 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 5861 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 5862 | active->linetime = hw->wm_linetime[pipe]; |
| 5863 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5864 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5865 | |
| 5866 | /* |
| 5867 | * For inactive pipes, all watermark levels |
| 5868 | * should be marked as enabled but zeroed, |
| 5869 | * which is what we'd compute them to. |
| 5870 | */ |
| 5871 | for (level = 0; level <= max_level; level++) |
| 5872 | active->wm[level].enable = true; |
| 5873 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5874 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5875 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5876 | } |
| 5877 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5878 | #define _FW_WM(value, plane) \ |
| 5879 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 5880 | #define _FW_WM_VLV(value, plane) \ |
| 5881 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 5882 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5883 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 5884 | struct g4x_wm_values *wm) |
| 5885 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5886 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5887 | |
| 5888 | tmp = I915_READ(DSPFW1); |
| 5889 | wm->sr.plane = _FW_WM(tmp, SR); |
| 5890 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5891 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 5892 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 5893 | |
| 5894 | tmp = I915_READ(DSPFW2); |
| 5895 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 5896 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 5897 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 5898 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 5899 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5900 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 5901 | |
| 5902 | tmp = I915_READ(DSPFW3); |
| 5903 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 5904 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5905 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 5906 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 5907 | } |
| 5908 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5909 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 5910 | struct vlv_wm_values *wm) |
| 5911 | { |
| 5912 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5913 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5914 | |
| 5915 | for_each_pipe(dev_priv, pipe) { |
| 5916 | tmp = I915_READ(VLV_DDL(pipe)); |
| 5917 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5918 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5919 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5920 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5921 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5922 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5923 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5924 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5925 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 5926 | } |
| 5927 | |
| 5928 | tmp = I915_READ(DSPFW1); |
| 5929 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5930 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5931 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 5932 | 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] | 5933 | |
| 5934 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5935 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 5936 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5937 | 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] | 5938 | |
| 5939 | tmp = I915_READ(DSPFW3); |
| 5940 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5941 | |
| 5942 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5943 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5944 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5945 | 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] | 5946 | |
| 5947 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5948 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 5949 | 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] | 5950 | |
| 5951 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5952 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 5953 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5954 | |
| 5955 | tmp = I915_READ(DSPHOWM); |
| 5956 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5957 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 5958 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 5959 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 5960 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5961 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5962 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5963 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5964 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5965 | 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] | 5966 | } else { |
| 5967 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5968 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5969 | 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] | 5970 | |
| 5971 | tmp = I915_READ(DSPHOWM); |
| 5972 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5973 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5974 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5975 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5976 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5977 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5978 | 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] | 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | #undef _FW_WM |
| 5983 | #undef _FW_WM_VLV |
| 5984 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5985 | 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] | 5986 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5987 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 5988 | struct intel_crtc *crtc; |
| 5989 | |
| 5990 | g4x_read_wm_values(dev_priv, wm); |
| 5991 | |
| 5992 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 5993 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5994 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5995 | struct intel_crtc_state *crtc_state = |
| 5996 | to_intel_crtc_state(crtc->base.state); |
| 5997 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 5998 | struct g4x_pipe_wm *raw; |
| 5999 | enum pipe pipe = crtc->pipe; |
| 6000 | enum plane_id plane_id; |
| 6001 | int level, max_level; |
| 6002 | |
| 6003 | active->cxsr = wm->cxsr; |
| 6004 | active->hpll_en = wm->hpll_en; |
| 6005 | active->fbc_en = wm->fbc_en; |
| 6006 | |
| 6007 | active->sr = wm->sr; |
| 6008 | active->hpll = wm->hpll; |
| 6009 | |
| 6010 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6011 | active->wm.plane[plane_id] = |
| 6012 | wm->pipe[pipe].plane[plane_id]; |
| 6013 | } |
| 6014 | |
| 6015 | if (wm->cxsr && wm->hpll_en) |
| 6016 | max_level = G4X_WM_LEVEL_HPLL; |
| 6017 | else if (wm->cxsr) |
| 6018 | max_level = G4X_WM_LEVEL_SR; |
| 6019 | else |
| 6020 | max_level = G4X_WM_LEVEL_NORMAL; |
| 6021 | |
| 6022 | level = G4X_WM_LEVEL_NORMAL; |
| 6023 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6024 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6025 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 6026 | |
| 6027 | if (++level > max_level) |
| 6028 | goto out; |
| 6029 | |
| 6030 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6031 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 6032 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 6033 | raw->plane[PLANE_SPRITE0] = 0; |
| 6034 | raw->fbc = active->sr.fbc; |
| 6035 | |
| 6036 | if (++level > max_level) |
| 6037 | goto out; |
| 6038 | |
| 6039 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6040 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 6041 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 6042 | raw->plane[PLANE_SPRITE0] = 0; |
| 6043 | raw->fbc = active->hpll.fbc; |
| 6044 | |
| 6045 | out: |
| 6046 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6047 | g4x_raw_plane_wm_set(crtc_state, level, |
| 6048 | plane_id, USHRT_MAX); |
| 6049 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 6050 | |
| 6051 | crtc_state->wm.g4x.optimal = *active; |
| 6052 | crtc_state->wm.g4x.intermediate = *active; |
| 6053 | |
| 6054 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 6055 | pipe_name(pipe), |
| 6056 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6057 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6058 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
| 6059 | } |
| 6060 | |
| 6061 | DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 6062 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 6063 | DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 6064 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 6065 | DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", |
| 6066 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
| 6067 | } |
| 6068 | |
| 6069 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6070 | { |
| 6071 | struct intel_plane *plane; |
| 6072 | struct intel_crtc *crtc; |
| 6073 | |
| 6074 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6075 | |
| 6076 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6077 | struct intel_crtc *crtc = |
| 6078 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6079 | struct intel_crtc_state *crtc_state = |
| 6080 | to_intel_crtc_state(crtc->base.state); |
| 6081 | struct intel_plane_state *plane_state = |
| 6082 | to_intel_plane_state(plane->base.state); |
| 6083 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 6084 | enum plane_id plane_id = plane->id; |
| 6085 | int level; |
| 6086 | |
| 6087 | if (plane_state->base.visible) |
| 6088 | continue; |
| 6089 | |
| 6090 | for (level = 0; level < 3; level++) { |
| 6091 | struct g4x_pipe_wm *raw = |
| 6092 | &crtc_state->wm.g4x.raw[level]; |
| 6093 | |
| 6094 | raw->plane[plane_id] = 0; |
| 6095 | wm_state->wm.plane[plane_id] = 0; |
| 6096 | } |
| 6097 | |
| 6098 | if (plane_id == PLANE_PRIMARY) { |
| 6099 | for (level = 0; level < 3; level++) { |
| 6100 | struct g4x_pipe_wm *raw = |
| 6101 | &crtc_state->wm.g4x.raw[level]; |
| 6102 | raw->fbc = 0; |
| 6103 | } |
| 6104 | |
| 6105 | wm_state->sr.fbc = 0; |
| 6106 | wm_state->hpll.fbc = 0; |
| 6107 | wm_state->fbc_en = false; |
| 6108 | } |
| 6109 | } |
| 6110 | |
| 6111 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6112 | struct intel_crtc_state *crtc_state = |
| 6113 | to_intel_crtc_state(crtc->base.state); |
| 6114 | |
| 6115 | crtc_state->wm.g4x.intermediate = |
| 6116 | crtc_state->wm.g4x.optimal; |
| 6117 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 6118 | } |
| 6119 | |
| 6120 | g4x_program_watermarks(dev_priv); |
| 6121 | |
| 6122 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6123 | } |
| 6124 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6125 | 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] | 6126 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6127 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 6128 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6129 | u32 val; |
| 6130 | |
| 6131 | vlv_read_wm_values(dev_priv, wm); |
| 6132 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6133 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 6134 | wm->level = VLV_WM_LEVEL_PM2; |
| 6135 | |
| 6136 | if (IS_CHERRYVIEW(dev_priv)) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6137 | vlv_punit_get(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6138 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 6139 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6140 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 6141 | wm->level = VLV_WM_LEVEL_PM5; |
| 6142 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6143 | /* |
| 6144 | * If DDR DVFS is disabled in the BIOS, Punit |
| 6145 | * will never ack the request. So if that happens |
| 6146 | * assume we don't have to enable/disable DDR DVFS |
| 6147 | * dynamically. To test that just set the REQ_ACK |
| 6148 | * bit to poke the Punit, but don't change the |
| 6149 | * HIGH/LOW bits so that we don't actually change |
| 6150 | * the current state. |
| 6151 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6152 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6153 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 6154 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 6155 | |
| 6156 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 6157 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 6158 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 6159 | "assuming DDR DVFS is disabled\n"); |
| 6160 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 6161 | } else { |
| 6162 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 6163 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 6164 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 6165 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6166 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6167 | vlv_punit_put(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6168 | } |
| 6169 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6170 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6171 | struct intel_crtc_state *crtc_state = |
| 6172 | to_intel_crtc_state(crtc->base.state); |
| 6173 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 6174 | const struct vlv_fifo_state *fifo_state = |
| 6175 | &crtc_state->wm.vlv.fifo_state; |
| 6176 | enum pipe pipe = crtc->pipe; |
| 6177 | enum plane_id plane_id; |
| 6178 | int level; |
| 6179 | |
| 6180 | vlv_get_fifo_size(crtc_state); |
| 6181 | |
| 6182 | active->num_levels = wm->level + 1; |
| 6183 | active->cxsr = wm->cxsr; |
| 6184 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6185 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6186 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6187 | &crtc_state->wm.vlv.raw[level]; |
| 6188 | |
| 6189 | active->sr[level].plane = wm->sr.plane; |
| 6190 | active->sr[level].cursor = wm->sr.cursor; |
| 6191 | |
| 6192 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6193 | active->wm[level].plane[plane_id] = |
| 6194 | wm->pipe[pipe].plane[plane_id]; |
| 6195 | |
| 6196 | raw->plane[plane_id] = |
| 6197 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 6198 | fifo_state->plane[plane_id]); |
| 6199 | } |
| 6200 | } |
| 6201 | |
| 6202 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6203 | vlv_raw_plane_wm_set(crtc_state, level, |
| 6204 | plane_id, USHRT_MAX); |
| 6205 | vlv_invalidate_wms(crtc, active, level); |
| 6206 | |
| 6207 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 6208 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6209 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6210 | 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] | 6211 | pipe_name(pipe), |
| 6212 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6213 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6214 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 6215 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6216 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6217 | |
| 6218 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 6219 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 6220 | } |
| 6221 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6222 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6223 | { |
| 6224 | struct intel_plane *plane; |
| 6225 | struct intel_crtc *crtc; |
| 6226 | |
| 6227 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6228 | |
| 6229 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6230 | struct intel_crtc *crtc = |
| 6231 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6232 | struct intel_crtc_state *crtc_state = |
| 6233 | to_intel_crtc_state(crtc->base.state); |
| 6234 | struct intel_plane_state *plane_state = |
| 6235 | to_intel_plane_state(plane->base.state); |
| 6236 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 6237 | const struct vlv_fifo_state *fifo_state = |
| 6238 | &crtc_state->wm.vlv.fifo_state; |
| 6239 | enum plane_id plane_id = plane->id; |
| 6240 | int level; |
| 6241 | |
| 6242 | if (plane_state->base.visible) |
| 6243 | continue; |
| 6244 | |
| 6245 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6246 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6247 | &crtc_state->wm.vlv.raw[level]; |
| 6248 | |
| 6249 | raw->plane[plane_id] = 0; |
| 6250 | |
| 6251 | wm_state->wm[level].plane[plane_id] = |
| 6252 | vlv_invert_wm_value(raw->plane[plane_id], |
| 6253 | fifo_state->plane[plane_id]); |
| 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6258 | struct intel_crtc_state *crtc_state = |
| 6259 | to_intel_crtc_state(crtc->base.state); |
| 6260 | |
| 6261 | crtc_state->wm.vlv.intermediate = |
| 6262 | crtc_state->wm.vlv.optimal; |
| 6263 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 6264 | } |
| 6265 | |
| 6266 | vlv_program_watermarks(dev_priv); |
| 6267 | |
| 6268 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6269 | } |
| 6270 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6271 | /* |
| 6272 | * FIXME should probably kill this and improve |
| 6273 | * the real watermark readout/sanitation instead |
| 6274 | */ |
| 6275 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 6276 | { |
| 6277 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 6278 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 6279 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 6280 | |
| 6281 | /* |
| 6282 | * Don't touch WM1S_LP_EN here. |
| 6283 | * Doing so could cause underruns. |
| 6284 | */ |
| 6285 | } |
| 6286 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6287 | 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] | 6288 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6289 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6290 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6291 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6292 | ilk_init_lp_watermarks(dev_priv); |
| 6293 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6294 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6295 | ilk_pipe_wm_get_hw_state(crtc); |
| 6296 | |
| 6297 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 6298 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 6299 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 6300 | |
| 6301 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 6302 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 6303 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 6304 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 6305 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6306 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6307 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6308 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 6309 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 6310 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6311 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 6312 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6313 | |
| 6314 | hw->enable_fbc_wm = |
| 6315 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 6316 | } |
| 6317 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6318 | /** |
| 6319 | * intel_update_watermarks - update FIFO watermark values based on current modes |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 6320 | * @crtc: the #intel_crtc on which to compute the WM |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6321 | * |
| 6322 | * Calculate watermark values for the various WM regs based on current mode |
| 6323 | * and plane configuration. |
| 6324 | * |
| 6325 | * There are several cases to deal with here: |
| 6326 | * - normal (i.e. non-self-refresh) |
| 6327 | * - self-refresh (SR) mode |
| 6328 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 6329 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 6330 | * lines), so need to account for TLB latency |
| 6331 | * |
| 6332 | * The normal calculation is: |
| 6333 | * watermark = dotclock * bytes per pixel * latency |
| 6334 | * where latency is platform & configuration dependent (we assume pessimal |
| 6335 | * values here). |
| 6336 | * |
| 6337 | * The SR calculation is: |
| 6338 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 6339 | * bytes per pixel |
| 6340 | * where |
| 6341 | * line time = htotal / dotclock |
| 6342 | * surface width = hdisplay for normal plane and 64 for cursor |
| 6343 | * and latency is assumed to be high, as above. |
| 6344 | * |
| 6345 | * The final value programmed to the register should always be rounded up, |
| 6346 | * and include an extra 2 entries to account for clock crossings. |
| 6347 | * |
| 6348 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 6349 | * to set the non-SR watermarks to 8. |
| 6350 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6351 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6352 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6353 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6354 | |
| 6355 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 6356 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6357 | } |
| 6358 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6359 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 6360 | { |
| 6361 | u32 val; |
| 6362 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 6363 | if (!HAS_IPC(dev_priv)) |
| 6364 | return; |
| 6365 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6366 | val = I915_READ(DISP_ARB_CTL2); |
| 6367 | |
| 6368 | if (dev_priv->ipc_enabled) |
| 6369 | val |= DISP_IPC_ENABLE; |
| 6370 | else |
| 6371 | val &= ~DISP_IPC_ENABLE; |
| 6372 | |
| 6373 | I915_WRITE(DISP_ARB_CTL2, val); |
| 6374 | } |
| 6375 | |
| 6376 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 6377 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6378 | if (!HAS_IPC(dev_priv)) |
| 6379 | return; |
| 6380 | |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 6381 | /* Display WA #1141: SKL:all KBL:all CFL */ |
| 6382 | if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) |
| 6383 | dev_priv->ipc_enabled = dev_priv->dram_info.symmetric_memory; |
| 6384 | else |
| 6385 | dev_priv->ipc_enabled = true; |
| 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 | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6395 | bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6396 | { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6397 | u16 rgvswctl; |
| 6398 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 6399 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6400 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6401 | rgvswctl = I915_READ16(MEMSWCTL); |
| 6402 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 6403 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 6404 | return false; /* still busy with another command */ |
| 6405 | } |
| 6406 | |
| 6407 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 6408 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 6409 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 6410 | POSTING_READ16(MEMSWCTL); |
| 6411 | |
| 6412 | rgvswctl |= MEMCTL_CMD_STS; |
| 6413 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 6414 | |
| 6415 | return true; |
| 6416 | } |
| 6417 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6418 | static void ironlake_enable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6419 | { |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 6420 | u32 rgvmodectl; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6421 | u8 fmax, fmin, fstart, vstart; |
| 6422 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6423 | spin_lock_irq(&mchdev_lock); |
| 6424 | |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 6425 | rgvmodectl = I915_READ(MEMMODECTL); |
| 6426 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6427 | /* Enable temp reporting */ |
| 6428 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 6429 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 6430 | |
| 6431 | /* 100ms RC evaluation intervals */ |
| 6432 | I915_WRITE(RCUPEI, 100000); |
| 6433 | I915_WRITE(RCDNEI, 100000); |
| 6434 | |
| 6435 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 6436 | I915_WRITE(RCBMAXAVG, 90000); |
| 6437 | I915_WRITE(RCBMINAVG, 80000); |
| 6438 | |
| 6439 | I915_WRITE(MEMIHYST, 1); |
| 6440 | |
| 6441 | /* Set up min, max, and cur for interrupt handling */ |
| 6442 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 6443 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 6444 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 6445 | MEMMODE_FSTART_SHIFT; |
| 6446 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 6447 | vstart = (I915_READ(PXVFREQ(fstart)) & PXVFREQ_PX_MASK) >> |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6448 | PXVFREQ_PX_SHIFT; |
| 6449 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6450 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 6451 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6452 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6453 | dev_priv->ips.max_delay = fstart; |
| 6454 | dev_priv->ips.min_delay = fmin; |
| 6455 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6456 | |
| 6457 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 6458 | fmax, fmin, fstart); |
| 6459 | |
| 6460 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 6461 | |
| 6462 | /* |
| 6463 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 6464 | */ |
| 6465 | |
| 6466 | I915_WRITE(VIDSTART, vstart); |
| 6467 | POSTING_READ(VIDSTART); |
| 6468 | |
| 6469 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 6470 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 6471 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6472 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6473 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6474 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6475 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6476 | ironlake_set_drps(dev_priv, fstart); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6477 | |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 6478 | dev_priv->ips.last_count1 = I915_READ(DMIEC) + |
| 6479 | I915_READ(DDREC) + I915_READ(CSIEC); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6480 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 6481 | dev_priv->ips.last_count2 = I915_READ(GFXEC); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 6482 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6483 | |
| 6484 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6485 | } |
| 6486 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6487 | static void ironlake_disable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6488 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6489 | u16 rgvswctl; |
| 6490 | |
| 6491 | spin_lock_irq(&mchdev_lock); |
| 6492 | |
| 6493 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6494 | |
| 6495 | /* Ack interrupts, disable EFC interrupt */ |
| 6496 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 6497 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 6498 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 6499 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 6500 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 6501 | |
| 6502 | /* Go back to the starting frequency */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6503 | ironlake_set_drps(dev_priv, dev_priv->ips.fstart); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6504 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6505 | rgvswctl |= MEMCTL_CMD_STS; |
| 6506 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6507 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6508 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6509 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6510 | } |
| 6511 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 6512 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 6513 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 6514 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 6515 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 6516 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6517 | 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] | 6518 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6519 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6520 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6521 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6522 | /* Only set the down limit when we've reached the lowest level to avoid |
| 6523 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 6524 | * race in the hw when coming out of rc6: There's a tiny window where |
| 6525 | * the hw runs at the minimal clock before selecting the desired |
| 6526 | * frequency, if the down threshold expires in that window we will not |
| 6527 | * receive a down interrupt. */ |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6528 | if (INTEL_GEN(dev_priv) >= 9) { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6529 | limits = (rps->max_freq_softlimit) << 23; |
| 6530 | if (val <= rps->min_freq_softlimit) |
| 6531 | limits |= (rps->min_freq_softlimit) << 14; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6532 | } else { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6533 | limits = rps->max_freq_softlimit << 24; |
| 6534 | if (val <= rps->min_freq_softlimit) |
| 6535 | limits |= rps->min_freq_softlimit << 16; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6536 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6537 | |
| 6538 | return limits; |
| 6539 | } |
| 6540 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6541 | 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] | 6542 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6543 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6544 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 6545 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6546 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6547 | lockdep_assert_held(&rps->power.mutex); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6548 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6549 | if (new_power == rps->power.mode) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6550 | return; |
| 6551 | |
| 6552 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 6553 | switch (new_power) { |
| 6554 | case LOW_POWER: |
| 6555 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6556 | ei_up = 16000; |
| 6557 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6558 | |
| 6559 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6560 | ei_down = 32000; |
| 6561 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6562 | break; |
| 6563 | |
| 6564 | case BETWEEN: |
| 6565 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6566 | ei_up = 13000; |
| 6567 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6568 | |
| 6569 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6570 | ei_down = 32000; |
| 6571 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6572 | break; |
| 6573 | |
| 6574 | case HIGH_POWER: |
| 6575 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6576 | ei_up = 10000; |
| 6577 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6578 | |
| 6579 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6580 | ei_down = 32000; |
| 6581 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6582 | break; |
| 6583 | } |
| 6584 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6585 | /* When byt can survive without system hang with dynamic |
| 6586 | * sw freq adjustments, this restriction can be lifted. |
| 6587 | */ |
| 6588 | if (IS_VALLEYVIEW(dev_priv)) |
| 6589 | goto skip_hw_write; |
| 6590 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6591 | I915_WRITE(GEN6_RP_UP_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6592 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6593 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6594 | GT_INTERVAL_FROM_US(dev_priv, |
| 6595 | ei_up * threshold_up / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6596 | |
| 6597 | I915_WRITE(GEN6_RP_DOWN_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6598 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6599 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6600 | GT_INTERVAL_FROM_US(dev_priv, |
| 6601 | ei_down * threshold_down / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6602 | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6603 | I915_WRITE(GEN6_RP_CONTROL, |
Mika Kuoppala | 1071d0f | 2019-04-10 16:24:36 +0300 | [diff] [blame] | 6604 | (INTEL_GEN(dev_priv) > 9 ? 0 : GEN6_RP_MEDIA_TURBO) | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6605 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6606 | GEN6_RP_MEDIA_IS_GFX | |
| 6607 | GEN6_RP_ENABLE | |
| 6608 | GEN6_RP_UP_BUSY_AVG | |
| 6609 | GEN6_RP_DOWN_IDLE_AVG); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6610 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6611 | skip_hw_write: |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6612 | rps->power.mode = new_power; |
| 6613 | rps->power.up_threshold = threshold_up; |
| 6614 | rps->power.down_threshold = threshold_down; |
| 6615 | } |
| 6616 | |
| 6617 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 6618 | { |
| 6619 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6620 | int new_power; |
| 6621 | |
| 6622 | new_power = rps->power.mode; |
| 6623 | switch (rps->power.mode) { |
| 6624 | case LOW_POWER: |
| 6625 | if (val > rps->efficient_freq + 1 && |
| 6626 | val > rps->cur_freq) |
| 6627 | new_power = BETWEEN; |
| 6628 | break; |
| 6629 | |
| 6630 | case BETWEEN: |
| 6631 | if (val <= rps->efficient_freq && |
| 6632 | val < rps->cur_freq) |
| 6633 | new_power = LOW_POWER; |
| 6634 | else if (val >= rps->rp0_freq && |
| 6635 | val > rps->cur_freq) |
| 6636 | new_power = HIGH_POWER; |
| 6637 | break; |
| 6638 | |
| 6639 | case HIGH_POWER: |
| 6640 | if (val < (rps->rp1_freq + rps->rp0_freq) >> 1 && |
| 6641 | val < rps->cur_freq) |
| 6642 | new_power = BETWEEN; |
| 6643 | break; |
| 6644 | } |
| 6645 | /* Max/min bins are special */ |
| 6646 | if (val <= rps->min_freq_softlimit) |
| 6647 | new_power = LOW_POWER; |
| 6648 | if (val >= rps->max_freq_softlimit) |
| 6649 | new_power = HIGH_POWER; |
| 6650 | |
| 6651 | mutex_lock(&rps->power.mutex); |
| 6652 | if (rps->power.interactive) |
| 6653 | new_power = HIGH_POWER; |
| 6654 | rps_set_power(dev_priv, new_power); |
| 6655 | mutex_unlock(&rps->power.mutex); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6656 | } |
| 6657 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6658 | void intel_rps_mark_interactive(struct drm_i915_private *i915, bool interactive) |
| 6659 | { |
| 6660 | struct intel_rps *rps = &i915->gt_pm.rps; |
| 6661 | |
| 6662 | if (INTEL_GEN(i915) < 6) |
| 6663 | return; |
| 6664 | |
| 6665 | mutex_lock(&rps->power.mutex); |
| 6666 | if (interactive) { |
| 6667 | if (!rps->power.interactive++ && READ_ONCE(i915->gt.awake)) |
| 6668 | rps_set_power(i915, HIGH_POWER); |
| 6669 | } else { |
| 6670 | GEM_BUG_ON(!rps->power.interactive); |
| 6671 | rps->power.interactive--; |
| 6672 | } |
| 6673 | mutex_unlock(&rps->power.mutex); |
| 6674 | } |
| 6675 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6676 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 6677 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6678 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6679 | u32 mask = 0; |
| 6680 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6681 | /* 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] | 6682 | if (val > rps->min_freq_softlimit) |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6683 | 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] | 6684 | if (val < rps->max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 6685 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6686 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 6687 | mask &= dev_priv->pm_rps_events; |
| 6688 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 6689 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6690 | } |
| 6691 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6692 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 6693 | * called when the range (min_delay and max_delay) is modified so that we can |
| 6694 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6695 | 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] | 6696 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6697 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6698 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6699 | /* min/max delay may still have been modified so be sure to |
| 6700 | * write the limits value. |
| 6701 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6702 | if (val != rps->cur_freq) { |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6703 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6704 | |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6705 | if (INTEL_GEN(dev_priv) >= 9) |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 6706 | I915_WRITE(GEN6_RPNSWREQ, |
| 6707 | GEN9_FREQUENCY(val)); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6708 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6709 | I915_WRITE(GEN6_RPNSWREQ, |
| 6710 | HSW_FREQUENCY(val)); |
| 6711 | else |
| 6712 | I915_WRITE(GEN6_RPNSWREQ, |
| 6713 | GEN6_FREQUENCY(val) | |
| 6714 | GEN6_OFFSET(0) | |
| 6715 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6716 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6717 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6718 | /* Make sure we continue to get interrupts |
| 6719 | * until we hit the minimum or maximum frequencies. |
| 6720 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6721 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6722 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6723 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6724 | rps->cur_freq = val; |
Mika Kuoppala | 0f94592 | 2015-11-17 18:14:26 +0200 | [diff] [blame] | 6725 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6726 | |
| 6727 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6728 | } |
| 6729 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6730 | 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] | 6731 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6732 | int err; |
| 6733 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6734 | if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1), |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6735 | "Odd GPU freq value\n")) |
| 6736 | val &= ~1; |
| 6737 | |
Deepak S | cd25dd5 | 2015-07-10 18:31:40 +0530 | [diff] [blame] | 6738 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 6739 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6740 | if (val != dev_priv->gt_pm.rps.cur_freq) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6741 | vlv_punit_get(dev_priv); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6742 | err = vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6743 | vlv_punit_put(dev_priv); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6744 | if (err) |
| 6745 | return err; |
| 6746 | |
Chris Wilson | db4c5e0 | 2017-02-10 15:03:46 +0000 | [diff] [blame] | 6747 | gen6_set_rps_thresholds(dev_priv, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 6748 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6749 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6750 | dev_priv->gt_pm.rps.cur_freq = val; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6751 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6752 | |
| 6753 | return 0; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6754 | } |
| 6755 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6756 | /* 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] | 6757 | * |
| 6758 | * * If Gfx is Idle, then |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6759 | * 1. Forcewake Media well. |
| 6760 | * 2. Request idle freq. |
| 6761 | * 3. Release Forcewake of Media well. |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6762 | */ |
| 6763 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 6764 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6765 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6766 | u32 val = rps->idle_freq; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6767 | int err; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 6768 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6769 | if (rps->cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6770 | return; |
| 6771 | |
Chris Wilson | c9efef7 | 2017-01-02 15:28:45 +0000 | [diff] [blame] | 6772 | /* The punit delays the write of the frequency and voltage until it |
| 6773 | * determines the GPU is awake. During normal usage we don't want to |
| 6774 | * waste power changing the frequency if the GPU is sleeping (rc6). |
| 6775 | * However, the GPU and driver is now idle and we do not want to delay |
| 6776 | * switching to minimum voltage (reducing power whilst idle) as we do |
| 6777 | * not expect to be woken in the near future and so must flush the |
| 6778 | * change by waking the device. |
| 6779 | * |
| 6780 | * We choose to take the media powerwell (either would do to trick the |
| 6781 | * punit into committing the voltage change) as that takes a lot less |
| 6782 | * power than the render powerwell. |
| 6783 | */ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6784 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6785 | err = valleyview_set_rps(dev_priv, val); |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6786 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6787 | |
| 6788 | if (err) |
| 6789 | DRM_ERROR("Failed to set RPS for idle\n"); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6790 | } |
| 6791 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6792 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 6793 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6794 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6795 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6796 | mutex_lock(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6797 | if (rps->enabled) { |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6798 | u8 freq; |
| 6799 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6800 | if (dev_priv->pm_rps_events & GEN6_PM_RP_UP_EI_EXPIRED) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6801 | gen6_rps_reset_ei(dev_priv); |
| 6802 | I915_WRITE(GEN6_PMINTRMSK, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6803 | gen6_rps_pm_mask(dev_priv, rps->cur_freq)); |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 6804 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6805 | gen6_enable_rps_interrupts(dev_priv); |
| 6806 | |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6807 | /* Use the user's desired frequency as a guide, but for better |
| 6808 | * performance, jump directly to RPe as our starting frequency. |
| 6809 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6810 | freq = max(rps->cur_freq, |
| 6811 | rps->efficient_freq); |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6812 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6813 | if (intel_set_rps(dev_priv, |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6814 | clamp(freq, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6815 | rps->min_freq_softlimit, |
| 6816 | rps->max_freq_softlimit))) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6817 | DRM_DEBUG_DRIVER("Failed to set idle frequency\n"); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6818 | } |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6819 | mutex_unlock(&rps->lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6820 | } |
| 6821 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6822 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 6823 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6824 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6825 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6826 | /* Flush our bottom-half so that it does not race with us |
| 6827 | * setting the idle frequency and so that it is bounded by |
| 6828 | * our rpm wakeref. And then disable the interrupts to stop any |
| 6829 | * futher RPS reclocking whilst we are asleep. |
| 6830 | */ |
| 6831 | gen6_disable_rps_interrupts(dev_priv); |
| 6832 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6833 | mutex_lock(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6834 | if (rps->enabled) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6835 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6836 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6837 | else |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6838 | gen6_set_rps(dev_priv, rps->idle_freq); |
| 6839 | rps->last_adj = 0; |
Ville Syrjälä | 12c100b | 2016-05-23 17:42:48 +0300 | [diff] [blame] | 6840 | I915_WRITE(GEN6_PMINTRMSK, |
| 6841 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6842 | } |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6843 | mutex_unlock(&rps->lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6844 | } |
| 6845 | |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 6846 | void gen6_rps_boost(struct i915_request *rq) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6847 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6848 | struct intel_rps *rps = &rq->i915->gt_pm.rps; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6849 | unsigned long flags; |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6850 | bool boost; |
| 6851 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6852 | /* This is intentionally racy! We peek at the state here, then |
| 6853 | * validate inside the RPS worker. |
| 6854 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6855 | if (!rps->enabled) |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6856 | return; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6857 | |
Chris Wilson | 0e21834 | 2019-01-21 22:21:02 +0000 | [diff] [blame] | 6858 | if (i915_request_signaled(rq)) |
Chris Wilson | 253a281 | 2018-02-06 14:31:37 +0000 | [diff] [blame] | 6859 | return; |
| 6860 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 6861 | /* Serializes with i915_request_retire() */ |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6862 | boost = false; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6863 | spin_lock_irqsave(&rq->lock, flags); |
Chris Wilson | 253a281 | 2018-02-06 14:31:37 +0000 | [diff] [blame] | 6864 | if (!rq->waitboost && !dma_fence_is_signaled_locked(&rq->fence)) { |
| 6865 | boost = !atomic_fetch_inc(&rps->num_waiters); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6866 | rq->waitboost = true; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6867 | } |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6868 | spin_unlock_irqrestore(&rq->lock, flags); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6869 | if (!boost) |
| 6870 | return; |
| 6871 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6872 | if (READ_ONCE(rps->cur_freq) < rps->boost_freq) |
| 6873 | schedule_work(&rps->work); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6874 | |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 6875 | atomic_inc(&rps->boosts); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6876 | } |
| 6877 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6878 | int intel_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6879 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6880 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6881 | int err; |
| 6882 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 6883 | lockdep_assert_held(&rps->lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6884 | GEM_BUG_ON(val > rps->max_freq); |
| 6885 | GEM_BUG_ON(val < rps->min_freq); |
Chris Wilson | cfd1c48 | 2017-02-20 09:47:07 +0000 | [diff] [blame] | 6886 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6887 | if (!rps->enabled) { |
| 6888 | rps->cur_freq = val; |
Chris Wilson | 76e4e4b | 2017-02-20 09:47:08 +0000 | [diff] [blame] | 6889 | return 0; |
| 6890 | } |
| 6891 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6892 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6893 | err = valleyview_set_rps(dev_priv, val); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6894 | else |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6895 | err = gen6_set_rps(dev_priv, val); |
| 6896 | |
| 6897 | return err; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6898 | } |
| 6899 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6900 | static void gen9_disable_rc6(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6901 | { |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6902 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6903 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6904 | } |
| 6905 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6906 | static void gen9_disable_rps(struct drm_i915_private *dev_priv) |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6907 | { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6908 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6909 | } |
| 6910 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6911 | static void gen6_disable_rc6(struct drm_i915_private *dev_priv) |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6912 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6913 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6914 | } |
| 6915 | |
| 6916 | static void gen6_disable_rps(struct drm_i915_private *dev_priv) |
| 6917 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6918 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6919 | I915_WRITE(GEN6_RP_CONTROL, 0); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6920 | } |
| 6921 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6922 | static void cherryview_disable_rc6(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6923 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6924 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6925 | } |
| 6926 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6927 | static void cherryview_disable_rps(struct drm_i915_private *dev_priv) |
| 6928 | { |
| 6929 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6930 | } |
| 6931 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6932 | static void valleyview_disable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6933 | { |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6934 | /* We're doing forcewake before Disabling RC6, |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6935 | * This what the BIOS expects when going into suspend */ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6936 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6937 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6938 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6939 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 6940 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6941 | } |
| 6942 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6943 | static void valleyview_disable_rps(struct drm_i915_private *dev_priv) |
| 6944 | { |
| 6945 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6946 | } |
| 6947 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6948 | 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] | 6949 | { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6950 | bool enable_rc6 = true; |
| 6951 | unsigned long rc6_ctx_base; |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6952 | u32 rc_ctl; |
| 6953 | int rc_sw_target; |
| 6954 | |
| 6955 | rc_ctl = I915_READ(GEN6_RC_CONTROL); |
| 6956 | rc_sw_target = (I915_READ(GEN6_RC_STATE) & RC_SW_TARGET_STATE_MASK) >> |
| 6957 | RC_SW_TARGET_STATE_SHIFT; |
| 6958 | DRM_DEBUG_DRIVER("BIOS enabled RC states: " |
| 6959 | "HW_CTRL %s HW_RC6 %s SW_TARGET_STATE %x\n", |
| 6960 | onoff(rc_ctl & GEN6_RC_CTL_HW_ENABLE), |
| 6961 | onoff(rc_ctl & GEN6_RC_CTL_RC6_ENABLE), |
| 6962 | rc_sw_target); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6963 | |
| 6964 | if (!(I915_READ(RC6_LOCATION) & RC6_CTX_IN_DRAM)) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6965 | DRM_DEBUG_DRIVER("RC6 Base location not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6966 | enable_rc6 = false; |
| 6967 | } |
| 6968 | |
| 6969 | /* |
| 6970 | * The exact context size is not known for BXT, so assume a page size |
| 6971 | * for this check. |
| 6972 | */ |
| 6973 | rc6_ctx_base = I915_READ(RC6_CTX_BASE) & RC6_CTX_BASE_MASK; |
Matthew Auld | 17a0534 | 2017-12-11 15:18:19 +0000 | [diff] [blame] | 6974 | if (!((rc6_ctx_base >= dev_priv->dsm_reserved.start) && |
| 6975 | (rc6_ctx_base + PAGE_SIZE < dev_priv->dsm_reserved.end))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6976 | DRM_DEBUG_DRIVER("RC6 Base address not as expected.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6977 | enable_rc6 = false; |
| 6978 | } |
| 6979 | |
| 6980 | if (!(((I915_READ(PWRCTX_MAXCNT_RCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6981 | ((I915_READ(PWRCTX_MAXCNT_VCSUNIT0) & IDLE_TIME_MASK) > 1) && |
| 6982 | ((I915_READ(PWRCTX_MAXCNT_BCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6983 | ((I915_READ(PWRCTX_MAXCNT_VECSUNIT) & IDLE_TIME_MASK) > 1))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6984 | DRM_DEBUG_DRIVER("Engine Idle wait time not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6985 | enable_rc6 = false; |
| 6986 | } |
| 6987 | |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6988 | if (!I915_READ(GEN8_PUSHBUS_CONTROL) || |
| 6989 | !I915_READ(GEN8_PUSHBUS_ENABLE) || |
| 6990 | !I915_READ(GEN8_PUSHBUS_SHIFT)) { |
| 6991 | DRM_DEBUG_DRIVER("Pushbus not setup properly.\n"); |
| 6992 | enable_rc6 = false; |
| 6993 | } |
| 6994 | |
| 6995 | if (!I915_READ(GEN6_GFXPAUSE)) { |
| 6996 | DRM_DEBUG_DRIVER("GFX pause not setup properly.\n"); |
| 6997 | enable_rc6 = false; |
| 6998 | } |
| 6999 | |
| 7000 | if (!I915_READ(GEN8_MISC_CTRL0)) { |
| 7001 | DRM_DEBUG_DRIVER("GPM control not setup properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7002 | enable_rc6 = false; |
| 7003 | } |
| 7004 | |
| 7005 | return enable_rc6; |
| 7006 | } |
| 7007 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7008 | static bool sanitize_rc6(struct drm_i915_private *i915) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7009 | { |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7010 | struct intel_device_info *info = mkwrite_device_info(i915); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7011 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7012 | /* Powersaving is controlled by the host when inside a VM */ |
Chris Wilson | 91cbdb8 | 2019-04-19 14:48:36 +0100 | [diff] [blame] | 7013 | if (intel_vgpu_active(i915)) { |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7014 | info->has_rc6 = 0; |
Chris Wilson | 91cbdb8 | 2019-04-19 14:48:36 +0100 | [diff] [blame] | 7015 | info->has_rps = false; |
| 7016 | } |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7017 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7018 | if (info->has_rc6 && |
| 7019 | IS_GEN9_LP(i915) && !bxt_check_bios_rc6_setup(i915)) { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7020 | DRM_INFO("RC6 disabled by BIOS\n"); |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7021 | info->has_rc6 = 0; |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 7022 | } |
| 7023 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7024 | /* |
| 7025 | * We assume that we do not have any deep rc6 levels if we don't have |
| 7026 | * have the previous rc6 level supported, i.e. we use HAS_RC6() |
| 7027 | * as the initial coarse check for rc6 in general, moving on to |
| 7028 | * progressively finer/deeper levels. |
| 7029 | */ |
| 7030 | if (!info->has_rc6 && info->has_rc6p) |
| 7031 | info->has_rc6p = 0; |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7032 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7033 | return info->has_rc6; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7034 | } |
| 7035 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7036 | static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7037 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7038 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7039 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7040 | /* All of these values are in units of 50MHz */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7041 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 7042 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 7043 | if (IS_GEN9_LP(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7044 | u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7045 | rps->rp0_freq = (rp_state_cap >> 16) & 0xff; |
| 7046 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 7047 | rps->min_freq = (rp_state_cap >> 0) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 7048 | } else { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7049 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7050 | rps->rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 7051 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 7052 | rps->min_freq = (rp_state_cap >> 16) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 7053 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7054 | /* hw_max = RP0 until we check for overclocking */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7055 | rps->max_freq = rps->rp0_freq; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7056 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7057 | rps->efficient_freq = rps->rp1_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7058 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) || |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7059 | IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7060 | u32 ddcc_status = 0; |
| 7061 | |
| 7062 | if (sandybridge_pcode_read(dev_priv, |
| 7063 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 7064 | &ddcc_status) == 0) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7065 | rps->efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 7066 | clamp_t(u8, |
| 7067 | ((ddcc_status >> 8) & 0xff), |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7068 | rps->min_freq, |
| 7069 | rps->max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 7070 | } |
| 7071 | |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7072 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 7073 | /* Store the frequency values in 16.66 MHZ units, which is |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7074 | * the natural hardware unit for SKL |
| 7075 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7076 | rps->rp0_freq *= GEN9_FREQ_SCALER; |
| 7077 | rps->rp1_freq *= GEN9_FREQ_SCALER; |
| 7078 | rps->min_freq *= GEN9_FREQ_SCALER; |
| 7079 | rps->max_freq *= GEN9_FREQ_SCALER; |
| 7080 | rps->efficient_freq *= GEN9_FREQ_SCALER; |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 7081 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7082 | } |
| 7083 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7084 | static void reset_rps(struct drm_i915_private *dev_priv, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 7085 | int (*set)(struct drm_i915_private *, u8)) |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7086 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7087 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7088 | u8 freq = rps->cur_freq; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7089 | |
| 7090 | /* force a reset */ |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 7091 | rps->power.mode = -1; |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7092 | rps->cur_freq = -1; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7093 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 7094 | if (set(dev_priv, freq)) |
| 7095 | DRM_ERROR("Failed to reset RPS to initial values\n"); |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7096 | } |
| 7097 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7098 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7099 | static void gen9_enable_rps(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7100 | { |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7101 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7102 | |
David Weinehall | 36fe778 | 2017-11-17 10:01:46 +0200 | [diff] [blame] | 7103 | /* Program defaults and thresholds for RPS */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7104 | if (IS_GEN(dev_priv, 9)) |
David Weinehall | 36fe778 | 2017-11-17 10:01:46 +0200 | [diff] [blame] | 7105 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 7106 | GEN9_FREQUENCY(dev_priv->gt_pm.rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7107 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 7108 | /* 1 second timeout*/ |
| 7109 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 7110 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 7111 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7112 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7113 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 7114 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 7115 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 7116 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7117 | reset_rps(dev_priv, gen6_set_rps); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7118 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7119 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7120 | } |
| 7121 | |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7122 | static void gen11_enable_rc6(struct drm_i915_private *dev_priv) |
| 7123 | { |
| 7124 | struct intel_engine_cs *engine; |
| 7125 | enum intel_engine_id id; |
| 7126 | |
| 7127 | /* 1a: Software RC state - RC0 */ |
| 7128 | I915_WRITE(GEN6_RC_STATE, 0); |
| 7129 | |
| 7130 | /* |
| 7131 | * 1b: Get forcewake during program sequence. Although the driver |
| 7132 | * hasn't enabled a state yet where we need forcewake, BIOS may have. |
| 7133 | */ |
| 7134 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
| 7135 | |
| 7136 | /* 2a: Disable RC states. */ |
| 7137 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7138 | |
| 7139 | /* 2b: Program RC6 thresholds.*/ |
| 7140 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16 | 85); |
| 7141 | I915_WRITE(GEN10_MEDIA_WAKE_RATE_LIMIT, 150); |
| 7142 | |
| 7143 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7144 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 7145 | for_each_engine(engine, dev_priv, id) |
| 7146 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
| 7147 | |
| 7148 | if (HAS_GUC(dev_priv)) |
| 7149 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 7150 | |
| 7151 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7152 | |
Mika Kuoppala | d105e9a | 2019-04-10 13:59:18 +0300 | [diff] [blame] | 7153 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 7154 | |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7155 | /* |
| 7156 | * 2c: Program Coarse Power Gating Policies. |
| 7157 | * |
| 7158 | * Bspec's guidance is to use 25us (really 25 * 1280ns) here. What we |
| 7159 | * use instead is a more conservative estimate for the maximum time |
| 7160 | * it takes us to service a CS interrupt and submit a new ELSP - that |
| 7161 | * is the time which the GPU is idle waiting for the CPU to select the |
| 7162 | * next request to execute. If the idle hysteresis is less than that |
| 7163 | * interrupt service latency, the hardware will automatically gate |
| 7164 | * the power well and we will then incur the wake up cost on top of |
| 7165 | * the service latency. A similar guide from intel_pstate is that we |
| 7166 | * do not want the enable hysteresis to less than the wakeup latency. |
| 7167 | * |
| 7168 | * igt/gem_exec_nop/sequential provides a rough estimate for the |
| 7169 | * service latency, and puts it around 10us for Broadwell (and other |
| 7170 | * big core) and around 40us for Broxton (and other low power cores). |
| 7171 | * [Note that for legacy ringbuffer submission, this is less than 1us!] |
| 7172 | * However, the wakeup latency on Broxton is closer to 100us. To be |
| 7173 | * conservative, we have to factor in a context switch on top (due |
| 7174 | * to ksoftirqd). |
| 7175 | */ |
| 7176 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 250); |
| 7177 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 250); |
| 7178 | |
| 7179 | /* 3a: Enable RC6 */ |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7180 | I915_WRITE(GEN6_RC_CONTROL, |
| 7181 | GEN6_RC_CTL_HW_ENABLE | |
| 7182 | GEN6_RC_CTL_RC6_ENABLE | |
| 7183 | GEN6_RC_CTL_EI_MODE(1)); |
| 7184 | |
| 7185 | /* 3b: Enable Coarse Power Gating only when RC6 is enabled. */ |
| 7186 | I915_WRITE(GEN9_PG_ENABLE, |
Mika Kuoppala | 2ea7414 | 2019-04-10 13:59:19 +0300 | [diff] [blame] | 7187 | GEN9_RENDER_PG_ENABLE | |
| 7188 | GEN9_MEDIA_PG_ENABLE | |
| 7189 | GEN11_MEDIA_SAMPLER_PG_ENABLE); |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 7190 | |
| 7191 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
| 7192 | } |
| 7193 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7194 | static void gen9_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7195 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7196 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7197 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7198 | u32 rc6_mode; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7199 | |
| 7200 | /* 1a: Software RC state - RC0 */ |
| 7201 | I915_WRITE(GEN6_RC_STATE, 0); |
| 7202 | |
| 7203 | /* 1b: Get forcewake during program sequence. Although the driver |
| 7204 | * 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] | 7205 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7206 | |
| 7207 | /* 2a: Disable RC states. */ |
| 7208 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7209 | |
| 7210 | /* 2b: Program RC6 thresholds.*/ |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7211 | if (INTEL_GEN(dev_priv) >= 10) { |
| 7212 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16 | 85); |
| 7213 | I915_WRITE(GEN10_MEDIA_WAKE_RATE_LIMIT, 150); |
| 7214 | } else if (IS_SKYLAKE(dev_priv)) { |
| 7215 | /* |
| 7216 | * WaRsDoubleRc6WrlWithCoarsePowerGating:skl Doubling WRL only |
| 7217 | * when CPG is enabled |
| 7218 | */ |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 7219 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 108 << 16); |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7220 | } else { |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 7221 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7222 | } |
| 7223 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7224 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7225 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7226 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7227 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 7228 | |
Dave Gordon | 1a3d189 | 2016-05-13 15:36:30 +0100 | [diff] [blame] | 7229 | if (HAS_GUC(dev_priv)) |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 7230 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 7231 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7232 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7233 | |
Chris Wilson | c1beabc | 2018-01-22 13:55:41 +0000 | [diff] [blame] | 7234 | /* |
| 7235 | * 2c: Program Coarse Power Gating Policies. |
| 7236 | * |
| 7237 | * Bspec's guidance is to use 25us (really 25 * 1280ns) here. What we |
| 7238 | * use instead is a more conservative estimate for the maximum time |
| 7239 | * it takes us to service a CS interrupt and submit a new ELSP - that |
| 7240 | * is the time which the GPU is idle waiting for the CPU to select the |
| 7241 | * next request to execute. If the idle hysteresis is less than that |
| 7242 | * interrupt service latency, the hardware will automatically gate |
| 7243 | * the power well and we will then incur the wake up cost on top of |
| 7244 | * the service latency. A similar guide from intel_pstate is that we |
| 7245 | * do not want the enable hysteresis to less than the wakeup latency. |
| 7246 | * |
| 7247 | * igt/gem_exec_nop/sequential provides a rough estimate for the |
| 7248 | * service latency, and puts it around 10us for Broadwell (and other |
| 7249 | * big core) and around 40us for Broxton (and other low power cores). |
| 7250 | * [Note that for legacy ringbuffer submission, this is less than 1us!] |
| 7251 | * However, the wakeup latency on Broxton is closer to 100us. To be |
| 7252 | * conservative, we have to factor in a context switch on top (due |
| 7253 | * to ksoftirqd). |
| 7254 | */ |
| 7255 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 250); |
| 7256 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 250); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 7257 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7258 | /* 3a: Enable RC6 */ |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 7259 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
Rodrigo Vivi | e4ffc83 | 2017-08-22 16:58:28 -0700 | [diff] [blame] | 7260 | |
| 7261 | /* WaRsUseTimeoutMode:cnl (pre-prod) */ |
| 7262 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_C0)) |
| 7263 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
| 7264 | else |
| 7265 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 7266 | |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 7267 | I915_WRITE(GEN6_RC_CONTROL, |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7268 | GEN6_RC_CTL_HW_ENABLE | |
| 7269 | GEN6_RC_CTL_RC6_ENABLE | |
| 7270 | rc6_mode); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7271 | |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 7272 | /* |
| 7273 | * 3b: Enable Coarse Power Gating only when RC6 is enabled. |
Rodrigo Vivi | d66047e4 | 2018-02-22 12:05:35 -0800 | [diff] [blame] | 7274 | * WaRsDisableCoarsePowerGating:skl,cnl - Render/Media PG need to be disabled with RC6. |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 7275 | */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7276 | if (NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 7277 | I915_WRITE(GEN9_PG_ENABLE, 0); |
| 7278 | else |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7279 | I915_WRITE(GEN9_PG_ENABLE, |
| 7280 | GEN9_RENDER_PG_ENABLE | GEN9_MEDIA_PG_ENABLE); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 7281 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7282 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7283 | } |
| 7284 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7285 | static void gen8_enable_rc6(struct drm_i915_private *dev_priv) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7286 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7287 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7288 | enum intel_engine_id id; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7289 | |
| 7290 | /* 1a: Software RC state - RC0 */ |
| 7291 | I915_WRITE(GEN6_RC_STATE, 0); |
| 7292 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7293 | /* 1b: Get forcewake during program sequence. Although the driver |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7294 | * 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] | 7295 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7296 | |
| 7297 | /* 2a: Disable RC states. */ |
| 7298 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7299 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7300 | /* 2b: Program RC6 thresholds.*/ |
| 7301 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 7302 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7303 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7304 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7305 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7306 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Sagar Arun Kamble | 415544d | 2017-10-10 22:30:00 +0100 | [diff] [blame] | 7307 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7308 | |
| 7309 | /* 3: Enable RC6 */ |
Sagar Arun Kamble | 415544d | 2017-10-10 22:30:00 +0100 | [diff] [blame] | 7310 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7311 | I915_WRITE(GEN6_RC_CONTROL, |
| 7312 | GEN6_RC_CTL_HW_ENABLE | |
| 7313 | GEN7_RC_CTL_TO_MODE | |
| 7314 | GEN6_RC_CTL_RC6_ENABLE); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7315 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7316 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7317 | } |
| 7318 | |
| 7319 | static void gen8_enable_rps(struct drm_i915_private *dev_priv) |
| 7320 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7321 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7322 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7323 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7324 | |
| 7325 | /* 1 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 7326 | I915_WRITE(GEN6_RPNSWREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7327 | HSW_FREQUENCY(rps->rp1_freq)); |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 7328 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7329 | HSW_FREQUENCY(rps->rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7330 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 7331 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7332 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7333 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 7334 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7335 | rps->max_freq_softlimit << 24 | |
| 7336 | rps->min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7337 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7338 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 7339 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 7340 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 7341 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7342 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7343 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7344 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7345 | /* 2: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7346 | I915_WRITE(GEN6_RP_CONTROL, |
| 7347 | GEN6_RP_MEDIA_TURBO | |
| 7348 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7349 | GEN6_RP_MEDIA_IS_GFX | |
| 7350 | GEN6_RP_ENABLE | |
| 7351 | GEN6_RP_UP_BUSY_AVG | |
| 7352 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7353 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7354 | reset_rps(dev_priv, gen6_set_rps); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7355 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7356 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7357 | } |
| 7358 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7359 | static void gen6_enable_rc6(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7360 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7361 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7362 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7363 | u32 rc6vids, rc6_mask; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7364 | u32 gtfifodbg; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 7365 | int ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7366 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7367 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7368 | |
| 7369 | /* Clear the DBG now so we don't confuse earlier errors */ |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7370 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7371 | if (gtfifodbg) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7372 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 7373 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7374 | } |
| 7375 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7376 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7377 | |
| 7378 | /* disable the counters and set deterministic thresholds */ |
| 7379 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7380 | |
| 7381 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 7382 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 7383 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 7384 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 7385 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 7386 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7387 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7388 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7389 | |
| 7390 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7391 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7392 | if (IS_IVYBRIDGE(dev_priv)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 7393 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 7394 | else |
| 7395 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 7396 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7397 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 7398 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 7399 | /* We don't use those on Haswell */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7400 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 7401 | if (HAS_RC6p(dev_priv)) |
| 7402 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
| 7403 | if (HAS_RC6pp(dev_priv)) |
| 7404 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7405 | I915_WRITE(GEN6_RC_CONTROL, |
| 7406 | rc6_mask | |
| 7407 | GEN6_RC_CTL_EI_MODE(1) | |
| 7408 | GEN6_RC_CTL_HW_ENABLE); |
| 7409 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 7410 | rc6vids = 0; |
| 7411 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7412 | if (IS_GEN(dev_priv, 6) && ret) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 7413 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7414 | } 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] | 7415 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 7416 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 7417 | rc6vids &= 0xffff00; |
| 7418 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 7419 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 7420 | if (ret) |
| 7421 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 7422 | } |
| 7423 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7424 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7425 | } |
| 7426 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7427 | static void gen6_enable_rps(struct drm_i915_private *dev_priv) |
| 7428 | { |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7429 | /* Here begins a magic sequence of register writes to enable |
| 7430 | * auto-downclocking. |
| 7431 | * |
| 7432 | * Perhaps there might be some value in exposing these to |
| 7433 | * userspace... |
| 7434 | */ |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7435 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7436 | |
| 7437 | /* Power down if completely idle for over 50ms */ |
| 7438 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
| 7439 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7440 | |
| 7441 | reset_rps(dev_priv, gen6_set_rps); |
| 7442 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7443 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7444 | } |
| 7445 | |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7446 | static void gen6_update_ring_freq(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7447 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7448 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Mika Kuoppala | 66c1f77 | 2018-03-20 17:17:33 +0200 | [diff] [blame] | 7449 | const int min_freq = 15; |
| 7450 | const int scaling_factor = 180; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7451 | unsigned int gpu_freq; |
| 7452 | unsigned int max_ia_freq, min_ring_freq; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7453 | unsigned int max_gpu_freq, min_gpu_freq; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7454 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7455 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 7456 | lockdep_assert_held(&rps->lock); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 7457 | |
Mika Kuoppala | 66c1f77 | 2018-03-20 17:17:33 +0200 | [diff] [blame] | 7458 | if (rps->max_freq <= rps->min_freq) |
| 7459 | return; |
| 7460 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7461 | policy = cpufreq_cpu_get(0); |
| 7462 | if (policy) { |
| 7463 | max_ia_freq = policy->cpuinfo.max_freq; |
| 7464 | cpufreq_cpu_put(policy); |
| 7465 | } else { |
| 7466 | /* |
| 7467 | * Default to measured freq if none found, PCU will ensure we |
| 7468 | * don't go over |
| 7469 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7470 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7471 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7472 | |
| 7473 | /* Convert from kHz to MHz */ |
| 7474 | max_ia_freq /= 1000; |
| 7475 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 7476 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 7477 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 7478 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7479 | |
Chris Wilson | d586b5f | 2018-03-08 14:26:48 +0000 | [diff] [blame] | 7480 | min_gpu_freq = rps->min_freq; |
| 7481 | max_gpu_freq = rps->max_freq; |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7482 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7483 | /* Convert GT frequency to 50 HZ units */ |
Chris Wilson | d586b5f | 2018-03-08 14:26:48 +0000 | [diff] [blame] | 7484 | min_gpu_freq /= GEN9_FREQ_SCALER; |
| 7485 | max_gpu_freq /= GEN9_FREQ_SCALER; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7486 | } |
| 7487 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7488 | /* |
| 7489 | * For each potential GPU frequency, load a ring frequency we'd like |
| 7490 | * to use for memory access. We do this by specifying the IA frequency |
| 7491 | * the PCU should use as a reference to determine the ring frequency. |
| 7492 | */ |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7493 | 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] | 7494 | const int diff = max_gpu_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7495 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7496 | |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7497 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7498 | /* |
| 7499 | * ring_freq = 2 * GT. ring_freq is in 100MHz units |
| 7500 | * No floor required for ring frequency on SKL. |
| 7501 | */ |
| 7502 | ring_freq = gpu_freq; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 7503 | } else if (INTEL_GEN(dev_priv) >= 8) { |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 7504 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 7505 | ring_freq = max(min_ring_freq, gpu_freq); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7506 | } else if (IS_HASWELL(dev_priv)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 7507 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7508 | ring_freq = max(min_ring_freq, ring_freq); |
| 7509 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 7510 | } else { |
| 7511 | /* On older processors, there is no separate ring |
| 7512 | * clock domain, so in order to boost the bandwidth |
| 7513 | * of the ring, we need to upclock the CPU (ia_freq). |
| 7514 | * |
| 7515 | * For GPU frequencies less than 750MHz, |
| 7516 | * just use the lowest ring freq. |
| 7517 | */ |
| 7518 | if (gpu_freq < min_freq) |
| 7519 | ia_freq = 800; |
| 7520 | else |
| 7521 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 7522 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 7523 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7524 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7525 | sandybridge_pcode_write(dev_priv, |
| 7526 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7527 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 7528 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 7529 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7530 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7531 | } |
| 7532 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7533 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7534 | { |
| 7535 | u32 val, rp0; |
| 7536 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7537 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7538 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 7539 | switch (RUNTIME_INFO(dev_priv)->sseu.eu_total) { |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7540 | case 8: |
| 7541 | /* (2 * 4) config */ |
| 7542 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 7543 | break; |
| 7544 | case 12: |
| 7545 | /* (2 * 6) config */ |
| 7546 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 7547 | break; |
| 7548 | case 16: |
| 7549 | /* (2 * 8) config */ |
| 7550 | default: |
| 7551 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 7552 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 7553 | break; |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 7554 | } |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7555 | |
| 7556 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 7557 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7558 | return rp0; |
| 7559 | } |
| 7560 | |
| 7561 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7562 | { |
| 7563 | u32 val, rpe; |
| 7564 | |
| 7565 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 7566 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 7567 | |
| 7568 | return rpe; |
| 7569 | } |
| 7570 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7571 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7572 | { |
| 7573 | u32 val, rp1; |
| 7574 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7575 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 7576 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 7577 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7578 | return rp1; |
| 7579 | } |
| 7580 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 7581 | static u32 cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 7582 | { |
| 7583 | u32 val, rpn; |
| 7584 | |
| 7585 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 7586 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 7587 | FB_GFX_FREQ_FUSE_MASK); |
| 7588 | |
| 7589 | return rpn; |
| 7590 | } |
| 7591 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7592 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7593 | { |
| 7594 | u32 val, rp1; |
| 7595 | |
| 7596 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 7597 | |
| 7598 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 7599 | |
| 7600 | return rp1; |
| 7601 | } |
| 7602 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7603 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7604 | { |
| 7605 | u32 val, rp0; |
| 7606 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7607 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7608 | |
| 7609 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 7610 | /* Clamp to max */ |
| 7611 | rp0 = min_t(u32, rp0, 0xea); |
| 7612 | |
| 7613 | return rp0; |
| 7614 | } |
| 7615 | |
| 7616 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7617 | { |
| 7618 | u32 val, rpe; |
| 7619 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7620 | 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] | 7621 | 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] | 7622 | 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] | 7623 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 7624 | |
| 7625 | return rpe; |
| 7626 | } |
| 7627 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7628 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7629 | { |
Imre Deak | 3614603 | 2014-12-04 18:39:35 +0200 | [diff] [blame] | 7630 | u32 val; |
| 7631 | |
| 7632 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
| 7633 | /* |
| 7634 | * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value |
| 7635 | * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on |
| 7636 | * a BYT-M B0 the above register contains 0xbf. Moreover when setting |
| 7637 | * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0 |
| 7638 | * to make sure it matches what Punit accepts. |
| 7639 | */ |
| 7640 | return max_t(u32, val, 0xc0); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7641 | } |
| 7642 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7643 | /* Check that the pctx buffer wasn't move under us. */ |
| 7644 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 7645 | { |
| 7646 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 7647 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7648 | WARN_ON(pctx_addr != dev_priv->dsm.start + |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7649 | dev_priv->vlv_pctx->stolen->start); |
| 7650 | } |
| 7651 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7652 | |
| 7653 | /* Check that the pcbr address is not empty. */ |
| 7654 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 7655 | { |
| 7656 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 7657 | |
| 7658 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 7659 | } |
| 7660 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7661 | static void cherryview_setup_pctx(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7662 | { |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7663 | resource_size_t pctx_paddr, paddr; |
| 7664 | resource_size_t pctx_size = 32*1024; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7665 | u32 pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7666 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7667 | pcbr = I915_READ(VLV_PCBR); |
| 7668 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7669 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7670 | paddr = dev_priv->dsm.end + 1 - pctx_size; |
| 7671 | GEM_BUG_ON(paddr > U32_MAX); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7672 | |
| 7673 | pctx_paddr = (paddr & (~4095)); |
| 7674 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 7675 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7676 | |
| 7677 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7678 | } |
| 7679 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7680 | static void valleyview_setup_pctx(struct drm_i915_private *dev_priv) |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7681 | { |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7682 | struct drm_i915_gem_object *pctx; |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7683 | resource_size_t pctx_paddr; |
| 7684 | resource_size_t pctx_size = 24*1024; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7685 | u32 pcbr; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7686 | |
| 7687 | pcbr = I915_READ(VLV_PCBR); |
| 7688 | if (pcbr) { |
| 7689 | /* BIOS set it up already, grab the pre-alloc'd space */ |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7690 | resource_size_t pcbr_offset; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7691 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7692 | pcbr_offset = (pcbr & (~4095)) - dev_priv->dsm.start; |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 7693 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7694 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 7695 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7696 | pctx_size); |
| 7697 | goto out; |
| 7698 | } |
| 7699 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7700 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 7701 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7702 | /* |
| 7703 | * From the Gunit register HAS: |
| 7704 | * The Gfx driver is expected to program this register and ensure |
| 7705 | * proper allocation within Gfx stolen memory. For example, this |
| 7706 | * register should be programmed such than the PCBR range does not |
| 7707 | * overlap with other ranges, such as the frame buffer, protected |
| 7708 | * memory, or any other relevant ranges. |
| 7709 | */ |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 7710 | pctx = i915_gem_object_create_stolen(dev_priv, pctx_size); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7711 | if (!pctx) { |
| 7712 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
Tvrtko Ursulin | ee50489 | 2016-02-11 10:27:30 +0000 | [diff] [blame] | 7713 | goto out; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7714 | } |
| 7715 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7716 | GEM_BUG_ON(range_overflows_t(u64, |
| 7717 | dev_priv->dsm.start, |
| 7718 | pctx->stolen->start, |
| 7719 | U32_MAX)); |
| 7720 | pctx_paddr = dev_priv->dsm.start + pctx->stolen->start; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7721 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 7722 | |
| 7723 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7724 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7725 | dev_priv->vlv_pctx = pctx; |
| 7726 | } |
| 7727 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7728 | static void valleyview_cleanup_pctx(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7729 | { |
Chris Wilson | 818fed4 | 2018-07-12 11:54:54 +0100 | [diff] [blame] | 7730 | struct drm_i915_gem_object *pctx; |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7731 | |
Chris Wilson | 818fed4 | 2018-07-12 11:54:54 +0100 | [diff] [blame] | 7732 | pctx = fetch_and_zero(&dev_priv->vlv_pctx); |
| 7733 | if (pctx) |
| 7734 | i915_gem_object_put(pctx); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7735 | } |
| 7736 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7737 | static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv) |
| 7738 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7739 | dev_priv->gt_pm.rps.gpll_ref_freq = |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7740 | vlv_get_cck_clock(dev_priv, "GPLL ref", |
| 7741 | CCK_GPLL_CLOCK_CONTROL, |
| 7742 | dev_priv->czclk_freq); |
| 7743 | |
| 7744 | DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7745 | dev_priv->gt_pm.rps.gpll_ref_freq); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7746 | } |
| 7747 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7748 | static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7749 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7750 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7751 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7752 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7753 | valleyview_setup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7754 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7755 | vlv_iosf_sb_get(dev_priv, |
| 7756 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7757 | BIT(VLV_IOSF_SB_NC) | |
| 7758 | BIT(VLV_IOSF_SB_CCK)); |
| 7759 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7760 | vlv_init_gpll_ref_freq(dev_priv); |
| 7761 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7762 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7763 | switch ((val >> 6) & 3) { |
| 7764 | case 0: |
| 7765 | case 1: |
| 7766 | dev_priv->mem_freq = 800; |
| 7767 | break; |
| 7768 | case 2: |
| 7769 | dev_priv->mem_freq = 1066; |
| 7770 | break; |
| 7771 | case 3: |
| 7772 | dev_priv->mem_freq = 1333; |
| 7773 | break; |
| 7774 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7775 | 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] | 7776 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7777 | rps->max_freq = valleyview_rps_max_freq(dev_priv); |
| 7778 | rps->rp0_freq = rps->max_freq; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7779 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7780 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7781 | rps->max_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7782 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7783 | rps->efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7784 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7785 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7786 | rps->efficient_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7787 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7788 | rps->rp1_freq = valleyview_rps_guar_freq(dev_priv); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7789 | 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] | 7790 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7791 | rps->rp1_freq); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7792 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7793 | rps->min_freq = valleyview_rps_min_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7794 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7795 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7796 | rps->min_freq); |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7797 | |
| 7798 | vlv_iosf_sb_put(dev_priv, |
| 7799 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7800 | BIT(VLV_IOSF_SB_NC) | |
| 7801 | BIT(VLV_IOSF_SB_CCK)); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7802 | } |
| 7803 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7804 | static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7805 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7806 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7807 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7808 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7809 | cherryview_setup_pctx(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7810 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7811 | vlv_iosf_sb_get(dev_priv, |
| 7812 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7813 | BIT(VLV_IOSF_SB_NC) | |
| 7814 | BIT(VLV_IOSF_SB_CCK)); |
| 7815 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7816 | vlv_init_gpll_ref_freq(dev_priv); |
| 7817 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7818 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7819 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7820 | switch ((val >> 2) & 0x7) { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7821 | case 3: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7822 | dev_priv->mem_freq = 2000; |
| 7823 | break; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 7824 | default: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7825 | dev_priv->mem_freq = 1600; |
| 7826 | break; |
| 7827 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7828 | 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] | 7829 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7830 | rps->max_freq = cherryview_rps_max_freq(dev_priv); |
| 7831 | rps->rp0_freq = rps->max_freq; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7832 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7833 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7834 | rps->max_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7835 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7836 | rps->efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7837 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7838 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7839 | rps->efficient_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7840 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7841 | rps->rp1_freq = cherryview_rps_guar_freq(dev_priv); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7842 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7843 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7844 | rps->rp1_freq); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7845 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7846 | rps->min_freq = cherryview_rps_min_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7847 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7848 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7849 | rps->min_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7850 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7851 | vlv_iosf_sb_put(dev_priv, |
| 7852 | BIT(VLV_IOSF_SB_PUNIT) | |
| 7853 | BIT(VLV_IOSF_SB_NC) | |
| 7854 | BIT(VLV_IOSF_SB_CCK)); |
| 7855 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7856 | WARN_ONCE((rps->max_freq | rps->efficient_freq | rps->rp1_freq | |
| 7857 | rps->min_freq) & 1, |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7858 | "Odd GPU freq values\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7859 | } |
| 7860 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7861 | static void valleyview_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7862 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7863 | valleyview_cleanup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7864 | } |
| 7865 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7866 | static void cherryview_enable_rc6(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7867 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7868 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7869 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7870 | u32 gtfifodbg, rc6_mode, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7871 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7872 | gtfifodbg = I915_READ(GTFIFODBG) & ~(GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV | |
| 7873 | GT_FIFO_FREE_ENTRIES_CHV); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7874 | if (gtfifodbg) { |
| 7875 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7876 | gtfifodbg); |
| 7877 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7878 | } |
| 7879 | |
| 7880 | cherryview_check_pctx(dev_priv); |
| 7881 | |
| 7882 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 7883 | * 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] | 7884 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7885 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7886 | /* Disable RC states. */ |
| 7887 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7888 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7889 | /* 2a: Program RC6 thresholds.*/ |
| 7890 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 7891 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7892 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 7893 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7894 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7895 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7896 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7897 | |
Deepak S | f4f71c7 | 2015-03-28 15:23:35 +0530 | [diff] [blame] | 7898 | /* TO threshold set to 500 us ( 0x186 * 1.28 us) */ |
| 7899 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x186); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7900 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7901 | /* Allows RC6 residency counter to work */ |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7902 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 7903 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7904 | VLV_MEDIA_RC6_COUNT_EN | |
| 7905 | VLV_RENDER_RC6_COUNT_EN)); |
| 7906 | |
| 7907 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 7908 | pcbr = I915_READ(VLV_PCBR); |
| 7909 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7910 | /* 3: Enable RC6 */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7911 | rc6_mode = 0; |
| 7912 | if (pcbr >> VLV_PCBR_ADDR_SHIFT) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 7913 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7914 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 7915 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7916 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7917 | } |
| 7918 | |
| 7919 | static void cherryview_enable_rps(struct drm_i915_private *dev_priv) |
| 7920 | { |
| 7921 | u32 val; |
| 7922 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7923 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7924 | |
| 7925 | /* 1: Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 7926 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7927 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7928 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7929 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7930 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7931 | |
| 7932 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7933 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7934 | /* 2: Enable RPS */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7935 | I915_WRITE(GEN6_RP_CONTROL, |
| 7936 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 7937 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7938 | GEN6_RP_ENABLE | |
| 7939 | GEN6_RP_UP_BUSY_AVG | |
| 7940 | GEN6_RP_DOWN_IDLE_AVG); |
| 7941 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7942 | /* Setting Fixed Bias */ |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7943 | vlv_punit_get(dev_priv); |
| 7944 | |
| 7945 | 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] | 7946 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7947 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7948 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7949 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7950 | vlv_punit_put(dev_priv); |
| 7951 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7952 | /* RPS code assumes GPLL is used */ |
| 7953 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7954 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7955 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7956 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7957 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7958 | reset_rps(dev_priv, valleyview_set_rps); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7959 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7960 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7961 | } |
| 7962 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7963 | static void valleyview_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7964 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7965 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7966 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7967 | u32 gtfifodbg; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7968 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7969 | valleyview_check_pctx(dev_priv); |
| 7970 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7971 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7972 | if (gtfifodbg) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 7973 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7974 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7975 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7976 | } |
| 7977 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 7978 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7979 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7980 | /* Disable RC states. */ |
| 7981 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7982 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7983 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 7984 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 7985 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 7986 | |
| 7987 | for_each_engine(engine, dev_priv, id) |
| 7988 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
| 7989 | |
| 7990 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
| 7991 | |
| 7992 | /* Allows RC6 residency counter to work */ |
| 7993 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 7994 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7995 | VLV_MEDIA_RC0_COUNT_EN | |
| 7996 | VLV_RENDER_RC0_COUNT_EN | |
| 7997 | VLV_MEDIA_RC6_COUNT_EN | |
| 7998 | VLV_RENDER_RC6_COUNT_EN)); |
| 7999 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8000 | I915_WRITE(GEN6_RC_CONTROL, |
| 8001 | GEN7_RC_CTL_TO_MODE | VLV_RC_CTL_CTX_RST_PARALLEL); |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 8002 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 8003 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 8004 | } |
| 8005 | |
| 8006 | static void valleyview_enable_rps(struct drm_i915_private *dev_priv) |
| 8007 | { |
| 8008 | u32 val; |
| 8009 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 8010 | intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL); |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 8011 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 8012 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8013 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 8014 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 8015 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 8016 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 8017 | |
| 8018 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 8019 | |
| 8020 | I915_WRITE(GEN6_RP_CONTROL, |
| 8021 | GEN6_RP_MEDIA_TURBO | |
| 8022 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 8023 | GEN6_RP_MEDIA_IS_GFX | |
| 8024 | GEN6_RP_ENABLE | |
| 8025 | GEN6_RP_UP_BUSY_AVG | |
| 8026 | GEN6_RP_DOWN_IDLE_CONT); |
| 8027 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 8028 | vlv_punit_get(dev_priv); |
| 8029 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 8030 | /* Setting Fixed Bias */ |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 8031 | 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] | 8032 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 8033 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 8034 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8035 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 8036 | vlv_punit_put(dev_priv); |
| 8037 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 8038 | /* RPS code assumes GPLL is used */ |
| 8039 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 8040 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 8041 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8042 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 8043 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 8044 | reset_rps(dev_priv, valleyview_set_rps); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8045 | |
Daniele Ceraolo Spurio | 3ceea6a | 2019-03-19 11:35:36 -0700 | [diff] [blame] | 8046 | intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8047 | } |
| 8048 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8049 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 8050 | { |
| 8051 | unsigned long freq; |
| 8052 | int div = (vidfreq & 0x3f0000) >> 16; |
| 8053 | int post = (vidfreq & 0x3000) >> 12; |
| 8054 | int pre = (vidfreq & 0x7); |
| 8055 | |
| 8056 | if (!pre) |
| 8057 | return 0; |
| 8058 | |
| 8059 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 8060 | |
| 8061 | return freq; |
| 8062 | } |
| 8063 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8064 | static const struct cparams { |
| 8065 | u16 i; |
| 8066 | u16 t; |
| 8067 | u16 m; |
| 8068 | u16 c; |
| 8069 | } cparams[] = { |
| 8070 | { 1, 1333, 301, 28664 }, |
| 8071 | { 1, 1066, 294, 24460 }, |
| 8072 | { 1, 800, 294, 25192 }, |
| 8073 | { 0, 1333, 276, 27605 }, |
| 8074 | { 0, 1066, 276, 27605 }, |
| 8075 | { 0, 800, 231, 23784 }, |
| 8076 | }; |
| 8077 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8078 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8079 | { |
| 8080 | u64 total_count, diff, ret; |
| 8081 | u32 count1, count2, count3, m = 0, c = 0; |
| 8082 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 8083 | int i; |
| 8084 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 8085 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8086 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8087 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8088 | |
| 8089 | /* Prevent division-by-zero if we are asking too fast. |
| 8090 | * Also, we don't get interesting results if we are polling |
| 8091 | * faster than once in 10ms, so just return the saved value |
| 8092 | * in such cases. |
| 8093 | */ |
| 8094 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8095 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8096 | |
| 8097 | count1 = I915_READ(DMIEC); |
| 8098 | count2 = I915_READ(DDREC); |
| 8099 | count3 = I915_READ(CSIEC); |
| 8100 | |
| 8101 | total_count = count1 + count2 + count3; |
| 8102 | |
| 8103 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8104 | if (total_count < dev_priv->ips.last_count1) { |
| 8105 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8106 | diff += total_count; |
| 8107 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8108 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8109 | } |
| 8110 | |
| 8111 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8112 | if (cparams[i].i == dev_priv->ips.c_m && |
| 8113 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8114 | m = cparams[i].m; |
| 8115 | c = cparams[i].c; |
| 8116 | break; |
| 8117 | } |
| 8118 | } |
| 8119 | |
| 8120 | diff = div_u64(diff, diff1); |
| 8121 | ret = ((m * diff) + c); |
| 8122 | ret = div_u64(ret, 10); |
| 8123 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8124 | dev_priv->ips.last_count1 = total_count; |
| 8125 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8126 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8127 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8128 | |
| 8129 | return ret; |
| 8130 | } |
| 8131 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8132 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 8133 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8134 | intel_wakeref_t wakeref; |
| 8135 | unsigned long val = 0; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8136 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8137 | if (!IS_GEN(dev_priv, 5)) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8138 | return 0; |
| 8139 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8140 | with_intel_runtime_pm(dev_priv, wakeref) { |
| 8141 | spin_lock_irq(&mchdev_lock); |
| 8142 | val = __i915_chipset_val(dev_priv); |
| 8143 | spin_unlock_irq(&mchdev_lock); |
| 8144 | } |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8145 | |
| 8146 | return val; |
| 8147 | } |
| 8148 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8149 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 8150 | { |
| 8151 | unsigned long m, x, b; |
| 8152 | u32 tsfs; |
| 8153 | |
| 8154 | tsfs = I915_READ(TSFS); |
| 8155 | |
| 8156 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 8157 | x = I915_READ8(TR1); |
| 8158 | |
| 8159 | b = tsfs & TSFS_INTR_MASK; |
| 8160 | |
| 8161 | return ((m * x) / 127) - b; |
| 8162 | } |
| 8163 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8164 | static int _pxvid_to_vd(u8 pxvid) |
| 8165 | { |
| 8166 | if (pxvid == 0) |
| 8167 | return 0; |
| 8168 | |
| 8169 | if (pxvid >= 8 && pxvid < 31) |
| 8170 | pxvid = 31; |
| 8171 | |
| 8172 | return (pxvid + 2) * 125; |
| 8173 | } |
| 8174 | |
| 8175 | 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] | 8176 | { |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8177 | const int vd = _pxvid_to_vd(pxvid); |
| 8178 | const int vm = vd - 1125; |
| 8179 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8180 | if (INTEL_INFO(dev_priv)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8181 | return vm > 0 ? vm : 0; |
| 8182 | |
| 8183 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8184 | } |
| 8185 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8186 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8187 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 8188 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8189 | u32 count; |
| 8190 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 8191 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8192 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 8193 | now = ktime_get_raw_ns(); |
| 8194 | diffms = now - dev_priv->ips.last_time2; |
| 8195 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8196 | |
| 8197 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8198 | if (!diffms) |
| 8199 | return; |
| 8200 | |
| 8201 | count = I915_READ(GFXEC); |
| 8202 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8203 | if (count < dev_priv->ips.last_count2) { |
| 8204 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8205 | diff += count; |
| 8206 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8207 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8208 | } |
| 8209 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8210 | dev_priv->ips.last_count2 = count; |
| 8211 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8212 | |
| 8213 | /* More magic constants... */ |
| 8214 | diff = diff * 1181; |
| 8215 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8216 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8217 | } |
| 8218 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8219 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 8220 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8221 | intel_wakeref_t wakeref; |
| 8222 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8223 | if (!IS_GEN(dev_priv, 5)) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8224 | return; |
| 8225 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8226 | with_intel_runtime_pm(dev_priv, wakeref) { |
| 8227 | spin_lock_irq(&mchdev_lock); |
| 8228 | __i915_update_gfx_val(dev_priv); |
| 8229 | spin_unlock_irq(&mchdev_lock); |
| 8230 | } |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8231 | } |
| 8232 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8233 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8234 | { |
| 8235 | unsigned long t, corr, state1, corr2, state2; |
| 8236 | u32 pxvid, ext_v; |
| 8237 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 8238 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8239 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8240 | pxvid = I915_READ(PXVFREQ(dev_priv->gt_pm.rps.cur_freq)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8241 | pxvid = (pxvid >> 24) & 0x7f; |
| 8242 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 8243 | |
| 8244 | state1 = ext_v; |
| 8245 | |
| 8246 | t = i915_mch_val(dev_priv); |
| 8247 | |
| 8248 | /* Revel in the empirically derived constants */ |
| 8249 | |
| 8250 | /* Correction factor in 1/100000 units */ |
| 8251 | if (t > 80) |
| 8252 | corr = ((t * 2349) + 135940); |
| 8253 | else if (t >= 50) |
| 8254 | corr = ((t * 964) + 29317); |
| 8255 | else /* < 50 */ |
| 8256 | corr = ((t * 301) + 1004); |
| 8257 | |
| 8258 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 8259 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8260 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8261 | |
| 8262 | state2 = (corr2 * state1) / 10000; |
| 8263 | state2 /= 100; /* convert to mW */ |
| 8264 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8265 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8266 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8267 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8268 | } |
| 8269 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8270 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 8271 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8272 | intel_wakeref_t wakeref; |
| 8273 | unsigned long val = 0; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8274 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8275 | if (!IS_GEN(dev_priv, 5)) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8276 | return 0; |
| 8277 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8278 | with_intel_runtime_pm(dev_priv, wakeref) { |
| 8279 | spin_lock_irq(&mchdev_lock); |
| 8280 | val = __i915_gfx_val(dev_priv); |
| 8281 | spin_unlock_irq(&mchdev_lock); |
| 8282 | } |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8283 | |
| 8284 | return val; |
| 8285 | } |
| 8286 | |
Chris Wilson | adc674c | 2019-04-12 09:53:22 +0100 | [diff] [blame] | 8287 | static struct drm_i915_private __rcu *i915_mch_dev; |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8288 | |
| 8289 | static struct drm_i915_private *mchdev_get(void) |
| 8290 | { |
| 8291 | struct drm_i915_private *i915; |
| 8292 | |
| 8293 | rcu_read_lock(); |
Chris Wilson | adc674c | 2019-04-12 09:53:22 +0100 | [diff] [blame] | 8294 | i915 = rcu_dereference(i915_mch_dev); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8295 | if (!kref_get_unless_zero(&i915->drm.ref)) |
| 8296 | i915 = NULL; |
| 8297 | rcu_read_unlock(); |
| 8298 | |
| 8299 | return i915; |
| 8300 | } |
| 8301 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8302 | /** |
| 8303 | * i915_read_mch_val - return value for IPS use |
| 8304 | * |
| 8305 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 8306 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 8307 | */ |
| 8308 | unsigned long i915_read_mch_val(void) |
| 8309 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8310 | struct drm_i915_private *i915; |
| 8311 | unsigned long chipset_val = 0; |
| 8312 | unsigned long graphics_val = 0; |
| 8313 | intel_wakeref_t wakeref; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8314 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8315 | i915 = mchdev_get(); |
| 8316 | if (!i915) |
| 8317 | return 0; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8318 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8319 | with_intel_runtime_pm(i915, wakeref) { |
| 8320 | spin_lock_irq(&mchdev_lock); |
| 8321 | chipset_val = __i915_chipset_val(i915); |
| 8322 | graphics_val = __i915_gfx_val(i915); |
| 8323 | spin_unlock_irq(&mchdev_lock); |
| 8324 | } |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8325 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8326 | drm_dev_put(&i915->drm); |
| 8327 | return chipset_val + graphics_val; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8328 | } |
| 8329 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 8330 | |
| 8331 | /** |
| 8332 | * i915_gpu_raise - raise GPU frequency limit |
| 8333 | * |
| 8334 | * Raise the limit; IPS indicates we have thermal headroom. |
| 8335 | */ |
| 8336 | bool i915_gpu_raise(void) |
| 8337 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8338 | struct drm_i915_private *i915; |
| 8339 | |
| 8340 | i915 = mchdev_get(); |
| 8341 | if (!i915) |
| 8342 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8343 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8344 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8345 | if (i915->ips.max_delay > i915->ips.fmax) |
| 8346 | i915->ips.max_delay--; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8347 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8348 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8349 | drm_dev_put(&i915->drm); |
| 8350 | return true; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8351 | } |
| 8352 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 8353 | |
| 8354 | /** |
| 8355 | * i915_gpu_lower - lower GPU frequency limit |
| 8356 | * |
| 8357 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 8358 | * frequency maximum. |
| 8359 | */ |
| 8360 | bool i915_gpu_lower(void) |
| 8361 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8362 | struct drm_i915_private *i915; |
| 8363 | |
| 8364 | i915 = mchdev_get(); |
| 8365 | if (!i915) |
| 8366 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8367 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8368 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8369 | if (i915->ips.max_delay < i915->ips.min_delay) |
| 8370 | i915->ips.max_delay++; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8371 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8372 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8373 | drm_dev_put(&i915->drm); |
| 8374 | return true; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8375 | } |
| 8376 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 8377 | |
| 8378 | /** |
| 8379 | * i915_gpu_busy - indicate GPU business to IPS |
| 8380 | * |
| 8381 | * Tell the IPS driver whether or not the GPU is busy. |
| 8382 | */ |
| 8383 | bool i915_gpu_busy(void) |
| 8384 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8385 | struct drm_i915_private *i915; |
| 8386 | bool ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8387 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8388 | i915 = mchdev_get(); |
| 8389 | if (!i915) |
| 8390 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8391 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8392 | ret = i915->gt.awake; |
| 8393 | |
| 8394 | drm_dev_put(&i915->drm); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8395 | return ret; |
| 8396 | } |
| 8397 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 8398 | |
| 8399 | /** |
| 8400 | * i915_gpu_turbo_disable - disable graphics turbo |
| 8401 | * |
| 8402 | * Disable graphics turbo by resetting the max frequency and setting the |
| 8403 | * current frequency to the default. |
| 8404 | */ |
| 8405 | bool i915_gpu_turbo_disable(void) |
| 8406 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8407 | struct drm_i915_private *i915; |
| 8408 | bool ret; |
| 8409 | |
| 8410 | i915 = mchdev_get(); |
| 8411 | if (!i915) |
| 8412 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8413 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8414 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8415 | i915->ips.max_delay = i915->ips.fstart; |
| 8416 | ret = ironlake_set_drps(i915, i915->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8417 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8418 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8419 | drm_dev_put(&i915->drm); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8420 | return ret; |
| 8421 | } |
| 8422 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 8423 | |
| 8424 | /** |
| 8425 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 8426 | * IPS got loaded first. |
| 8427 | * |
| 8428 | * This awkward dance is so that neither module has to depend on the |
| 8429 | * other in order for IPS to do the appropriate communication of |
| 8430 | * GPU turbo limits to i915. |
| 8431 | */ |
| 8432 | static void |
| 8433 | ips_ping_for_i915_load(void) |
| 8434 | { |
| 8435 | void (*link)(void); |
| 8436 | |
| 8437 | link = symbol_get(ips_link_to_i915_driver); |
| 8438 | if (link) { |
| 8439 | link(); |
| 8440 | symbol_put(ips_link_to_i915_driver); |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 8445 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8446 | /* We only register the i915 ips part with intel-ips once everything is |
| 8447 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8448 | rcu_assign_pointer(i915_mch_dev, dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8449 | |
| 8450 | ips_ping_for_i915_load(); |
| 8451 | } |
| 8452 | |
| 8453 | void intel_gpu_ips_teardown(void) |
| 8454 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8455 | rcu_assign_pointer(i915_mch_dev, NULL); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8456 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 8457 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8458 | static void intel_init_emon(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8459 | { |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8460 | u32 lcfuse; |
| 8461 | u8 pxw[16]; |
| 8462 | int i; |
| 8463 | |
| 8464 | /* Disable to program */ |
| 8465 | I915_WRITE(ECR, 0); |
| 8466 | POSTING_READ(ECR); |
| 8467 | |
| 8468 | /* Program energy weights for various events */ |
| 8469 | I915_WRITE(SDEW, 0x15040d00); |
| 8470 | I915_WRITE(CSIEW0, 0x007f0000); |
| 8471 | I915_WRITE(CSIEW1, 0x1e220004); |
| 8472 | I915_WRITE(CSIEW2, 0x04000004); |
| 8473 | |
| 8474 | for (i = 0; i < 5; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8475 | I915_WRITE(PEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8476 | for (i = 0; i < 3; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8477 | I915_WRITE(DEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8478 | |
| 8479 | /* Program P-state weights to account for frequency power adjustment */ |
| 8480 | for (i = 0; i < 16; i++) { |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8481 | u32 pxvidfreq = I915_READ(PXVFREQ(i)); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8482 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 8483 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 8484 | PXVFREQ_PX_SHIFT; |
| 8485 | unsigned long val; |
| 8486 | |
| 8487 | val = vid * vid; |
| 8488 | val *= (freq / 1000); |
| 8489 | val *= 255; |
| 8490 | val /= (127*127*900); |
| 8491 | if (val > 0xff) |
| 8492 | DRM_ERROR("bad pxval: %ld\n", val); |
| 8493 | pxw[i] = val; |
| 8494 | } |
| 8495 | /* Render standby states get 0 weight */ |
| 8496 | pxw[14] = 0; |
| 8497 | pxw[15] = 0; |
| 8498 | |
| 8499 | for (i = 0; i < 4; i++) { |
| 8500 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 8501 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8502 | I915_WRITE(PXW(i), val); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8503 | } |
| 8504 | |
| 8505 | /* Adjust magic regs to magic values (more experimental results) */ |
| 8506 | I915_WRITE(OGW0, 0); |
| 8507 | I915_WRITE(OGW1, 0); |
| 8508 | I915_WRITE(EG0, 0x00007f00); |
| 8509 | I915_WRITE(EG1, 0x0000000e); |
| 8510 | I915_WRITE(EG2, 0x000e0000); |
| 8511 | I915_WRITE(EG3, 0x68000300); |
| 8512 | I915_WRITE(EG4, 0x42000000); |
| 8513 | I915_WRITE(EG5, 0x00140031); |
| 8514 | I915_WRITE(EG6, 0); |
| 8515 | I915_WRITE(EG7, 0); |
| 8516 | |
| 8517 | for (i = 0; i < 8; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8518 | I915_WRITE(PXWL(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8519 | |
| 8520 | /* Enable PMON + select events */ |
| 8521 | I915_WRITE(ECR, 0x80000019); |
| 8522 | |
| 8523 | lcfuse = I915_READ(LCFUSE02); |
| 8524 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8525 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8526 | } |
| 8527 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8528 | void intel_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8529 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8530 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8531 | |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8532 | /* |
| 8533 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 8534 | * requirement. |
| 8535 | */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8536 | if (!sanitize_rc6(dev_priv)) { |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8537 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 8538 | pm_runtime_get(&dev_priv->drm.pdev->dev); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8539 | } |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 8540 | |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8541 | /* Initialize RPS limits (for userspace) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8542 | if (IS_CHERRYVIEW(dev_priv)) |
| 8543 | cherryview_init_gt_powersave(dev_priv); |
| 8544 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8545 | valleyview_init_gt_powersave(dev_priv); |
Chris Wilson | 2a13ae7 | 2016-08-02 11:15:27 +0100 | [diff] [blame] | 8546 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8547 | gen6_init_rps_frequencies(dev_priv); |
| 8548 | |
| 8549 | /* Derive initial user preferences/limits from the hardware limits */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8550 | rps->max_freq_softlimit = rps->max_freq; |
| 8551 | rps->min_freq_softlimit = rps->min_freq; |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8552 | |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8553 | /* After setting max-softlimit, find the overclock max freq */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8554 | if (IS_GEN(dev_priv, 6) || |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8555 | IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
| 8556 | u32 params = 0; |
| 8557 | |
| 8558 | sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, ¶ms); |
| 8559 | if (params & BIT(31)) { /* OC supported */ |
| 8560 | DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8561 | (rps->max_freq & 0xff) * 50, |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8562 | (params & 0xff) * 50); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8563 | rps->max_freq = params & 0xff; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8564 | } |
| 8565 | } |
| 8566 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 8567 | /* Finally allow us to boost to max by default */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8568 | rps->boost_freq = rps->max_freq; |
Chris Wilson | 844e331 | 2019-04-18 21:53:58 +0100 | [diff] [blame] | 8569 | rps->idle_freq = rps->min_freq; |
| 8570 | rps->cur_freq = rps->idle_freq; |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8571 | } |
| 8572 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8573 | void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8574 | { |
Ville Syrjälä | 8dac1e1 | 2016-08-02 14:07:33 +0300 | [diff] [blame] | 8575 | if (IS_VALLEYVIEW(dev_priv)) |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8576 | valleyview_cleanup_gt_powersave(dev_priv); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8577 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8578 | if (!HAS_RC6(dev_priv)) |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 8579 | pm_runtime_put(&dev_priv->drm.pdev->dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8580 | } |
| 8581 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8582 | void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv) |
| 8583 | { |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8584 | dev_priv->gt_pm.rps.enabled = true; /* force RPS disabling */ |
| 8585 | dev_priv->gt_pm.rc6.enabled = true; /* force RC6 disabling */ |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8586 | intel_disable_gt_powersave(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 8587 | |
Oscar Mateo | d02b98b | 2018-04-05 17:00:50 +0300 | [diff] [blame] | 8588 | if (INTEL_GEN(dev_priv) >= 11) |
| 8589 | gen11_reset_rps_interrupts(dev_priv); |
Chris Wilson | 61e1e37 | 2018-08-12 23:36:30 +0100 | [diff] [blame] | 8590 | else if (INTEL_GEN(dev_priv) >= 6) |
Oscar Mateo | d02b98b | 2018-04-05 17:00:50 +0300 | [diff] [blame] | 8591 | gen6_reset_rps_interrupts(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 8592 | } |
| 8593 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8594 | static inline void intel_disable_llc_pstate(struct drm_i915_private *i915) |
| 8595 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8596 | lockdep_assert_held(&i915->gt_pm.rps.lock); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8597 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8598 | if (!i915->gt_pm.llc_pstate.enabled) |
| 8599 | return; |
| 8600 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8601 | /* Currently there is no HW configuration to be done to disable. */ |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8602 | |
| 8603 | i915->gt_pm.llc_pstate.enabled = false; |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8604 | } |
| 8605 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8606 | static void intel_disable_rc6(struct drm_i915_private *dev_priv) |
| 8607 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8608 | lockdep_assert_held(&dev_priv->gt_pm.rps.lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8609 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8610 | if (!dev_priv->gt_pm.rc6.enabled) |
| 8611 | return; |
| 8612 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8613 | if (INTEL_GEN(dev_priv) >= 9) |
| 8614 | gen9_disable_rc6(dev_priv); |
| 8615 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8616 | cherryview_disable_rc6(dev_priv); |
| 8617 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8618 | valleyview_disable_rc6(dev_priv); |
| 8619 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8620 | gen6_disable_rc6(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8621 | |
| 8622 | dev_priv->gt_pm.rc6.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8623 | } |
| 8624 | |
| 8625 | static void intel_disable_rps(struct drm_i915_private *dev_priv) |
| 8626 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8627 | lockdep_assert_held(&dev_priv->gt_pm.rps.lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8628 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8629 | if (!dev_priv->gt_pm.rps.enabled) |
| 8630 | return; |
| 8631 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8632 | if (INTEL_GEN(dev_priv) >= 9) |
| 8633 | gen9_disable_rps(dev_priv); |
| 8634 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8635 | cherryview_disable_rps(dev_priv); |
| 8636 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8637 | valleyview_disable_rps(dev_priv); |
| 8638 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8639 | gen6_disable_rps(dev_priv); |
| 8640 | else if (IS_IRONLAKE_M(dev_priv)) |
| 8641 | ironlake_disable_drps(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8642 | |
| 8643 | dev_priv->gt_pm.rps.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8644 | } |
| 8645 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8646 | void intel_disable_gt_powersave(struct drm_i915_private *dev_priv) |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 8647 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8648 | mutex_lock(&dev_priv->gt_pm.rps.lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8649 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8650 | intel_disable_rc6(dev_priv); |
| 8651 | intel_disable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8652 | if (HAS_LLC(dev_priv)) |
| 8653 | intel_disable_llc_pstate(dev_priv); |
| 8654 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8655 | mutex_unlock(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8656 | } |
| 8657 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8658 | static inline void intel_enable_llc_pstate(struct drm_i915_private *i915) |
| 8659 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8660 | lockdep_assert_held(&i915->gt_pm.rps.lock); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8661 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8662 | if (i915->gt_pm.llc_pstate.enabled) |
| 8663 | return; |
| 8664 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8665 | gen6_update_ring_freq(i915); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8666 | |
| 8667 | i915->gt_pm.llc_pstate.enabled = true; |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8668 | } |
| 8669 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8670 | static void intel_enable_rc6(struct drm_i915_private *dev_priv) |
| 8671 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8672 | lockdep_assert_held(&dev_priv->gt_pm.rps.lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8673 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8674 | if (dev_priv->gt_pm.rc6.enabled) |
| 8675 | return; |
| 8676 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8677 | if (IS_CHERRYVIEW(dev_priv)) |
| 8678 | cherryview_enable_rc6(dev_priv); |
| 8679 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8680 | valleyview_enable_rc6(dev_priv); |
Mika Kuoppala | a79208d | 2019-04-10 13:59:17 +0300 | [diff] [blame] | 8681 | else if (INTEL_GEN(dev_priv) >= 11) |
| 8682 | gen11_enable_rc6(dev_priv); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8683 | else if (INTEL_GEN(dev_priv) >= 9) |
| 8684 | gen9_enable_rc6(dev_priv); |
| 8685 | else if (IS_BROADWELL(dev_priv)) |
| 8686 | gen8_enable_rc6(dev_priv); |
| 8687 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8688 | gen6_enable_rc6(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8689 | |
| 8690 | dev_priv->gt_pm.rc6.enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8691 | } |
| 8692 | |
| 8693 | static void intel_enable_rps(struct drm_i915_private *dev_priv) |
| 8694 | { |
| 8695 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8696 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8697 | lockdep_assert_held(&rps->lock); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8698 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8699 | if (rps->enabled) |
| 8700 | return; |
| 8701 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8702 | if (IS_CHERRYVIEW(dev_priv)) { |
| 8703 | cherryview_enable_rps(dev_priv); |
| 8704 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 8705 | valleyview_enable_rps(dev_priv); |
| 8706 | } else if (INTEL_GEN(dev_priv) >= 9) { |
| 8707 | gen9_enable_rps(dev_priv); |
| 8708 | } else if (IS_BROADWELL(dev_priv)) { |
| 8709 | gen8_enable_rps(dev_priv); |
| 8710 | } else if (INTEL_GEN(dev_priv) >= 6) { |
| 8711 | gen6_enable_rps(dev_priv); |
| 8712 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 8713 | ironlake_enable_drps(dev_priv); |
| 8714 | intel_init_emon(dev_priv); |
| 8715 | } |
| 8716 | |
| 8717 | WARN_ON(rps->max_freq < rps->min_freq); |
| 8718 | WARN_ON(rps->idle_freq > rps->max_freq); |
| 8719 | |
| 8720 | WARN_ON(rps->efficient_freq < rps->min_freq); |
| 8721 | WARN_ON(rps->efficient_freq > rps->max_freq); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8722 | |
| 8723 | rps->enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8724 | } |
| 8725 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8726 | void intel_enable_gt_powersave(struct drm_i915_private *dev_priv) |
| 8727 | { |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8728 | /* Powersaving is controlled by the host when inside a VM */ |
| 8729 | if (intel_vgpu_active(dev_priv)) |
| 8730 | return; |
| 8731 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8732 | mutex_lock(&dev_priv->gt_pm.rps.lock); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 8733 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8734 | if (HAS_RC6(dev_priv)) |
| 8735 | intel_enable_rc6(dev_priv); |
Chris Wilson | 91cbdb8 | 2019-04-19 14:48:36 +0100 | [diff] [blame] | 8736 | if (HAS_RPS(dev_priv)) |
| 8737 | intel_enable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8738 | if (HAS_LLC(dev_priv)) |
| 8739 | intel_enable_llc_pstate(dev_priv); |
| 8740 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 8741 | mutex_unlock(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8742 | } |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 8743 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8744 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8745 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8746 | /* |
| 8747 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8748 | * gating for the panel power sequencer or it will fail to |
| 8749 | * start up when no ports are active. |
| 8750 | */ |
| 8751 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 8752 | } |
| 8753 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8754 | 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] | 8755 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 8756 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8757 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8758 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8759 | I915_WRITE(DSPCNTR(pipe), |
| 8760 | I915_READ(DSPCNTR(pipe)) | |
| 8761 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 8762 | |
| 8763 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 8764 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8765 | } |
| 8766 | } |
| 8767 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8768 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8769 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8770 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8771 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 8772 | /* |
| 8773 | * Required for FBC |
| 8774 | * WaFbcDisableDpfcClockGating:ilk |
| 8775 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8776 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 8777 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 8778 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8779 | |
| 8780 | I915_WRITE(PCH_3DCGDIS0, |
| 8781 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 8782 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 8783 | I915_WRITE(PCH_3DCGDIS1, |
| 8784 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 8785 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8786 | /* |
| 8787 | * According to the spec the following bits should be set in |
| 8788 | * order to enable memory self-refresh |
| 8789 | * The bit 22/21 of 0x42004 |
| 8790 | * The bit 5 of 0x42020 |
| 8791 | * The bit 15 of 0x45000 |
| 8792 | */ |
| 8793 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8794 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8795 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8796 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8797 | I915_WRITE(DISP_ARB_CTL, |
| 8798 | (I915_READ(DISP_ARB_CTL) | |
| 8799 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 8800 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8801 | /* |
| 8802 | * Based on the document from hardware guys the following bits |
| 8803 | * should be set unconditionally in order to enable FBC. |
| 8804 | * The bit 22 of 0x42000 |
| 8805 | * The bit 22 of 0x42004 |
| 8806 | * The bit 7,8,9 of 0x42020. |
| 8807 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8808 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8809 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8810 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8811 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8812 | ILK_FBCQ_DIS); |
| 8813 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8814 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8815 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8816 | } |
| 8817 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8818 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 8819 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8820 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8821 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8822 | ILK_ELPIN_409_SELECT); |
| 8823 | I915_WRITE(_3D_CHICKEN2, |
| 8824 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 8825 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8826 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8827 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8828 | I915_WRITE(CACHE_MODE_0, |
| 8829 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8830 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8831 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 8832 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8833 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8834 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 8835 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8836 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8837 | } |
| 8838 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8839 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8840 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8841 | int pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8842 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8843 | |
| 8844 | /* |
| 8845 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8846 | * gating for the panel power sequencer or it will fail to |
| 8847 | * start up when no ports are active. |
| 8848 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 8849 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 8850 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 8851 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8852 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 8853 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 8854 | /* The below fixes the weird display corruption, a few pixels shifted |
| 8855 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 8856 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8857 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8858 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 8859 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 8860 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8861 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8862 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8863 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 8864 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 8865 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8866 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 8867 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8868 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8869 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8870 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 8871 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 8872 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8873 | } |
| 8874 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8875 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8876 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8877 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8878 | |
| 8879 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 8880 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 8881 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 8882 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8883 | } |
| 8884 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8885 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8886 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8887 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8888 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8889 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8890 | |
| 8891 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8892 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8893 | ILK_ELPIN_409_SELECT); |
| 8894 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8895 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 8896 | I915_WRITE(_3D_CHICKEN, |
| 8897 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 8898 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8899 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 8900 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8901 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8902 | /* |
| 8903 | * BSpec recoomends 8x4 when MSAA is used, |
| 8904 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8905 | * |
| 8906 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8907 | * disable bit, which we don't touch here, but it's good |
| 8908 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8909 | */ |
| 8910 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8911 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8912 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8913 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 8914 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8915 | |
| 8916 | I915_WRITE(GEN6_UCGCTL1, |
| 8917 | I915_READ(GEN6_UCGCTL1) | |
| 8918 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 8919 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 8920 | |
| 8921 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 8922 | * gating disable must be set. Failure to set it results in |
| 8923 | * flickering pixels due to Z write ordering failures after |
| 8924 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 8925 | * Sanctuary and Tropics, and apparently anything else with |
| 8926 | * alpha test or pixel discard. |
| 8927 | * |
| 8928 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 8929 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8930 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 8931 | * WaDisableRCCUnitClockGating:snb |
| 8932 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8933 | */ |
| 8934 | I915_WRITE(GEN6_UCGCTL2, |
| 8935 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 8936 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 8937 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 8938 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 8939 | I915_WRITE(_3D_CHICKEN3, |
| 8940 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8941 | |
| 8942 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 8943 | * Bspec says: |
| 8944 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 8945 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 8946 | */ |
| 8947 | I915_WRITE(_3D_CHICKEN3, |
| 8948 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 8949 | |
| 8950 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8951 | * According to the spec the following bits should be |
| 8952 | * set in order to enable memory self-refresh and fbc: |
| 8953 | * The bit21 and bit22 of 0x42000 |
| 8954 | * The bit21 and bit22 of 0x42004 |
| 8955 | * The bit5 and bit7 of 0x42020 |
| 8956 | * The bit14 of 0x70180 |
| 8957 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8958 | * |
| 8959 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8960 | */ |
| 8961 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8962 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8963 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 8964 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8965 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8966 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8967 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 8968 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 8969 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 8970 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8971 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8972 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 8973 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8974 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8975 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8976 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8977 | } |
| 8978 | |
| 8979 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 8980 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8981 | u32 reg = I915_READ(GEN7_FF_THREAD_MODE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8982 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8983 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8984 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8985 | * |
| 8986 | * This actually overrides the dispatch |
| 8987 | * mode for all thread types. |
| 8988 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8989 | reg &= ~GEN7_FF_SCHED_MASK; |
| 8990 | reg |= GEN7_FF_TS_SCHED_HW; |
| 8991 | reg |= GEN7_FF_VS_SCHED_HW; |
| 8992 | reg |= GEN7_FF_DS_SCHED_HW; |
| 8993 | |
| 8994 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 8995 | } |
| 8996 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8997 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8998 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8999 | /* |
| 9000 | * TODO: this bit should only be enabled when really needed, then |
| 9001 | * disabled when not needed anymore in order to save power. |
| 9002 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9003 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 9004 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 9005 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 9006 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 9007 | |
| 9008 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 9009 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 9010 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 9011 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 9012 | } |
| 9013 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 9014 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9015 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9016 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9017 | u32 val = I915_READ(SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9018 | |
| 9019 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9020 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9021 | } |
| 9022 | } |
| 9023 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9024 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 9025 | int general_prio_credits, |
| 9026 | int high_prio_credits) |
| 9027 | { |
| 9028 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 9029 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9030 | |
| 9031 | /* WaTempDisableDOPClkGating:bdw */ |
| 9032 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 9033 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 9034 | |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 9035 | val = I915_READ(GEN8_L3SQCREG1); |
| 9036 | val &= ~L3_PRIO_CREDITS_MASK; |
| 9037 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 9038 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
| 9039 | I915_WRITE(GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9040 | |
| 9041 | /* |
| 9042 | * Wait at least 100 clocks before re-enabling clock gating. |
| 9043 | * See the definition of L3SQCREG1 in BSpec. |
| 9044 | */ |
| 9045 | POSTING_READ(GEN8_L3SQCREG1); |
| 9046 | udelay(1); |
| 9047 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 9048 | } |
| 9049 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 9050 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 9051 | { |
| 9052 | /* This is not an Wa. Enable to reduce Sampler power */ |
| 9053 | I915_WRITE(GEN10_DFR_RATIO_EN_AND_CHICKEN, |
| 9054 | I915_READ(GEN10_DFR_RATIO_EN_AND_CHICKEN) & ~DFR_DISABLE); |
Radhakrishna Sripada | 622b3f6 | 2018-10-30 01:45:01 -0700 | [diff] [blame] | 9055 | |
| 9056 | /* WaEnable32PlaneMode:icl */ |
| 9057 | I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, |
| 9058 | _MASKED_BIT_ENABLE(GEN11_ENABLE_32_PLANE_MODE)); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 9059 | } |
| 9060 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9061 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 9062 | { |
| 9063 | if (!HAS_PCH_CNP(dev_priv)) |
| 9064 | return; |
| 9065 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 9066 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Rodrigo Vivi | 4cc6feb | 2017-09-08 16:45:33 -0700 | [diff] [blame] | 9067 | I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 9068 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9069 | } |
| 9070 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9071 | static void cnl_init_clock_gating(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9072 | { |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 9073 | u32 val; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9074 | cnp_init_clock_gating(dev_priv); |
| 9075 | |
Rodrigo Vivi | 1a25db6 | 2017-08-15 16:16:51 -0700 | [diff] [blame] | 9076 | /* This is not an Wa. Enable for better image quality */ |
| 9077 | I915_WRITE(_3D_CHICKEN3, |
| 9078 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE)); |
| 9079 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9080 | /* WaEnableChickenDCPR:cnl */ |
| 9081 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 9082 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
| 9083 | |
| 9084 | /* WaFbcWakeMemOn:cnl */ |
| 9085 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 9086 | DISP_FBC_MEMORY_WAKE); |
| 9087 | |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 9088 | val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE); |
| 9089 | /* ReadHitWriteOnlyDisable:cnl */ |
| 9090 | val |= RCCUNIT_CLKGATE_DIS; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9091 | /* WaSarbUnitClockGatingDisable:cnl (pre-prod) */ |
| 9092 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 9093 | val |= SARBUNIT_CLKGATE_DIS; |
| 9094 | I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val); |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 9095 | |
Rodrigo Vivi | a4713c5 | 2018-03-07 14:09:12 -0800 | [diff] [blame] | 9096 | /* Wa_2201832410:cnl */ |
| 9097 | val = I915_READ(SUBSLICE_UNIT_LEVEL_CLKGATE); |
| 9098 | val |= GWUNIT_CLKGATE_DIS; |
| 9099 | I915_WRITE(SUBSLICE_UNIT_LEVEL_CLKGATE, val); |
| 9100 | |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 9101 | /* WaDisableVFclkgate:cnl */ |
Rodrigo Vivi | 14941b6 | 2018-03-05 17:20:00 -0800 | [diff] [blame] | 9102 | /* WaVFUnitClockGatingDisable:cnl */ |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 9103 | val = I915_READ(UNSLICE_UNIT_LEVEL_CLKGATE); |
| 9104 | val |= VFUNIT_CLKGATE_DIS; |
| 9105 | I915_WRITE(UNSLICE_UNIT_LEVEL_CLKGATE, val); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9106 | } |
| 9107 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9108 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 9109 | { |
| 9110 | cnp_init_clock_gating(dev_priv); |
| 9111 | gen9_init_clock_gating(dev_priv); |
| 9112 | |
| 9113 | /* WaFbcNukeOnHostModify:cfl */ |
| 9114 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 9115 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 9116 | } |
| 9117 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9118 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9119 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9120 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9121 | |
| 9122 | /* WaDisableSDEUnitClockGating:kbl */ |
| 9123 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 9124 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9125 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 9126 | |
| 9127 | /* WaDisableGamClockGating:kbl */ |
| 9128 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 9129 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 9130 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9131 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9132 | /* WaFbcNukeOnHostModify:kbl */ |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9133 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 9134 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9135 | } |
| 9136 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9137 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 9138 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9139 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 9140 | |
| 9141 | /* WAC6entrylatency:skl */ |
| 9142 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 9143 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9144 | |
| 9145 | /* WaFbcNukeOnHostModify:skl */ |
| 9146 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 9147 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 9148 | } |
| 9149 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9150 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9151 | { |
Matthew Auld | 8cb0983 | 2017-10-06 23:18:23 +0100 | [diff] [blame] | 9152 | /* The GTT cache must be disabled if the system is using 2M pages. */ |
| 9153 | bool can_use_gtt_cache = !HAS_PAGE_SIZES(dev_priv, |
| 9154 | I915_GTT_PAGE_SIZE_2M); |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 9155 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9156 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9157 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 9158 | 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] | 9159 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9160 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 9161 | I915_WRITE(CHICKEN_PAR1_1, |
| 9162 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 9163 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9164 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 9165 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 9166 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 9167 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 9168 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 9169 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 9170 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9171 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 9172 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 9173 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9174 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 9175 | ~(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] | 9176 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 9177 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 9178 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 9179 | |
| 9180 | /* WaDisableSDEUnitClockGating:bdw */ |
| 9181 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9182 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 9183 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9184 | /* WaProgramL3SqcReg1Default:bdw */ |
| 9185 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 9186 | |
Matthew Auld | 8cb0983 | 2017-10-06 23:18:23 +0100 | [diff] [blame] | 9187 | /* WaGttCachingOffByDefault:bdw */ |
| 9188 | 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] | 9189 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 9190 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 9191 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 9192 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 9193 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9194 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 9195 | |
| 9196 | /* WaDisableDopClockGating:bdw |
| 9197 | * |
| 9198 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 9199 | * clock gating. |
| 9200 | */ |
| 9201 | I915_WRITE(GEN6_UCGCTL1, |
| 9202 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9203 | } |
| 9204 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9205 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9206 | { |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 9207 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 9208 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 9209 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 9210 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 9211 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9212 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9213 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9214 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9215 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9216 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 9217 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 9218 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9219 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9220 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9221 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 9222 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9223 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 9224 | /* enable HiZ Raw Stall Optimization */ |
| 9225 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 9226 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 9227 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9228 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9229 | I915_WRITE(CACHE_MODE_1, |
| 9230 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 9231 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9232 | /* |
| 9233 | * BSpec recommends 8x4 when MSAA is used, |
| 9234 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 9235 | * |
| 9236 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9237 | * disable bit, which we don't touch here, but it's good |
| 9238 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9239 | */ |
| 9240 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 9241 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9242 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 9243 | /* WaSampleCChickenBitEnable:hsw */ |
| 9244 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 9245 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 9246 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9247 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 9248 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 9249 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9250 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9251 | } |
| 9252 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9253 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9254 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9255 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9256 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 9257 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9258 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9259 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 9260 | I915_WRITE(_3D_CHICKEN3, |
| 9261 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 9262 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9263 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9264 | I915_WRITE(IVB_CHICKEN3, |
| 9265 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 9266 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 9267 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9268 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9269 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9270 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 9271 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9272 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9273 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 9274 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9275 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9276 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9277 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 9278 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 9279 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9280 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9281 | I915_WRITE(GEN7_L3CNTLREG1, |
| 9282 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 9283 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9284 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9285 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9286 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9287 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 9288 | else { |
| 9289 | /* must write both registers */ |
| 9290 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9291 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9292 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 9293 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 9294 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9295 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9296 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 9297 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 9298 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 9299 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 9300 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9301 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9302 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9303 | */ |
| 9304 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 9305 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9306 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9307 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9308 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9309 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9310 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9311 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9312 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9313 | |
| 9314 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 9315 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 9316 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 9317 | /* enable HiZ Raw Stall Optimization */ |
| 9318 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 9319 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 9320 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 9321 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9322 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 9323 | I915_WRITE(CACHE_MODE_1, |
| 9324 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 9325 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9326 | /* |
| 9327 | * BSpec recommends 8x4 when MSAA is used, |
| 9328 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 9329 | * |
| 9330 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9331 | * disable bit, which we don't touch here, but it's good |
| 9332 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9333 | */ |
| 9334 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 9335 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9336 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 9337 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 9338 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 9339 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 9340 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 9341 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9342 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9343 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 9344 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9345 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9346 | } |
| 9347 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9348 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9349 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9350 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 9351 | I915_WRITE(_3D_CHICKEN3, |
| 9352 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 9353 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9354 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9355 | I915_WRITE(IVB_CHICKEN3, |
| 9356 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 9357 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 9358 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 9359 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9360 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9361 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 9362 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 9363 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9364 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9365 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 9366 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9367 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9368 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 9369 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 9370 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 9371 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9372 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9373 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9374 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 9375 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9376 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9377 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9378 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9379 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9380 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 9381 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 9382 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 9383 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9384 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9385 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9386 | */ |
| 9387 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 9388 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9389 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 9390 | /* WaDisableL3Bank2xClockGate:vlv |
| 9391 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 9392 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 9393 | I915_WRITE(GEN7_UCGCTL4, |
| 9394 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 9395 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 9396 | /* |
| 9397 | * BSpec says this must be set, even though |
| 9398 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 9399 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 9400 | I915_WRITE(CACHE_MODE_1, |
| 9401 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 9402 | |
| 9403 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 9404 | * BSpec recommends 8x4 when MSAA is used, |
| 9405 | * however in practice 16x4 seems fastest. |
| 9406 | * |
| 9407 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9408 | * disable bit, which we don't touch here, but it's good |
| 9409 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 9410 | */ |
| 9411 | I915_WRITE(GEN7_GT_MODE, |
| 9412 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 9413 | |
| 9414 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 9415 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 9416 | * This is the hardware default actually. |
| 9417 | */ |
| 9418 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 9419 | |
| 9420 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9421 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 9422 | * Disable clock gating on th GCFG unit to prevent a delay |
| 9423 | * in the reporting of vblank events. |
| 9424 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 9425 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9426 | } |
| 9427 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9428 | 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] | 9429 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 9430 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 9431 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 9432 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9433 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 9434 | ~(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] | 9435 | |
| 9436 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 9437 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 9438 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 9439 | |
| 9440 | /* WaDisableCSUnitClockGating:chv */ |
| 9441 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 9442 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 9443 | |
| 9444 | /* WaDisableSDEUnitClockGating:chv */ |
| 9445 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9446 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 9447 | |
| 9448 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9449 | * WaProgramL3SqcReg1Default:chv |
| 9450 | * See gfxspecs/Related Documents/Performance Guide/ |
| 9451 | * LSQC Setting Recommendations. |
| 9452 | */ |
| 9453 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
| 9454 | |
| 9455 | /* |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 9456 | * GTT cache may not work with big pages, so if those |
| 9457 | * are ever enabled GTT cache may need to be disabled. |
| 9458 | */ |
| 9459 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 9460 | } |
| 9461 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9462 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9463 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9464 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9465 | |
| 9466 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 9467 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 9468 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 9469 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 9470 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 9471 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 9472 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 9473 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9474 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9475 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 9476 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 9477 | |
| 9478 | /* WaDisableRenderCachePipelinedFlush */ |
| 9479 | I915_WRITE(CACHE_MODE_0, |
| 9480 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 9481 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9482 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 9483 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9484 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9485 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9486 | } |
| 9487 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9488 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9489 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9490 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 9491 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 9492 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 9493 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 9494 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 9495 | I915_WRITE(MI_ARB_STATE, |
| 9496 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9497 | |
| 9498 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 9499 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9500 | } |
| 9501 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9502 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9503 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9504 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 9505 | I965_RCC_CLOCK_GATE_DISABLE | |
| 9506 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 9507 | I965_ISC_CLOCK_GATE_DISABLE | |
| 9508 | I965_FBC_CLOCK_GATE_DISABLE); |
| 9509 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 9510 | I915_WRITE(MI_ARB_STATE, |
| 9511 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9512 | |
| 9513 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 9514 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9515 | } |
| 9516 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9517 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9518 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9519 | u32 dstate = I915_READ(D_STATE); |
| 9520 | |
| 9521 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 9522 | DSTATE_DOT_CLOCK_GATING; |
| 9523 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 9524 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9525 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 9526 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 9527 | |
| 9528 | /* IIR "flip pending" means done if this bit is set */ |
| 9529 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 9530 | |
| 9531 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 9532 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 9533 | |
| 9534 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 9535 | 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] | 9536 | |
| 9537 | I915_WRITE(MI_ARB_STATE, |
| 9538 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9539 | } |
| 9540 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9541 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9542 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9543 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 9544 | |
| 9545 | /* interrupts should cause a wake up from C3 */ |
| 9546 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 9547 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 9548 | |
| 9549 | I915_WRITE(MEM_MODE, |
| 9550 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9551 | } |
| 9552 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9553 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9554 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 9555 | I915_WRITE(MEM_MODE, |
| 9556 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 9557 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9558 | } |
| 9559 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9560 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9561 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9562 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9563 | } |
| 9564 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 9565 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9566 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 9567 | if (HAS_PCH_LPT(dev_priv)) |
| 9568 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9569 | } |
| 9570 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9571 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9572 | { |
| 9573 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 9574 | } |
| 9575 | |
| 9576 | /** |
| 9577 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 9578 | * @dev_priv: device private |
| 9579 | * |
| 9580 | * Setup the hooks that configure which clocks of a given platform can be |
| 9581 | * gated and also apply various GT and display specific workarounds for these |
| 9582 | * platforms. Note that some GT specific workarounds are applied separately |
| 9583 | * when GPU contexts or batchbuffers start their execution. |
| 9584 | */ |
| 9585 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 9586 | { |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 9587 | if (IS_GEN(dev_priv, 11)) |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 9588 | dev_priv->display.init_clock_gating = icl_init_clock_gating; |
Oscar Mateo | cc38cae | 2018-05-08 14:29:23 -0700 | [diff] [blame] | 9589 | else if (IS_CANNONLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9590 | dev_priv->display.init_clock_gating = cnl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9591 | else if (IS_COFFEELAKE(dev_priv)) |
| 9592 | dev_priv->display.init_clock_gating = cfl_init_clock_gating; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9593 | else if (IS_SKYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9594 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9595 | else if (IS_KABYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9596 | dev_priv->display.init_clock_gating = kbl_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 9597 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9598 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 9599 | else if (IS_GEMINILAKE(dev_priv)) |
| 9600 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9601 | else if (IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9602 | dev_priv->display.init_clock_gating = bdw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9603 | else if (IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9604 | dev_priv->display.init_clock_gating = chv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9605 | else if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9606 | dev_priv->display.init_clock_gating = hsw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9607 | else if (IS_IVYBRIDGE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9608 | dev_priv->display.init_clock_gating = ivb_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9609 | else if (IS_VALLEYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9610 | dev_priv->display.init_clock_gating = vlv_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9611 | else if (IS_GEN(dev_priv, 6)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9612 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9613 | else if (IS_GEN(dev_priv, 5)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9614 | dev_priv->display.init_clock_gating = ilk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9615 | else if (IS_G4X(dev_priv)) |
| 9616 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 9617 | else if (IS_I965GM(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9618 | dev_priv->display.init_clock_gating = i965gm_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 9619 | else if (IS_I965G(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9620 | dev_priv->display.init_clock_gating = i965g_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9621 | else if (IS_GEN(dev_priv, 3)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9622 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 9623 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 9624 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9625 | else if (IS_GEN(dev_priv, 2)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9626 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 9627 | else { |
| 9628 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 9629 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 9630 | } |
| 9631 | } |
| 9632 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9633 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9634 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9635 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 9636 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9637 | if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 9638 | i915_pineview_get_mem_freq(dev_priv); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9639 | else if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 9640 | i915_ironlake_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 9641 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9642 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9643 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9644 | skl_setup_wm_latency(dev_priv); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 9645 | dev_priv->display.initial_watermarks = skl_initial_wm; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 9646 | dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 9647 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9648 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9649 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 9650 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9651 | 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] | 9652 | 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] | 9653 | (!IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9654 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 9655 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 9656 | dev_priv->display.compute_intermediate_wm = |
| 9657 | ilk_compute_intermediate_wm; |
| 9658 | dev_priv->display.initial_watermarks = |
| 9659 | ilk_initial_watermarks; |
| 9660 | dev_priv->display.optimize_watermarks = |
| 9661 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9662 | } else { |
| 9663 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 9664 | "Disable CxSR\n"); |
| 9665 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 9666 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9667 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9668 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 9669 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9670 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 9671 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9672 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 9673 | } else if (IS_G4X(dev_priv)) { |
| 9674 | g4x_setup_wm_latency(dev_priv); |
| 9675 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 9676 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 9677 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 9678 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9679 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 9680 | if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9681 | dev_priv->is_ddr3, |
| 9682 | dev_priv->fsb_freq, |
| 9683 | dev_priv->mem_freq)) { |
| 9684 | DRM_INFO("failed to find known CxSR latency " |
| 9685 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 9686 | "disabling CxSR\n", |
| 9687 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 9688 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 9689 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 9690 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9691 | dev_priv->display.update_wm = NULL; |
| 9692 | } else |
| 9693 | dev_priv->display.update_wm = pineview_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9694 | } else if (IS_GEN(dev_priv, 4)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9695 | dev_priv->display.update_wm = i965_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9696 | } else if (IS_GEN(dev_priv, 3)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9697 | dev_priv->display.update_wm = i9xx_update_wm; |
| 9698 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9699 | } else if (IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9700 | if (INTEL_INFO(dev_priv)->num_pipes == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9701 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9702 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9703 | } else { |
| 9704 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9705 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9706 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9707 | } else { |
| 9708 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9709 | } |
| 9710 | } |
| 9711 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 9712 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9713 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9714 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9715 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9716 | /* |
| 9717 | * N = val - 0xb7 |
| 9718 | * Slow = Fast = GPLL ref * N |
| 9719 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9720 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * (val - 0xb7), 1000); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 9721 | } |
| 9722 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9723 | 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] | 9724 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9725 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9726 | |
| 9727 | return DIV_ROUND_CLOSEST(1000 * val, rps->gpll_ref_freq) + 0xb7; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 9728 | } |
| 9729 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9730 | 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] | 9731 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9732 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9733 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9734 | /* |
| 9735 | * N = val / 2 |
| 9736 | * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2 |
| 9737 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9738 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * val, 2 * 2 * 1000); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9739 | } |
| 9740 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9741 | 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] | 9742 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9743 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9744 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 9745 | /* CHV needs even values */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9746 | return DIV_ROUND_CLOSEST(2 * 1000 * val, rps->gpll_ref_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9747 | } |
| 9748 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9749 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9750 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 9751 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9752 | return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, |
| 9753 | GEN9_FREQ_SCALER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9754 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9755 | return chv_gpu_freq(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9756 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9757 | return byt_gpu_freq(dev_priv, val); |
| 9758 | else |
| 9759 | return val * GT_FREQUENCY_MULTIPLIER; |
| 9760 | } |
| 9761 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9762 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 9763 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 9764 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9765 | return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, |
| 9766 | GT_FREQUENCY_MULTIPLIER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9767 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9768 | return chv_freq_opcode(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9769 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9770 | return byt_freq_opcode(dev_priv, val); |
| 9771 | else |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9772 | return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9773 | } |
| 9774 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 9775 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9776 | { |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 9777 | mutex_init(&dev_priv->gt_pm.rps.lock); |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 9778 | mutex_init(&dev_priv->gt_pm.rps.power.mutex); |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9779 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9780 | atomic_set(&dev_priv->gt_pm.rps.num_waiters, 0); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 9781 | |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 9782 | dev_priv->runtime_pm.suspended = false; |
| 9783 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9784 | } |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9785 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9786 | static u64 vlv_residency_raw(struct drm_i915_private *dev_priv, |
| 9787 | const i915_reg_t reg) |
| 9788 | { |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9789 | u32 lower, upper, tmp; |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9790 | int loop = 2; |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9791 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9792 | /* |
| 9793 | * The register accessed do not need forcewake. We borrow |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9794 | * uncore lock to prevent concurrent access to range reg. |
| 9795 | */ |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9796 | lockdep_assert_held(&dev_priv->uncore.lock); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9797 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9798 | /* |
| 9799 | * vlv and chv residency counters are 40 bits in width. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9800 | * With a control bit, we can choose between upper or lower |
| 9801 | * 32bit window into this counter. |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9802 | * |
| 9803 | * Although we always use the counter in high-range mode elsewhere, |
| 9804 | * userspace may attempt to read the value before rc6 is initialised, |
| 9805 | * before we have set the default VLV_COUNTER_CONTROL value. So always |
| 9806 | * set the high bit to be safe. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9807 | */ |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9808 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9809 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9810 | upper = I915_READ_FW(reg); |
| 9811 | do { |
| 9812 | tmp = upper; |
| 9813 | |
| 9814 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9815 | _MASKED_BIT_DISABLE(VLV_COUNT_RANGE_HIGH)); |
| 9816 | lower = I915_READ_FW(reg); |
| 9817 | |
| 9818 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9819 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
| 9820 | upper = I915_READ_FW(reg); |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9821 | } while (upper != tmp && --loop); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9822 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9823 | /* |
| 9824 | * Everywhere else we always use VLV_COUNTER_CONTROL with the |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9825 | * VLV_COUNT_RANGE_HIGH bit set - so it is safe to leave it set |
| 9826 | * now. |
| 9827 | */ |
| 9828 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9829 | return lower | (u64)upper << 8; |
| 9830 | } |
| 9831 | |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9832 | u64 intel_rc6_residency_ns(struct drm_i915_private *dev_priv, |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9833 | const i915_reg_t reg) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9834 | { |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9835 | struct intel_uncore *uncore = &dev_priv->uncore; |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9836 | u64 time_hw, prev_hw, overflow_hw; |
| 9837 | unsigned int fw_domains; |
| 9838 | unsigned long flags; |
| 9839 | unsigned int i; |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9840 | u32 mul, div; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9841 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 9842 | if (!HAS_RC6(dev_priv)) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9843 | return 0; |
| 9844 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9845 | /* |
| 9846 | * Store previous hw counter values for counter wrap-around handling. |
| 9847 | * |
| 9848 | * There are only four interesting registers and they live next to each |
| 9849 | * other so we can use the relative address, compared to the smallest |
| 9850 | * one as the index into driver storage. |
| 9851 | */ |
| 9852 | i = (i915_mmio_reg_offset(reg) - |
| 9853 | i915_mmio_reg_offset(GEN6_GT_GFX_RC6_LOCKED)) / sizeof(u32); |
| 9854 | if (WARN_ON_ONCE(i >= ARRAY_SIZE(dev_priv->gt_pm.rc6.cur_residency))) |
| 9855 | return 0; |
| 9856 | |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9857 | fw_domains = intel_uncore_forcewake_for_reg(uncore, reg, FW_REG_READ); |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9858 | |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9859 | spin_lock_irqsave(&uncore->lock, flags); |
| 9860 | intel_uncore_forcewake_get__locked(uncore, fw_domains); |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9861 | |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9862 | /* On VLV and CHV, residency time is in CZ units rather than 1.28us */ |
| 9863 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9864 | mul = 1000000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9865 | div = dev_priv->czclk_freq; |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9866 | overflow_hw = BIT_ULL(40); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9867 | time_hw = vlv_residency_raw(dev_priv, reg); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9868 | } else { |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9869 | /* 833.33ns units on Gen9LP, 1.28us elsewhere. */ |
| 9870 | if (IS_GEN9_LP(dev_priv)) { |
| 9871 | mul = 10000; |
| 9872 | div = 12; |
| 9873 | } else { |
| 9874 | mul = 1280; |
| 9875 | div = 1; |
| 9876 | } |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9877 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9878 | overflow_hw = BIT_ULL(32); |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9879 | time_hw = intel_uncore_read_fw(uncore, reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9880 | } |
| 9881 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9882 | /* |
| 9883 | * Counter wrap handling. |
| 9884 | * |
| 9885 | * But relying on a sufficient frequency of queries otherwise counters |
| 9886 | * can still wrap. |
| 9887 | */ |
| 9888 | prev_hw = dev_priv->gt_pm.rc6.prev_hw_residency[i]; |
| 9889 | dev_priv->gt_pm.rc6.prev_hw_residency[i] = time_hw; |
| 9890 | |
| 9891 | /* RC6 delta from last sample. */ |
| 9892 | if (time_hw >= prev_hw) |
| 9893 | time_hw -= prev_hw; |
| 9894 | else |
| 9895 | time_hw += overflow_hw - prev_hw; |
| 9896 | |
| 9897 | /* Add delta to RC6 extended raw driver copy. */ |
| 9898 | time_hw += dev_priv->gt_pm.rc6.cur_residency[i]; |
| 9899 | dev_priv->gt_pm.rc6.cur_residency[i] = time_hw; |
| 9900 | |
Daniele Ceraolo Spurio | 4319382 | 2019-03-25 14:49:37 -0700 | [diff] [blame] | 9901 | intel_uncore_forcewake_put__locked(uncore, fw_domains); |
| 9902 | spin_unlock_irqrestore(&uncore->lock, flags); |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9903 | |
| 9904 | return mul_u64_u32_div(time_hw, mul, div); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9905 | } |
Tvrtko Ursulin | c84b270 | 2017-11-21 18:18:44 +0000 | [diff] [blame] | 9906 | |
Jani Nikula | ecbb5fb | 2019-04-29 15:29:37 +0300 | [diff] [blame] | 9907 | u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv, |
| 9908 | i915_reg_t reg) |
| 9909 | { |
| 9910 | return DIV_ROUND_UP_ULL(intel_rc6_residency_ns(dev_priv, reg), 1000); |
| 9911 | } |
| 9912 | |
Tvrtko Ursulin | c84b270 | 2017-11-21 18:18:44 +0000 | [diff] [blame] | 9913 | u32 intel_get_cagf(struct drm_i915_private *dev_priv, u32 rpstat) |
| 9914 | { |
| 9915 | u32 cagf; |
| 9916 | |
| 9917 | if (INTEL_GEN(dev_priv) >= 9) |
| 9918 | cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT; |
| 9919 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 9920 | cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT; |
| 9921 | else |
| 9922 | cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT; |
| 9923 | |
| 9924 | return cagf; |
| 9925 | } |