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" |
| 37 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 38 | #include "../../../platform/x86/intel_ips.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 39 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 40 | /** |
Jani Nikula | 18afd44 | 2016-01-18 09:19:48 +0200 | [diff] [blame] | 41 | * DOC: RC6 |
| 42 | * |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 43 | * RC6 is a special power stage which allows the GPU to enter an very |
| 44 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 45 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 46 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 47 | * |
| 48 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 49 | * among each other with the latency required to enter and leave RC6 and |
| 50 | * voltage consumed by the GPU in different states. |
| 51 | * |
| 52 | * The combination of the following flags define which states GPU is allowed |
| 53 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 54 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 55 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 56 | * which brings the most power savings; deeper states save more power, but |
| 57 | * require higher latency to switch to and wake up. |
| 58 | */ |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 59 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 60 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 61 | { |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 62 | if (HAS_LLC(dev_priv)) { |
| 63 | /* |
| 64 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
Lucas De Marchi | e0403cb | 2017-12-05 11:01:17 -0800 | [diff] [blame] | 65 | * Display WA #0390: skl,kbl |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 66 | * |
| 67 | * Must match Sampler, Pixel Back End, and Media. See |
| 68 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 69 | */ |
| 70 | I915_WRITE(CHICKEN_PAR1_1, |
| 71 | I915_READ(CHICKEN_PAR1_1) | |
| 72 | SKL_DE_COMPRESSED_HASH_MODE); |
| 73 | } |
| 74 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 75 | /* 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] | 76 | I915_WRITE(CHICKEN_PAR1_1, |
| 77 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 78 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 79 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 80 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 81 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 82 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 83 | /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl,cfl */ |
| 84 | /* WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 85 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 86 | DISP_FBC_WM_DIS | |
| 87 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 88 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 89 | /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl,cfl */ |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 90 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 91 | ILK_DPFC_DISABLE_DUMMY0); |
Praveen Paneri | 32087d1 | 2017-08-03 23:02:10 +0530 | [diff] [blame] | 92 | |
| 93 | if (IS_SKYLAKE(dev_priv)) { |
| 94 | /* WaDisableDopClockGating */ |
| 95 | I915_WRITE(GEN7_MISCCPCTL, I915_READ(GEN7_MISCCPCTL) |
| 96 | & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 97 | } |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 98 | } |
| 99 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 100 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 101 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 102 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 103 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 104 | /* WaDisableSDEUnitClockGating:bxt */ |
| 105 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 106 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 107 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 108 | /* |
| 109 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 110 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 111 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 112 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 113 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 114 | |
| 115 | /* |
| 116 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 117 | * to stay fully on. |
| 118 | */ |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 119 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 120 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 123 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 124 | { |
| 125 | gen9_init_clock_gating(dev_priv); |
| 126 | |
| 127 | /* |
| 128 | * WaDisablePWMClockGating:glk |
| 129 | * Backlight PWM may stop in the asserted state, causing backlight |
| 130 | * to stay fully on. |
| 131 | */ |
| 132 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 133 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Ander Conselvan de Oliveira | f4f4b59 | 2017-02-22 08:34:29 +0200 | [diff] [blame] | 134 | |
| 135 | /* WaDDIIOTimeout:glk */ |
| 136 | if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1)) { |
| 137 | u32 val = I915_READ(CHICKEN_MISC_2); |
| 138 | val &= ~(GLK_CL0_PWR_DOWN | |
| 139 | GLK_CL1_PWR_DOWN | |
| 140 | GLK_CL2_PWR_DOWN); |
| 141 | I915_WRITE(CHICKEN_MISC_2, val); |
| 142 | } |
| 143 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 146 | 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] | 147 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 148 | u32 tmp; |
| 149 | |
| 150 | tmp = I915_READ(CLKCFG); |
| 151 | |
| 152 | switch (tmp & CLKCFG_FSB_MASK) { |
| 153 | case CLKCFG_FSB_533: |
| 154 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 155 | break; |
| 156 | case CLKCFG_FSB_800: |
| 157 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 158 | break; |
| 159 | case CLKCFG_FSB_667: |
| 160 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 161 | break; |
| 162 | case CLKCFG_FSB_400: |
| 163 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | switch (tmp & CLKCFG_MEM_MASK) { |
| 168 | case CLKCFG_MEM_533: |
| 169 | dev_priv->mem_freq = 533; |
| 170 | break; |
| 171 | case CLKCFG_MEM_667: |
| 172 | dev_priv->mem_freq = 667; |
| 173 | break; |
| 174 | case CLKCFG_MEM_800: |
| 175 | dev_priv->mem_freq = 800; |
| 176 | break; |
| 177 | } |
| 178 | |
| 179 | /* detect pineview DDR3 setting */ |
| 180 | tmp = I915_READ(CSHRDDR3CTL); |
| 181 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 182 | } |
| 183 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 184 | 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] | 185 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 186 | u16 ddrpll, csipll; |
| 187 | |
| 188 | ddrpll = I915_READ16(DDRMPLL1); |
| 189 | csipll = I915_READ16(CSIPLL0); |
| 190 | |
| 191 | switch (ddrpll & 0xff) { |
| 192 | case 0xc: |
| 193 | dev_priv->mem_freq = 800; |
| 194 | break; |
| 195 | case 0x10: |
| 196 | dev_priv->mem_freq = 1066; |
| 197 | break; |
| 198 | case 0x14: |
| 199 | dev_priv->mem_freq = 1333; |
| 200 | break; |
| 201 | case 0x18: |
| 202 | dev_priv->mem_freq = 1600; |
| 203 | break; |
| 204 | default: |
| 205 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 206 | ddrpll & 0xff); |
| 207 | dev_priv->mem_freq = 0; |
| 208 | break; |
| 209 | } |
| 210 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 211 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 212 | |
| 213 | switch (csipll & 0x3ff) { |
| 214 | case 0x00c: |
| 215 | dev_priv->fsb_freq = 3200; |
| 216 | break; |
| 217 | case 0x00e: |
| 218 | dev_priv->fsb_freq = 3733; |
| 219 | break; |
| 220 | case 0x010: |
| 221 | dev_priv->fsb_freq = 4266; |
| 222 | break; |
| 223 | case 0x012: |
| 224 | dev_priv->fsb_freq = 4800; |
| 225 | break; |
| 226 | case 0x014: |
| 227 | dev_priv->fsb_freq = 5333; |
| 228 | break; |
| 229 | case 0x016: |
| 230 | dev_priv->fsb_freq = 5866; |
| 231 | break; |
| 232 | case 0x018: |
| 233 | dev_priv->fsb_freq = 6400; |
| 234 | break; |
| 235 | default: |
| 236 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 237 | csipll & 0x3ff); |
| 238 | dev_priv->fsb_freq = 0; |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 243 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 244 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 245 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 246 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 247 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 251 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 252 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 253 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 254 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 255 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 256 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 257 | |
| 258 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 259 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 260 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 261 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 262 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 263 | |
| 264 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 265 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 266 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 267 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 268 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 269 | |
| 270 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 271 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 272 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 273 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 274 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 275 | |
| 276 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 277 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 278 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 279 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 280 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 281 | |
| 282 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 283 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 284 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 285 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 286 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 287 | }; |
| 288 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 289 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 290 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 291 | int fsb, |
| 292 | int mem) |
| 293 | { |
| 294 | const struct cxsr_latency *latency; |
| 295 | int i; |
| 296 | |
| 297 | if (fsb == 0 || mem == 0) |
| 298 | return NULL; |
| 299 | |
| 300 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 301 | latency = &cxsr_latency_table[i]; |
| 302 | if (is_desktop == latency->is_desktop && |
| 303 | is_ddr3 == latency->is_ddr3 && |
| 304 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 305 | return latency; |
| 306 | } |
| 307 | |
| 308 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 309 | |
| 310 | return NULL; |
| 311 | } |
| 312 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 313 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 314 | { |
| 315 | u32 val; |
| 316 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 317 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 318 | |
| 319 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 320 | if (enable) |
| 321 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 322 | else |
| 323 | val |= FORCE_DDR_HIGH_FREQ; |
| 324 | val &= ~FORCE_DDR_LOW_FREQ; |
| 325 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 326 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 327 | |
| 328 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 329 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 330 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 331 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 332 | mutex_unlock(&dev_priv->pcu_lock); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 333 | } |
| 334 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 335 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 336 | { |
| 337 | u32 val; |
| 338 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 339 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 340 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 341 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 342 | if (enable) |
| 343 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 344 | else |
| 345 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 346 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 347 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 348 | mutex_unlock(&dev_priv->pcu_lock); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 351 | #define FW_WM(value, plane) \ |
| 352 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 353 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 354 | 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] | 355 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 356 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 357 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 358 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 359 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 360 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 361 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 362 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 363 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 364 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 365 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 366 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 367 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 368 | val = I915_READ(DSPFW3); |
| 369 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 370 | if (enable) |
| 371 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 372 | else |
| 373 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 374 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 375 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 376 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 377 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 378 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 379 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 380 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 381 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 382 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 383 | /* |
| 384 | * FIXME can't find a bit like this for 915G, and |
| 385 | * and yet it does have the related watermark in |
| 386 | * FW_BLC_SELF. What's going on? |
| 387 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 388 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 389 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 390 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 391 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 392 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 393 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 394 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 395 | } |
| 396 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 397 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 398 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 399 | DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", |
| 400 | enableddisabled(enable), |
| 401 | enableddisabled(was_enabled)); |
| 402 | |
| 403 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 404 | } |
| 405 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 406 | /** |
| 407 | * intel_set_memory_cxsr - Configure CxSR state |
| 408 | * @dev_priv: i915 device |
| 409 | * @enable: Allow vs. disallow CxSR |
| 410 | * |
| 411 | * Allow or disallow the system to enter a special CxSR |
| 412 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 413 | * is that several display FIFOs may get combined into a single larger |
| 414 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 415 | * system to defer memory fetches longer, and the memory will enter |
| 416 | * self refresh. |
| 417 | * |
| 418 | * Note that enabling CxSR does not guarantee that the system enter |
| 419 | * this special mode, nor does it guarantee that the system stays |
| 420 | * in that mode once entered. So this just allows/disallows the system |
| 421 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 422 | * C-states will affect when/if the system actually enters/exits the |
| 423 | * CxSR mode. |
| 424 | * |
| 425 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 426 | * and the system is free to enter/exit memory self refresh at any time |
| 427 | * even when the use of CxSR has been disallowed. |
| 428 | * |
| 429 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 430 | * control registers will not get latched on vblank. Thus in order to |
| 431 | * guarantee the system will respond to changes in the plane registers |
| 432 | * we must always disallow CxSR prior to making changes to those registers. |
| 433 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 434 | * frame start which happens after vblank start (which is when the plane |
| 435 | * registers would get latched), so we can't proceed with the plane update |
| 436 | * during the same frame where we disallowed CxSR. |
| 437 | * |
| 438 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 439 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 440 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 441 | * Disallowing just CxSR is sufficient. |
| 442 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 443 | 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] | 444 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 445 | bool ret; |
| 446 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 447 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 448 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 449 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 450 | dev_priv->wm.vlv.cxsr = enable; |
| 451 | else if (IS_G4X(dev_priv)) |
| 452 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 453 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 454 | |
| 455 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 456 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 457 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 458 | /* |
| 459 | * Latency for FIFO fetches is dependent on several factors: |
| 460 | * - memory configuration (speed, channels) |
| 461 | * - chipset |
| 462 | * - current MCH state |
| 463 | * It can be fairly high in some situations, so here we assume a fairly |
| 464 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 465 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 466 | * and power consumption (set it too low to save power and we might see |
| 467 | * FIFO underruns and display "flicker"). |
| 468 | * |
| 469 | * A value of 5us seems to be a good balance; safe for very low end |
| 470 | * platforms but not overly aggressive on lower latency configs. |
| 471 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 472 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 473 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 474 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 475 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 476 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 477 | 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] | 478 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 479 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 480 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 481 | 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] | 482 | enum pipe pipe = crtc->pipe; |
| 483 | int sprite0_start, sprite1_start; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 484 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 485 | switch (pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 486 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 487 | case PIPE_A: |
| 488 | dsparb = I915_READ(DSPARB); |
| 489 | dsparb2 = I915_READ(DSPARB2); |
| 490 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 491 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 492 | break; |
| 493 | case PIPE_B: |
| 494 | dsparb = I915_READ(DSPARB); |
| 495 | dsparb2 = I915_READ(DSPARB2); |
| 496 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 497 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 498 | break; |
| 499 | case PIPE_C: |
| 500 | dsparb2 = I915_READ(DSPARB2); |
| 501 | dsparb3 = I915_READ(DSPARB3); |
| 502 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 503 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 504 | break; |
| 505 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 506 | MISSING_CASE(pipe); |
| 507 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 508 | } |
| 509 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 510 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 511 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 512 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 513 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 516 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 517 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 518 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 519 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 520 | int size; |
| 521 | |
| 522 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 523 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 524 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 525 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 526 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 527 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 528 | |
| 529 | return size; |
| 530 | } |
| 531 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 532 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 533 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 534 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 535 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 536 | int size; |
| 537 | |
| 538 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 539 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 540 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 541 | size >>= 1; /* Convert to cachelines */ |
| 542 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 543 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 544 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 545 | |
| 546 | return size; |
| 547 | } |
| 548 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 549 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 550 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 551 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 552 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 553 | int size; |
| 554 | |
| 555 | size = dsparb & 0x7f; |
| 556 | size >>= 2; /* Convert to cachelines */ |
| 557 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 558 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", |
| 559 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 560 | |
| 561 | return size; |
| 562 | } |
| 563 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 564 | /* Pineview has different values for various configs */ |
| 565 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 566 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 567 | .max_wm = PINEVIEW_MAX_WM, |
| 568 | .default_wm = PINEVIEW_DFT_WM, |
| 569 | .guard_size = PINEVIEW_GUARD_WM, |
| 570 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 571 | }; |
| 572 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 573 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 574 | .max_wm = PINEVIEW_MAX_WM, |
| 575 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 576 | .guard_size = PINEVIEW_GUARD_WM, |
| 577 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 578 | }; |
| 579 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 580 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 581 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 582 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 583 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 584 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 585 | }; |
| 586 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 587 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 588 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 589 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 590 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 591 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 592 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 593 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 594 | .fifo_size = I965_CURSOR_FIFO, |
| 595 | .max_wm = I965_CURSOR_MAX_WM, |
| 596 | .default_wm = I965_CURSOR_DFT_WM, |
| 597 | .guard_size = 2, |
| 598 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 599 | }; |
| 600 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 601 | .fifo_size = I945_FIFO_SIZE, |
| 602 | .max_wm = I915_MAX_WM, |
| 603 | .default_wm = 1, |
| 604 | .guard_size = 2, |
| 605 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 606 | }; |
| 607 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 608 | .fifo_size = I915_FIFO_SIZE, |
| 609 | .max_wm = I915_MAX_WM, |
| 610 | .default_wm = 1, |
| 611 | .guard_size = 2, |
| 612 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 613 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 614 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 615 | .fifo_size = I855GM_FIFO_SIZE, |
| 616 | .max_wm = I915_MAX_WM, |
| 617 | .default_wm = 1, |
| 618 | .guard_size = 2, |
| 619 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 620 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 621 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 622 | .fifo_size = I855GM_FIFO_SIZE, |
| 623 | .max_wm = I915_MAX_WM/2, |
| 624 | .default_wm = 1, |
| 625 | .guard_size = 2, |
| 626 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 627 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 628 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 629 | .fifo_size = I830_FIFO_SIZE, |
| 630 | .max_wm = I915_MAX_WM, |
| 631 | .default_wm = 1, |
| 632 | .guard_size = 2, |
| 633 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 634 | }; |
| 635 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 636 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 637 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 638 | * @pixel_rate: Pipe pixel rate in kHz |
| 639 | * @cpp: Plane bytes per pixel |
| 640 | * @latency: Memory wakeup latency in 0.1us units |
| 641 | * |
| 642 | * Compute the watermark using the method 1 or "small buffer" |
| 643 | * formula. The caller may additonally add extra cachelines |
| 644 | * to account for TLB misses and clock crossings. |
| 645 | * |
| 646 | * This method is concerned with the short term drain rate |
| 647 | * of the FIFO, ie. it does not account for blanking periods |
| 648 | * which would effectively reduce the average drain rate across |
| 649 | * a longer period. The name "small" refers to the fact the |
| 650 | * FIFO is relatively small compared to the amount of data |
| 651 | * fetched. |
| 652 | * |
| 653 | * The FIFO level vs. time graph might look something like: |
| 654 | * |
| 655 | * |\ |\ |
| 656 | * | \ | \ |
| 657 | * __---__---__ (- plane active, _ blanking) |
| 658 | * -> time |
| 659 | * |
| 660 | * or perhaps like this: |
| 661 | * |
| 662 | * |\|\ |\|\ |
| 663 | * __----__----__ (- plane active, _ blanking) |
| 664 | * -> time |
| 665 | * |
| 666 | * Returns: |
| 667 | * The watermark in bytes |
| 668 | */ |
| 669 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 670 | unsigned int cpp, |
| 671 | unsigned int latency) |
| 672 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 673 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 674 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 675 | ret = (u64)pixel_rate * cpp * latency; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 676 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 677 | |
| 678 | return ret; |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 683 | * @pixel_rate: Pipe pixel rate in kHz |
| 684 | * @htotal: Pipe horizontal total |
| 685 | * @width: Plane width in pixels |
| 686 | * @cpp: Plane bytes per pixel |
| 687 | * @latency: Memory wakeup latency in 0.1us units |
| 688 | * |
| 689 | * Compute the watermark using the method 2 or "large buffer" |
| 690 | * formula. The caller may additonally add extra cachelines |
| 691 | * to account for TLB misses and clock crossings. |
| 692 | * |
| 693 | * This method is concerned with the long term drain rate |
| 694 | * of the FIFO, ie. it does account for blanking periods |
| 695 | * which effectively reduce the average drain rate across |
| 696 | * a longer period. The name "large" refers to the fact the |
| 697 | * FIFO is relatively large compared to the amount of data |
| 698 | * fetched. |
| 699 | * |
| 700 | * The FIFO level vs. time graph might look something like: |
| 701 | * |
| 702 | * |\___ |\___ |
| 703 | * | \___ | \___ |
| 704 | * | \ | \ |
| 705 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 706 | * -> time |
| 707 | * |
| 708 | * Returns: |
| 709 | * The watermark in bytes |
| 710 | */ |
| 711 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 712 | unsigned int htotal, |
| 713 | unsigned int width, |
| 714 | unsigned int cpp, |
| 715 | unsigned int latency) |
| 716 | { |
| 717 | unsigned int ret; |
| 718 | |
| 719 | /* |
| 720 | * FIXME remove once all users are computing |
| 721 | * watermarks in the correct place. |
| 722 | */ |
| 723 | if (WARN_ON_ONCE(htotal == 0)) |
| 724 | htotal = 1; |
| 725 | |
| 726 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 727 | ret = (ret + 1) * width * cpp; |
| 728 | |
| 729 | return ret; |
| 730 | } |
| 731 | |
| 732 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 733 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 734 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 735 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 736 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 737 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 738 | * @latency_ns: memory latency for the platform |
| 739 | * |
| 740 | * Calculate the watermark level (the level at which the display plane will |
| 741 | * start fetching from memory again). Each chip has a different display |
| 742 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 743 | * in the correct intel_watermark_params structure. |
| 744 | * |
| 745 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 746 | * on the pixel size. When it reaches the watermark level, it'll start |
| 747 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 748 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 749 | * will occur, and a display engine hang could result. |
| 750 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 751 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 752 | const struct intel_watermark_params *wm, |
| 753 | int fifo_size, int cpp, |
| 754 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 755 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 756 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 757 | |
| 758 | /* |
| 759 | * Note: we need to make sure we don't overflow for various clock & |
| 760 | * latency values. |
| 761 | * clocks go from a few thousand to several hundred thousand. |
| 762 | * latency is usually a few thousand |
| 763 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 764 | entries = intel_wm_method1(pixel_rate, cpp, |
| 765 | latency_ns / 100); |
| 766 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 767 | wm->guard_size; |
| 768 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 769 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 770 | wm_size = fifo_size - entries; |
| 771 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 772 | |
| 773 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 774 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 775 | wm_size = wm->max_wm; |
| 776 | if (wm_size <= 0) |
| 777 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 778 | |
| 779 | /* |
| 780 | * Bspec seems to indicate that the value shouldn't be lower than |
| 781 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 782 | * Lets go for 8 which is the burst size since certain platforms |
| 783 | * already use a hardcoded 8 (which is what the spec says should be |
| 784 | * done). |
| 785 | */ |
| 786 | if (wm_size <= 8) |
| 787 | wm_size = 8; |
| 788 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 789 | return wm_size; |
| 790 | } |
| 791 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 792 | static bool is_disabling(int old, int new, int threshold) |
| 793 | { |
| 794 | return old >= threshold && new < threshold; |
| 795 | } |
| 796 | |
| 797 | static bool is_enabling(int old, int new, int threshold) |
| 798 | { |
| 799 | return old < threshold && new >= threshold; |
| 800 | } |
| 801 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 802 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 803 | { |
| 804 | return dev_priv->wm.max_level + 1; |
| 805 | } |
| 806 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 807 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 808 | const struct intel_plane_state *plane_state) |
| 809 | { |
| 810 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 811 | |
| 812 | /* FIXME check the 'enable' instead */ |
| 813 | if (!crtc_state->base.active) |
| 814 | return false; |
| 815 | |
| 816 | /* |
| 817 | * Treat cursor with fb as always visible since cursor updates |
| 818 | * can happen faster than the vrefresh rate, and the current |
| 819 | * watermark code doesn't handle that correctly. Cursor updates |
| 820 | * which set/clear the fb or change the cursor size are going |
| 821 | * to get throttled by intel_legacy_cursor_update() to work |
| 822 | * around this problem with the watermark code. |
| 823 | */ |
| 824 | if (plane->id == PLANE_CURSOR) |
| 825 | return plane_state->base.fb != NULL; |
| 826 | else |
| 827 | return plane_state->base.visible; |
| 828 | } |
| 829 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 830 | 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] | 831 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 832 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 833 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 834 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 835 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 836 | if (enabled) |
| 837 | return NULL; |
| 838 | enabled = crtc; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | return enabled; |
| 843 | } |
| 844 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 845 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 846 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 847 | 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] | 848 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 849 | const struct cxsr_latency *latency; |
| 850 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 851 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 852 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 853 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
| 854 | dev_priv->is_ddr3, |
| 855 | dev_priv->fsb_freq, |
| 856 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 857 | if (!latency) { |
| 858 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 859 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 860 | return; |
| 861 | } |
| 862 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 863 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 864 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 865 | const struct drm_display_mode *adjusted_mode = |
| 866 | &crtc->config->base.adjusted_mode; |
| 867 | const struct drm_framebuffer *fb = |
| 868 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 869 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 870 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 871 | |
| 872 | /* Display SR */ |
| 873 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 874 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 875 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 876 | reg = I915_READ(DSPFW1); |
| 877 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 878 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 879 | I915_WRITE(DSPFW1, reg); |
| 880 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 881 | |
| 882 | /* cursor SR */ |
| 883 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 884 | pineview_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 885 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 886 | reg = I915_READ(DSPFW3); |
| 887 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 888 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 889 | I915_WRITE(DSPFW3, reg); |
| 890 | |
| 891 | /* Display HPLL off SR */ |
| 892 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 893 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 894 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 895 | reg = I915_READ(DSPFW3); |
| 896 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 897 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 898 | I915_WRITE(DSPFW3, reg); |
| 899 | |
| 900 | /* cursor HPLL off SR */ |
| 901 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 902 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 903 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 904 | reg = I915_READ(DSPFW3); |
| 905 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 906 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 907 | I915_WRITE(DSPFW3, reg); |
| 908 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 909 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 910 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 911 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 912 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 916 | /* |
| 917 | * Documentation says: |
| 918 | * "If the line size is small, the TLB fetches can get in the way of the |
| 919 | * data fetches, causing some lag in the pixel data return which is not |
| 920 | * accounted for in the above formulas. The following adjustment only |
| 921 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 922 | * The WM is adjusted upwards by the difference between the FIFO size |
| 923 | * and the size of 8 whole lines. This adjustment is always performed |
| 924 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 925 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 926 | 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] | 927 | { |
| 928 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 929 | |
| 930 | return max(0, tlb_miss); |
| 931 | } |
| 932 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 933 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 934 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 935 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 936 | enum pipe pipe; |
| 937 | |
| 938 | for_each_pipe(dev_priv, pipe) |
| 939 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 940 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 941 | I915_WRITE(DSPFW1, |
| 942 | FW_WM(wm->sr.plane, SR) | |
| 943 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 944 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 945 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 946 | I915_WRITE(DSPFW2, |
| 947 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 948 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 949 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 950 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 951 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 952 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 953 | I915_WRITE(DSPFW3, |
| 954 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 955 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 956 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 957 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 958 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 959 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 960 | } |
| 961 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 962 | #define FW_WM_VLV(value, plane) \ |
| 963 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 964 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 965 | 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] | 966 | const struct vlv_wm_values *wm) |
| 967 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 968 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 969 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 970 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 971 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 972 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 973 | I915_WRITE(VLV_DDL(pipe), |
| 974 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 975 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 976 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 977 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 978 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 979 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 980 | /* |
| 981 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 982 | * high order bits so that there are no out of bounds values |
| 983 | * present in the registers during the reprogramming. |
| 984 | */ |
| 985 | I915_WRITE(DSPHOWM, 0); |
| 986 | I915_WRITE(DSPHOWM1, 0); |
| 987 | I915_WRITE(DSPFW4, 0); |
| 988 | I915_WRITE(DSPFW5, 0); |
| 989 | I915_WRITE(DSPFW6, 0); |
| 990 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 991 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 992 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 993 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 994 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 995 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 996 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 997 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 998 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 999 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1000 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1001 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1002 | |
| 1003 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1004 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1005 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1006 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1007 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1008 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 1009 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1010 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1011 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1012 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1013 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1014 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1015 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1016 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1017 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 1018 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1019 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1020 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1021 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1022 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1023 | 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] | 1024 | } else { |
| 1025 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1026 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1027 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1028 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1029 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1030 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1031 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1032 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1033 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1034 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1035 | 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] | 1036 | } |
| 1037 | |
| 1038 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1039 | } |
| 1040 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1041 | #undef FW_WM_VLV |
| 1042 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1043 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1044 | { |
| 1045 | /* all latencies in usec */ |
| 1046 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1047 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1048 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1049 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1050 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1054 | { |
| 1055 | /* |
| 1056 | * DSPCNTR[13] supposedly controls whether the |
| 1057 | * primary plane can use the FIFO space otherwise |
| 1058 | * reserved for the sprite plane. It's not 100% clear |
| 1059 | * what the actual FIFO size is, but it looks like we |
| 1060 | * can happily set both primary and sprite watermarks |
| 1061 | * up to 127 cachelines. So that would seem to mean |
| 1062 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1063 | * the total FIFO is >= 256 cachelines in size. Either |
| 1064 | * way, we don't seem to have to worry about this |
| 1065 | * repartitioning as the maximum watermark value the |
| 1066 | * register can hold for each plane is lower than the |
| 1067 | * minimum FIFO size. |
| 1068 | */ |
| 1069 | switch (plane_id) { |
| 1070 | case PLANE_CURSOR: |
| 1071 | return 63; |
| 1072 | case PLANE_PRIMARY: |
| 1073 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1074 | case PLANE_SPRITE0: |
| 1075 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1076 | default: |
| 1077 | MISSING_CASE(plane_id); |
| 1078 | return 0; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | static int g4x_fbc_fifo_size(int level) |
| 1083 | { |
| 1084 | switch (level) { |
| 1085 | case G4X_WM_LEVEL_SR: |
| 1086 | return 7; |
| 1087 | case G4X_WM_LEVEL_HPLL: |
| 1088 | return 15; |
| 1089 | default: |
| 1090 | MISSING_CASE(level); |
| 1091 | return 0; |
| 1092 | } |
| 1093 | } |
| 1094 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1095 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1096 | const struct intel_plane_state *plane_state, |
| 1097 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1098 | { |
| 1099 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1100 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 1101 | const struct drm_display_mode *adjusted_mode = |
| 1102 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1103 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1104 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1105 | |
| 1106 | if (latency == 0) |
| 1107 | return USHRT_MAX; |
| 1108 | |
| 1109 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1110 | return 0; |
| 1111 | |
| 1112 | /* |
| 1113 | * Not 100% sure which way ELK should go here as the |
| 1114 | * spec only says CL/CTG should assume 32bpp and BW |
| 1115 | * doesn't need to. But as these things followed the |
| 1116 | * mobile vs. desktop lines on gen3 as well, let's |
| 1117 | * assume ELK doesn't need this. |
| 1118 | * |
| 1119 | * The spec also fails to list such a restriction for |
| 1120 | * the HPLL watermark, which seems a little strange. |
| 1121 | * Let's use 32bpp for the HPLL watermark as well. |
| 1122 | */ |
| 1123 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1124 | level != G4X_WM_LEVEL_NORMAL) |
| 1125 | cpp = 4; |
| 1126 | else |
| 1127 | cpp = plane_state->base.fb->format->cpp[0]; |
| 1128 | |
| 1129 | clock = adjusted_mode->crtc_clock; |
| 1130 | htotal = adjusted_mode->crtc_htotal; |
| 1131 | |
| 1132 | if (plane->id == PLANE_CURSOR) |
| 1133 | width = plane_state->base.crtc_w; |
| 1134 | else |
| 1135 | width = drm_rect_width(&plane_state->base.dst); |
| 1136 | |
| 1137 | if (plane->id == PLANE_CURSOR) { |
| 1138 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1139 | } else if (plane->id == PLANE_PRIMARY && |
| 1140 | level == G4X_WM_LEVEL_NORMAL) { |
| 1141 | wm = intel_wm_method1(clock, cpp, latency); |
| 1142 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1143 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1144 | |
| 1145 | small = intel_wm_method1(clock, cpp, latency); |
| 1146 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1147 | |
| 1148 | wm = min(small, large); |
| 1149 | } |
| 1150 | |
| 1151 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1152 | width, cpp); |
| 1153 | |
| 1154 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1155 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1156 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1160 | int level, enum plane_id plane_id, u16 value) |
| 1161 | { |
| 1162 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1163 | bool dirty = false; |
| 1164 | |
| 1165 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1166 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1167 | |
| 1168 | dirty |= raw->plane[plane_id] != value; |
| 1169 | raw->plane[plane_id] = value; |
| 1170 | } |
| 1171 | |
| 1172 | return dirty; |
| 1173 | } |
| 1174 | |
| 1175 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1176 | int level, u16 value) |
| 1177 | { |
| 1178 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1179 | bool dirty = false; |
| 1180 | |
| 1181 | /* NORMAL level doesn't have an FBC watermark */ |
| 1182 | level = max(level, G4X_WM_LEVEL_SR); |
| 1183 | |
| 1184 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1185 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1186 | |
| 1187 | dirty |= raw->fbc != value; |
| 1188 | raw->fbc = value; |
| 1189 | } |
| 1190 | |
| 1191 | return dirty; |
| 1192 | } |
| 1193 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1194 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
| 1195 | const struct intel_plane_state *pstate, |
| 1196 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1197 | |
| 1198 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1199 | const struct intel_plane_state *plane_state) |
| 1200 | { |
| 1201 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1202 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1203 | enum plane_id plane_id = plane->id; |
| 1204 | bool dirty = false; |
| 1205 | int level; |
| 1206 | |
| 1207 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1208 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1209 | if (plane_id == PLANE_PRIMARY) |
| 1210 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1211 | goto out; |
| 1212 | } |
| 1213 | |
| 1214 | for (level = 0; level < num_levels; level++) { |
| 1215 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1216 | int wm, max_wm; |
| 1217 | |
| 1218 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1219 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1220 | |
| 1221 | if (wm > max_wm) |
| 1222 | break; |
| 1223 | |
| 1224 | dirty |= raw->plane[plane_id] != wm; |
| 1225 | raw->plane[plane_id] = wm; |
| 1226 | |
| 1227 | if (plane_id != PLANE_PRIMARY || |
| 1228 | level == G4X_WM_LEVEL_NORMAL) |
| 1229 | continue; |
| 1230 | |
| 1231 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1232 | raw->plane[plane_id]); |
| 1233 | max_wm = g4x_fbc_fifo_size(level); |
| 1234 | |
| 1235 | /* |
| 1236 | * FBC wm is not mandatory as we |
| 1237 | * can always just disable its use. |
| 1238 | */ |
| 1239 | if (wm > max_wm) |
| 1240 | wm = USHRT_MAX; |
| 1241 | |
| 1242 | dirty |= raw->fbc != wm; |
| 1243 | raw->fbc = wm; |
| 1244 | } |
| 1245 | |
| 1246 | /* mark watermarks as invalid */ |
| 1247 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1248 | |
| 1249 | if (plane_id == PLANE_PRIMARY) |
| 1250 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1251 | |
| 1252 | out: |
| 1253 | if (dirty) { |
| 1254 | DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1255 | plane->base.name, |
| 1256 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1257 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1258 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
| 1259 | |
| 1260 | if (plane_id == PLANE_PRIMARY) |
| 1261 | DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", |
| 1262 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1263 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
| 1264 | } |
| 1265 | |
| 1266 | return dirty; |
| 1267 | } |
| 1268 | |
| 1269 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1270 | enum plane_id plane_id, int level) |
| 1271 | { |
| 1272 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1273 | |
| 1274 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1275 | } |
| 1276 | |
| 1277 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1278 | int level) |
| 1279 | { |
| 1280 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1281 | |
| 1282 | if (level > dev_priv->wm.max_level) |
| 1283 | return false; |
| 1284 | |
| 1285 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1286 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1287 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1288 | } |
| 1289 | |
| 1290 | /* mark all levels starting from 'level' as invalid */ |
| 1291 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1292 | struct g4x_wm_state *wm_state, int level) |
| 1293 | { |
| 1294 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1295 | enum plane_id plane_id; |
| 1296 | |
| 1297 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1298 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1299 | } |
| 1300 | |
| 1301 | if (level <= G4X_WM_LEVEL_SR) { |
| 1302 | wm_state->cxsr = false; |
| 1303 | wm_state->sr.cursor = USHRT_MAX; |
| 1304 | wm_state->sr.plane = USHRT_MAX; |
| 1305 | wm_state->sr.fbc = USHRT_MAX; |
| 1306 | } |
| 1307 | |
| 1308 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1309 | wm_state->hpll_en = false; |
| 1310 | wm_state->hpll.cursor = USHRT_MAX; |
| 1311 | wm_state->hpll.plane = USHRT_MAX; |
| 1312 | wm_state->hpll.fbc = USHRT_MAX; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1317 | { |
| 1318 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1319 | struct intel_atomic_state *state = |
| 1320 | to_intel_atomic_state(crtc_state->base.state); |
| 1321 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 1322 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1323 | ~BIT(PLANE_CURSOR)); |
| 1324 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1325 | const struct intel_plane_state *old_plane_state; |
| 1326 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1327 | struct intel_plane *plane; |
| 1328 | enum plane_id plane_id; |
| 1329 | int i, level; |
| 1330 | unsigned int dirty = 0; |
| 1331 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1332 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1333 | old_plane_state, |
| 1334 | new_plane_state, i) { |
| 1335 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1336 | old_plane_state->base.crtc != &crtc->base) |
| 1337 | continue; |
| 1338 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1339 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1340 | dirty |= BIT(plane->id); |
| 1341 | } |
| 1342 | |
| 1343 | if (!dirty) |
| 1344 | return 0; |
| 1345 | |
| 1346 | level = G4X_WM_LEVEL_NORMAL; |
| 1347 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1348 | goto out; |
| 1349 | |
| 1350 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1351 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1352 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1353 | |
| 1354 | level = G4X_WM_LEVEL_SR; |
| 1355 | |
| 1356 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1357 | goto out; |
| 1358 | |
| 1359 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1360 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1361 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1362 | wm_state->sr.fbc = raw->fbc; |
| 1363 | |
| 1364 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1365 | |
| 1366 | level = G4X_WM_LEVEL_HPLL; |
| 1367 | |
| 1368 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1369 | goto out; |
| 1370 | |
| 1371 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1372 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1373 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1374 | wm_state->hpll.fbc = raw->fbc; |
| 1375 | |
| 1376 | wm_state->hpll_en = wm_state->cxsr; |
| 1377 | |
| 1378 | level++; |
| 1379 | |
| 1380 | out: |
| 1381 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1382 | return -EINVAL; |
| 1383 | |
| 1384 | /* invalidate the higher levels */ |
| 1385 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1386 | |
| 1387 | /* |
| 1388 | * Determine if the FBC watermark(s) can be used. IF |
| 1389 | * this isn't the case we prefer to disable the FBC |
| 1390 | ( watermark(s) rather than disable the SR/HPLL |
| 1391 | * level(s) entirely. |
| 1392 | */ |
| 1393 | wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL; |
| 1394 | |
| 1395 | if (level >= G4X_WM_LEVEL_SR && |
| 1396 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1397 | wm_state->fbc_en = false; |
| 1398 | else if (level >= G4X_WM_LEVEL_HPLL && |
| 1399 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1400 | wm_state->fbc_en = false; |
| 1401 | |
| 1402 | return 0; |
| 1403 | } |
| 1404 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1405 | 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] | 1406 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1407 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1408 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1409 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
| 1410 | struct intel_atomic_state *intel_state = |
| 1411 | to_intel_atomic_state(new_crtc_state->base.state); |
| 1412 | const struct intel_crtc_state *old_crtc_state = |
| 1413 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 1414 | 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] | 1415 | enum plane_id plane_id; |
| 1416 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1417 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 1418 | *intermediate = *optimal; |
| 1419 | |
| 1420 | intermediate->cxsr = false; |
| 1421 | intermediate->hpll_en = false; |
| 1422 | goto out; |
| 1423 | } |
| 1424 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1425 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1426 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1427 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1428 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1429 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1430 | |
| 1431 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1432 | intermediate->wm.plane[plane_id] = |
| 1433 | max(optimal->wm.plane[plane_id], |
| 1434 | active->wm.plane[plane_id]); |
| 1435 | |
| 1436 | WARN_ON(intermediate->wm.plane[plane_id] > |
| 1437 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
| 1438 | } |
| 1439 | |
| 1440 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1441 | active->sr.plane); |
| 1442 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1443 | active->sr.cursor); |
| 1444 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1445 | active->sr.fbc); |
| 1446 | |
| 1447 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1448 | active->hpll.plane); |
| 1449 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1450 | active->hpll.cursor); |
| 1451 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1452 | active->hpll.fbc); |
| 1453 | |
| 1454 | WARN_ON((intermediate->sr.plane > |
| 1455 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1456 | intermediate->sr.cursor > |
| 1457 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1458 | intermediate->cxsr); |
| 1459 | WARN_ON((intermediate->sr.plane > |
| 1460 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1461 | intermediate->sr.cursor > |
| 1462 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1463 | intermediate->hpll_en); |
| 1464 | |
| 1465 | WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1466 | intermediate->fbc_en && intermediate->cxsr); |
| 1467 | WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1468 | intermediate->fbc_en && intermediate->hpll_en); |
| 1469 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1470 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1471 | /* |
| 1472 | * If our intermediate WM are identical to the final WM, then we can |
| 1473 | * omit the post-vblank programming; only update if it's different. |
| 1474 | */ |
| 1475 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1476 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1477 | |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
| 1481 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1482 | struct g4x_wm_values *wm) |
| 1483 | { |
| 1484 | struct intel_crtc *crtc; |
| 1485 | int num_active_crtcs = 0; |
| 1486 | |
| 1487 | wm->cxsr = true; |
| 1488 | wm->hpll_en = true; |
| 1489 | wm->fbc_en = true; |
| 1490 | |
| 1491 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1492 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1493 | |
| 1494 | if (!crtc->active) |
| 1495 | continue; |
| 1496 | |
| 1497 | if (!wm_state->cxsr) |
| 1498 | wm->cxsr = false; |
| 1499 | if (!wm_state->hpll_en) |
| 1500 | wm->hpll_en = false; |
| 1501 | if (!wm_state->fbc_en) |
| 1502 | wm->fbc_en = false; |
| 1503 | |
| 1504 | num_active_crtcs++; |
| 1505 | } |
| 1506 | |
| 1507 | if (num_active_crtcs != 1) { |
| 1508 | wm->cxsr = false; |
| 1509 | wm->hpll_en = false; |
| 1510 | wm->fbc_en = false; |
| 1511 | } |
| 1512 | |
| 1513 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1514 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1515 | enum pipe pipe = crtc->pipe; |
| 1516 | |
| 1517 | wm->pipe[pipe] = wm_state->wm; |
| 1518 | if (crtc->active && wm->cxsr) |
| 1519 | wm->sr = wm_state->sr; |
| 1520 | if (crtc->active && wm->hpll_en) |
| 1521 | wm->hpll = wm_state->hpll; |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1526 | { |
| 1527 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1528 | struct g4x_wm_values new_wm = {}; |
| 1529 | |
| 1530 | g4x_merge_wm(dev_priv, &new_wm); |
| 1531 | |
| 1532 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1533 | return; |
| 1534 | |
| 1535 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1536 | _intel_set_memory_cxsr(dev_priv, false); |
| 1537 | |
| 1538 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1539 | |
| 1540 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1541 | _intel_set_memory_cxsr(dev_priv, true); |
| 1542 | |
| 1543 | *old_wm = new_wm; |
| 1544 | } |
| 1545 | |
| 1546 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
| 1547 | struct intel_crtc_state *crtc_state) |
| 1548 | { |
| 1549 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1550 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1551 | |
| 1552 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1553 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1554 | g4x_program_watermarks(dev_priv); |
| 1555 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1556 | } |
| 1557 | |
| 1558 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
| 1559 | struct intel_crtc_state *crtc_state) |
| 1560 | { |
| 1561 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1562 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1563 | |
| 1564 | if (!crtc_state->wm.need_postvbl_update) |
| 1565 | return; |
| 1566 | |
| 1567 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1568 | intel_crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 1569 | g4x_program_watermarks(dev_priv); |
| 1570 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1571 | } |
| 1572 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1573 | /* latency must be in 0.1us units. */ |
| 1574 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1575 | unsigned int htotal, |
| 1576 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1577 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1578 | unsigned int latency) |
| 1579 | { |
| 1580 | unsigned int ret; |
| 1581 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1582 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1583 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1584 | ret = DIV_ROUND_UP(ret, 64); |
| 1585 | |
| 1586 | return ret; |
| 1587 | } |
| 1588 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1589 | 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] | 1590 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1591 | /* all latencies in usec */ |
| 1592 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1593 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1594 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1595 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1596 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1597 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1598 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1599 | |
| 1600 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1601 | } |
| 1602 | } |
| 1603 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1604 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1605 | const struct intel_plane_state *plane_state, |
| 1606 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1607 | { |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1608 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1609 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1610 | const struct drm_display_mode *adjusted_mode = |
| 1611 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1612 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1613 | |
| 1614 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1615 | return USHRT_MAX; |
| 1616 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1617 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1618 | return 0; |
| 1619 | |
Daniel Vetter | ef426c1 | 2017-01-04 11:41:10 +0100 | [diff] [blame] | 1620 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1621 | clock = adjusted_mode->crtc_clock; |
| 1622 | htotal = adjusted_mode->crtc_htotal; |
| 1623 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1624 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1625 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1626 | /* |
| 1627 | * FIXME the formula gives values that are |
| 1628 | * too big for the cursor FIFO, and hence we |
| 1629 | * would never be able to use cursors. For |
| 1630 | * now just hardcode the watermark. |
| 1631 | */ |
| 1632 | wm = 63; |
| 1633 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1634 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1635 | dev_priv->wm.pri_latency[level] * 10); |
| 1636 | } |
| 1637 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1638 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1639 | } |
| 1640 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1641 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1642 | { |
| 1643 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1644 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1645 | } |
| 1646 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1647 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1648 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1649 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1650 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1651 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1652 | 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] | 1653 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1654 | int num_active_planes = hweight32(active_planes); |
| 1655 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1656 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1657 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1658 | unsigned int total_rate; |
| 1659 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1660 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1661 | /* |
| 1662 | * When enabling sprite0 after sprite1 has already been enabled |
| 1663 | * we tend to get an underrun unless sprite0 already has some |
| 1664 | * FIFO space allcoated. Hence we always allocate at least one |
| 1665 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1666 | * |
| 1667 | * All other plane enable sequences appear immune to this problem. |
| 1668 | */ |
| 1669 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1670 | sprite0_fifo_extra = 1; |
| 1671 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1672 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1673 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1674 | raw->plane[PLANE_SPRITE1] + |
| 1675 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1676 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1677 | if (total_rate > fifo_size) |
| 1678 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1679 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1680 | if (total_rate == 0) |
| 1681 | total_rate = 1; |
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 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1684 | unsigned int rate; |
| 1685 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1686 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1687 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1688 | continue; |
| 1689 | } |
| 1690 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1691 | rate = raw->plane[plane_id]; |
| 1692 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1693 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1694 | } |
| 1695 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1696 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1697 | fifo_left -= sprite0_fifo_extra; |
| 1698 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1699 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1700 | |
| 1701 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1702 | |
| 1703 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1704 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1705 | int plane_extra; |
| 1706 | |
| 1707 | if (fifo_left == 0) |
| 1708 | break; |
| 1709 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1710 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1711 | continue; |
| 1712 | |
| 1713 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1714 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1715 | fifo_left -= plane_extra; |
| 1716 | } |
| 1717 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1718 | WARN_ON(active_planes != 0 && fifo_left != 0); |
| 1719 | |
| 1720 | /* give it all to the first plane if none are active */ |
| 1721 | if (active_planes == 0) { |
| 1722 | WARN_ON(fifo_left != fifo_size); |
| 1723 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1724 | } |
| 1725 | |
| 1726 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1727 | } |
| 1728 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1729 | /* mark all levels starting from 'level' as invalid */ |
| 1730 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1731 | struct vlv_wm_state *wm_state, int level) |
| 1732 | { |
| 1733 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1734 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1735 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1736 | enum plane_id plane_id; |
| 1737 | |
| 1738 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1739 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1740 | |
| 1741 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1742 | wm_state->sr[level].plane = USHRT_MAX; |
| 1743 | } |
| 1744 | } |
| 1745 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1746 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1747 | { |
| 1748 | if (wm > fifo_size) |
| 1749 | return USHRT_MAX; |
| 1750 | else |
| 1751 | return fifo_size - wm; |
| 1752 | } |
| 1753 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1754 | /* |
| 1755 | * Starting from 'level' set all higher |
| 1756 | * levels to 'value' in the "raw" watermarks. |
| 1757 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1758 | 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] | 1759 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1760 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1761 | 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] | 1762 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1763 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1764 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1765 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1766 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1767 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1768 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1769 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1770 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1771 | |
| 1772 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1773 | } |
| 1774 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1775 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1776 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1777 | { |
| 1778 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1779 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1780 | 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] | 1781 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1782 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1783 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1784 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1785 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1786 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1790 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1791 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1792 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1793 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1794 | if (wm > max_wm) |
| 1795 | break; |
| 1796 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1797 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1798 | raw->plane[plane_id] = wm; |
| 1799 | } |
| 1800 | |
| 1801 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1802 | 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] | 1803 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1804 | out: |
| 1805 | if (dirty) |
Ville Syrjälä | 57a6528 | 2017-04-21 21:14:22 +0300 | [diff] [blame] | 1806 | 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] | 1807 | plane->base.name, |
| 1808 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1809 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1810 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
| 1811 | |
| 1812 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1813 | } |
| 1814 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1815 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1816 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1817 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1818 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1819 | &crtc_state->wm.vlv.raw[level]; |
| 1820 | const struct vlv_fifo_state *fifo_state = |
| 1821 | &crtc_state->wm.vlv.fifo_state; |
| 1822 | |
| 1823 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1824 | } |
| 1825 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1826 | 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] | 1827 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1828 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1829 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1830 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1831 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | 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] | 1835 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1836 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1837 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1838 | struct intel_atomic_state *state = |
| 1839 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1840 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1841 | const struct vlv_fifo_state *fifo_state = |
| 1842 | &crtc_state->wm.vlv.fifo_state; |
| 1843 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1844 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1845 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->base); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1846 | const struct intel_plane_state *old_plane_state; |
| 1847 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1848 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1849 | enum plane_id plane_id; |
| 1850 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1851 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1852 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1853 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1854 | old_plane_state, |
| 1855 | new_plane_state, i) { |
| 1856 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1857 | old_plane_state->base.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1858 | continue; |
| 1859 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1860 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1861 | dirty |= BIT(plane->id); |
| 1862 | } |
| 1863 | |
| 1864 | /* |
| 1865 | * DSPARB registers may have been reset due to the |
| 1866 | * power well being turned off. Make sure we restore |
| 1867 | * them to a consistent state even if no primary/sprite |
| 1868 | * planes are initially active. |
| 1869 | */ |
| 1870 | if (needs_modeset) |
| 1871 | crtc_state->fifo_changed = true; |
| 1872 | |
| 1873 | if (!dirty) |
| 1874 | return 0; |
| 1875 | |
| 1876 | /* cursor changes don't warrant a FIFO recompute */ |
| 1877 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1878 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1879 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1880 | const struct vlv_fifo_state *old_fifo_state = |
| 1881 | &old_crtc_state->wm.vlv.fifo_state; |
| 1882 | |
| 1883 | ret = vlv_compute_fifo(crtc_state); |
| 1884 | if (ret) |
| 1885 | return ret; |
| 1886 | |
| 1887 | if (needs_modeset || |
| 1888 | memcmp(old_fifo_state, fifo_state, |
| 1889 | sizeof(*fifo_state)) != 0) |
| 1890 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1891 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1892 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1893 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1894 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1895 | /* |
| 1896 | * Note that enabling cxsr with no primary/sprite planes |
| 1897 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1898 | * with exactly one enabled primary/sprite plane. |
| 1899 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1900 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1901 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1902 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1903 | 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] | 1904 | 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] | 1905 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1906 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1907 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1908 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1909 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1910 | wm_state->wm[level].plane[plane_id] = |
| 1911 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1912 | fifo_state->plane[plane_id]); |
| 1913 | } |
| 1914 | |
| 1915 | wm_state->sr[level].plane = |
| 1916 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1917 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1918 | raw->plane[PLANE_SPRITE1]), |
| 1919 | sr_fifo_size); |
| 1920 | |
| 1921 | wm_state->sr[level].cursor = |
| 1922 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1923 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1924 | } |
| 1925 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1926 | if (level == 0) |
| 1927 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1928 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1929 | /* limit to only levels we can actually handle */ |
| 1930 | wm_state->num_levels = level; |
| 1931 | |
| 1932 | /* invalidate the higher levels */ |
| 1933 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1934 | |
| 1935 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1936 | } |
| 1937 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1938 | #define VLV_FIFO(plane, value) \ |
| 1939 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1940 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1941 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
| 1942 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1943 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1944 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1945 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1946 | const struct vlv_fifo_state *fifo_state = |
| 1947 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1948 | int sprite0_start, sprite1_start, fifo_size; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1949 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1950 | if (!crtc_state->fifo_changed) |
| 1951 | return; |
| 1952 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1953 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 1954 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 1955 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1956 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1957 | WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63); |
| 1958 | WARN_ON(fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1959 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1960 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 1961 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1962 | /* |
| 1963 | * uncore.lock serves a double purpose here. It allows us to |
| 1964 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 1965 | * it protects the DSPARB registers from getting clobbered by |
| 1966 | * parallel updates from multiple pipes. |
| 1967 | * |
| 1968 | * intel_pipe_update_start() has already disabled interrupts |
| 1969 | * for us, so a plain spin_lock() is sufficient here. |
| 1970 | */ |
| 1971 | spin_lock(&dev_priv->uncore.lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1972 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1973 | switch (crtc->pipe) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1974 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1975 | case PIPE_A: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1976 | dsparb = I915_READ_FW(DSPARB); |
| 1977 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1978 | |
| 1979 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1980 | VLV_FIFO(SPRITEB, 0xff)); |
| 1981 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1982 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1983 | |
| 1984 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1985 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1986 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1987 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1988 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1989 | I915_WRITE_FW(DSPARB, dsparb); |
| 1990 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1991 | break; |
| 1992 | case PIPE_B: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1993 | dsparb = I915_READ_FW(DSPARB); |
| 1994 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1995 | |
| 1996 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 1997 | VLV_FIFO(SPRITED, 0xff)); |
| 1998 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 1999 | VLV_FIFO(SPRITED, sprite1_start)); |
| 2000 | |
| 2001 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 2002 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 2003 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 2004 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 2005 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2006 | I915_WRITE_FW(DSPARB, dsparb); |
| 2007 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2008 | break; |
| 2009 | case PIPE_C: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2010 | dsparb3 = I915_READ_FW(DSPARB3); |
| 2011 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2012 | |
| 2013 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2014 | VLV_FIFO(SPRITEF, 0xff)); |
| 2015 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2016 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2017 | |
| 2018 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2019 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2020 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2021 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2022 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2023 | I915_WRITE_FW(DSPARB3, dsparb3); |
| 2024 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2025 | break; |
| 2026 | default: |
| 2027 | break; |
| 2028 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2029 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2030 | POSTING_READ_FW(DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2031 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2032 | spin_unlock(&dev_priv->uncore.lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | #undef VLV_FIFO |
| 2036 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2037 | 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] | 2038 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2039 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2040 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2041 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
| 2042 | struct intel_atomic_state *intel_state = |
| 2043 | to_intel_atomic_state(new_crtc_state->base.state); |
| 2044 | const struct intel_crtc_state *old_crtc_state = |
| 2045 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 2046 | 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] | 2047 | int level; |
| 2048 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2049 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 2050 | *intermediate = *optimal; |
| 2051 | |
| 2052 | intermediate->cxsr = false; |
| 2053 | goto out; |
| 2054 | } |
| 2055 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2056 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2057 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2058 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2059 | |
| 2060 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2061 | enum plane_id plane_id; |
| 2062 | |
| 2063 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2064 | intermediate->wm[level].plane[plane_id] = |
| 2065 | min(optimal->wm[level].plane[plane_id], |
| 2066 | active->wm[level].plane[plane_id]); |
| 2067 | } |
| 2068 | |
| 2069 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2070 | active->sr[level].plane); |
| 2071 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2072 | active->sr[level].cursor); |
| 2073 | } |
| 2074 | |
| 2075 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2076 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2077 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2078 | /* |
| 2079 | * If our intermediate WM are identical to the final WM, then we can |
| 2080 | * omit the post-vblank programming; only update if it's different. |
| 2081 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2082 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2083 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2084 | |
| 2085 | return 0; |
| 2086 | } |
| 2087 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2088 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2089 | struct vlv_wm_values *wm) |
| 2090 | { |
| 2091 | struct intel_crtc *crtc; |
| 2092 | int num_active_crtcs = 0; |
| 2093 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2094 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2095 | wm->cxsr = true; |
| 2096 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2097 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2098 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2099 | |
| 2100 | if (!crtc->active) |
| 2101 | continue; |
| 2102 | |
| 2103 | if (!wm_state->cxsr) |
| 2104 | wm->cxsr = false; |
| 2105 | |
| 2106 | num_active_crtcs++; |
| 2107 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2108 | } |
| 2109 | |
| 2110 | if (num_active_crtcs != 1) |
| 2111 | wm->cxsr = false; |
| 2112 | |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2113 | if (num_active_crtcs > 1) |
| 2114 | wm->level = VLV_WM_LEVEL_PM2; |
| 2115 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2116 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2117 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2118 | enum pipe pipe = crtc->pipe; |
| 2119 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2120 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2121 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2122 | wm->sr = wm_state->sr[wm->level]; |
| 2123 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2124 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2125 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2126 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2127 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2128 | } |
| 2129 | } |
| 2130 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2131 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2132 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2133 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2134 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2135 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2136 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2137 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2138 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2139 | return; |
| 2140 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2141 | 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] | 2142 | chv_set_memory_dvfs(dev_priv, false); |
| 2143 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2144 | 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] | 2145 | chv_set_memory_pm5(dev_priv, false); |
| 2146 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2147 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2148 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2149 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2150 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2151 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2152 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2153 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2154 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2155 | 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] | 2156 | chv_set_memory_pm5(dev_priv, true); |
| 2157 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2158 | 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] | 2159 | chv_set_memory_dvfs(dev_priv, true); |
| 2160 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2161 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2162 | } |
| 2163 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2164 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
| 2165 | struct intel_crtc_state *crtc_state) |
| 2166 | { |
| 2167 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2168 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2169 | |
| 2170 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2171 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2172 | vlv_program_watermarks(dev_priv); |
| 2173 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2174 | } |
| 2175 | |
| 2176 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
| 2177 | struct intel_crtc_state *crtc_state) |
| 2178 | { |
| 2179 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2181 | |
| 2182 | if (!crtc_state->wm.need_postvbl_update) |
| 2183 | return; |
| 2184 | |
| 2185 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 2186 | intel_crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2187 | vlv_program_watermarks(dev_priv); |
| 2188 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2189 | } |
| 2190 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2191 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2192 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2193 | 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] | 2194 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2195 | int srwm = 1; |
| 2196 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2197 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2198 | |
| 2199 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2200 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2201 | if (crtc) { |
| 2202 | /* self-refresh has much higher latency */ |
| 2203 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2204 | const struct drm_display_mode *adjusted_mode = |
| 2205 | &crtc->config->base.adjusted_mode; |
| 2206 | const struct drm_framebuffer *fb = |
| 2207 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2208 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2209 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2210 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2211 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2212 | int entries; |
| 2213 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2214 | entries = intel_wm_method2(clock, htotal, |
| 2215 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2216 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2217 | srwm = I965_FIFO_SIZE - entries; |
| 2218 | if (srwm < 0) |
| 2219 | srwm = 1; |
| 2220 | srwm &= 0x1ff; |
| 2221 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 2222 | entries, srwm); |
| 2223 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2224 | entries = intel_wm_method2(clock, htotal, |
| 2225 | crtc->base.cursor->state->crtc_w, 4, |
| 2226 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2227 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2228 | i965_cursor_wm_info.cacheline_size) + |
| 2229 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2230 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2231 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2232 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2233 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2234 | |
| 2235 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 2236 | "cursor %d\n", srwm, cursor_sr); |
| 2237 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2238 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2239 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2240 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2241 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2242 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2246 | srwm); |
| 2247 | |
| 2248 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2249 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2250 | FW_WM(8, CURSORB) | |
| 2251 | FW_WM(8, PLANEB) | |
| 2252 | FW_WM(8, PLANEA)); |
| 2253 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2254 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2255 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2256 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2257 | |
| 2258 | if (cxsr_enabled) |
| 2259 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2260 | } |
| 2261 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2262 | #undef FW_WM |
| 2263 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2264 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2265 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2266 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2267 | const struct intel_watermark_params *wm_info; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2268 | u32 fwater_lo; |
| 2269 | u32 fwater_hi; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2270 | int cwm, srwm = 1; |
| 2271 | int fifo_size; |
| 2272 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2273 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2274 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2275 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2276 | wm_info = &i945_wm_info; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2277 | else if (!IS_GEN(dev_priv, 2)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2278 | wm_info = &i915_wm_info; |
| 2279 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2280 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2281 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2282 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_A); |
| 2283 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2284 | if (intel_crtc_active(crtc)) { |
| 2285 | const struct drm_display_mode *adjusted_mode = |
| 2286 | &crtc->config->base.adjusted_mode; |
| 2287 | const struct drm_framebuffer *fb = |
| 2288 | crtc->base.primary->state->fb; |
| 2289 | int cpp; |
| 2290 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2291 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2292 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2293 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2294 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2295 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2296 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2297 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2298 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2299 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2300 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2301 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2302 | if (planea_wm > (long)wm_info->max_wm) |
| 2303 | planea_wm = wm_info->max_wm; |
| 2304 | } |
| 2305 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2306 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2307 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2308 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2309 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_B); |
| 2310 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2311 | if (intel_crtc_active(crtc)) { |
| 2312 | const struct drm_display_mode *adjusted_mode = |
| 2313 | &crtc->config->base.adjusted_mode; |
| 2314 | const struct drm_framebuffer *fb = |
| 2315 | crtc->base.primary->state->fb; |
| 2316 | int cpp; |
| 2317 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2318 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2319 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2320 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2321 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2322 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2323 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2324 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2325 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2326 | if (enabled == NULL) |
| 2327 | enabled = crtc; |
| 2328 | else |
| 2329 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2330 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2331 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2332 | if (planeb_wm > (long)wm_info->max_wm) |
| 2333 | planeb_wm = wm_info->max_wm; |
| 2334 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2335 | |
| 2336 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2337 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2338 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2339 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2340 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2341 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2342 | |
| 2343 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2344 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2345 | enabled = NULL; |
| 2346 | } |
| 2347 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2348 | /* |
| 2349 | * Overlay gets an aggressive default since video jitter is bad. |
| 2350 | */ |
| 2351 | cwm = 2; |
| 2352 | |
| 2353 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2354 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2355 | |
| 2356 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2357 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2358 | /* self-refresh has much higher latency */ |
| 2359 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2360 | const struct drm_display_mode *adjusted_mode = |
| 2361 | &enabled->config->base.adjusted_mode; |
| 2362 | const struct drm_framebuffer *fb = |
| 2363 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2364 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2365 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2366 | int hdisplay = enabled->config->pipe_src_w; |
| 2367 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2368 | int entries; |
| 2369 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2370 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2371 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2372 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2373 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2374 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2375 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2376 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2377 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 2378 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 2379 | srwm = wm_info->fifo_size - entries; |
| 2380 | if (srwm < 0) |
| 2381 | srwm = 1; |
| 2382 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2383 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2384 | I915_WRITE(FW_BLC_SELF, |
| 2385 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2386 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2387 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2388 | } |
| 2389 | |
| 2390 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2391 | planea_wm, planeb_wm, cwm, srwm); |
| 2392 | |
| 2393 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2394 | fwater_hi = (cwm & 0x1f); |
| 2395 | |
| 2396 | /* Set request length to 8 cachelines per fetch */ |
| 2397 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2398 | fwater_hi = fwater_hi | (1 << 8); |
| 2399 | |
| 2400 | I915_WRITE(FW_BLC, fwater_lo); |
| 2401 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2402 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2403 | if (enabled) |
| 2404 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2405 | } |
| 2406 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2407 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2408 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2409 | 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] | 2410 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2411 | const struct drm_display_mode *adjusted_mode; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2412 | u32 fwater_lo; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2413 | int planea_wm; |
| 2414 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2415 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2416 | if (crtc == NULL) |
| 2417 | return; |
| 2418 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2419 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2420 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2421 | &i845_wm_info, |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2422 | dev_priv->display.get_fifo_size(dev_priv, PLANE_A), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2423 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2424 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2425 | fwater_lo |= (3<<8) | planea_wm; |
| 2426 | |
| 2427 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 2428 | |
| 2429 | I915_WRITE(FW_BLC, fwater_lo); |
| 2430 | } |
| 2431 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2432 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2433 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2434 | unsigned int cpp, |
| 2435 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2436 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2437 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2438 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2439 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2440 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2441 | |
| 2442 | return ret; |
| 2443 | } |
| 2444 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2445 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2446 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2447 | unsigned int htotal, |
| 2448 | unsigned int width, |
| 2449 | unsigned int cpp, |
| 2450 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2451 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2452 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2453 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2454 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2455 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2456 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2457 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2458 | return ret; |
| 2459 | } |
| 2460 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2461 | 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] | 2462 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2463 | /* |
| 2464 | * Neither of these should be possible since this function shouldn't be |
| 2465 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2466 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2467 | * elsewhere in the driver. |
| 2468 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2469 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2470 | return 0; |
| 2471 | if (WARN_ON(!horiz_pixels)) |
| 2472 | return 0; |
| 2473 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2474 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2475 | } |
| 2476 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2477 | struct ilk_wm_maximums { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2478 | u16 pri; |
| 2479 | u16 spr; |
| 2480 | u16 cur; |
| 2481 | u16 fbc; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2482 | }; |
| 2483 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2484 | /* |
| 2485 | * For both WM_PIPE and WM_LP. |
| 2486 | * mem_value must be in 0.1us units. |
| 2487 | */ |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2488 | static u32 ilk_compute_pri_wm(const struct intel_crtc_state *cstate, |
| 2489 | const struct intel_plane_state *pstate, |
| 2490 | u32 mem_value, bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2491 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2492 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2493 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2494 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2495 | if (mem_value == 0) |
| 2496 | return U32_MAX; |
| 2497 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2498 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2499 | return 0; |
| 2500 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2501 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2502 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2503 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2504 | |
| 2505 | if (!is_lp) |
| 2506 | return method1; |
| 2507 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2508 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2509 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2510 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2511 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2512 | |
| 2513 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2514 | } |
| 2515 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2516 | /* |
| 2517 | * For both WM_PIPE and WM_LP. |
| 2518 | * mem_value must be in 0.1us units. |
| 2519 | */ |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2520 | static u32 ilk_compute_spr_wm(const struct intel_crtc_state *cstate, |
| 2521 | const struct intel_plane_state *pstate, |
| 2522 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2523 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2524 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2525 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2526 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2527 | if (mem_value == 0) |
| 2528 | return U32_MAX; |
| 2529 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2530 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2531 | return 0; |
| 2532 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2533 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2534 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2535 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
| 2536 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2537 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2538 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2539 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2540 | return min(method1, method2); |
| 2541 | } |
| 2542 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2543 | /* |
| 2544 | * For both WM_PIPE and WM_LP. |
| 2545 | * mem_value must be in 0.1us units. |
| 2546 | */ |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2547 | static u32 ilk_compute_cur_wm(const struct intel_crtc_state *cstate, |
| 2548 | const struct intel_plane_state *pstate, |
| 2549 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2550 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2551 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2552 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2553 | if (mem_value == 0) |
| 2554 | return U32_MAX; |
| 2555 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2556 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2557 | return 0; |
| 2558 | |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2559 | cpp = pstate->base.fb->format->cpp[0]; |
| 2560 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2561 | return ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2562 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2563 | pstate->base.crtc_w, cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2564 | } |
| 2565 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2566 | /* Only for WM_LP. */ |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2567 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
| 2568 | const struct intel_plane_state *pstate, |
| 2569 | u32 pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2570 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2571 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2572 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2573 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2574 | return 0; |
| 2575 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2576 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2577 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2578 | 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] | 2579 | } |
| 2580 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2581 | static unsigned int |
| 2582 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2583 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2584 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2585 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2586 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2587 | return 768; |
| 2588 | else |
| 2589 | return 512; |
| 2590 | } |
| 2591 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2592 | static unsigned int |
| 2593 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2594 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2595 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2596 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2597 | /* BDW primary/sprite plane watermarks */ |
| 2598 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2599 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2600 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2601 | return level == 0 ? 127 : 1023; |
| 2602 | else if (!is_sprite) |
| 2603 | /* ILK/SNB primary plane watermarks */ |
| 2604 | return level == 0 ? 127 : 511; |
| 2605 | else |
| 2606 | /* ILK/SNB sprite plane watermarks */ |
| 2607 | return level == 0 ? 63 : 255; |
| 2608 | } |
| 2609 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2610 | static unsigned int |
| 2611 | 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] | 2612 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2613 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2614 | return level == 0 ? 63 : 255; |
| 2615 | else |
| 2616 | return level == 0 ? 31 : 63; |
| 2617 | } |
| 2618 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2619 | 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] | 2620 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2621 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2622 | return 31; |
| 2623 | else |
| 2624 | return 15; |
| 2625 | } |
| 2626 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2627 | /* Calculate the maximum primary/sprite plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2628 | 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] | 2629 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2630 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2631 | enum intel_ddb_partitioning ddb_partitioning, |
| 2632 | bool is_sprite) |
| 2633 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2634 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2635 | |
| 2636 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2637 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2638 | return 0; |
| 2639 | |
| 2640 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2641 | if (level == 0 || config->num_pipes_active > 1) { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2642 | fifo_size /= INTEL_INFO(dev_priv)->num_pipes; |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2643 | |
| 2644 | /* |
| 2645 | * For some reason the non self refresh |
| 2646 | * FIFO size is only half of the self |
| 2647 | * refresh FIFO size on ILK/SNB. |
| 2648 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2649 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2650 | fifo_size /= 2; |
| 2651 | } |
| 2652 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2653 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2654 | /* level 0 is always calculated with 1:1 split */ |
| 2655 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2656 | if (is_sprite) |
| 2657 | fifo_size *= 5; |
| 2658 | fifo_size /= 6; |
| 2659 | } else { |
| 2660 | fifo_size /= 2; |
| 2661 | } |
| 2662 | } |
| 2663 | |
| 2664 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2665 | 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] | 2666 | } |
| 2667 | |
| 2668 | /* Calculate the maximum cursor plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2669 | 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] | 2670 | int level, |
| 2671 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2672 | { |
| 2673 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2674 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2675 | return 64; |
| 2676 | |
| 2677 | /* otherwise just report max that registers can hold */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2678 | return ilk_cursor_wm_reg_max(dev_priv, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2679 | } |
| 2680 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2681 | 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] | 2682 | int level, |
| 2683 | const struct intel_wm_config *config, |
| 2684 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2685 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2686 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2687 | max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false); |
| 2688 | max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true); |
| 2689 | max->cur = ilk_cursor_wm_max(dev_priv, level, config); |
| 2690 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2691 | } |
| 2692 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2693 | 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] | 2694 | int level, |
| 2695 | struct ilk_wm_maximums *max) |
| 2696 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2697 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2698 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2699 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2700 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2701 | } |
| 2702 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2703 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2704 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2705 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2706 | { |
| 2707 | bool ret; |
| 2708 | |
| 2709 | /* already determined to be invalid? */ |
| 2710 | if (!result->enable) |
| 2711 | return false; |
| 2712 | |
| 2713 | result->enable = result->pri_val <= max->pri && |
| 2714 | result->spr_val <= max->spr && |
| 2715 | result->cur_val <= max->cur; |
| 2716 | |
| 2717 | ret = result->enable; |
| 2718 | |
| 2719 | /* |
| 2720 | * HACK until we can pre-compute everything, |
| 2721 | * and thus fail gracefully if LP0 watermarks |
| 2722 | * are exceeded... |
| 2723 | */ |
| 2724 | if (level == 0 && !result->enable) { |
| 2725 | if (result->pri_val > max->pri) |
| 2726 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2727 | level, result->pri_val, max->pri); |
| 2728 | if (result->spr_val > max->spr) |
| 2729 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2730 | level, result->spr_val, max->spr); |
| 2731 | if (result->cur_val > max->cur) |
| 2732 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2733 | level, result->cur_val, max->cur); |
| 2734 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2735 | result->pri_val = min_t(u32, result->pri_val, max->pri); |
| 2736 | result->spr_val = min_t(u32, result->spr_val, max->spr); |
| 2737 | result->cur_val = min_t(u32, result->cur_val, max->cur); |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2738 | result->enable = true; |
| 2739 | } |
| 2740 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2741 | return ret; |
| 2742 | } |
| 2743 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2744 | 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] | 2745 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2746 | int level, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2747 | struct intel_crtc_state *cstate, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2748 | const struct intel_plane_state *pristate, |
| 2749 | const struct intel_plane_state *sprstate, |
| 2750 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2751 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2752 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2753 | u16 pri_latency = dev_priv->wm.pri_latency[level]; |
| 2754 | u16 spr_latency = dev_priv->wm.spr_latency[level]; |
| 2755 | u16 cur_latency = dev_priv->wm.cur_latency[level]; |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2756 | |
| 2757 | /* WM1+ latency values stored in 0.5us units */ |
| 2758 | if (level > 0) { |
| 2759 | pri_latency *= 5; |
| 2760 | spr_latency *= 5; |
| 2761 | cur_latency *= 5; |
| 2762 | } |
| 2763 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2764 | if (pristate) { |
| 2765 | result->pri_val = ilk_compute_pri_wm(cstate, pristate, |
| 2766 | pri_latency, level); |
| 2767 | result->fbc_val = ilk_compute_fbc_wm(cstate, pristate, result->pri_val); |
| 2768 | } |
| 2769 | |
| 2770 | if (sprstate) |
| 2771 | result->spr_val = ilk_compute_spr_wm(cstate, sprstate, spr_latency); |
| 2772 | |
| 2773 | if (curstate) |
| 2774 | result->cur_val = ilk_compute_cur_wm(cstate, curstate, cur_latency); |
| 2775 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2776 | result->enable = true; |
| 2777 | } |
| 2778 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2779 | static u32 |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2780 | hsw_compute_linetime_wm(const struct intel_crtc_state *cstate) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2781 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2782 | const struct intel_atomic_state *intel_state = |
| 2783 | to_intel_atomic_state(cstate->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2784 | const struct drm_display_mode *adjusted_mode = |
| 2785 | &cstate->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2786 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2787 | |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2788 | if (!cstate->base.active) |
| 2789 | return 0; |
| 2790 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2791 | return 0; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2792 | if (WARN_ON(intel_state->cdclk.logical.cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2793 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2794 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2795 | /* The WM are computed with base on how long it takes to fill a single |
| 2796 | * row at the given clock rate, multiplied by 8. |
| 2797 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2798 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2799 | adjusted_mode->crtc_clock); |
| 2800 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2801 | intel_state->cdclk.logical.cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2802 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2803 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2804 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2805 | } |
| 2806 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2807 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2808 | u16 wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2809 | { |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2810 | if (INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2811 | u32 val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2812 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2813 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2814 | |
| 2815 | /* read the first set of memory latencies[0:3] */ |
| 2816 | val = 0; /* data0 to be programmed to 0 for first set */ |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 2817 | mutex_lock(&dev_priv->pcu_lock); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2818 | ret = sandybridge_pcode_read(dev_priv, |
| 2819 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2820 | &val); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 2821 | mutex_unlock(&dev_priv->pcu_lock); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2822 | |
| 2823 | if (ret) { |
| 2824 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2825 | return; |
| 2826 | } |
| 2827 | |
| 2828 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2829 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2830 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2831 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2832 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2833 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2834 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2835 | |
| 2836 | /* read the second set of memory latencies[4:7] */ |
| 2837 | val = 1; /* data0 to be programmed to 1 for second set */ |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 2838 | mutex_lock(&dev_priv->pcu_lock); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2839 | ret = sandybridge_pcode_read(dev_priv, |
| 2840 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2841 | &val); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 2842 | mutex_unlock(&dev_priv->pcu_lock); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2843 | if (ret) { |
| 2844 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2845 | return; |
| 2846 | } |
| 2847 | |
| 2848 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2849 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2850 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2851 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2852 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2853 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2854 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2855 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2856 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2857 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2858 | * need to be disabled. We make sure to sanitize the values out |
| 2859 | * of the punit to satisfy this requirement. |
| 2860 | */ |
| 2861 | for (level = 1; level <= max_level; level++) { |
| 2862 | if (wm[level] == 0) { |
| 2863 | for (i = level + 1; i <= max_level; i++) |
| 2864 | wm[i] = 0; |
| 2865 | break; |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | /* |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2870 | * WaWmMemoryReadLatency:skl+,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2871 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2872 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2873 | * to add 2us to the various latency levels we retrieve from the |
| 2874 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2875 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2876 | if (wm[0] == 0) { |
| 2877 | wm[0] += 2; |
| 2878 | for (level = 1; level <= max_level; level++) { |
| 2879 | if (wm[level] == 0) |
| 2880 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2881 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2882 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2883 | } |
| 2884 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2885 | /* |
| 2886 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2887 | * If we could not get dimm info enable this WA to prevent from |
| 2888 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2889 | * to avoid any underrun. |
| 2890 | */ |
Ville Syrjälä | 5d6f36b | 2018-10-23 21:21:02 +0300 | [diff] [blame] | 2891 | if (dev_priv->dram_info.is_16gb_dimm) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2892 | wm[0] += 1; |
| 2893 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2894 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2895 | u64 sskpd = I915_READ64(MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2896 | |
| 2897 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2898 | if (wm[0] == 0) |
| 2899 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2900 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2901 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2902 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2903 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2904 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2905 | u32 sskpd = I915_READ(MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2906 | |
| 2907 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2908 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2909 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2910 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2911 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2912 | u32 mltr = I915_READ(MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2913 | |
| 2914 | /* ILK primary LP0 latency is 700 ns */ |
| 2915 | wm[0] = 7; |
| 2916 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2917 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2918 | } else { |
| 2919 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2920 | } |
| 2921 | } |
| 2922 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2923 | 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] | 2924 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2925 | { |
| 2926 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2927 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2928 | wm[0] = 13; |
| 2929 | } |
| 2930 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2931 | 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] | 2932 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2933 | { |
| 2934 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2935 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2936 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2937 | } |
| 2938 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2939 | 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] | 2940 | { |
| 2941 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2942 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2943 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2944 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2945 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2946 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2947 | return 3; |
| 2948 | else |
| 2949 | return 2; |
| 2950 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2951 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2952 | 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] | 2953 | const char *name, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2954 | const u16 wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2955 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2956 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2957 | |
| 2958 | for (level = 0; level <= max_level; level++) { |
| 2959 | unsigned int latency = wm[level]; |
| 2960 | |
| 2961 | if (latency == 0) { |
Chris Wilson | 86c1c87 | 2018-07-26 17:15:27 +0100 | [diff] [blame] | 2962 | DRM_DEBUG_KMS("%s WM%d latency not provided\n", |
| 2963 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2964 | continue; |
| 2965 | } |
| 2966 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2967 | /* |
| 2968 | * - latencies are in us on gen9. |
| 2969 | * - before then, WM1+ latency values are in 0.5us units |
| 2970 | */ |
Paulo Zanoni | dfc267a | 2017-08-09 13:52:46 -0700 | [diff] [blame] | 2971 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2972 | latency *= 10; |
| 2973 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2974 | latency *= 5; |
| 2975 | |
| 2976 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2977 | name, level, wm[level], |
| 2978 | latency / 10, latency % 10); |
| 2979 | } |
| 2980 | } |
| 2981 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2982 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2983 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2984 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2985 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2986 | |
| 2987 | if (wm[0] >= min) |
| 2988 | return false; |
| 2989 | |
| 2990 | wm[0] = max(wm[0], min); |
| 2991 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2992 | 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] | 2993 | |
| 2994 | return true; |
| 2995 | } |
| 2996 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2997 | 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] | 2998 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2999 | bool changed; |
| 3000 | |
| 3001 | /* |
| 3002 | * The BIOS provided WM memory latency values are often |
| 3003 | * inadequate for high resolution displays. Adjust them. |
| 3004 | */ |
| 3005 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 3006 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 3007 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 3008 | |
| 3009 | if (!changed) |
| 3010 | return; |
| 3011 | |
| 3012 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3013 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3014 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3015 | 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] | 3016 | } |
| 3017 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3018 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 3019 | { |
| 3020 | /* |
| 3021 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 3022 | * LP3 usage can cause vblank interrupts to be lost. |
| 3023 | * The DEIIR bit will go high but it looks like the CPU |
| 3024 | * never gets interrupted. |
| 3025 | * |
| 3026 | * It's not clear whether other interrupt source could |
| 3027 | * be affected or if this is somehow limited to vblank |
| 3028 | * interrupts only. To play it safe we disable LP3 |
| 3029 | * watermarks entirely. |
| 3030 | */ |
| 3031 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3032 | dev_priv->wm.spr_latency[3] == 0 && |
| 3033 | dev_priv->wm.cur_latency[3] == 0) |
| 3034 | return; |
| 3035 | |
| 3036 | dev_priv->wm.pri_latency[3] = 0; |
| 3037 | dev_priv->wm.spr_latency[3] = 0; |
| 3038 | dev_priv->wm.cur_latency[3] = 0; |
| 3039 | |
| 3040 | DRM_DEBUG_KMS("LP3 watermarks disabled due to potential for lost interrupts\n"); |
| 3041 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3042 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3043 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3044 | } |
| 3045 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3046 | 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] | 3047 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3048 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3049 | |
| 3050 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3051 | sizeof(dev_priv->wm.pri_latency)); |
| 3052 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3053 | sizeof(dev_priv->wm.pri_latency)); |
| 3054 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3055 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3056 | 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] | 3057 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3058 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3059 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3060 | 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] | 3061 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3062 | if (IS_GEN(dev_priv, 6)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3063 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3064 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3065 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3066 | } |
| 3067 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3068 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3069 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3070 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3071 | 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] | 3072 | } |
| 3073 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3074 | 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] | 3075 | struct intel_pipe_wm *pipe_wm) |
| 3076 | { |
| 3077 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3078 | const struct intel_wm_config config = { |
| 3079 | .num_pipes_active = 1, |
| 3080 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3081 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3082 | }; |
| 3083 | struct ilk_wm_maximums max; |
| 3084 | |
| 3085 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3086 | 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] | 3087 | |
| 3088 | /* At least LP0 must be valid */ |
| 3089 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 3090 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 3091 | return false; |
| 3092 | } |
| 3093 | |
| 3094 | return true; |
| 3095 | } |
| 3096 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3097 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3098 | static int ilk_compute_pipe_wm(struct intel_crtc_state *cstate) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3099 | { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3100 | struct drm_atomic_state *state = cstate->base.state; |
| 3101 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3102 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3103 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3104 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3105 | struct drm_plane *plane; |
| 3106 | const struct drm_plane_state *plane_state; |
| 3107 | const struct intel_plane_state *pristate = NULL; |
| 3108 | const struct intel_plane_state *sprstate = NULL; |
| 3109 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3110 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3111 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3112 | |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3113 | pipe_wm = &cstate->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3114 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3115 | drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, &cstate->base) { |
| 3116 | const struct intel_plane_state *ps = to_intel_plane_state(plane_state); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3117 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3118 | if (plane->type == DRM_PLANE_TYPE_PRIMARY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3119 | pristate = ps; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3120 | else if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3121 | sprstate = ps; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3122 | else if (plane->type == DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3123 | curstate = ps; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3126 | pipe_wm->pipe_enabled = cstate->base.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3127 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3128 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 3129 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 3130 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 3131 | 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] | 3132 | } |
| 3133 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3134 | usable_level = max_level; |
| 3135 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3136 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3137 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3138 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3139 | |
| 3140 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3141 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3142 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3143 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3144 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3145 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, cstate, |
| 3146 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3147 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3148 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 3149 | pipe_wm->linetime = hsw_compute_linetime_wm(cstate); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3150 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3151 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3152 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3153 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3154 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3155 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3156 | for (level = 1; level <= usable_level; level++) { |
| 3157 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3158 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3159 | ilk_compute_wm_level(dev_priv, intel_crtc, level, cstate, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3160 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3161 | |
| 3162 | /* |
| 3163 | * Disable any watermark level that exceeds the |
| 3164 | * register maximums since such watermarks are |
| 3165 | * always invalid. |
| 3166 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3167 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3168 | memset(wm, 0, sizeof(*wm)); |
| 3169 | break; |
| 3170 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3171 | } |
| 3172 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3173 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3177 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3178 | * state and the new state. These can be programmed to the hardware |
| 3179 | * immediately. |
| 3180 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3181 | static int ilk_compute_intermediate_wm(struct intel_crtc_state *newstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3182 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3183 | struct intel_crtc *intel_crtc = to_intel_crtc(newstate->base.crtc); |
| 3184 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3185 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3186 | struct intel_atomic_state *intel_state = |
| 3187 | to_intel_atomic_state(newstate->base.state); |
| 3188 | const struct intel_crtc_state *oldstate = |
| 3189 | intel_atomic_get_old_crtc_state(intel_state, intel_crtc); |
| 3190 | const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3191 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3192 | |
| 3193 | /* |
| 3194 | * Start with the final, target watermarks, then combine with the |
| 3195 | * currently active watermarks to get values that are safe both before |
| 3196 | * and after the vblank. |
| 3197 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3198 | *a = newstate->wm.ilk.optimal; |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 3199 | if (!newstate->base.active || drm_atomic_crtc_needs_modeset(&newstate->base) || |
| 3200 | intel_state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3201 | return 0; |
| 3202 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3203 | a->pipe_enabled |= b->pipe_enabled; |
| 3204 | a->sprites_enabled |= b->sprites_enabled; |
| 3205 | a->sprites_scaled |= b->sprites_scaled; |
| 3206 | |
| 3207 | for (level = 0; level <= max_level; level++) { |
| 3208 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3209 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3210 | |
| 3211 | a_wm->enable &= b_wm->enable; |
| 3212 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3213 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3214 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3215 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3216 | } |
| 3217 | |
| 3218 | /* |
| 3219 | * We need to make sure that these merged watermark values are |
| 3220 | * actually a valid configuration themselves. If they're not, |
| 3221 | * there's no safe way to transition from the old state to |
| 3222 | * the new state, so we need to fail the atomic transaction. |
| 3223 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3224 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3225 | return -EINVAL; |
| 3226 | |
| 3227 | /* |
| 3228 | * If our intermediate WM are identical to the final WM, then we can |
| 3229 | * omit the post-vblank programming; only update if it's different. |
| 3230 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3231 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3232 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3233 | |
| 3234 | return 0; |
| 3235 | } |
| 3236 | |
| 3237 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3238 | * Merge the watermarks from all active pipes for a specific level. |
| 3239 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3240 | 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] | 3241 | int level, |
| 3242 | struct intel_wm_level *ret_wm) |
| 3243 | { |
| 3244 | const struct intel_crtc *intel_crtc; |
| 3245 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3246 | ret_wm->enable = true; |
| 3247 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3248 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3249 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3250 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3251 | |
| 3252 | if (!active->pipe_enabled) |
| 3253 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3254 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3255 | /* |
| 3256 | * The watermark values may have been used in the past, |
| 3257 | * so we must maintain them in the registers for some |
| 3258 | * time even if the level is now disabled. |
| 3259 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3260 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3261 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3262 | |
| 3263 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3264 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3265 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3266 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3267 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | /* |
| 3271 | * Merge all low power watermarks for all active pipes. |
| 3272 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3273 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3274 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3275 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3276 | struct intel_pipe_wm *merged) |
| 3277 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3278 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3279 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3280 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3281 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3282 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3283 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3284 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3285 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3286 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3287 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3288 | |
| 3289 | /* merge each WM1+ level */ |
| 3290 | for (level = 1; level <= max_level; level++) { |
| 3291 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3292 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3293 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3294 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3295 | if (level > last_enabled_level) |
| 3296 | wm->enable = false; |
| 3297 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3298 | /* make sure all following levels get disabled */ |
| 3299 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3300 | |
| 3301 | /* |
| 3302 | * The spec says it is preferred to disable |
| 3303 | * FBC WMs instead of disabling a WM level. |
| 3304 | */ |
| 3305 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3306 | if (wm->enable) |
| 3307 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3308 | wm->fbc_val = 0; |
| 3309 | } |
| 3310 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3311 | |
| 3312 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3313 | /* |
| 3314 | * FIXME this is racy. FBC might get enabled later. |
| 3315 | * What we should check here is whether FBC can be |
| 3316 | * enabled sometime later. |
| 3317 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3318 | if (IS_GEN(dev_priv, 5) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3319 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3320 | for (level = 2; level <= max_level; level++) { |
| 3321 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3322 | |
| 3323 | wm->enable = false; |
| 3324 | } |
| 3325 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3326 | } |
| 3327 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3328 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3329 | { |
| 3330 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3331 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3332 | } |
| 3333 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3334 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3335 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3336 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3337 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3338 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3339 | return 2 * level; |
| 3340 | else |
| 3341 | return dev_priv->wm.pri_latency[level]; |
| 3342 | } |
| 3343 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3344 | 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] | 3345 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3346 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3347 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3348 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3349 | struct intel_crtc *intel_crtc; |
| 3350 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3351 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3352 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3353 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3354 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3355 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3356 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3357 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3358 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3359 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3360 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3361 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3362 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3363 | /* |
| 3364 | * Maintain the watermark values even if the level is |
| 3365 | * disabled. Doing otherwise could cause underruns. |
| 3366 | */ |
| 3367 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3368 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3369 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3370 | r->cur_val; |
| 3371 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3372 | if (r->enable) |
| 3373 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3374 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3375 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3376 | results->wm_lp[wm_lp - 1] |= |
| 3377 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3378 | else |
| 3379 | results->wm_lp[wm_lp - 1] |= |
| 3380 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3381 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3382 | /* |
| 3383 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3384 | * level is disabled. Doing otherwise could cause underruns. |
| 3385 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3386 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3387 | WARN_ON(wm_lp != 1); |
| 3388 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3389 | } else |
| 3390 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3391 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3392 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3393 | /* LP0 register values */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3394 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3395 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3396 | const struct intel_wm_level *r = |
| 3397 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3398 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3399 | if (WARN_ON(!r->enable)) |
| 3400 | continue; |
| 3401 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3402 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3403 | |
| 3404 | results->wm_pipe[pipe] = |
| 3405 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3406 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3407 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3408 | } |
| 3409 | } |
| 3410 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3411 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3412 | * 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] | 3413 | static struct intel_pipe_wm * |
| 3414 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3415 | struct intel_pipe_wm *r1, |
| 3416 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3417 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3418 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3419 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3420 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3421 | for (level = 1; level <= max_level; level++) { |
| 3422 | if (r1->wm[level].enable) |
| 3423 | level1 = level; |
| 3424 | if (r2->wm[level].enable) |
| 3425 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3426 | } |
| 3427 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3428 | if (level1 == level2) { |
| 3429 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3430 | return r2; |
| 3431 | else |
| 3432 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3433 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3434 | return r1; |
| 3435 | } else { |
| 3436 | return r2; |
| 3437 | } |
| 3438 | } |
| 3439 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3440 | /* dirty bits used to track which watermarks need changes */ |
| 3441 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 3442 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 3443 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3444 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3445 | #define WM_DIRTY_FBC (1 << 24) |
| 3446 | #define WM_DIRTY_DDB (1 << 25) |
| 3447 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3448 | 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] | 3449 | const struct ilk_wm_values *old, |
| 3450 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3451 | { |
| 3452 | unsigned int dirty = 0; |
| 3453 | enum pipe pipe; |
| 3454 | int wm_lp; |
| 3455 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3456 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3457 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 3458 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 3459 | /* Must disable LP1+ watermarks too */ |
| 3460 | dirty |= WM_DIRTY_LP_ALL; |
| 3461 | } |
| 3462 | |
| 3463 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3464 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3465 | /* Must disable LP1+ watermarks too */ |
| 3466 | dirty |= WM_DIRTY_LP_ALL; |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3471 | dirty |= WM_DIRTY_FBC; |
| 3472 | /* Must disable LP1+ watermarks too */ |
| 3473 | dirty |= WM_DIRTY_LP_ALL; |
| 3474 | } |
| 3475 | |
| 3476 | if (old->partitioning != new->partitioning) { |
| 3477 | dirty |= WM_DIRTY_DDB; |
| 3478 | /* Must disable LP1+ watermarks too */ |
| 3479 | dirty |= WM_DIRTY_LP_ALL; |
| 3480 | } |
| 3481 | |
| 3482 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3483 | if (dirty & WM_DIRTY_LP_ALL) |
| 3484 | return dirty; |
| 3485 | |
| 3486 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3487 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3488 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3489 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3490 | break; |
| 3491 | } |
| 3492 | |
| 3493 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3494 | for (; wm_lp <= 3; wm_lp++) |
| 3495 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3496 | |
| 3497 | return dirty; |
| 3498 | } |
| 3499 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3500 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3501 | unsigned int dirty) |
| 3502 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3503 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3504 | bool changed = false; |
| 3505 | |
| 3506 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3507 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3508 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3509 | changed = true; |
| 3510 | } |
| 3511 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3512 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3513 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3514 | changed = true; |
| 3515 | } |
| 3516 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3517 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3518 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3519 | changed = true; |
| 3520 | } |
| 3521 | |
| 3522 | /* |
| 3523 | * Don't touch WM1S_LP_EN here. |
| 3524 | * Doing so could cause underruns. |
| 3525 | */ |
| 3526 | |
| 3527 | return changed; |
| 3528 | } |
| 3529 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3530 | /* |
| 3531 | * The spec says we shouldn't write when we don't need, because every write |
| 3532 | * causes WMs to be re-evaluated, expending some power. |
| 3533 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3534 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3535 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3536 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3537 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3538 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3539 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3540 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3541 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3542 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3543 | return; |
| 3544 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3545 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3546 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3547 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3548 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3549 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3550 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3551 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3552 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 3553 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3554 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3555 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3556 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3557 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3558 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3559 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 3560 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3561 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3562 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3563 | val = I915_READ(WM_MISC); |
| 3564 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3565 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3566 | else |
| 3567 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3568 | I915_WRITE(WM_MISC, val); |
| 3569 | } else { |
| 3570 | val = I915_READ(DISP_ARB_CTL2); |
| 3571 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3572 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3573 | else |
| 3574 | val |= DISP_DATA_PARTITION_5_6; |
| 3575 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3576 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3577 | } |
| 3578 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3579 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3580 | val = I915_READ(DISP_ARB_CTL); |
| 3581 | if (results->enable_fbc_wm) |
| 3582 | val &= ~DISP_FBC_WM_DIS; |
| 3583 | else |
| 3584 | val |= DISP_FBC_WM_DIS; |
| 3585 | I915_WRITE(DISP_ARB_CTL, val); |
| 3586 | } |
| 3587 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3588 | if (dirty & WM_DIRTY_LP(1) && |
| 3589 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3590 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3591 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3592 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3593 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3594 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3595 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3596 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3597 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3598 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3599 | 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] | 3600 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3601 | 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] | 3602 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3603 | 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] | 3604 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3605 | |
| 3606 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3607 | } |
| 3608 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3609 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3610 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3611 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3612 | |
| 3613 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3614 | } |
| 3615 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3616 | static u8 intel_enabled_dbuf_slices_num(struct drm_i915_private *dev_priv) |
| 3617 | { |
| 3618 | u8 enabled_slices; |
| 3619 | |
| 3620 | /* Slice 1 will always be enabled */ |
| 3621 | enabled_slices = 1; |
| 3622 | |
| 3623 | /* Gen prior to GEN11 have only one DBuf slice */ |
| 3624 | if (INTEL_GEN(dev_priv) < 11) |
| 3625 | return enabled_slices; |
| 3626 | |
Imre Deak | 209d735 | 2019-03-07 12:32:35 +0200 | [diff] [blame] | 3627 | /* |
| 3628 | * FIXME: for now we'll only ever use 1 slice; pretend that we have |
| 3629 | * only that 1 slice enabled until we have a proper way for on-demand |
| 3630 | * toggling of the second slice. |
| 3631 | */ |
| 3632 | if (0 && I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3633 | enabled_slices++; |
| 3634 | |
| 3635 | return enabled_slices; |
| 3636 | } |
| 3637 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3638 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3639 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3640 | * so assume we'll always need it in order to avoid underruns. |
| 3641 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3642 | 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] | 3643 | { |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3644 | return IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3645 | } |
| 3646 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3647 | static bool |
| 3648 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3649 | { |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3650 | return (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) && |
| 3651 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3652 | } |
| 3653 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3654 | /* |
| 3655 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3656 | * depending on power and performance requirements. The display engine access |
| 3657 | * to system memory is blocked during the adjustment time. Because of the |
| 3658 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3659 | * underruns if we don't meet all of the following requirements: |
| 3660 | * |
| 3661 | * - <= 1 pipe enabled |
| 3662 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3663 | * - We're not using an interlaced display configuration |
| 3664 | */ |
| 3665 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3666 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3667 | { |
| 3668 | int ret; |
| 3669 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3670 | if (!intel_has_sagv(dev_priv)) |
| 3671 | return 0; |
| 3672 | |
| 3673 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3674 | return 0; |
| 3675 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3676 | DRM_DEBUG_KMS("Enabling SAGV\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 3677 | mutex_lock(&dev_priv->pcu_lock); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3678 | |
| 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 */ |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 3683 | mutex_unlock(&dev_priv->pcu_lock); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3684 | |
| 3685 | /* |
| 3686 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3687 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3688 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3689 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3690 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3691 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3692 | return 0; |
| 3693 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3694 | DRM_ERROR("Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3695 | return ret; |
| 3696 | } |
| 3697 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3698 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3699 | return 0; |
| 3700 | } |
| 3701 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3702 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3703 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3704 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3705 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3706 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3707 | if (!intel_has_sagv(dev_priv)) |
| 3708 | return 0; |
| 3709 | |
| 3710 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3711 | return 0; |
| 3712 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3713 | DRM_DEBUG_KMS("Disabling SAGV\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 3714 | mutex_lock(&dev_priv->pcu_lock); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3715 | |
| 3716 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3717 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3718 | GEN9_SAGV_DISABLE, |
| 3719 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3720 | 1); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 3721 | mutex_unlock(&dev_priv->pcu_lock); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3722 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3723 | /* |
| 3724 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3725 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3726 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3727 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3728 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3729 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3730 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3731 | } else if (ret < 0) { |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3732 | DRM_ERROR("Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3733 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3734 | } |
| 3735 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3736 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3737 | return 0; |
| 3738 | } |
| 3739 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3740 | bool intel_can_enable_sagv(struct drm_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3741 | { |
| 3742 | struct drm_device *dev = state->dev; |
| 3743 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3744 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3745 | struct intel_crtc *crtc; |
| 3746 | struct intel_plane *plane; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3747 | struct intel_crtc_state *cstate; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3748 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3749 | int level, latency; |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3750 | int sagv_block_time_us; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3751 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3752 | if (!intel_has_sagv(dev_priv)) |
| 3753 | return false; |
| 3754 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3755 | if (IS_GEN(dev_priv, 9)) |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3756 | sagv_block_time_us = 30; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3757 | else if (IS_GEN(dev_priv, 10)) |
Paulo Zanoni | 4357ce0 | 2018-01-30 11:49:15 -0200 | [diff] [blame] | 3758 | sagv_block_time_us = 20; |
| 3759 | else |
| 3760 | sagv_block_time_us = 10; |
| 3761 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3762 | /* |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3763 | * SKL+ workaround: bspec recommends we disable SAGV when we have |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3764 | * more then one pipe enabled |
| 3765 | * |
| 3766 | * If there are no active CRTCs, no additional checks need be performed |
| 3767 | */ |
| 3768 | if (hweight32(intel_state->active_crtcs) == 0) |
| 3769 | return true; |
| 3770 | else if (hweight32(intel_state->active_crtcs) > 1) |
| 3771 | return false; |
| 3772 | |
| 3773 | /* Since we're now guaranteed to only have one active CRTC... */ |
| 3774 | pipe = ffs(intel_state->active_crtcs) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 3775 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3776 | cstate = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3777 | |
Paulo Zanoni | c89cadd | 2016-10-10 17:30:59 -0300 | [diff] [blame] | 3778 | if (crtc->base.state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3779 | return false; |
| 3780 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3781 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3782 | struct skl_plane_wm *wm = |
| 3783 | &cstate->wm.skl.optimal.planes[plane->id]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3784 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3785 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3786 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3787 | continue; |
| 3788 | |
| 3789 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3790 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3791 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3792 | { } |
| 3793 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3794 | latency = dev_priv->wm.skl_latency[level]; |
| 3795 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3796 | if (skl_needs_memory_bw_wa(dev_priv) && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3797 | plane->base.state->fb->modifier == |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3798 | I915_FORMAT_MOD_X_TILED) |
| 3799 | latency += 15; |
| 3800 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3801 | /* |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3802 | * If any of the planes on this pipe don't enable wm levels that |
| 3803 | * incur memory latencies higher than sagv_block_time_us we |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3804 | * can't enable SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3805 | */ |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3806 | if (latency < sagv_block_time_us) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3807 | return false; |
| 3808 | } |
| 3809 | |
| 3810 | return true; |
| 3811 | } |
| 3812 | |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3813 | static u16 intel_get_ddb_size(struct drm_i915_private *dev_priv, |
| 3814 | const struct intel_crtc_state *cstate, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3815 | const u64 total_data_rate, |
Mahesh Kumar | aaa0237 | 2018-07-31 19:54:44 +0530 | [diff] [blame] | 3816 | const int num_active, |
| 3817 | struct skl_ddb_allocation *ddb) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3818 | { |
| 3819 | const struct drm_display_mode *adjusted_mode; |
| 3820 | u64 total_data_bw; |
| 3821 | u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3822 | |
| 3823 | WARN_ON(ddb_size == 0); |
| 3824 | |
| 3825 | if (INTEL_GEN(dev_priv) < 11) |
| 3826 | return ddb_size - 4; /* 4 blocks for bypass path allocation */ |
| 3827 | |
| 3828 | adjusted_mode = &cstate->base.adjusted_mode; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3829 | total_data_bw = total_data_rate * drm_mode_vrefresh(adjusted_mode); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3830 | |
| 3831 | /* |
| 3832 | * 12GB/s is maximum BW supported by single DBuf slice. |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3833 | * |
| 3834 | * FIXME dbuf slice code is broken: |
| 3835 | * - must wait for planes to stop using the slice before powering it off |
| 3836 | * - plane straddling both slices is illegal in multi-pipe scenarios |
| 3837 | * - should validate we stay within the hw bandwidth limits |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3838 | */ |
Ville Syrjälä | ad3e7b8 | 2019-01-30 17:51:10 +0200 | [diff] [blame] | 3839 | if (0 && (num_active > 1 || total_data_bw >= GBps(12))) { |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3840 | ddb->enabled_slices = 2; |
| 3841 | } else { |
| 3842 | ddb->enabled_slices = 1; |
| 3843 | ddb_size /= 2; |
| 3844 | } |
| 3845 | |
| 3846 | return ddb_size; |
| 3847 | } |
| 3848 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3849 | static void |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 3850 | skl_ddb_get_pipe_allocation_limits(struct drm_i915_private *dev_priv, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3851 | const struct intel_crtc_state *cstate, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 3852 | const u64 total_data_rate, |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3853 | struct skl_ddb_allocation *ddb, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3854 | struct skl_ddb_entry *alloc, /* out */ |
| 3855 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3856 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3857 | struct drm_atomic_state *state = cstate->base.state; |
| 3858 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3859 | struct drm_crtc *for_crtc = cstate->base.crtc; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3860 | const struct drm_crtc_state *crtc_state; |
| 3861 | const struct drm_crtc *crtc; |
| 3862 | u32 pipe_width = 0, total_width = 0, width_before_pipe = 0; |
| 3863 | enum pipe for_pipe = to_intel_crtc(for_crtc)->pipe; |
| 3864 | u16 ddb_size; |
| 3865 | u32 i; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3866 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3867 | if (WARN_ON(!state) || !cstate->base.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3868 | alloc->start = 0; |
| 3869 | alloc->end = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3870 | *num_active = hweight32(dev_priv->active_crtcs); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3871 | return; |
| 3872 | } |
| 3873 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3874 | if (intel_state->active_pipe_changes) |
| 3875 | *num_active = hweight32(intel_state->active_crtcs); |
| 3876 | else |
| 3877 | *num_active = hweight32(dev_priv->active_crtcs); |
| 3878 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 3879 | ddb_size = intel_get_ddb_size(dev_priv, cstate, total_data_rate, |
| 3880 | *num_active, ddb); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3881 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3882 | /* |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3883 | * If the state doesn't change the active CRTC's or there is no |
| 3884 | * modeset request, then there's no need to recalculate; |
| 3885 | * the existing pipe allocation limits should remain unchanged. |
| 3886 | * Note that we're safe from racing commits since any racing commit |
| 3887 | * that changes the active CRTC list or do modeset would need to |
| 3888 | * grab _all_ crtc locks, including the one we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3889 | */ |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3890 | if (!intel_state->active_pipe_changes && !intel_state->modeset) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 3891 | /* |
| 3892 | * alloc may be cleared by clear_intel_crtc_state, |
| 3893 | * copy from old state to be sure |
| 3894 | */ |
| 3895 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3896 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3897 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3898 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 3899 | /* |
| 3900 | * Watermark/ddb requirement highly depends upon width of the |
| 3901 | * framebuffer, So instead of allocating DDB equally among pipes |
| 3902 | * distribute DDB based on resolution/width of the display. |
| 3903 | */ |
| 3904 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
| 3905 | const struct drm_display_mode *adjusted_mode; |
| 3906 | int hdisplay, vdisplay; |
| 3907 | enum pipe pipe; |
| 3908 | |
| 3909 | if (!crtc_state->enable) |
| 3910 | continue; |
| 3911 | |
| 3912 | pipe = to_intel_crtc(crtc)->pipe; |
| 3913 | adjusted_mode = &crtc_state->adjusted_mode; |
| 3914 | drm_mode_get_hv_timing(adjusted_mode, &hdisplay, &vdisplay); |
| 3915 | total_width += hdisplay; |
| 3916 | |
| 3917 | if (pipe < for_pipe) |
| 3918 | width_before_pipe += hdisplay; |
| 3919 | else if (pipe == for_pipe) |
| 3920 | pipe_width = hdisplay; |
| 3921 | } |
| 3922 | |
| 3923 | alloc->start = ddb_size * width_before_pipe / total_width; |
| 3924 | alloc->end = ddb_size * (width_before_pipe + pipe_width) / total_width; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3927 | static unsigned int skl_cursor_allocation(int num_active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3928 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3929 | if (num_active == 1) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3930 | return 32; |
| 3931 | |
| 3932 | return 8; |
| 3933 | } |
| 3934 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3935 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 3936 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3937 | { |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3938 | |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 3939 | entry->start = reg & DDB_ENTRY_MASK; |
| 3940 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 3941 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3942 | if (entry->end) |
| 3943 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3944 | } |
| 3945 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3946 | static void |
| 3947 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 3948 | const enum pipe pipe, |
| 3949 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3950 | struct skl_ddb_entry *ddb_y, |
| 3951 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3952 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3953 | u32 val, val2; |
| 3954 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3955 | |
| 3956 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 3957 | if (plane_id == PLANE_CURSOR) { |
| 3958 | val = I915_READ(CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3959 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3960 | return; |
| 3961 | } |
| 3962 | |
| 3963 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
| 3964 | |
| 3965 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3966 | if (val & PLANE_CTL_ENABLE) |
| 3967 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 3968 | val & PLANE_CTL_ORDER_RGBX, |
| 3969 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3970 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3971 | if (INTEL_GEN(dev_priv) >= 11) { |
| 3972 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 3973 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 3974 | } else { |
| 3975 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
Paulo Zanoni | 12a6c93 | 2018-07-31 17:46:14 -0700 | [diff] [blame] | 3976 | val2 = I915_READ(PLANE_NV12_BUF_CFG(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3977 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 3978 | if (is_planar_yuv_format(fourcc)) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3979 | swap(val, val2); |
| 3980 | |
| 3981 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 3982 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3986 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 3987 | struct skl_ddb_entry *ddb_y, |
| 3988 | struct skl_ddb_entry *ddb_uv) |
| 3989 | { |
| 3990 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3991 | enum intel_display_power_domain power_domain; |
| 3992 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3993 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3994 | enum plane_id plane_id; |
| 3995 | |
| 3996 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3997 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 3998 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 3999 | return; |
| 4000 | |
| 4001 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4002 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4003 | plane_id, |
| 4004 | &ddb_y[plane_id], |
| 4005 | &ddb_uv[plane_id]); |
| 4006 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4007 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4008 | } |
| 4009 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 4010 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 4011 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4012 | { |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 4013 | ddb->enabled_slices = intel_enabled_dbuf_slices_num(dev_priv); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4014 | } |
| 4015 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4016 | /* |
| 4017 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4018 | * The bspec defines downscale amount as: |
| 4019 | * |
| 4020 | * """ |
| 4021 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4022 | * Horizontal destination size] |
| 4023 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4024 | * Vertical destination size] |
| 4025 | * Total down scale amount = Horizontal down scale amount * |
| 4026 | * Vertical down scale amount |
| 4027 | * """ |
| 4028 | * |
| 4029 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4030 | * Caller should take care of dividing & rounding off the value. |
| 4031 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4032 | static uint_fixed_16_16_t |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4033 | skl_plane_downscale_amount(const struct intel_crtc_state *cstate, |
| 4034 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4035 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4036 | struct intel_plane *plane = to_intel_plane(pstate->base.plane); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4037 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4038 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4039 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4040 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4041 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4042 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4043 | |
| 4044 | /* 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] | 4045 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4046 | /* |
| 4047 | * Cursors only support 0/180 degree rotation, |
| 4048 | * hence no need to account for rotation here. |
| 4049 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4050 | src_w = pstate->base.src_w >> 16; |
| 4051 | src_h = pstate->base.src_h >> 16; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4052 | dst_w = pstate->base.crtc_w; |
| 4053 | dst_h = pstate->base.crtc_h; |
| 4054 | } else { |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4055 | /* |
| 4056 | * Src coordinates are already rotated by 270 degrees for |
| 4057 | * the 90/270 degree plane rotation cases (to match the |
| 4058 | * GTT mapping), hence no need to account for rotation here. |
| 4059 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4060 | src_w = drm_rect_width(&pstate->base.src) >> 16; |
| 4061 | src_h = drm_rect_height(&pstate->base.src) >> 16; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4062 | dst_w = drm_rect_width(&pstate->base.dst); |
| 4063 | dst_h = drm_rect_height(&pstate->base.dst); |
| 4064 | } |
| 4065 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4066 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4067 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4068 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4069 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4070 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4071 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4074 | static uint_fixed_16_16_t |
| 4075 | skl_pipe_downscale_amount(const struct intel_crtc_state *crtc_state) |
| 4076 | { |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4077 | uint_fixed_16_16_t pipe_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4078 | |
| 4079 | if (!crtc_state->base.enable) |
| 4080 | return pipe_downscale; |
| 4081 | |
| 4082 | if (crtc_state->pch_pfit.enabled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4083 | u32 src_w, src_h, dst_w, dst_h; |
| 4084 | u32 pfit_size = crtc_state->pch_pfit.size; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4085 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4086 | uint_fixed_16_16_t downscale_h, downscale_w; |
| 4087 | |
| 4088 | src_w = crtc_state->pipe_src_w; |
| 4089 | src_h = crtc_state->pipe_src_h; |
| 4090 | dst_w = pfit_size >> 16; |
| 4091 | dst_h = pfit_size & 0xffff; |
| 4092 | |
| 4093 | if (!dst_w || !dst_h) |
| 4094 | return pipe_downscale; |
| 4095 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4096 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4097 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4098 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4099 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4100 | |
| 4101 | pipe_downscale = mul_fixed16(downscale_w, downscale_h); |
| 4102 | } |
| 4103 | |
| 4104 | return pipe_downscale; |
| 4105 | } |
| 4106 | |
| 4107 | int skl_check_pipe_max_pixel_rate(struct intel_crtc *intel_crtc, |
| 4108 | struct intel_crtc_state *cstate) |
| 4109 | { |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 4110 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4111 | struct drm_crtc_state *crtc_state = &cstate->base; |
| 4112 | struct drm_atomic_state *state = crtc_state->state; |
| 4113 | struct drm_plane *plane; |
| 4114 | const struct drm_plane_state *pstate; |
| 4115 | struct intel_plane_state *intel_pstate; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4116 | int crtc_clock, dotclk; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4117 | u32 pipe_max_pixel_rate; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4118 | uint_fixed_16_16_t pipe_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4119 | uint_fixed_16_16_t max_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4120 | |
| 4121 | if (!cstate->base.enable) |
| 4122 | return 0; |
| 4123 | |
| 4124 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { |
| 4125 | uint_fixed_16_16_t plane_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4126 | 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] | 4127 | int bpp; |
| 4128 | |
| 4129 | if (!intel_wm_plane_visible(cstate, |
| 4130 | to_intel_plane_state(pstate))) |
| 4131 | continue; |
| 4132 | |
| 4133 | if (WARN_ON(!pstate->fb)) |
| 4134 | return -EINVAL; |
| 4135 | |
| 4136 | intel_pstate = to_intel_plane_state(pstate); |
| 4137 | plane_downscale = skl_plane_downscale_amount(cstate, |
| 4138 | intel_pstate); |
| 4139 | bpp = pstate->fb->format->cpp[0] * 8; |
| 4140 | if (bpp == 64) |
| 4141 | plane_downscale = mul_fixed16(plane_downscale, |
| 4142 | fp_9_div_8); |
| 4143 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4144 | max_downscale = max_fixed16(plane_downscale, max_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4145 | } |
| 4146 | pipe_downscale = skl_pipe_downscale_amount(cstate); |
| 4147 | |
| 4148 | pipe_downscale = mul_fixed16(pipe_downscale, max_downscale); |
| 4149 | |
| 4150 | crtc_clock = crtc_state->adjusted_mode.crtc_clock; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4151 | dotclk = to_intel_atomic_state(state)->cdclk.logical.cdclk; |
| 4152 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 4153 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4154 | dotclk *= 2; |
| 4155 | |
| 4156 | pipe_max_pixel_rate = div_round_up_u32_fixed16(dotclk, pipe_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4157 | |
| 4158 | if (pipe_max_pixel_rate < crtc_clock) { |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 4159 | DRM_DEBUG_KMS("Max supported pixel clock with scaling exceeded\n"); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 4160 | return -EINVAL; |
| 4161 | } |
| 4162 | |
| 4163 | return 0; |
| 4164 | } |
| 4165 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4166 | static u64 |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4167 | skl_plane_relative_data_rate(const struct intel_crtc_state *cstate, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4168 | const struct intel_plane_state *intel_pstate, |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4169 | const int plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4170 | { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4171 | struct intel_plane *intel_plane = |
| 4172 | to_intel_plane(intel_pstate->base.plane); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4173 | u32 data_rate; |
| 4174 | u32 width = 0, height = 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4175 | struct drm_framebuffer *fb; |
| 4176 | u32 format; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4177 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4178 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4179 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4180 | if (!intel_pstate->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4181 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4182 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4183 | fb = intel_pstate->base.fb; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4184 | format = fb->format->format; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4185 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4186 | if (intel_plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4187 | return 0; |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4188 | if (plane == 1 && !is_planar_yuv_format(format)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4189 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4190 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4191 | /* |
| 4192 | * Src coordinates are already rotated by 270 degrees for |
| 4193 | * the 90/270 degree plane rotation cases (to match the |
| 4194 | * GTT mapping), hence no need to account for rotation here. |
| 4195 | */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4196 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4197 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4198 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4199 | /* UV plane does 1/2 pixel sub-sampling */ |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4200 | if (plane == 1 && is_planar_yuv_format(format)) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4201 | width /= 2; |
| 4202 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4203 | } |
| 4204 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4205 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4206 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4207 | down_scale_amount = skl_plane_downscale_amount(cstate, intel_pstate); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4208 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4209 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4210 | |
| 4211 | rate *= fb->format->cpp[plane]; |
| 4212 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4213 | } |
| 4214 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4215 | static u64 |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4216 | skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4217 | u64 *plane_data_rate, |
| 4218 | u64 *uv_plane_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4219 | { |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4220 | struct drm_crtc_state *cstate = &intel_cstate->base; |
| 4221 | struct drm_atomic_state *state = cstate->state; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4222 | struct drm_plane *plane; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4223 | const struct drm_plane_state *pstate; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4224 | u64 total_data_rate = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4225 | |
| 4226 | if (WARN_ON(!state)) |
| 4227 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4228 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4229 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4230 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, cstate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4231 | enum plane_id plane_id = to_intel_plane(plane)->id; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4232 | u64 rate; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4233 | const struct intel_plane_state *intel_pstate = |
| 4234 | to_intel_plane_state(pstate); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4235 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4236 | /* packed/y */ |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4237 | rate = skl_plane_relative_data_rate(intel_cstate, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4238 | intel_pstate, 0); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4239 | plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4240 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4241 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4242 | /* uv-plane */ |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4243 | rate = skl_plane_relative_data_rate(intel_cstate, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4244 | intel_pstate, 1); |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4245 | uv_plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4246 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | return total_data_rate; |
| 4250 | } |
| 4251 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4252 | static u64 |
| 4253 | icl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate, |
| 4254 | u64 *plane_data_rate) |
| 4255 | { |
| 4256 | struct drm_crtc_state *cstate = &intel_cstate->base; |
| 4257 | struct drm_atomic_state *state = cstate->state; |
| 4258 | struct drm_plane *plane; |
| 4259 | const struct drm_plane_state *pstate; |
| 4260 | u64 total_data_rate = 0; |
| 4261 | |
| 4262 | if (WARN_ON(!state)) |
| 4263 | return 0; |
| 4264 | |
| 4265 | /* Calculate and cache data rate for each plane */ |
| 4266 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, cstate) { |
| 4267 | const struct intel_plane_state *intel_pstate = |
| 4268 | to_intel_plane_state(pstate); |
| 4269 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 4270 | u64 rate; |
| 4271 | |
| 4272 | if (!intel_pstate->linked_plane) { |
| 4273 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4274 | intel_pstate, 0); |
| 4275 | plane_data_rate[plane_id] = rate; |
| 4276 | total_data_rate += rate; |
| 4277 | } else { |
| 4278 | enum plane_id y_plane_id; |
| 4279 | |
| 4280 | /* |
| 4281 | * The slave plane might not iterate in |
| 4282 | * drm_atomic_crtc_state_for_each_plane_state(), |
| 4283 | * and needs the master plane state which may be |
| 4284 | * NULL if we try get_new_plane_state(), so we |
| 4285 | * always calculate from the master. |
| 4286 | */ |
| 4287 | if (intel_pstate->slave) |
| 4288 | continue; |
| 4289 | |
| 4290 | /* Y plane rate is calculated on the slave */ |
| 4291 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4292 | intel_pstate, 0); |
| 4293 | y_plane_id = intel_pstate->linked_plane->id; |
| 4294 | plane_data_rate[y_plane_id] = rate; |
| 4295 | total_data_rate += rate; |
| 4296 | |
| 4297 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4298 | intel_pstate, 1); |
| 4299 | plane_data_rate[plane_id] = rate; |
| 4300 | total_data_rate += rate; |
| 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | return total_data_rate; |
| 4305 | } |
| 4306 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4307 | static int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4308 | skl_allocate_pipe_ddb(struct intel_crtc_state *cstate, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4309 | struct skl_ddb_allocation *ddb /* out */) |
| 4310 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4311 | struct drm_atomic_state *state = cstate->base.state; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4312 | struct drm_crtc *crtc = cstate->base.crtc; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4313 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4314 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4315 | struct skl_ddb_entry *alloc = &cstate->wm.skl.ddb; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4316 | struct skl_plane_wm *wm; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4317 | u16 alloc_size, start = 0; |
| 4318 | u16 total[I915_MAX_PLANES] = {}; |
| 4319 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4320 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4321 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4322 | int num_active; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4323 | u64 plane_data_rate[I915_MAX_PLANES] = {}; |
| 4324 | u64 uv_plane_data_rate[I915_MAX_PLANES] = {}; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4325 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4326 | int level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4327 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4328 | /* Clear the partitioning for disabled planes. */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4329 | memset(cstate->wm.skl.plane_ddb_y, 0, sizeof(cstate->wm.skl.plane_ddb_y)); |
| 4330 | 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] | 4331 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4332 | if (WARN_ON(!state)) |
| 4333 | return 0; |
| 4334 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4335 | if (!cstate->base.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4336 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4337 | return 0; |
| 4338 | } |
| 4339 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4340 | if (INTEL_GEN(dev_priv) < 11) |
| 4341 | total_data_rate = |
| 4342 | skl_get_total_relative_data_rate(cstate, |
| 4343 | plane_data_rate, |
| 4344 | uv_plane_data_rate); |
| 4345 | else |
| 4346 | total_data_rate = |
| 4347 | icl_get_total_relative_data_rate(cstate, |
| 4348 | plane_data_rate); |
| 4349 | |
| 4350 | skl_ddb_get_pipe_allocation_limits(dev_priv, cstate, total_data_rate, |
| 4351 | ddb, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4352 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 4353 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4354 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4355 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4356 | /* Allocate fixed number of blocks for cursor. */ |
| 4357 | total[PLANE_CURSOR] = skl_cursor_allocation(num_active); |
| 4358 | alloc_size -= total[PLANE_CURSOR]; |
| 4359 | cstate->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
| 4360 | alloc->end - total[PLANE_CURSOR]; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4361 | cstate->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4362 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4363 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4364 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4365 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4366 | /* |
| 4367 | * Find the highest watermark level for which we can satisfy the block |
| 4368 | * requirement of active planes. |
| 4369 | */ |
| 4370 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 4371 | blocks = 0; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4372 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 4373 | if (plane_id == PLANE_CURSOR) |
| 4374 | continue; |
| 4375 | |
| 4376 | wm = &cstate->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4377 | blocks += wm->wm[level].min_ddb_alloc; |
| 4378 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4379 | } |
| 4380 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame^] | 4381 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4382 | alloc_size -= blocks; |
| 4383 | break; |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | if (level < 0) { |
| 4388 | DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); |
| 4389 | DRM_DEBUG_KMS("minimum required %d/%d\n", blocks, |
| 4390 | alloc_size); |
| 4391 | return -EINVAL; |
| 4392 | } |
| 4393 | |
| 4394 | /* |
| 4395 | * Grant each plane the blocks it requires at the highest achievable |
| 4396 | * watermark level, plus an extra share of the leftover blocks |
| 4397 | * proportional to its relative data rate. |
| 4398 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4399 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4400 | u64 rate; |
| 4401 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4402 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4403 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4404 | continue; |
| 4405 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4406 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4407 | * We've accounted for all active planes; remaining planes are |
| 4408 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4409 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4410 | if (total_data_rate == 0) |
| 4411 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4412 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4413 | wm = &cstate->wm.skl.optimal.planes[plane_id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4414 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4415 | rate = plane_data_rate[plane_id]; |
| 4416 | extra = min_t(u16, alloc_size, |
| 4417 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4418 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4419 | total[plane_id] = wm->wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4420 | alloc_size -= extra; |
| 4421 | total_data_rate -= rate; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4422 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4423 | if (total_data_rate == 0) |
| 4424 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4425 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4426 | rate = uv_plane_data_rate[plane_id]; |
| 4427 | extra = min_t(u16, alloc_size, |
| 4428 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4429 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4430 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4431 | alloc_size -= extra; |
| 4432 | total_data_rate -= rate; |
| 4433 | } |
| 4434 | WARN_ON(alloc_size != 0 || total_data_rate != 0); |
| 4435 | |
| 4436 | /* Set the actual DDB start/end points for each plane */ |
| 4437 | start = alloc->start; |
| 4438 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 4439 | struct skl_ddb_entry *plane_alloc, *uv_plane_alloc; |
| 4440 | |
| 4441 | if (plane_id == PLANE_CURSOR) |
| 4442 | continue; |
| 4443 | |
| 4444 | plane_alloc = &cstate->wm.skl.plane_ddb_y[plane_id]; |
| 4445 | uv_plane_alloc = &cstate->wm.skl.plane_ddb_uv[plane_id]; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4446 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4447 | /* Gen11+ uses a separate plane for UV watermarks */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4448 | WARN_ON(INTEL_GEN(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4449 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4450 | /* Leave disabled planes at (0,0) */ |
| 4451 | if (total[plane_id]) { |
| 4452 | plane_alloc->start = start; |
| 4453 | start += total[plane_id]; |
| 4454 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4455 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4456 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4457 | if (uv_total[plane_id]) { |
| 4458 | uv_plane_alloc->start = start; |
| 4459 | start += uv_total[plane_id]; |
| 4460 | uv_plane_alloc->end = start; |
| 4461 | } |
| 4462 | } |
| 4463 | |
| 4464 | /* |
| 4465 | * When we calculated watermark values we didn't know how high |
| 4466 | * of a level we'd actually be able to hit, so we just marked |
| 4467 | * all levels as "enabled." Go back now and disable the ones |
| 4468 | * that aren't actually possible. |
| 4469 | */ |
| 4470 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
| 4471 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 4472 | wm = &cstate->wm.skl.optimal.planes[plane_id]; |
| 4473 | memset(&wm->wm[level], 0, sizeof(wm->wm[level])); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4474 | |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 4475 | /* |
| 4476 | * Wa_1408961008:icl |
| 4477 | * Underruns with WM1+ disabled |
| 4478 | */ |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4479 | if (IS_ICELAKE(dev_priv) && |
| 4480 | level == 1 && wm->wm[0].plane_en) { |
| 4481 | 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] | 4482 | wm->wm[level].plane_res_l = wm->wm[0].plane_res_l; |
| 4483 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 4484 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4485 | } |
| 4486 | } |
| 4487 | |
| 4488 | /* |
| 4489 | * Go back and disable the transition watermark if it turns out we |
| 4490 | * don't have enough DDB blocks for it. |
| 4491 | */ |
| 4492 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 4493 | wm = &cstate->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | b19c9bc | 2018-12-21 19:14:31 +0200 | [diff] [blame] | 4494 | if (wm->trans_wm.plane_res_b >= total[plane_id]) |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4495 | memset(&wm->trans_wm, 0, sizeof(wm->trans_wm)); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4496 | } |
| 4497 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4498 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4499 | } |
| 4500 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4501 | /* |
| 4502 | * 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] | 4503 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4504 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 4505 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 4506 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4507 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4508 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 4509 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4510 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4511 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4512 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4513 | |
| 4514 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4515 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4516 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4517 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4518 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4519 | |
| 4520 | if (INTEL_GEN(dev_priv) >= 10) |
| 4521 | ret = add_fixed16_u32(ret, 1); |
| 4522 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4523 | return ret; |
| 4524 | } |
| 4525 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4526 | static uint_fixed_16_16_t |
| 4527 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 4528 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4529 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4530 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4531 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4532 | |
| 4533 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4534 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4535 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4536 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4537 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 4538 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4539 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4540 | return ret; |
| 4541 | } |
| 4542 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4543 | static uint_fixed_16_16_t |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4544 | intel_get_linetime_us(const struct intel_crtc_state *cstate) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4545 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4546 | u32 pixel_rate; |
| 4547 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4548 | uint_fixed_16_16_t linetime_us; |
| 4549 | |
| 4550 | if (!cstate->base.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4551 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4552 | |
| 4553 | pixel_rate = cstate->pixel_rate; |
| 4554 | |
| 4555 | if (WARN_ON(pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4556 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4557 | |
| 4558 | crtc_htotal = cstate->base.adjusted_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4559 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4560 | |
| 4561 | return linetime_us; |
| 4562 | } |
| 4563 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4564 | static u32 |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4565 | skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *cstate, |
| 4566 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4567 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4568 | u64 adjusted_pixel_rate; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4569 | uint_fixed_16_16_t downscale_amount; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4570 | |
| 4571 | /* Shouldn't reach here on disabled planes... */ |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4572 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4573 | return 0; |
| 4574 | |
| 4575 | /* |
| 4576 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 4577 | * with additional adjustments for plane-specific scaling. |
| 4578 | */ |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 4579 | adjusted_pixel_rate = cstate->pixel_rate; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4580 | downscale_amount = skl_plane_downscale_amount(cstate, pstate); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4581 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4582 | return mul_round_up_u32_fixed16(adjusted_pixel_rate, |
| 4583 | downscale_amount); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4584 | } |
| 4585 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4586 | static int |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4587 | skl_compute_plane_wm_params(const struct intel_crtc_state *cstate, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4588 | const struct intel_plane_state *intel_pstate, |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 4589 | struct skl_wm_params *wp, int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4590 | { |
| 4591 | struct intel_plane *plane = to_intel_plane(intel_pstate->base.plane); |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4592 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4593 | const struct drm_plane_state *pstate = &intel_pstate->base; |
| 4594 | const struct drm_framebuffer *fb = pstate->fb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4595 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4596 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4597 | /* only planar format has two planes */ |
| 4598 | if (color_plane == 1 && !is_planar_yuv_format(fb->format->format)) { |
| 4599 | DRM_DEBUG_KMS("Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4600 | return -EINVAL; |
| 4601 | } |
| 4602 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4603 | wp->y_tiled = fb->modifier == I915_FORMAT_MOD_Y_TILED || |
| 4604 | fb->modifier == I915_FORMAT_MOD_Yf_TILED || |
| 4605 | fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4606 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4607 | wp->x_tiled = fb->modifier == I915_FORMAT_MOD_X_TILED; |
| 4608 | wp->rc_surface = fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4609 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 4610 | wp->is_planar = is_planar_yuv_format(fb->format->format); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4611 | |
| 4612 | if (plane->id == PLANE_CURSOR) { |
| 4613 | wp->width = intel_pstate->base.crtc_w; |
| 4614 | } else { |
| 4615 | /* |
| 4616 | * Src coordinates are already rotated by 270 degrees for |
| 4617 | * the 90/270 degree plane rotation cases (to match the |
| 4618 | * GTT mapping), hence no need to account for rotation here. |
| 4619 | */ |
| 4620 | wp->width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4621 | } |
| 4622 | |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 4623 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 4624 | wp->width /= 2; |
| 4625 | |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 4626 | wp->cpp = fb->format->cpp[color_plane]; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4627 | wp->plane_pixel_rate = skl_adjusted_plane_pixel_rate(cstate, |
| 4628 | intel_pstate); |
| 4629 | |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4630 | if (INTEL_GEN(dev_priv) >= 11 && |
Ville Syrjälä | 17b1605 | 2018-12-21 19:14:30 +0200 | [diff] [blame] | 4631 | fb->modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4632 | wp->dbuf_block_size = 256; |
| 4633 | else |
| 4634 | wp->dbuf_block_size = 512; |
| 4635 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4636 | if (drm_rotation_90_or_270(pstate->rotation)) { |
| 4637 | |
| 4638 | switch (wp->cpp) { |
| 4639 | case 1: |
| 4640 | wp->y_min_scanlines = 16; |
| 4641 | break; |
| 4642 | case 2: |
| 4643 | wp->y_min_scanlines = 8; |
| 4644 | break; |
| 4645 | case 4: |
| 4646 | wp->y_min_scanlines = 4; |
| 4647 | break; |
| 4648 | default: |
| 4649 | MISSING_CASE(wp->cpp); |
| 4650 | return -EINVAL; |
| 4651 | } |
| 4652 | } else { |
| 4653 | wp->y_min_scanlines = 4; |
| 4654 | } |
| 4655 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4656 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4657 | wp->y_min_scanlines *= 2; |
| 4658 | |
| 4659 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 4660 | if (wp->y_tiled) { |
| 4661 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4662 | wp->y_min_scanlines, |
| 4663 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4664 | |
| 4665 | if (INTEL_GEN(dev_priv) >= 10) |
| 4666 | interm_pbpl++; |
| 4667 | |
| 4668 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 4669 | wp->y_min_scanlines); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4670 | } else if (wp->x_tiled && IS_GEN(dev_priv, 9)) { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4671 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4672 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4673 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4674 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4675 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
| 4676 | wp->dbuf_block_size) + 1; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4677 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4678 | } |
| 4679 | |
| 4680 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 4681 | wp->plane_blocks_per_line); |
| 4682 | wp->linetime_us = fixed16_to_u32_round_up( |
| 4683 | intel_get_linetime_us(cstate)); |
| 4684 | |
| 4685 | return 0; |
| 4686 | } |
| 4687 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4688 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 4689 | { |
| 4690 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 4691 | return true; |
| 4692 | |
| 4693 | /* The number of lines are ignored for the level 0 watermark. */ |
| 4694 | return level > 0; |
| 4695 | } |
| 4696 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4697 | static void skl_compute_plane_wm(const struct intel_crtc_state *cstate, |
| 4698 | const struct intel_plane_state *intel_pstate, |
| 4699 | int level, |
| 4700 | const struct skl_wm_params *wp, |
| 4701 | const struct skl_wm_level *result_prev, |
| 4702 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4703 | { |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4704 | struct drm_i915_private *dev_priv = |
| 4705 | to_i915(intel_pstate->base.plane->dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4706 | u32 latency = dev_priv->wm.skl_latency[level]; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4707 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4708 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4709 | u32 res_blocks, res_lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 4710 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4711 | if (latency == 0) { |
| 4712 | /* reject it */ |
| 4713 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4714 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4715 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 4716 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4717 | /* Display WA #1141: kbl,cfl */ |
Kumar, Mahesh | d86ba62 | 2017-08-17 19:15:26 +0530 | [diff] [blame] | 4718 | if ((IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || |
| 4719 | IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) && |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4720 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 4721 | latency += 4; |
| 4722 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 4723 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4724 | latency += 15; |
| 4725 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4726 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4727 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4728 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4729 | cstate->base.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4730 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4731 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4732 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4733 | if (wp->y_tiled) { |
| 4734 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4735 | } else { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4736 | if ((wp->cpp * cstate->base.adjusted_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 4737 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4738 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 4739 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4740 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4741 | if (IS_GEN(dev_priv, 9) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4742 | !IS_GEMINILAKE(dev_priv)) |
| 4743 | selected_result = min_fixed16(method1, method2); |
| 4744 | else |
| 4745 | selected_result = method2; |
| 4746 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4747 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 4748 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4749 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4750 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4751 | res_blocks = fixed16_to_u32_round_up(selected_result) + 1; |
Kumar, Mahesh | d273ecc | 2017-05-17 17:28:22 +0530 | [diff] [blame] | 4752 | res_lines = div_round_up_fixed16(selected_result, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4753 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4754 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4755 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) { |
| 4756 | /* Display WA #1125: skl,bxt,kbl */ |
| 4757 | if (level == 0 && wp->rc_surface) |
| 4758 | res_blocks += |
| 4759 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 4760 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 4761 | /* Display WA #1126: skl,bxt,kbl */ |
| 4762 | if (level >= 1 && level <= 7) { |
| 4763 | if (wp->y_tiled) { |
| 4764 | res_blocks += |
| 4765 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 4766 | res_lines += wp->y_min_scanlines; |
| 4767 | } else { |
| 4768 | res_blocks++; |
| 4769 | } |
| 4770 | |
| 4771 | /* |
| 4772 | * Make sure result blocks for higher latency levels are |
| 4773 | * atleast as high as level below the current level. |
| 4774 | * Assumption in DDB algorithm optimization for special |
| 4775 | * cases. Also covers Display WA #1125 for RC. |
| 4776 | */ |
| 4777 | if (result_prev->plane_res_b > res_blocks) |
| 4778 | res_blocks = result_prev->plane_res_b; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4779 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4780 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4781 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4782 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4783 | if (wp->y_tiled) { |
| 4784 | int extra_lines; |
| 4785 | |
| 4786 | if (res_lines % wp->y_min_scanlines == 0) |
| 4787 | extra_lines = wp->y_min_scanlines; |
| 4788 | else |
| 4789 | extra_lines = wp->y_min_scanlines * 2 - |
| 4790 | res_lines % wp->y_min_scanlines; |
| 4791 | |
| 4792 | min_ddb_alloc = mul_round_up_u32_fixed16(res_lines + extra_lines, |
| 4793 | wp->plane_blocks_per_line); |
| 4794 | } else { |
| 4795 | min_ddb_alloc = res_blocks + |
| 4796 | DIV_ROUND_UP(res_blocks, 10); |
| 4797 | } |
| 4798 | } |
| 4799 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 4800 | if (!skl_wm_has_lines(dev_priv, level)) |
| 4801 | res_lines = 0; |
| 4802 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4803 | if (res_lines > 31) { |
| 4804 | /* reject it */ |
| 4805 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4806 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4807 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4808 | |
| 4809 | /* |
| 4810 | * If res_lines is valid, assume we can use this watermark level |
| 4811 | * for now. We'll come back and disable it after we calculate the |
| 4812 | * DDB allocation if it turns out we don't actually have enough |
| 4813 | * blocks to satisfy it. |
| 4814 | */ |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4815 | result->plane_res_b = res_blocks; |
| 4816 | result->plane_res_l = res_lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4817 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
| 4818 | result->min_ddb_alloc = max(min_ddb_alloc, res_blocks) + 1; |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 4819 | result->plane_en = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4820 | } |
| 4821 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4822 | static void |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4823 | skl_compute_wm_levels(const struct intel_crtc_state *cstate, |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4824 | const struct intel_plane_state *intel_pstate, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4825 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4826 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4827 | { |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4828 | struct drm_i915_private *dev_priv = |
| 4829 | to_i915(intel_pstate->base.plane->dev); |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4830 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4831 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4832 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4833 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4834 | struct skl_wm_level *result = &levels[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4835 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4836 | skl_compute_plane_wm(cstate, intel_pstate, level, wm_params, |
| 4837 | result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4838 | |
| 4839 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4840 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4843 | static u32 |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4844 | skl_compute_linetime_wm(const struct intel_crtc_state *cstate) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4845 | { |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4846 | struct drm_atomic_state *state = cstate->base.state; |
| 4847 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4848 | uint_fixed_16_16_t linetime_us; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4849 | u32 linetime_wm; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4850 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4851 | linetime_us = intel_get_linetime_us(cstate); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4852 | 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] | 4853 | |
Ville Syrjälä | 717671c | 2018-12-21 19:14:36 +0200 | [diff] [blame] | 4854 | /* Display WA #1135: BXT:ALL GLK:ALL */ |
| 4855 | if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled) |
Kumar, Mahesh | 446e850 | 2017-08-17 19:15:25 +0530 | [diff] [blame] | 4856 | linetime_wm /= 2; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4857 | |
| 4858 | return linetime_wm; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4859 | } |
| 4860 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4861 | 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] | 4862 | const struct skl_wm_params *wp, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4863 | struct skl_plane_wm *wm) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4864 | { |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4865 | struct drm_device *dev = cstate->base.crtc->dev; |
| 4866 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4867 | u16 trans_min, trans_y_tile_min; |
| 4868 | const u16 trans_amount = 10; /* This is configurable amount */ |
| 4869 | u16 wm0_sel_res_b, trans_offset_b, res_blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4870 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4871 | /* Transition WM are not recommended by HW team for GEN9 */ |
| 4872 | if (INTEL_GEN(dev_priv) <= 9) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4873 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4874 | |
| 4875 | /* Transition WM don't make any sense if ipc is disabled */ |
| 4876 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 4877 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4878 | |
Paulo Zanoni | 91961a8 | 2018-10-04 16:15:56 -0700 | [diff] [blame] | 4879 | trans_min = 14; |
| 4880 | if (INTEL_GEN(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4881 | trans_min = 4; |
| 4882 | |
| 4883 | trans_offset_b = trans_min + trans_amount; |
| 4884 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4885 | /* |
| 4886 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 4887 | * not Result Blocks (the integer value). Pay attention to the capital |
| 4888 | * letters. The value wm_l0->plane_res_b is actually Result Blocks, but |
| 4889 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 4890 | * and since we later will have to get the ceiling of the sum in the |
| 4891 | * transition watermarks calculation, we can just pretend Selected |
| 4892 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 4893 | * current platforms. |
| 4894 | */ |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 4895 | wm0_sel_res_b = wm->wm[0].plane_res_b - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4896 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4897 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4898 | trans_y_tile_min = |
| 4899 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4900 | res_blocks = max(wm0_sel_res_b, trans_y_tile_min) + |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4901 | trans_offset_b; |
| 4902 | } else { |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 4903 | res_blocks = wm0_sel_res_b + trans_offset_b; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4904 | |
| 4905 | /* WA BUG:1938466 add one block for non y-tile planes */ |
| 4906 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_A0)) |
| 4907 | res_blocks += 1; |
| 4908 | |
| 4909 | } |
| 4910 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4911 | /* |
| 4912 | * Just assume we can enable the transition watermark. After |
| 4913 | * computing the DDB we'll come back and disable it if that |
| 4914 | * assumption turns out to be false. |
| 4915 | */ |
| 4916 | wm->trans_wm.plane_res_b = res_blocks + 1; |
| 4917 | wm->trans_wm.plane_en = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4918 | } |
| 4919 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4920 | 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] | 4921 | const struct intel_plane_state *plane_state, |
| 4922 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4923 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4924 | 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] | 4925 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4926 | int ret; |
| 4927 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4928 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4929 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4930 | if (ret) |
| 4931 | return ret; |
| 4932 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4933 | skl_compute_wm_levels(crtc_state, plane_state, &wm_params, wm->wm); |
| 4934 | skl_compute_transition_wm(crtc_state, &wm_params, wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4935 | |
| 4936 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4937 | } |
| 4938 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4939 | 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] | 4940 | const struct intel_plane_state *plane_state, |
| 4941 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4942 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4943 | struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 4944 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4945 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4946 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4947 | wm->is_planar = true; |
| 4948 | |
| 4949 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 4950 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4951 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4952 | if (ret) |
| 4953 | return ret; |
| 4954 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4955 | skl_compute_wm_levels(crtc_state, plane_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4956 | |
| 4957 | return 0; |
| 4958 | } |
| 4959 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4960 | static int skl_build_plane_wm(struct skl_pipe_wm *pipe_wm, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4961 | struct intel_crtc_state *crtc_state, |
| 4962 | const struct intel_plane_state *plane_state) |
| 4963 | { |
| 4964 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 4965 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 4966 | enum plane_id plane_id = plane->id; |
| 4967 | int ret; |
| 4968 | |
| 4969 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 4970 | return 0; |
| 4971 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4972 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4973 | plane_id, 0); |
| 4974 | if (ret) |
| 4975 | return ret; |
| 4976 | |
| 4977 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4978 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4979 | plane_id); |
| 4980 | if (ret) |
| 4981 | return ret; |
| 4982 | } |
| 4983 | |
| 4984 | return 0; |
| 4985 | } |
| 4986 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4987 | static int icl_build_plane_wm(struct skl_pipe_wm *pipe_wm, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 4988 | struct intel_crtc_state *crtc_state, |
| 4989 | const struct intel_plane_state *plane_state) |
| 4990 | { |
| 4991 | enum plane_id plane_id = to_intel_plane(plane_state->base.plane)->id; |
| 4992 | int ret; |
| 4993 | |
| 4994 | /* Watermarks calculated in master */ |
| 4995 | if (plane_state->slave) |
| 4996 | return 0; |
| 4997 | |
| 4998 | if (plane_state->linked_plane) { |
| 4999 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 5000 | enum plane_id y_plane_id = plane_state->linked_plane->id; |
| 5001 | |
| 5002 | WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state)); |
| 5003 | WARN_ON(!fb->format->is_yuv || |
| 5004 | fb->format->num_planes == 1); |
| 5005 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5006 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5007 | y_plane_id, 0); |
| 5008 | if (ret) |
| 5009 | return ret; |
| 5010 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5011 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5012 | plane_id, 1); |
| 5013 | if (ret) |
| 5014 | return ret; |
| 5015 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5016 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5017 | plane_id, 0); |
| 5018 | if (ret) |
| 5019 | return ret; |
| 5020 | } |
| 5021 | |
| 5022 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5023 | } |
| 5024 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5025 | static int skl_build_pipe_wm(struct intel_crtc_state *cstate, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5026 | struct skl_pipe_wm *pipe_wm) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5027 | { |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5028 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5029 | struct drm_crtc_state *crtc_state = &cstate->base; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5030 | struct drm_plane *plane; |
| 5031 | const struct drm_plane_state *pstate; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5032 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5033 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 5034 | /* |
| 5035 | * We'll only calculate watermarks for planes that are actually |
| 5036 | * enabled, so make sure all other planes are set as disabled. |
| 5037 | */ |
| 5038 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 5039 | |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5040 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { |
| 5041 | const struct intel_plane_state *intel_pstate = |
| 5042 | to_intel_plane_state(pstate); |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5043 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5044 | if (INTEL_GEN(dev_priv) >= 11) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5045 | ret = icl_build_plane_wm(pipe_wm, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5046 | cstate, intel_pstate); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5047 | else |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5048 | ret = skl_build_plane_wm(pipe_wm, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5049 | cstate, intel_pstate); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5050 | if (ret) |
| 5051 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5052 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5053 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 5054 | pipe_wm->linetime = skl_compute_linetime_wm(cstate); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5055 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5056 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5057 | } |
| 5058 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5059 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 5060 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5061 | const struct skl_ddb_entry *entry) |
| 5062 | { |
| 5063 | if (entry->end) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5064 | I915_WRITE_FW(reg, (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5065 | else |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5066 | I915_WRITE_FW(reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5067 | } |
| 5068 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5069 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5070 | i915_reg_t reg, |
| 5071 | const struct skl_wm_level *level) |
| 5072 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5073 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5074 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5075 | if (level->plane_en) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5076 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5077 | if (level->ignore_lines) |
| 5078 | val |= PLANE_WM_IGNORE_LINES; |
| 5079 | val |= level->plane_res_b; |
| 5080 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5081 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5082 | I915_WRITE_FW(reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5083 | } |
| 5084 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5085 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5086 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5087 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5088 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5089 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5090 | enum plane_id plane_id = plane->id; |
| 5091 | enum pipe pipe = plane->pipe; |
| 5092 | const struct skl_plane_wm *wm = |
| 5093 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5094 | const struct skl_ddb_entry *ddb_y = |
| 5095 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5096 | const struct skl_ddb_entry *ddb_uv = |
| 5097 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5098 | |
| 5099 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5100 | 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] | 5101 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5102 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5103 | 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] | 5104 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5105 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5106 | if (INTEL_GEN(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5107 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5108 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5109 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5110 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5111 | |
| 5112 | if (wm->is_planar) |
| 5113 | swap(ddb_y, ddb_uv); |
| 5114 | |
| 5115 | skl_ddb_entry_write(dev_priv, |
| 5116 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5117 | skl_ddb_entry_write(dev_priv, |
| 5118 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5119 | } |
| 5120 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5121 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5122 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5123 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5124 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5125 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5126 | enum plane_id plane_id = plane->id; |
| 5127 | enum pipe pipe = plane->pipe; |
| 5128 | const struct skl_plane_wm *wm = |
| 5129 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5130 | const struct skl_ddb_entry *ddb = |
| 5131 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5132 | |
| 5133 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5134 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 5135 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5136 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5137 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5138 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5139 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5140 | } |
| 5141 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5142 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5143 | const struct skl_wm_level *l2) |
| 5144 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5145 | return l1->plane_en == l2->plane_en && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5146 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5147 | l1->plane_res_l == l2->plane_res_l && |
| 5148 | l1->plane_res_b == l2->plane_res_b; |
| 5149 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5150 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5151 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5152 | const struct skl_plane_wm *wm1, |
| 5153 | const struct skl_plane_wm *wm2) |
| 5154 | { |
| 5155 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5156 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5157 | for (level = 0; level <= max_level; level++) { |
| 5158 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level]) || |
| 5159 | !skl_wm_level_equals(&wm1->uv_wm[level], &wm2->uv_wm[level])) |
| 5160 | return false; |
| 5161 | } |
| 5162 | |
| 5163 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5164 | } |
| 5165 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5166 | static bool skl_pipe_wm_equals(struct intel_crtc *crtc, |
| 5167 | const struct skl_pipe_wm *wm1, |
| 5168 | const struct skl_pipe_wm *wm2) |
| 5169 | { |
| 5170 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5171 | enum plane_id plane_id; |
| 5172 | |
| 5173 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5174 | if (!skl_plane_wm_equals(dev_priv, |
| 5175 | &wm1->planes[plane_id], |
| 5176 | &wm2->planes[plane_id])) |
| 5177 | return false; |
| 5178 | } |
| 5179 | |
| 5180 | return wm1->linetime == wm2->linetime; |
| 5181 | } |
| 5182 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5183 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 5184 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5185 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5186 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5187 | } |
| 5188 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5189 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
| 5190 | const struct skl_ddb_entry entries[], |
| 5191 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5192 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5193 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5194 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5195 | for (i = 0; i < num_entries; i++) { |
| 5196 | if (i != ignore_idx && |
| 5197 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5198 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 5199 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5200 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5201 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5202 | } |
| 5203 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5204 | static int skl_update_pipe_wm(struct intel_crtc_state *cstate, |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5205 | const struct skl_pipe_wm *old_pipe_wm, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5206 | struct skl_pipe_wm *pipe_wm, /* out */ |
| 5207 | bool *changed /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5208 | { |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5209 | struct intel_crtc *crtc = to_intel_crtc(cstate->base.crtc); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5210 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5211 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5212 | ret = skl_build_pipe_wm(cstate, pipe_wm); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5213 | if (ret) |
| 5214 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5215 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5216 | *changed = !skl_pipe_wm_equals(crtc, old_pipe_wm, pipe_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5217 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5218 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5219 | } |
| 5220 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5221 | static u32 |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5222 | pipes_modified(struct intel_atomic_state *state) |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5223 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5224 | struct intel_crtc *crtc; |
| 5225 | struct intel_crtc_state *cstate; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5226 | u32 i, ret = 0; |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5227 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5228 | for_each_new_intel_crtc_in_state(state, crtc, cstate, i) |
| 5229 | ret |= drm_crtc_mask(&crtc->base); |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 5230 | |
| 5231 | return ret; |
| 5232 | } |
| 5233 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 5234 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5235 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 5236 | struct intel_crtc_state *new_crtc_state) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5237 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5238 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->base.state); |
| 5239 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5240 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5241 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5242 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5243 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5244 | struct intel_plane_state *plane_state; |
| 5245 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5246 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5247 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 5248 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 5249 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 5250 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5251 | continue; |
| 5252 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5253 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5254 | if (IS_ERR(plane_state)) |
| 5255 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 5256 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5257 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | return 0; |
| 5261 | } |
| 5262 | |
| 5263 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5264 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5265 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5266 | const struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5267 | struct skl_ddb_allocation *ddb = &state->wm_results.ddb; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5268 | struct intel_crtc_state *old_crtc_state; |
| 5269 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5270 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5271 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5272 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 5273 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 5274 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5275 | 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] | 5276 | new_crtc_state, i) { |
| 5277 | ret = skl_allocate_pipe_ddb(new_crtc_state, ddb); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5278 | if (ret) |
| 5279 | return ret; |
| 5280 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5281 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 5282 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5283 | if (ret) |
| 5284 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | return 0; |
| 5288 | } |
| 5289 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5290 | static char enast(bool enable) |
| 5291 | { |
| 5292 | return enable ? '*' : ' '; |
| 5293 | } |
| 5294 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 5295 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5296 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5297 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5298 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5299 | const struct intel_crtc_state *old_crtc_state; |
| 5300 | const struct intel_crtc_state *new_crtc_state; |
| 5301 | struct intel_plane *plane; |
| 5302 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5303 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5304 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5305 | if ((drm_debug & DRM_UT_KMS) == 0) |
| 5306 | return; |
| 5307 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5308 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 5309 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5310 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 5311 | |
| 5312 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 5313 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 5314 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5315 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5316 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5317 | const struct skl_ddb_entry *old, *new; |
| 5318 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5319 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5320 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5321 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5322 | if (skl_ddb_entry_equal(old, new)) |
| 5323 | continue; |
| 5324 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5325 | 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] | 5326 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5327 | old->start, old->end, new->start, new->end, |
| 5328 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
| 5329 | } |
| 5330 | |
| 5331 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5332 | enum plane_id plane_id = plane->id; |
| 5333 | const struct skl_plane_wm *old_wm, *new_wm; |
| 5334 | |
| 5335 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 5336 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 5337 | |
| 5338 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 5339 | continue; |
| 5340 | |
| 5341 | DRM_DEBUG_KMS("[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm" |
| 5342 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm\n", |
| 5343 | plane->base.base.id, plane->base.name, |
| 5344 | enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en), |
| 5345 | enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en), |
| 5346 | enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en), |
| 5347 | enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en), |
| 5348 | enast(old_wm->trans_wm.plane_en), |
| 5349 | enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en), |
| 5350 | enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en), |
| 5351 | enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en), |
| 5352 | enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en), |
| 5353 | enast(new_wm->trans_wm.plane_en)); |
| 5354 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5355 | 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" |
| 5356 | " -> %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] | 5357 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5358 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l, |
| 5359 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l, |
| 5360 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l, |
| 5361 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l, |
| 5362 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l, |
| 5363 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l, |
| 5364 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l, |
| 5365 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l, |
| 5366 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l, |
| 5367 | |
| 5368 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l, |
| 5369 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l, |
| 5370 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l, |
| 5371 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l, |
| 5372 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l, |
| 5373 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l, |
| 5374 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l, |
| 5375 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l, |
| 5376 | 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] | 5377 | |
| 5378 | DRM_DEBUG_KMS("[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5379 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5380 | plane->base.base.id, plane->base.name, |
| 5381 | old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b, |
| 5382 | old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b, |
| 5383 | old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b, |
| 5384 | old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b, |
| 5385 | old_wm->trans_wm.plane_res_b, |
| 5386 | new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b, |
| 5387 | new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b, |
| 5388 | new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b, |
| 5389 | new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b, |
| 5390 | new_wm->trans_wm.plane_res_b); |
| 5391 | |
| 5392 | DRM_DEBUG_KMS("[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5393 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
| 5394 | plane->base.base.id, plane->base.name, |
| 5395 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 5396 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 5397 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 5398 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 5399 | old_wm->trans_wm.min_ddb_alloc, |
| 5400 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 5401 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 5402 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 5403 | new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc, |
| 5404 | new_wm->trans_wm.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5405 | } |
| 5406 | } |
| 5407 | } |
| 5408 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5409 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5410 | skl_ddb_add_affected_pipes(struct intel_atomic_state *state, bool *changed) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5411 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5412 | struct drm_device *dev = state->base.dev; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5413 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5414 | struct intel_crtc *crtc; |
| 5415 | struct intel_crtc_state *crtc_state; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5416 | u32 realloc_pipes = pipes_modified(state); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5417 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5418 | |
| 5419 | /* |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5420 | * When we distrust bios wm we always need to recompute to set the |
| 5421 | * expected DDB allocations for each CRTC. |
| 5422 | */ |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5423 | if (dev_priv->wm.distrust_bios_wm) |
| 5424 | (*changed) = true; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5425 | |
| 5426 | /* |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5427 | * If this transaction isn't actually touching any CRTC's, don't |
| 5428 | * bother with watermark calculation. Note that if we pass this |
| 5429 | * test, we're guaranteed to hold at least one CRTC state mutex, |
| 5430 | * which means we can safely use values like dev_priv->active_crtcs |
| 5431 | * since any racing commits that want to update them would need to |
| 5432 | * hold _all_ CRTC state mutexes. |
| 5433 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5434 | for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5435 | (*changed) = true; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5436 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5437 | if (!*changed) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5438 | return 0; |
| 5439 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5440 | /* |
| 5441 | * If this is our first atomic update following hardware readout, |
| 5442 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 5443 | * pretend that all pipes switched active status so that we'll |
| 5444 | * ensure a full DDB recompute. |
| 5445 | */ |
| 5446 | if (dev_priv->wm.distrust_bios_wm) { |
| 5447 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5448 | state->base.acquire_ctx); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5449 | if (ret) |
| 5450 | return ret; |
| 5451 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5452 | state->active_pipe_changes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5453 | |
| 5454 | /* |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5455 | * We usually only initialize state->active_crtcs if we |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5456 | * we're doing a modeset; make sure this field is always |
| 5457 | * initialized during the sanitization process that happens |
| 5458 | * on the first commit too. |
| 5459 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5460 | if (!state->modeset) |
| 5461 | state->active_crtcs = dev_priv->active_crtcs; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | /* |
| 5465 | * If the modeset changes which CRTC's are active, we need to |
| 5466 | * recompute the DDB allocation for *all* active pipes, even |
| 5467 | * those that weren't otherwise being modified in any way by this |
| 5468 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 5469 | * when new active CRTC's are added, it's possible for a pipe that |
| 5470 | * we were already using and aren't changing at all here to suddenly |
| 5471 | * become invalid if its DDB needs exceeds its new allocation. |
| 5472 | * |
| 5473 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 5474 | * any other display updates race with this transaction, so we need |
| 5475 | * to grab the lock on *all* CRTC's. |
| 5476 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5477 | if (state->active_pipe_changes || state->modeset) { |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5478 | realloc_pipes = ~0; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5479 | state->wm_results.dirty_pipes = ~0; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | /* |
| 5483 | * We're not recomputing for the pipes not included in the commit, so |
| 5484 | * make sure we start with the current state. |
| 5485 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5486 | for_each_intel_crtc_mask(dev, crtc, realloc_pipes) { |
| 5487 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 5488 | if (IS_ERR(crtc_state)) |
| 5489 | return PTR_ERR(crtc_state); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | return 0; |
| 5493 | } |
| 5494 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5495 | /* |
| 5496 | * To make sure the cursor watermark registers are always consistent |
| 5497 | * with our computed state the following scenario needs special |
| 5498 | * treatment: |
| 5499 | * |
| 5500 | * 1. enable cursor |
| 5501 | * 2. move cursor entirely offscreen |
| 5502 | * 3. disable cursor |
| 5503 | * |
| 5504 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 5505 | * (since we consider an offscreen cursor still active for the purposes |
| 5506 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 5507 | * because the actual plane visibility isn't changing, and we don't |
| 5508 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 5509 | * force step 3. to call .disable_plane() to update the watermark |
| 5510 | * registers properly. |
| 5511 | * |
| 5512 | * Other planes do not suffer from this issues as their watermarks are |
| 5513 | * calculated based on the actual plane visibility. The only time this |
| 5514 | * can trigger for the other planes is during the initial readout as the |
| 5515 | * default value of the watermarks registers is not zero. |
| 5516 | */ |
| 5517 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 5518 | struct intel_crtc *crtc) |
| 5519 | { |
| 5520 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5521 | const struct intel_crtc_state *old_crtc_state = |
| 5522 | intel_atomic_get_old_crtc_state(state, crtc); |
| 5523 | struct intel_crtc_state *new_crtc_state = |
| 5524 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5525 | struct intel_plane *plane; |
| 5526 | |
| 5527 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5528 | struct intel_plane_state *plane_state; |
| 5529 | enum plane_id plane_id = plane->id; |
| 5530 | |
| 5531 | /* |
| 5532 | * Force a full wm update for every plane on modeset. |
| 5533 | * Required because the reset value of the wm registers |
| 5534 | * is non-zero, whereas we want all disabled planes to |
| 5535 | * have zero watermarks. So if we turn off the relevant |
| 5536 | * power well the hardware state will go out of sync |
| 5537 | * with the software state. |
| 5538 | */ |
| 5539 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->base) && |
| 5540 | skl_plane_wm_equals(dev_priv, |
| 5541 | &old_crtc_state->wm.skl.optimal.planes[plane_id], |
| 5542 | &new_crtc_state->wm.skl.optimal.planes[plane_id])) |
| 5543 | continue; |
| 5544 | |
| 5545 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 5546 | if (IS_ERR(plane_state)) |
| 5547 | return PTR_ERR(plane_state); |
| 5548 | |
| 5549 | new_crtc_state->update_planes |= BIT(plane_id); |
| 5550 | } |
| 5551 | |
| 5552 | return 0; |
| 5553 | } |
| 5554 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5555 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5556 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5557 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5558 | struct intel_crtc *crtc; |
| 5559 | struct intel_crtc_state *cstate; |
| 5560 | struct intel_crtc_state *old_crtc_state; |
| 5561 | struct skl_ddb_values *results = &state->wm_results; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5562 | struct skl_pipe_wm *pipe_wm; |
| 5563 | bool changed = false; |
| 5564 | int ret, i; |
| 5565 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5566 | /* Clear all dirty flags */ |
| 5567 | results->dirty_pipes = 0; |
| 5568 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5569 | ret = skl_ddb_add_affected_pipes(state, &changed); |
| 5570 | if (ret || !changed) |
| 5571 | return ret; |
| 5572 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5573 | /* |
| 5574 | * Calculate WM's for all pipes that are part of this transaction. |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5575 | * 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] | 5576 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 5577 | * pipe allocations had to change. |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5578 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5579 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 5580 | cstate, i) { |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5581 | const struct skl_pipe_wm *old_pipe_wm = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5582 | &old_crtc_state->wm.skl.optimal; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5583 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5584 | pipe_wm = &cstate->wm.skl.optimal; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5585 | ret = skl_update_pipe_wm(cstate, old_pipe_wm, pipe_wm, &changed); |
| 5586 | if (ret) |
| 5587 | return ret; |
| 5588 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5589 | ret = skl_wm_add_affected_planes(state, crtc); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5590 | if (ret) |
| 5591 | return ret; |
| 5592 | |
| 5593 | if (changed) |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5594 | results->dirty_pipes |= drm_crtc_mask(&crtc->base); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5595 | } |
| 5596 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5597 | ret = skl_compute_ddb(state); |
| 5598 | if (ret) |
| 5599 | return ret; |
| 5600 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5601 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5602 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5603 | return 0; |
| 5604 | } |
| 5605 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5606 | static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state, |
| 5607 | struct intel_crtc_state *cstate) |
| 5608 | { |
| 5609 | struct intel_crtc *crtc = to_intel_crtc(cstate->base.crtc); |
| 5610 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5611 | struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal; |
| 5612 | enum pipe pipe = crtc->pipe; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5613 | |
| 5614 | if (!(state->wm_results.dirty_pipes & drm_crtc_mask(&crtc->base))) |
| 5615 | return; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5616 | |
| 5617 | I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime); |
| 5618 | } |
| 5619 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5620 | static void skl_initial_wm(struct intel_atomic_state *state, |
| 5621 | struct intel_crtc_state *cstate) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5622 | { |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5623 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5624 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5625 | struct drm_i915_private *dev_priv = to_i915(dev); |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5626 | struct skl_ddb_values *results = &state->wm_results; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 5627 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5628 | if ((results->dirty_pipes & drm_crtc_mask(&intel_crtc->base)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5629 | return; |
| 5630 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5631 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5632 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5633 | if (cstate->base.active_changed) |
| 5634 | skl_atomic_update_crtc_wm(state, cstate); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5635 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5636 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5637 | } |
| 5638 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5639 | 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] | 5640 | struct intel_wm_config *config) |
| 5641 | { |
| 5642 | struct intel_crtc *crtc; |
| 5643 | |
| 5644 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5645 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5646 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 5647 | |
| 5648 | if (!wm->pipe_enabled) |
| 5649 | continue; |
| 5650 | |
| 5651 | config->sprites_enabled |= wm->sprites_enabled; |
| 5652 | config->sprites_scaled |= wm->sprites_scaled; |
| 5653 | config->num_pipes_active++; |
| 5654 | } |
| 5655 | } |
| 5656 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5657 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 5658 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5659 | 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] | 5660 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5661 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5662 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5663 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 5664 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5665 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5666 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5667 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 5668 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 5669 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5670 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5671 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5672 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5673 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 5674 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5675 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5676 | 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] | 5677 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5678 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5679 | } |
| 5680 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5681 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5682 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5683 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5684 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 5685 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5686 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 5687 | } |
| 5688 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5689 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
| 5690 | struct intel_crtc_state *cstate) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5691 | { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5692 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 5693 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5694 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5695 | mutex_lock(&dev_priv->wm.wm_mutex); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5696 | intel_crtc->wm.active.ilk = cstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5697 | ilk_program_watermarks(dev_priv); |
| 5698 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5699 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5700 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5701 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
| 5702 | struct intel_crtc_state *cstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5703 | { |
| 5704 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 5705 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
| 5706 | |
| 5707 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5708 | if (cstate->wm.need_postvbl_update) { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5709 | intel_crtc->wm.active.ilk = cstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5710 | ilk_program_watermarks(dev_priv); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5711 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5712 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5713 | } |
| 5714 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5715 | static inline void skl_wm_level_from_reg_val(u32 val, |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5716 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5717 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5718 | level->plane_en = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5719 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5720 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 5721 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 5722 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5723 | } |
| 5724 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5725 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5726 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5727 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5728 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5729 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5730 | int level, max_level; |
| 5731 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5732 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5733 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5734 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5735 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5736 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5737 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5738 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5739 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5740 | if (plane_id != PLANE_CURSOR) |
| 5741 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5742 | else |
| 5743 | val = I915_READ(CUR_WM(pipe, level)); |
| 5744 | |
| 5745 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 5746 | } |
| 5747 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5748 | if (plane_id != PLANE_CURSOR) |
| 5749 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5750 | else |
| 5751 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 5752 | |
| 5753 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 5754 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5755 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5756 | if (!crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5757 | return; |
| 5758 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5759 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5760 | } |
| 5761 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5762 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5763 | { |
Mahesh Kumar | 60f8e87 | 2018-04-09 09:11:00 +0530 | [diff] [blame] | 5764 | struct skl_ddb_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5765 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5766 | struct intel_crtc *crtc; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5767 | struct intel_crtc_state *cstate; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5768 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5769 | skl_ddb_get_hw_state(dev_priv, ddb); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5770 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5771 | cstate = to_intel_crtc_state(crtc->base.state); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5772 | |
| 5773 | skl_pipe_wm_get_hw_state(crtc, &cstate->wm.skl.optimal); |
| 5774 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5775 | if (crtc->active) |
| 5776 | hw->dirty_pipes |= drm_crtc_mask(&crtc->base); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5777 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5778 | |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5779 | if (dev_priv->active_crtcs) { |
| 5780 | /* Fully recompute DDB on first atomic commit */ |
| 5781 | dev_priv->wm.distrust_bios_wm = true; |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5782 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5783 | } |
| 5784 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5785 | 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] | 5786 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5787 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5788 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5789 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5790 | struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->base.state); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5791 | struct intel_pipe_wm *active = &cstate->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5792 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5793 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5794 | [PIPE_A] = WM0_PIPEA_ILK, |
| 5795 | [PIPE_B] = WM0_PIPEB_ILK, |
| 5796 | [PIPE_C] = WM0_PIPEC_IVB, |
| 5797 | }; |
| 5798 | |
| 5799 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5800 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 5801 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5802 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 5803 | memset(active, 0, sizeof(*active)); |
| 5804 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5805 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 5806 | |
| 5807 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5808 | u32 tmp = hw->wm_pipe[pipe]; |
| 5809 | |
| 5810 | /* |
| 5811 | * For active pipes LP0 watermark is marked as |
| 5812 | * enabled, and LP1+ watermaks as disabled since |
| 5813 | * we can't really reverse compute them in case |
| 5814 | * multiple pipes are active. |
| 5815 | */ |
| 5816 | active->wm[0].enable = true; |
| 5817 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 5818 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 5819 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 5820 | active->linetime = hw->wm_linetime[pipe]; |
| 5821 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5822 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5823 | |
| 5824 | /* |
| 5825 | * For inactive pipes, all watermark levels |
| 5826 | * should be marked as enabled but zeroed, |
| 5827 | * which is what we'd compute them to. |
| 5828 | */ |
| 5829 | for (level = 0; level <= max_level; level++) |
| 5830 | active->wm[level].enable = true; |
| 5831 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5832 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5833 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5834 | } |
| 5835 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5836 | #define _FW_WM(value, plane) \ |
| 5837 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 5838 | #define _FW_WM_VLV(value, plane) \ |
| 5839 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 5840 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5841 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 5842 | struct g4x_wm_values *wm) |
| 5843 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5844 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5845 | |
| 5846 | tmp = I915_READ(DSPFW1); |
| 5847 | wm->sr.plane = _FW_WM(tmp, SR); |
| 5848 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5849 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 5850 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 5851 | |
| 5852 | tmp = I915_READ(DSPFW2); |
| 5853 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 5854 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 5855 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 5856 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 5857 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5858 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 5859 | |
| 5860 | tmp = I915_READ(DSPFW3); |
| 5861 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 5862 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5863 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 5864 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 5865 | } |
| 5866 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5867 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 5868 | struct vlv_wm_values *wm) |
| 5869 | { |
| 5870 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5871 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5872 | |
| 5873 | for_each_pipe(dev_priv, pipe) { |
| 5874 | tmp = I915_READ(VLV_DDL(pipe)); |
| 5875 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5876 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5877 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5878 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5879 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5880 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5881 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5882 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5883 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 5884 | } |
| 5885 | |
| 5886 | tmp = I915_READ(DSPFW1); |
| 5887 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5888 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5889 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 5890 | 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] | 5891 | |
| 5892 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5893 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 5894 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5895 | 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] | 5896 | |
| 5897 | tmp = I915_READ(DSPFW3); |
| 5898 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5899 | |
| 5900 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5901 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5902 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5903 | 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] | 5904 | |
| 5905 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5906 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 5907 | 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] | 5908 | |
| 5909 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5910 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 5911 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5912 | |
| 5913 | tmp = I915_READ(DSPHOWM); |
| 5914 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5915 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 5916 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 5917 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 5918 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5919 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5920 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5921 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5922 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5923 | 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] | 5924 | } else { |
| 5925 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5926 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5927 | 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] | 5928 | |
| 5929 | tmp = I915_READ(DSPHOWM); |
| 5930 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5931 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5932 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5933 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5934 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5935 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5936 | 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] | 5937 | } |
| 5938 | } |
| 5939 | |
| 5940 | #undef _FW_WM |
| 5941 | #undef _FW_WM_VLV |
| 5942 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5943 | 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] | 5944 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5945 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 5946 | struct intel_crtc *crtc; |
| 5947 | |
| 5948 | g4x_read_wm_values(dev_priv, wm); |
| 5949 | |
| 5950 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 5951 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5952 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5953 | struct intel_crtc_state *crtc_state = |
| 5954 | to_intel_crtc_state(crtc->base.state); |
| 5955 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 5956 | struct g4x_pipe_wm *raw; |
| 5957 | enum pipe pipe = crtc->pipe; |
| 5958 | enum plane_id plane_id; |
| 5959 | int level, max_level; |
| 5960 | |
| 5961 | active->cxsr = wm->cxsr; |
| 5962 | active->hpll_en = wm->hpll_en; |
| 5963 | active->fbc_en = wm->fbc_en; |
| 5964 | |
| 5965 | active->sr = wm->sr; |
| 5966 | active->hpll = wm->hpll; |
| 5967 | |
| 5968 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5969 | active->wm.plane[plane_id] = |
| 5970 | wm->pipe[pipe].plane[plane_id]; |
| 5971 | } |
| 5972 | |
| 5973 | if (wm->cxsr && wm->hpll_en) |
| 5974 | max_level = G4X_WM_LEVEL_HPLL; |
| 5975 | else if (wm->cxsr) |
| 5976 | max_level = G4X_WM_LEVEL_SR; |
| 5977 | else |
| 5978 | max_level = G4X_WM_LEVEL_NORMAL; |
| 5979 | |
| 5980 | level = G4X_WM_LEVEL_NORMAL; |
| 5981 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5982 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5983 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 5984 | |
| 5985 | if (++level > max_level) |
| 5986 | goto out; |
| 5987 | |
| 5988 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5989 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 5990 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 5991 | raw->plane[PLANE_SPRITE0] = 0; |
| 5992 | raw->fbc = active->sr.fbc; |
| 5993 | |
| 5994 | if (++level > max_level) |
| 5995 | goto out; |
| 5996 | |
| 5997 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5998 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 5999 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 6000 | raw->plane[PLANE_SPRITE0] = 0; |
| 6001 | raw->fbc = active->hpll.fbc; |
| 6002 | |
| 6003 | out: |
| 6004 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6005 | g4x_raw_plane_wm_set(crtc_state, level, |
| 6006 | plane_id, USHRT_MAX); |
| 6007 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 6008 | |
| 6009 | crtc_state->wm.g4x.optimal = *active; |
| 6010 | crtc_state->wm.g4x.intermediate = *active; |
| 6011 | |
| 6012 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 6013 | pipe_name(pipe), |
| 6014 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6015 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6016 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
| 6017 | } |
| 6018 | |
| 6019 | DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 6020 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 6021 | DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 6022 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 6023 | DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", |
| 6024 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
| 6025 | } |
| 6026 | |
| 6027 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6028 | { |
| 6029 | struct intel_plane *plane; |
| 6030 | struct intel_crtc *crtc; |
| 6031 | |
| 6032 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6033 | |
| 6034 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6035 | struct intel_crtc *crtc = |
| 6036 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6037 | struct intel_crtc_state *crtc_state = |
| 6038 | to_intel_crtc_state(crtc->base.state); |
| 6039 | struct intel_plane_state *plane_state = |
| 6040 | to_intel_plane_state(plane->base.state); |
| 6041 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 6042 | enum plane_id plane_id = plane->id; |
| 6043 | int level; |
| 6044 | |
| 6045 | if (plane_state->base.visible) |
| 6046 | continue; |
| 6047 | |
| 6048 | for (level = 0; level < 3; level++) { |
| 6049 | struct g4x_pipe_wm *raw = |
| 6050 | &crtc_state->wm.g4x.raw[level]; |
| 6051 | |
| 6052 | raw->plane[plane_id] = 0; |
| 6053 | wm_state->wm.plane[plane_id] = 0; |
| 6054 | } |
| 6055 | |
| 6056 | if (plane_id == PLANE_PRIMARY) { |
| 6057 | for (level = 0; level < 3; level++) { |
| 6058 | struct g4x_pipe_wm *raw = |
| 6059 | &crtc_state->wm.g4x.raw[level]; |
| 6060 | raw->fbc = 0; |
| 6061 | } |
| 6062 | |
| 6063 | wm_state->sr.fbc = 0; |
| 6064 | wm_state->hpll.fbc = 0; |
| 6065 | wm_state->fbc_en = false; |
| 6066 | } |
| 6067 | } |
| 6068 | |
| 6069 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6070 | struct intel_crtc_state *crtc_state = |
| 6071 | to_intel_crtc_state(crtc->base.state); |
| 6072 | |
| 6073 | crtc_state->wm.g4x.intermediate = |
| 6074 | crtc_state->wm.g4x.optimal; |
| 6075 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 6076 | } |
| 6077 | |
| 6078 | g4x_program_watermarks(dev_priv); |
| 6079 | |
| 6080 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6081 | } |
| 6082 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6083 | 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] | 6084 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6085 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 6086 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6087 | u32 val; |
| 6088 | |
| 6089 | vlv_read_wm_values(dev_priv, wm); |
| 6090 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6091 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 6092 | wm->level = VLV_WM_LEVEL_PM2; |
| 6093 | |
| 6094 | if (IS_CHERRYVIEW(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6095 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6096 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 6097 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6098 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 6099 | wm->level = VLV_WM_LEVEL_PM5; |
| 6100 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6101 | /* |
| 6102 | * If DDR DVFS is disabled in the BIOS, Punit |
| 6103 | * will never ack the request. So if that happens |
| 6104 | * assume we don't have to enable/disable DDR DVFS |
| 6105 | * dynamically. To test that just set the REQ_ACK |
| 6106 | * bit to poke the Punit, but don't change the |
| 6107 | * HIGH/LOW bits so that we don't actually change |
| 6108 | * the current state. |
| 6109 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6110 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6111 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 6112 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 6113 | |
| 6114 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 6115 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 6116 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 6117 | "assuming DDR DVFS is disabled\n"); |
| 6118 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 6119 | } else { |
| 6120 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 6121 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 6122 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 6123 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6124 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6125 | mutex_unlock(&dev_priv->pcu_lock); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6126 | } |
| 6127 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6128 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6129 | struct intel_crtc_state *crtc_state = |
| 6130 | to_intel_crtc_state(crtc->base.state); |
| 6131 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 6132 | const struct vlv_fifo_state *fifo_state = |
| 6133 | &crtc_state->wm.vlv.fifo_state; |
| 6134 | enum pipe pipe = crtc->pipe; |
| 6135 | enum plane_id plane_id; |
| 6136 | int level; |
| 6137 | |
| 6138 | vlv_get_fifo_size(crtc_state); |
| 6139 | |
| 6140 | active->num_levels = wm->level + 1; |
| 6141 | active->cxsr = wm->cxsr; |
| 6142 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6143 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6144 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6145 | &crtc_state->wm.vlv.raw[level]; |
| 6146 | |
| 6147 | active->sr[level].plane = wm->sr.plane; |
| 6148 | active->sr[level].cursor = wm->sr.cursor; |
| 6149 | |
| 6150 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6151 | active->wm[level].plane[plane_id] = |
| 6152 | wm->pipe[pipe].plane[plane_id]; |
| 6153 | |
| 6154 | raw->plane[plane_id] = |
| 6155 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 6156 | fifo_state->plane[plane_id]); |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6161 | vlv_raw_plane_wm_set(crtc_state, level, |
| 6162 | plane_id, USHRT_MAX); |
| 6163 | vlv_invalidate_wms(crtc, active, level); |
| 6164 | |
| 6165 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 6166 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6167 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6168 | 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] | 6169 | pipe_name(pipe), |
| 6170 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6171 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6172 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 6173 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6174 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6175 | |
| 6176 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 6177 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 6178 | } |
| 6179 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6180 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6181 | { |
| 6182 | struct intel_plane *plane; |
| 6183 | struct intel_crtc *crtc; |
| 6184 | |
| 6185 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6186 | |
| 6187 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6188 | struct intel_crtc *crtc = |
| 6189 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6190 | struct intel_crtc_state *crtc_state = |
| 6191 | to_intel_crtc_state(crtc->base.state); |
| 6192 | struct intel_plane_state *plane_state = |
| 6193 | to_intel_plane_state(plane->base.state); |
| 6194 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 6195 | const struct vlv_fifo_state *fifo_state = |
| 6196 | &crtc_state->wm.vlv.fifo_state; |
| 6197 | enum plane_id plane_id = plane->id; |
| 6198 | int level; |
| 6199 | |
| 6200 | if (plane_state->base.visible) |
| 6201 | continue; |
| 6202 | |
| 6203 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6204 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6205 | &crtc_state->wm.vlv.raw[level]; |
| 6206 | |
| 6207 | raw->plane[plane_id] = 0; |
| 6208 | |
| 6209 | wm_state->wm[level].plane[plane_id] = |
| 6210 | vlv_invert_wm_value(raw->plane[plane_id], |
| 6211 | fifo_state->plane[plane_id]); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6216 | struct intel_crtc_state *crtc_state = |
| 6217 | to_intel_crtc_state(crtc->base.state); |
| 6218 | |
| 6219 | crtc_state->wm.vlv.intermediate = |
| 6220 | crtc_state->wm.vlv.optimal; |
| 6221 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 6222 | } |
| 6223 | |
| 6224 | vlv_program_watermarks(dev_priv); |
| 6225 | |
| 6226 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6227 | } |
| 6228 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6229 | /* |
| 6230 | * FIXME should probably kill this and improve |
| 6231 | * the real watermark readout/sanitation instead |
| 6232 | */ |
| 6233 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 6234 | { |
| 6235 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 6236 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 6237 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 6238 | |
| 6239 | /* |
| 6240 | * Don't touch WM1S_LP_EN here. |
| 6241 | * Doing so could cause underruns. |
| 6242 | */ |
| 6243 | } |
| 6244 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6245 | 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] | 6246 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6247 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6248 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6249 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6250 | ilk_init_lp_watermarks(dev_priv); |
| 6251 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6252 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6253 | ilk_pipe_wm_get_hw_state(crtc); |
| 6254 | |
| 6255 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 6256 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 6257 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 6258 | |
| 6259 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 6260 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 6261 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 6262 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 6263 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6264 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6265 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6266 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 6267 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 6268 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6269 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 6270 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6271 | |
| 6272 | hw->enable_fbc_wm = |
| 6273 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 6274 | } |
| 6275 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6276 | /** |
| 6277 | * intel_update_watermarks - update FIFO watermark values based on current modes |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 6278 | * @crtc: the #intel_crtc on which to compute the WM |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6279 | * |
| 6280 | * Calculate watermark values for the various WM regs based on current mode |
| 6281 | * and plane configuration. |
| 6282 | * |
| 6283 | * There are several cases to deal with here: |
| 6284 | * - normal (i.e. non-self-refresh) |
| 6285 | * - self-refresh (SR) mode |
| 6286 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 6287 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 6288 | * lines), so need to account for TLB latency |
| 6289 | * |
| 6290 | * The normal calculation is: |
| 6291 | * watermark = dotclock * bytes per pixel * latency |
| 6292 | * where latency is platform & configuration dependent (we assume pessimal |
| 6293 | * values here). |
| 6294 | * |
| 6295 | * The SR calculation is: |
| 6296 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 6297 | * bytes per pixel |
| 6298 | * where |
| 6299 | * line time = htotal / dotclock |
| 6300 | * surface width = hdisplay for normal plane and 64 for cursor |
| 6301 | * and latency is assumed to be high, as above. |
| 6302 | * |
| 6303 | * The final value programmed to the register should always be rounded up, |
| 6304 | * and include an extra 2 entries to account for clock crossings. |
| 6305 | * |
| 6306 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 6307 | * to set the non-SR watermarks to 8. |
| 6308 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6309 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6310 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6311 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6312 | |
| 6313 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 6314 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6315 | } |
| 6316 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6317 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 6318 | { |
| 6319 | u32 val; |
| 6320 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 6321 | if (!HAS_IPC(dev_priv)) |
| 6322 | return; |
| 6323 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6324 | val = I915_READ(DISP_ARB_CTL2); |
| 6325 | |
| 6326 | if (dev_priv->ipc_enabled) |
| 6327 | val |= DISP_IPC_ENABLE; |
| 6328 | else |
| 6329 | val &= ~DISP_IPC_ENABLE; |
| 6330 | |
| 6331 | I915_WRITE(DISP_ARB_CTL2, val); |
| 6332 | } |
| 6333 | |
| 6334 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 6335 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6336 | if (!HAS_IPC(dev_priv)) |
| 6337 | return; |
| 6338 | |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 6339 | /* Display WA #1141: SKL:all KBL:all CFL */ |
| 6340 | if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) |
| 6341 | dev_priv->ipc_enabled = dev_priv->dram_info.symmetric_memory; |
| 6342 | else |
| 6343 | dev_priv->ipc_enabled = true; |
| 6344 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6345 | intel_enable_ipc(dev_priv); |
| 6346 | } |
| 6347 | |
Jani Nikula | e282891 | 2016-01-18 09:19:47 +0200 | [diff] [blame] | 6348 | /* |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6349 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6350 | */ |
| 6351 | DEFINE_SPINLOCK(mchdev_lock); |
| 6352 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6353 | bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6354 | { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6355 | u16 rgvswctl; |
| 6356 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 6357 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6358 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6359 | rgvswctl = I915_READ16(MEMSWCTL); |
| 6360 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 6361 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 6362 | return false; /* still busy with another command */ |
| 6363 | } |
| 6364 | |
| 6365 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 6366 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 6367 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 6368 | POSTING_READ16(MEMSWCTL); |
| 6369 | |
| 6370 | rgvswctl |= MEMCTL_CMD_STS; |
| 6371 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 6372 | |
| 6373 | return true; |
| 6374 | } |
| 6375 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6376 | static void ironlake_enable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6377 | { |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 6378 | u32 rgvmodectl; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6379 | u8 fmax, fmin, fstart, vstart; |
| 6380 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6381 | spin_lock_irq(&mchdev_lock); |
| 6382 | |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 6383 | rgvmodectl = I915_READ(MEMMODECTL); |
| 6384 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6385 | /* Enable temp reporting */ |
| 6386 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 6387 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 6388 | |
| 6389 | /* 100ms RC evaluation intervals */ |
| 6390 | I915_WRITE(RCUPEI, 100000); |
| 6391 | I915_WRITE(RCDNEI, 100000); |
| 6392 | |
| 6393 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 6394 | I915_WRITE(RCBMAXAVG, 90000); |
| 6395 | I915_WRITE(RCBMINAVG, 80000); |
| 6396 | |
| 6397 | I915_WRITE(MEMIHYST, 1); |
| 6398 | |
| 6399 | /* Set up min, max, and cur for interrupt handling */ |
| 6400 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 6401 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 6402 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 6403 | MEMMODE_FSTART_SHIFT; |
| 6404 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 6405 | vstart = (I915_READ(PXVFREQ(fstart)) & PXVFREQ_PX_MASK) >> |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6406 | PXVFREQ_PX_SHIFT; |
| 6407 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6408 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 6409 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6410 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6411 | dev_priv->ips.max_delay = fstart; |
| 6412 | dev_priv->ips.min_delay = fmin; |
| 6413 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6414 | |
| 6415 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 6416 | fmax, fmin, fstart); |
| 6417 | |
| 6418 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 6419 | |
| 6420 | /* |
| 6421 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 6422 | */ |
| 6423 | |
| 6424 | I915_WRITE(VIDSTART, vstart); |
| 6425 | POSTING_READ(VIDSTART); |
| 6426 | |
| 6427 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 6428 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 6429 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6430 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6431 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6432 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6433 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6434 | ironlake_set_drps(dev_priv, fstart); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6435 | |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 6436 | dev_priv->ips.last_count1 = I915_READ(DMIEC) + |
| 6437 | I915_READ(DDREC) + I915_READ(CSIEC); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6438 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 6439 | dev_priv->ips.last_count2 = I915_READ(GFXEC); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 6440 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6441 | |
| 6442 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6443 | } |
| 6444 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6445 | static void ironlake_disable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6446 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6447 | u16 rgvswctl; |
| 6448 | |
| 6449 | spin_lock_irq(&mchdev_lock); |
| 6450 | |
| 6451 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6452 | |
| 6453 | /* Ack interrupts, disable EFC interrupt */ |
| 6454 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 6455 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 6456 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 6457 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 6458 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 6459 | |
| 6460 | /* Go back to the starting frequency */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6461 | ironlake_set_drps(dev_priv, dev_priv->ips.fstart); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6462 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6463 | rgvswctl |= MEMCTL_CMD_STS; |
| 6464 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6465 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6466 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6467 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6468 | } |
| 6469 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 6470 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 6471 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 6472 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 6473 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 6474 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6475 | 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] | 6476 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6477 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6478 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6479 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6480 | /* Only set the down limit when we've reached the lowest level to avoid |
| 6481 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 6482 | * race in the hw when coming out of rc6: There's a tiny window where |
| 6483 | * the hw runs at the minimal clock before selecting the desired |
| 6484 | * frequency, if the down threshold expires in that window we will not |
| 6485 | * receive a down interrupt. */ |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6486 | if (INTEL_GEN(dev_priv) >= 9) { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6487 | limits = (rps->max_freq_softlimit) << 23; |
| 6488 | if (val <= rps->min_freq_softlimit) |
| 6489 | limits |= (rps->min_freq_softlimit) << 14; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6490 | } else { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6491 | limits = rps->max_freq_softlimit << 24; |
| 6492 | if (val <= rps->min_freq_softlimit) |
| 6493 | limits |= rps->min_freq_softlimit << 16; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6494 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6495 | |
| 6496 | return limits; |
| 6497 | } |
| 6498 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6499 | 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] | 6500 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6501 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6502 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 6503 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6504 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6505 | lockdep_assert_held(&rps->power.mutex); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6506 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6507 | if (new_power == rps->power.mode) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6508 | return; |
| 6509 | |
| 6510 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 6511 | switch (new_power) { |
| 6512 | case LOW_POWER: |
| 6513 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6514 | ei_up = 16000; |
| 6515 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6516 | |
| 6517 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6518 | ei_down = 32000; |
| 6519 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6520 | break; |
| 6521 | |
| 6522 | case BETWEEN: |
| 6523 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6524 | ei_up = 13000; |
| 6525 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6526 | |
| 6527 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6528 | ei_down = 32000; |
| 6529 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6530 | break; |
| 6531 | |
| 6532 | case HIGH_POWER: |
| 6533 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6534 | ei_up = 10000; |
| 6535 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6536 | |
| 6537 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6538 | ei_down = 32000; |
| 6539 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6540 | break; |
| 6541 | } |
| 6542 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6543 | /* When byt can survive without system hang with dynamic |
| 6544 | * sw freq adjustments, this restriction can be lifted. |
| 6545 | */ |
| 6546 | if (IS_VALLEYVIEW(dev_priv)) |
| 6547 | goto skip_hw_write; |
| 6548 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6549 | I915_WRITE(GEN6_RP_UP_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6550 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6551 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6552 | GT_INTERVAL_FROM_US(dev_priv, |
| 6553 | ei_up * threshold_up / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6554 | |
| 6555 | I915_WRITE(GEN6_RP_DOWN_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6556 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6557 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6558 | GT_INTERVAL_FROM_US(dev_priv, |
| 6559 | ei_down * threshold_down / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6560 | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6561 | I915_WRITE(GEN6_RP_CONTROL, |
| 6562 | GEN6_RP_MEDIA_TURBO | |
| 6563 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6564 | GEN6_RP_MEDIA_IS_GFX | |
| 6565 | GEN6_RP_ENABLE | |
| 6566 | GEN6_RP_UP_BUSY_AVG | |
| 6567 | GEN6_RP_DOWN_IDLE_AVG); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6568 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6569 | skip_hw_write: |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6570 | rps->power.mode = new_power; |
| 6571 | rps->power.up_threshold = threshold_up; |
| 6572 | rps->power.down_threshold = threshold_down; |
| 6573 | } |
| 6574 | |
| 6575 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 6576 | { |
| 6577 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6578 | int new_power; |
| 6579 | |
| 6580 | new_power = rps->power.mode; |
| 6581 | switch (rps->power.mode) { |
| 6582 | case LOW_POWER: |
| 6583 | if (val > rps->efficient_freq + 1 && |
| 6584 | val > rps->cur_freq) |
| 6585 | new_power = BETWEEN; |
| 6586 | break; |
| 6587 | |
| 6588 | case BETWEEN: |
| 6589 | if (val <= rps->efficient_freq && |
| 6590 | val < rps->cur_freq) |
| 6591 | new_power = LOW_POWER; |
| 6592 | else if (val >= rps->rp0_freq && |
| 6593 | val > rps->cur_freq) |
| 6594 | new_power = HIGH_POWER; |
| 6595 | break; |
| 6596 | |
| 6597 | case HIGH_POWER: |
| 6598 | if (val < (rps->rp1_freq + rps->rp0_freq) >> 1 && |
| 6599 | val < rps->cur_freq) |
| 6600 | new_power = BETWEEN; |
| 6601 | break; |
| 6602 | } |
| 6603 | /* Max/min bins are special */ |
| 6604 | if (val <= rps->min_freq_softlimit) |
| 6605 | new_power = LOW_POWER; |
| 6606 | if (val >= rps->max_freq_softlimit) |
| 6607 | new_power = HIGH_POWER; |
| 6608 | |
| 6609 | mutex_lock(&rps->power.mutex); |
| 6610 | if (rps->power.interactive) |
| 6611 | new_power = HIGH_POWER; |
| 6612 | rps_set_power(dev_priv, new_power); |
| 6613 | mutex_unlock(&rps->power.mutex); |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6614 | } |
| 6615 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 6616 | void intel_rps_mark_interactive(struct drm_i915_private *i915, bool interactive) |
| 6617 | { |
| 6618 | struct intel_rps *rps = &i915->gt_pm.rps; |
| 6619 | |
| 6620 | if (INTEL_GEN(i915) < 6) |
| 6621 | return; |
| 6622 | |
| 6623 | mutex_lock(&rps->power.mutex); |
| 6624 | if (interactive) { |
| 6625 | if (!rps->power.interactive++ && READ_ONCE(i915->gt.awake)) |
| 6626 | rps_set_power(i915, HIGH_POWER); |
| 6627 | } else { |
| 6628 | GEM_BUG_ON(!rps->power.interactive); |
| 6629 | rps->power.interactive--; |
| 6630 | } |
| 6631 | mutex_unlock(&rps->power.mutex); |
| 6632 | } |
| 6633 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6634 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 6635 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6636 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6637 | u32 mask = 0; |
| 6638 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6639 | /* 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] | 6640 | if (val > rps->min_freq_softlimit) |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6641 | 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] | 6642 | if (val < rps->max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 6643 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6644 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 6645 | mask &= dev_priv->pm_rps_events; |
| 6646 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 6647 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6648 | } |
| 6649 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6650 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 6651 | * called when the range (min_delay and max_delay) is modified so that we can |
| 6652 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6653 | 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] | 6654 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6655 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6656 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6657 | /* min/max delay may still have been modified so be sure to |
| 6658 | * write the limits value. |
| 6659 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6660 | if (val != rps->cur_freq) { |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6661 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6662 | |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6663 | if (INTEL_GEN(dev_priv) >= 9) |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 6664 | I915_WRITE(GEN6_RPNSWREQ, |
| 6665 | GEN9_FREQUENCY(val)); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6666 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6667 | I915_WRITE(GEN6_RPNSWREQ, |
| 6668 | HSW_FREQUENCY(val)); |
| 6669 | else |
| 6670 | I915_WRITE(GEN6_RPNSWREQ, |
| 6671 | GEN6_FREQUENCY(val) | |
| 6672 | GEN6_OFFSET(0) | |
| 6673 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6674 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6675 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6676 | /* Make sure we continue to get interrupts |
| 6677 | * until we hit the minimum or maximum frequencies. |
| 6678 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6679 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6680 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6681 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6682 | rps->cur_freq = val; |
Mika Kuoppala | 0f94592 | 2015-11-17 18:14:26 +0200 | [diff] [blame] | 6683 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6684 | |
| 6685 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6686 | } |
| 6687 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6688 | 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] | 6689 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6690 | int err; |
| 6691 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6692 | if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1), |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6693 | "Odd GPU freq value\n")) |
| 6694 | val &= ~1; |
| 6695 | |
Deepak S | cd25dd5 | 2015-07-10 18:31:40 +0530 | [diff] [blame] | 6696 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 6697 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6698 | if (val != dev_priv->gt_pm.rps.cur_freq) { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6699 | err = vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 6700 | if (err) |
| 6701 | return err; |
| 6702 | |
Chris Wilson | db4c5e0 | 2017-02-10 15:03:46 +0000 | [diff] [blame] | 6703 | gen6_set_rps_thresholds(dev_priv, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 6704 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6705 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6706 | dev_priv->gt_pm.rps.cur_freq = val; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6707 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6708 | |
| 6709 | return 0; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6710 | } |
| 6711 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6712 | /* 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] | 6713 | * |
| 6714 | * * If Gfx is Idle, then |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6715 | * 1. Forcewake Media well. |
| 6716 | * 2. Request idle freq. |
| 6717 | * 3. Release Forcewake of Media well. |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6718 | */ |
| 6719 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 6720 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6721 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6722 | u32 val = rps->idle_freq; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6723 | int err; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 6724 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6725 | if (rps->cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6726 | return; |
| 6727 | |
Chris Wilson | c9efef7 | 2017-01-02 15:28:45 +0000 | [diff] [blame] | 6728 | /* The punit delays the write of the frequency and voltage until it |
| 6729 | * determines the GPU is awake. During normal usage we don't want to |
| 6730 | * waste power changing the frequency if the GPU is sleeping (rc6). |
| 6731 | * However, the GPU and driver is now idle and we do not want to delay |
| 6732 | * switching to minimum voltage (reducing power whilst idle) as we do |
| 6733 | * not expect to be woken in the near future and so must flush the |
| 6734 | * change by waking the device. |
| 6735 | * |
| 6736 | * We choose to take the media powerwell (either would do to trick the |
| 6737 | * punit into committing the voltage change) as that takes a lot less |
| 6738 | * power than the render powerwell. |
| 6739 | */ |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6740 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6741 | err = valleyview_set_rps(dev_priv, val); |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6742 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6743 | |
| 6744 | if (err) |
| 6745 | DRM_ERROR("Failed to set RPS for idle\n"); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6746 | } |
| 6747 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6748 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 6749 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6750 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6751 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6752 | mutex_lock(&dev_priv->pcu_lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6753 | if (rps->enabled) { |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6754 | u8 freq; |
| 6755 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6756 | if (dev_priv->pm_rps_events & GEN6_PM_RP_UP_EI_EXPIRED) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6757 | gen6_rps_reset_ei(dev_priv); |
| 6758 | I915_WRITE(GEN6_PMINTRMSK, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6759 | gen6_rps_pm_mask(dev_priv, rps->cur_freq)); |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 6760 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6761 | gen6_enable_rps_interrupts(dev_priv); |
| 6762 | |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6763 | /* Use the user's desired frequency as a guide, but for better |
| 6764 | * performance, jump directly to RPe as our starting frequency. |
| 6765 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6766 | freq = max(rps->cur_freq, |
| 6767 | rps->efficient_freq); |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6768 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6769 | if (intel_set_rps(dev_priv, |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6770 | clamp(freq, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6771 | rps->min_freq_softlimit, |
| 6772 | rps->max_freq_softlimit))) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6773 | DRM_DEBUG_DRIVER("Failed to set idle frequency\n"); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6774 | } |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6775 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6776 | } |
| 6777 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6778 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 6779 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6780 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6781 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6782 | /* Flush our bottom-half so that it does not race with us |
| 6783 | * setting the idle frequency and so that it is bounded by |
| 6784 | * our rpm wakeref. And then disable the interrupts to stop any |
| 6785 | * futher RPS reclocking whilst we are asleep. |
| 6786 | */ |
| 6787 | gen6_disable_rps_interrupts(dev_priv); |
| 6788 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6789 | mutex_lock(&dev_priv->pcu_lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6790 | if (rps->enabled) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6791 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6792 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6793 | else |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6794 | gen6_set_rps(dev_priv, rps->idle_freq); |
| 6795 | rps->last_adj = 0; |
Ville Syrjälä | 12c100b | 2016-05-23 17:42:48 +0300 | [diff] [blame] | 6796 | I915_WRITE(GEN6_PMINTRMSK, |
| 6797 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6798 | } |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6799 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6800 | } |
| 6801 | |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 6802 | void gen6_rps_boost(struct i915_request *rq) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6803 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6804 | struct intel_rps *rps = &rq->i915->gt_pm.rps; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6805 | unsigned long flags; |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6806 | bool boost; |
| 6807 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6808 | /* This is intentionally racy! We peek at the state here, then |
| 6809 | * validate inside the RPS worker. |
| 6810 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6811 | if (!rps->enabled) |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6812 | return; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6813 | |
Chris Wilson | 0e21834 | 2019-01-21 22:21:02 +0000 | [diff] [blame] | 6814 | if (i915_request_signaled(rq)) |
Chris Wilson | 253a281 | 2018-02-06 14:31:37 +0000 | [diff] [blame] | 6815 | return; |
| 6816 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 6817 | /* Serializes with i915_request_retire() */ |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6818 | boost = false; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6819 | spin_lock_irqsave(&rq->lock, flags); |
Chris Wilson | 253a281 | 2018-02-06 14:31:37 +0000 | [diff] [blame] | 6820 | if (!rq->waitboost && !dma_fence_is_signaled_locked(&rq->fence)) { |
| 6821 | boost = !atomic_fetch_inc(&rps->num_waiters); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6822 | rq->waitboost = true; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6823 | } |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6824 | spin_unlock_irqrestore(&rq->lock, flags); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6825 | if (!boost) |
| 6826 | return; |
| 6827 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6828 | if (READ_ONCE(rps->cur_freq) < rps->boost_freq) |
| 6829 | schedule_work(&rps->work); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6830 | |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 6831 | atomic_inc(&rps->boosts); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6832 | } |
| 6833 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6834 | int intel_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6835 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6836 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6837 | int err; |
| 6838 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6839 | lockdep_assert_held(&dev_priv->pcu_lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6840 | GEM_BUG_ON(val > rps->max_freq); |
| 6841 | GEM_BUG_ON(val < rps->min_freq); |
Chris Wilson | cfd1c48 | 2017-02-20 09:47:07 +0000 | [diff] [blame] | 6842 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6843 | if (!rps->enabled) { |
| 6844 | rps->cur_freq = val; |
Chris Wilson | 76e4e4b | 2017-02-20 09:47:08 +0000 | [diff] [blame] | 6845 | return 0; |
| 6846 | } |
| 6847 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6848 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6849 | err = valleyview_set_rps(dev_priv, val); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6850 | else |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6851 | err = gen6_set_rps(dev_priv, val); |
| 6852 | |
| 6853 | return err; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6854 | } |
| 6855 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6856 | static void gen9_disable_rc6(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6857 | { |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6858 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6859 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6860 | } |
| 6861 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6862 | static void gen9_disable_rps(struct drm_i915_private *dev_priv) |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6863 | { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6864 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6865 | } |
| 6866 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6867 | static void gen6_disable_rc6(struct drm_i915_private *dev_priv) |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6868 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6869 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6870 | } |
| 6871 | |
| 6872 | static void gen6_disable_rps(struct drm_i915_private *dev_priv) |
| 6873 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6874 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6875 | I915_WRITE(GEN6_RP_CONTROL, 0); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6876 | } |
| 6877 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6878 | static void cherryview_disable_rc6(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6879 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6880 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6881 | } |
| 6882 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6883 | static void cherryview_disable_rps(struct drm_i915_private *dev_priv) |
| 6884 | { |
| 6885 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6886 | } |
| 6887 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6888 | static void valleyview_disable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6889 | { |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6890 | /* We're doing forcewake before Disabling RC6, |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6891 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6892 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6893 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6894 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6895 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6896 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6897 | } |
| 6898 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6899 | static void valleyview_disable_rps(struct drm_i915_private *dev_priv) |
| 6900 | { |
| 6901 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6902 | } |
| 6903 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6904 | 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] | 6905 | { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6906 | bool enable_rc6 = true; |
| 6907 | unsigned long rc6_ctx_base; |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6908 | u32 rc_ctl; |
| 6909 | int rc_sw_target; |
| 6910 | |
| 6911 | rc_ctl = I915_READ(GEN6_RC_CONTROL); |
| 6912 | rc_sw_target = (I915_READ(GEN6_RC_STATE) & RC_SW_TARGET_STATE_MASK) >> |
| 6913 | RC_SW_TARGET_STATE_SHIFT; |
| 6914 | DRM_DEBUG_DRIVER("BIOS enabled RC states: " |
| 6915 | "HW_CTRL %s HW_RC6 %s SW_TARGET_STATE %x\n", |
| 6916 | onoff(rc_ctl & GEN6_RC_CTL_HW_ENABLE), |
| 6917 | onoff(rc_ctl & GEN6_RC_CTL_RC6_ENABLE), |
| 6918 | rc_sw_target); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6919 | |
| 6920 | if (!(I915_READ(RC6_LOCATION) & RC6_CTX_IN_DRAM)) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6921 | DRM_DEBUG_DRIVER("RC6 Base location not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6922 | enable_rc6 = false; |
| 6923 | } |
| 6924 | |
| 6925 | /* |
| 6926 | * The exact context size is not known for BXT, so assume a page size |
| 6927 | * for this check. |
| 6928 | */ |
| 6929 | rc6_ctx_base = I915_READ(RC6_CTX_BASE) & RC6_CTX_BASE_MASK; |
Matthew Auld | 17a0534 | 2017-12-11 15:18:19 +0000 | [diff] [blame] | 6930 | if (!((rc6_ctx_base >= dev_priv->dsm_reserved.start) && |
| 6931 | (rc6_ctx_base + PAGE_SIZE < dev_priv->dsm_reserved.end))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6932 | DRM_DEBUG_DRIVER("RC6 Base address not as expected.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6933 | enable_rc6 = false; |
| 6934 | } |
| 6935 | |
| 6936 | if (!(((I915_READ(PWRCTX_MAXCNT_RCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6937 | ((I915_READ(PWRCTX_MAXCNT_VCSUNIT0) & IDLE_TIME_MASK) > 1) && |
| 6938 | ((I915_READ(PWRCTX_MAXCNT_BCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6939 | ((I915_READ(PWRCTX_MAXCNT_VECSUNIT) & IDLE_TIME_MASK) > 1))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6940 | DRM_DEBUG_DRIVER("Engine Idle wait time not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6941 | enable_rc6 = false; |
| 6942 | } |
| 6943 | |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6944 | if (!I915_READ(GEN8_PUSHBUS_CONTROL) || |
| 6945 | !I915_READ(GEN8_PUSHBUS_ENABLE) || |
| 6946 | !I915_READ(GEN8_PUSHBUS_SHIFT)) { |
| 6947 | DRM_DEBUG_DRIVER("Pushbus not setup properly.\n"); |
| 6948 | enable_rc6 = false; |
| 6949 | } |
| 6950 | |
| 6951 | if (!I915_READ(GEN6_GFXPAUSE)) { |
| 6952 | DRM_DEBUG_DRIVER("GFX pause not setup properly.\n"); |
| 6953 | enable_rc6 = false; |
| 6954 | } |
| 6955 | |
| 6956 | if (!I915_READ(GEN8_MISC_CTRL0)) { |
| 6957 | DRM_DEBUG_DRIVER("GPM control not setup properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6958 | enable_rc6 = false; |
| 6959 | } |
| 6960 | |
| 6961 | return enable_rc6; |
| 6962 | } |
| 6963 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 6964 | static bool sanitize_rc6(struct drm_i915_private *i915) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6965 | { |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 6966 | struct intel_device_info *info = mkwrite_device_info(i915); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6967 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 6968 | /* Powersaving is controlled by the host when inside a VM */ |
| 6969 | if (intel_vgpu_active(i915)) |
| 6970 | info->has_rc6 = 0; |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6971 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 6972 | if (info->has_rc6 && |
| 6973 | IS_GEN9_LP(i915) && !bxt_check_bios_rc6_setup(i915)) { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6974 | DRM_INFO("RC6 disabled by BIOS\n"); |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 6975 | info->has_rc6 = 0; |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6976 | } |
| 6977 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 6978 | /* |
| 6979 | * We assume that we do not have any deep rc6 levels if we don't have |
| 6980 | * have the previous rc6 level supported, i.e. we use HAS_RC6() |
| 6981 | * as the initial coarse check for rc6 in general, moving on to |
| 6982 | * progressively finer/deeper levels. |
| 6983 | */ |
| 6984 | if (!info->has_rc6 && info->has_rc6p) |
| 6985 | info->has_rc6p = 0; |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6986 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 6987 | return info->has_rc6; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6988 | } |
| 6989 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6990 | static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6991 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6992 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6993 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6994 | /* All of these values are in units of 50MHz */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6995 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6996 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 6997 | if (IS_GEN9_LP(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6998 | u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6999 | rps->rp0_freq = (rp_state_cap >> 16) & 0xff; |
| 7000 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 7001 | rps->min_freq = (rp_state_cap >> 0) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 7002 | } else { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7003 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7004 | rps->rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 7005 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 7006 | rps->min_freq = (rp_state_cap >> 16) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 7007 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7008 | /* hw_max = RP0 until we check for overclocking */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7009 | rps->max_freq = rps->rp0_freq; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7010 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7011 | rps->efficient_freq = rps->rp1_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7012 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) || |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7013 | IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7014 | u32 ddcc_status = 0; |
| 7015 | |
| 7016 | if (sandybridge_pcode_read(dev_priv, |
| 7017 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 7018 | &ddcc_status) == 0) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7019 | rps->efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 7020 | clamp_t(u8, |
| 7021 | ((ddcc_status >> 8) & 0xff), |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7022 | rps->min_freq, |
| 7023 | rps->max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 7024 | } |
| 7025 | |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7026 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 7027 | /* Store the frequency values in 16.66 MHZ units, which is |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7028 | * the natural hardware unit for SKL |
| 7029 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7030 | rps->rp0_freq *= GEN9_FREQ_SCALER; |
| 7031 | rps->rp1_freq *= GEN9_FREQ_SCALER; |
| 7032 | rps->min_freq *= GEN9_FREQ_SCALER; |
| 7033 | rps->max_freq *= GEN9_FREQ_SCALER; |
| 7034 | rps->efficient_freq *= GEN9_FREQ_SCALER; |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 7035 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 7036 | } |
| 7037 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7038 | static void reset_rps(struct drm_i915_private *dev_priv, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 7039 | int (*set)(struct drm_i915_private *, u8)) |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7040 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7041 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7042 | u8 freq = rps->cur_freq; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7043 | |
| 7044 | /* force a reset */ |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 7045 | rps->power.mode = -1; |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7046 | rps->cur_freq = -1; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7047 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 7048 | if (set(dev_priv, freq)) |
| 7049 | DRM_ERROR("Failed to reset RPS to initial values\n"); |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7050 | } |
| 7051 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7052 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7053 | static void gen9_enable_rps(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7054 | { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7055 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 7056 | |
David Weinehall | 36fe778 | 2017-11-17 10:01:46 +0200 | [diff] [blame] | 7057 | /* Program defaults and thresholds for RPS */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7058 | if (IS_GEN(dev_priv, 9)) |
David Weinehall | 36fe778 | 2017-11-17 10:01:46 +0200 | [diff] [blame] | 7059 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 7060 | GEN9_FREQUENCY(dev_priv->gt_pm.rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7061 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 7062 | /* 1 second timeout*/ |
| 7063 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 7064 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 7065 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7066 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7067 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 7068 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 7069 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 7070 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7071 | reset_rps(dev_priv, gen6_set_rps); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7072 | |
| 7073 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 7074 | } |
| 7075 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7076 | static void gen9_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 7077 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7078 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7079 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7080 | u32 rc6_mode; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7081 | |
| 7082 | /* 1a: Software RC state - RC0 */ |
| 7083 | I915_WRITE(GEN6_RC_STATE, 0); |
| 7084 | |
| 7085 | /* 1b: Get forcewake during program sequence. Although the driver |
| 7086 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7087 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7088 | |
| 7089 | /* 2a: Disable RC states. */ |
| 7090 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7091 | |
| 7092 | /* 2b: Program RC6 thresholds.*/ |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7093 | if (INTEL_GEN(dev_priv) >= 10) { |
| 7094 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16 | 85); |
| 7095 | I915_WRITE(GEN10_MEDIA_WAKE_RATE_LIMIT, 150); |
| 7096 | } else if (IS_SKYLAKE(dev_priv)) { |
| 7097 | /* |
| 7098 | * WaRsDoubleRc6WrlWithCoarsePowerGating:skl Doubling WRL only |
| 7099 | * when CPG is enabled |
| 7100 | */ |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 7101 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 108 << 16); |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7102 | } else { |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 7103 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 7104 | } |
| 7105 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7106 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7107 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7108 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7109 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 7110 | |
Dave Gordon | 1a3d189 | 2016-05-13 15:36:30 +0100 | [diff] [blame] | 7111 | if (HAS_GUC(dev_priv)) |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 7112 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 7113 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7114 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7115 | |
Chris Wilson | c1beabc | 2018-01-22 13:55:41 +0000 | [diff] [blame] | 7116 | /* |
| 7117 | * 2c: Program Coarse Power Gating Policies. |
| 7118 | * |
| 7119 | * Bspec's guidance is to use 25us (really 25 * 1280ns) here. What we |
| 7120 | * use instead is a more conservative estimate for the maximum time |
| 7121 | * it takes us to service a CS interrupt and submit a new ELSP - that |
| 7122 | * is the time which the GPU is idle waiting for the CPU to select the |
| 7123 | * next request to execute. If the idle hysteresis is less than that |
| 7124 | * interrupt service latency, the hardware will automatically gate |
| 7125 | * the power well and we will then incur the wake up cost on top of |
| 7126 | * the service latency. A similar guide from intel_pstate is that we |
| 7127 | * do not want the enable hysteresis to less than the wakeup latency. |
| 7128 | * |
| 7129 | * igt/gem_exec_nop/sequential provides a rough estimate for the |
| 7130 | * service latency, and puts it around 10us for Broadwell (and other |
| 7131 | * big core) and around 40us for Broxton (and other low power cores). |
| 7132 | * [Note that for legacy ringbuffer submission, this is less than 1us!] |
| 7133 | * However, the wakeup latency on Broxton is closer to 100us. To be |
| 7134 | * conservative, we have to factor in a context switch on top (due |
| 7135 | * to ksoftirqd). |
| 7136 | */ |
| 7137 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 250); |
| 7138 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 250); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 7139 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7140 | /* 3a: Enable RC6 */ |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 7141 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
Rodrigo Vivi | e4ffc83 | 2017-08-22 16:58:28 -0700 | [diff] [blame] | 7142 | |
| 7143 | /* WaRsUseTimeoutMode:cnl (pre-prod) */ |
| 7144 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_C0)) |
| 7145 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
| 7146 | else |
| 7147 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 7148 | |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 7149 | I915_WRITE(GEN6_RC_CONTROL, |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7150 | GEN6_RC_CTL_HW_ENABLE | |
| 7151 | GEN6_RC_CTL_RC6_ENABLE | |
| 7152 | rc6_mode); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7153 | |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 7154 | /* |
| 7155 | * 3b: Enable Coarse Power Gating only when RC6 is enabled. |
Rodrigo Vivi | d66047e4 | 2018-02-22 12:05:35 -0800 | [diff] [blame] | 7156 | * WaRsDisableCoarsePowerGating:skl,cnl - Render/Media PG need to be disabled with RC6. |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 7157 | */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7158 | if (NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 7159 | I915_WRITE(GEN9_PG_ENABLE, 0); |
| 7160 | else |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7161 | I915_WRITE(GEN9_PG_ENABLE, |
| 7162 | GEN9_RENDER_PG_ENABLE | GEN9_MEDIA_PG_ENABLE); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 7163 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7164 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 7165 | } |
| 7166 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7167 | static void gen8_enable_rc6(struct drm_i915_private *dev_priv) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7168 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7169 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7170 | enum intel_engine_id id; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7171 | |
| 7172 | /* 1a: Software RC state - RC0 */ |
| 7173 | I915_WRITE(GEN6_RC_STATE, 0); |
| 7174 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7175 | /* 1b: Get forcewake during program sequence. Although the driver |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7176 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7177 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7178 | |
| 7179 | /* 2a: Disable RC states. */ |
| 7180 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7181 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7182 | /* 2b: Program RC6 thresholds.*/ |
| 7183 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 7184 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7185 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7186 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7187 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7188 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Sagar Arun Kamble | 415544d | 2017-10-10 22:30:00 +0100 | [diff] [blame] | 7189 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7190 | |
| 7191 | /* 3: Enable RC6 */ |
Sagar Arun Kamble | 415544d | 2017-10-10 22:30:00 +0100 | [diff] [blame] | 7192 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7193 | I915_WRITE(GEN6_RC_CONTROL, |
| 7194 | GEN6_RC_CTL_HW_ENABLE | |
| 7195 | GEN7_RC_CTL_TO_MODE | |
| 7196 | GEN6_RC_CTL_RC6_ENABLE); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7197 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7198 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 7199 | } |
| 7200 | |
| 7201 | static void gen8_enable_rps(struct drm_i915_private *dev_priv) |
| 7202 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7203 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7204 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7205 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 7206 | |
| 7207 | /* 1 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 7208 | I915_WRITE(GEN6_RPNSWREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7209 | HSW_FREQUENCY(rps->rp1_freq)); |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 7210 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7211 | HSW_FREQUENCY(rps->rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7212 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 7213 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7214 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7215 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 7216 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7217 | rps->max_freq_softlimit << 24 | |
| 7218 | rps->min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7219 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7220 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 7221 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 7222 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 7223 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7224 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7225 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7226 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 7227 | /* 2: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7228 | I915_WRITE(GEN6_RP_CONTROL, |
| 7229 | GEN6_RP_MEDIA_TURBO | |
| 7230 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7231 | GEN6_RP_MEDIA_IS_GFX | |
| 7232 | GEN6_RP_ENABLE | |
| 7233 | GEN6_RP_UP_BUSY_AVG | |
| 7234 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7235 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7236 | reset_rps(dev_priv, gen6_set_rps); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 7237 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7238 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 7239 | } |
| 7240 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7241 | static void gen6_enable_rc6(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7242 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7243 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7244 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7245 | u32 rc6vids, rc6_mask; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7246 | u32 gtfifodbg; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 7247 | int ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7248 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7249 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7250 | |
| 7251 | /* Clear the DBG now so we don't confuse earlier errors */ |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7252 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7253 | if (gtfifodbg) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7254 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 7255 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7256 | } |
| 7257 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7258 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7259 | |
| 7260 | /* disable the counters and set deterministic thresholds */ |
| 7261 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7262 | |
| 7263 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 7264 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 7265 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 7266 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 7267 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 7268 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7269 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7270 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7271 | |
| 7272 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7273 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7274 | if (IS_IVYBRIDGE(dev_priv)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 7275 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 7276 | else |
| 7277 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 7278 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7279 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 7280 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 7281 | /* We don't use those on Haswell */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7282 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 7283 | if (HAS_RC6p(dev_priv)) |
| 7284 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
| 7285 | if (HAS_RC6pp(dev_priv)) |
| 7286 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7287 | I915_WRITE(GEN6_RC_CONTROL, |
| 7288 | rc6_mask | |
| 7289 | GEN6_RC_CTL_EI_MODE(1) | |
| 7290 | GEN6_RC_CTL_HW_ENABLE); |
| 7291 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 7292 | rc6vids = 0; |
| 7293 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7294 | if (IS_GEN(dev_priv, 6) && ret) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 7295 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7296 | } 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] | 7297 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 7298 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 7299 | rc6vids &= 0xffff00; |
| 7300 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 7301 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 7302 | if (ret) |
| 7303 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 7304 | } |
| 7305 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7306 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7307 | } |
| 7308 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7309 | static void gen6_enable_rps(struct drm_i915_private *dev_priv) |
| 7310 | { |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 7311 | /* Here begins a magic sequence of register writes to enable |
| 7312 | * auto-downclocking. |
| 7313 | * |
| 7314 | * Perhaps there might be some value in exposing these to |
| 7315 | * userspace... |
| 7316 | */ |
| 7317 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 7318 | |
| 7319 | /* Power down if completely idle for over 50ms */ |
| 7320 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
| 7321 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7322 | |
| 7323 | reset_rps(dev_priv, gen6_set_rps); |
| 7324 | |
| 7325 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 7326 | } |
| 7327 | |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7328 | static void gen6_update_ring_freq(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7329 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7330 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Mika Kuoppala | 66c1f77 | 2018-03-20 17:17:33 +0200 | [diff] [blame] | 7331 | const int min_freq = 15; |
| 7332 | const int scaling_factor = 180; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7333 | unsigned int gpu_freq; |
| 7334 | unsigned int max_ia_freq, min_ring_freq; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7335 | unsigned int max_gpu_freq, min_gpu_freq; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7336 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7337 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 7338 | WARN_ON(!mutex_is_locked(&dev_priv->pcu_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 7339 | |
Mika Kuoppala | 66c1f77 | 2018-03-20 17:17:33 +0200 | [diff] [blame] | 7340 | if (rps->max_freq <= rps->min_freq) |
| 7341 | return; |
| 7342 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7343 | policy = cpufreq_cpu_get(0); |
| 7344 | if (policy) { |
| 7345 | max_ia_freq = policy->cpuinfo.max_freq; |
| 7346 | cpufreq_cpu_put(policy); |
| 7347 | } else { |
| 7348 | /* |
| 7349 | * Default to measured freq if none found, PCU will ensure we |
| 7350 | * don't go over |
| 7351 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7352 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 7353 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7354 | |
| 7355 | /* Convert from kHz to MHz */ |
| 7356 | max_ia_freq /= 1000; |
| 7357 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 7358 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 7359 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 7360 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7361 | |
Chris Wilson | d586b5f | 2018-03-08 14:26:48 +0000 | [diff] [blame] | 7362 | min_gpu_freq = rps->min_freq; |
| 7363 | max_gpu_freq = rps->max_freq; |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7364 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7365 | /* Convert GT frequency to 50 HZ units */ |
Chris Wilson | d586b5f | 2018-03-08 14:26:48 +0000 | [diff] [blame] | 7366 | min_gpu_freq /= GEN9_FREQ_SCALER; |
| 7367 | max_gpu_freq /= GEN9_FREQ_SCALER; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7368 | } |
| 7369 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7370 | /* |
| 7371 | * For each potential GPU frequency, load a ring frequency we'd like |
| 7372 | * to use for memory access. We do this by specifying the IA frequency |
| 7373 | * the PCU should use as a reference to determine the ring frequency. |
| 7374 | */ |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7375 | 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] | 7376 | const int diff = max_gpu_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7377 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7378 | |
Oscar Mateo | 2b2874e | 2018-04-05 17:00:52 +0300 | [diff] [blame] | 7379 | if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 7380 | /* |
| 7381 | * ring_freq = 2 * GT. ring_freq is in 100MHz units |
| 7382 | * No floor required for ring frequency on SKL. |
| 7383 | */ |
| 7384 | ring_freq = gpu_freq; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 7385 | } else if (INTEL_GEN(dev_priv) >= 8) { |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 7386 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 7387 | ring_freq = max(min_ring_freq, gpu_freq); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7388 | } else if (IS_HASWELL(dev_priv)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 7389 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7390 | ring_freq = max(min_ring_freq, ring_freq); |
| 7391 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 7392 | } else { |
| 7393 | /* On older processors, there is no separate ring |
| 7394 | * clock domain, so in order to boost the bandwidth |
| 7395 | * of the ring, we need to upclock the CPU (ia_freq). |
| 7396 | * |
| 7397 | * For GPU frequencies less than 750MHz, |
| 7398 | * just use the lowest ring freq. |
| 7399 | */ |
| 7400 | if (gpu_freq < min_freq) |
| 7401 | ia_freq = 800; |
| 7402 | else |
| 7403 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 7404 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 7405 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7406 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7407 | sandybridge_pcode_write(dev_priv, |
| 7408 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 7409 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 7410 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 7411 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7412 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 7413 | } |
| 7414 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7415 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7416 | { |
| 7417 | u32 val, rp0; |
| 7418 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7419 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7420 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 7421 | switch (RUNTIME_INFO(dev_priv)->sseu.eu_total) { |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7422 | case 8: |
| 7423 | /* (2 * 4) config */ |
| 7424 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 7425 | break; |
| 7426 | case 12: |
| 7427 | /* (2 * 6) config */ |
| 7428 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 7429 | break; |
| 7430 | case 16: |
| 7431 | /* (2 * 8) config */ |
| 7432 | default: |
| 7433 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 7434 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 7435 | break; |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 7436 | } |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7437 | |
| 7438 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 7439 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7440 | return rp0; |
| 7441 | } |
| 7442 | |
| 7443 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7444 | { |
| 7445 | u32 val, rpe; |
| 7446 | |
| 7447 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 7448 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 7449 | |
| 7450 | return rpe; |
| 7451 | } |
| 7452 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7453 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7454 | { |
| 7455 | u32 val, rp1; |
| 7456 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 7457 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 7458 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 7459 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7460 | return rp1; |
| 7461 | } |
| 7462 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 7463 | static u32 cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 7464 | { |
| 7465 | u32 val, rpn; |
| 7466 | |
| 7467 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 7468 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 7469 | FB_GFX_FREQ_FUSE_MASK); |
| 7470 | |
| 7471 | return rpn; |
| 7472 | } |
| 7473 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7474 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7475 | { |
| 7476 | u32 val, rp1; |
| 7477 | |
| 7478 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 7479 | |
| 7480 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 7481 | |
| 7482 | return rp1; |
| 7483 | } |
| 7484 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7485 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7486 | { |
| 7487 | u32 val, rp0; |
| 7488 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7489 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7490 | |
| 7491 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 7492 | /* Clamp to max */ |
| 7493 | rp0 = min_t(u32, rp0, 0xea); |
| 7494 | |
| 7495 | return rp0; |
| 7496 | } |
| 7497 | |
| 7498 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7499 | { |
| 7500 | u32 val, rpe; |
| 7501 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7502 | 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] | 7503 | 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] | 7504 | 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] | 7505 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 7506 | |
| 7507 | return rpe; |
| 7508 | } |
| 7509 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7510 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7511 | { |
Imre Deak | 3614603 | 2014-12-04 18:39:35 +0200 | [diff] [blame] | 7512 | u32 val; |
| 7513 | |
| 7514 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
| 7515 | /* |
| 7516 | * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value |
| 7517 | * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on |
| 7518 | * a BYT-M B0 the above register contains 0xbf. Moreover when setting |
| 7519 | * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0 |
| 7520 | * to make sure it matches what Punit accepts. |
| 7521 | */ |
| 7522 | return max_t(u32, val, 0xc0); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7523 | } |
| 7524 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7525 | /* Check that the pctx buffer wasn't move under us. */ |
| 7526 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 7527 | { |
| 7528 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 7529 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7530 | WARN_ON(pctx_addr != dev_priv->dsm.start + |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7531 | dev_priv->vlv_pctx->stolen->start); |
| 7532 | } |
| 7533 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7534 | |
| 7535 | /* Check that the pcbr address is not empty. */ |
| 7536 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 7537 | { |
| 7538 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 7539 | |
| 7540 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 7541 | } |
| 7542 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7543 | static void cherryview_setup_pctx(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7544 | { |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7545 | resource_size_t pctx_paddr, paddr; |
| 7546 | resource_size_t pctx_size = 32*1024; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7547 | u32 pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7548 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7549 | pcbr = I915_READ(VLV_PCBR); |
| 7550 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7551 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7552 | paddr = dev_priv->dsm.end + 1 - pctx_size; |
| 7553 | GEM_BUG_ON(paddr > U32_MAX); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7554 | |
| 7555 | pctx_paddr = (paddr & (~4095)); |
| 7556 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 7557 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7558 | |
| 7559 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7560 | } |
| 7561 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7562 | static void valleyview_setup_pctx(struct drm_i915_private *dev_priv) |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7563 | { |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7564 | struct drm_i915_gem_object *pctx; |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7565 | resource_size_t pctx_paddr; |
| 7566 | resource_size_t pctx_size = 24*1024; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7567 | u32 pcbr; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7568 | |
| 7569 | pcbr = I915_READ(VLV_PCBR); |
| 7570 | if (pcbr) { |
| 7571 | /* BIOS set it up already, grab the pre-alloc'd space */ |
Matthew Auld | b7128ef | 2017-12-11 15:18:22 +0000 | [diff] [blame] | 7572 | resource_size_t pcbr_offset; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7573 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7574 | pcbr_offset = (pcbr & (~4095)) - dev_priv->dsm.start; |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 7575 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7576 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 7577 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7578 | pctx_size); |
| 7579 | goto out; |
| 7580 | } |
| 7581 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7582 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 7583 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7584 | /* |
| 7585 | * From the Gunit register HAS: |
| 7586 | * The Gfx driver is expected to program this register and ensure |
| 7587 | * proper allocation within Gfx stolen memory. For example, this |
| 7588 | * register should be programmed such than the PCBR range does not |
| 7589 | * overlap with other ranges, such as the frame buffer, protected |
| 7590 | * memory, or any other relevant ranges. |
| 7591 | */ |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 7592 | pctx = i915_gem_object_create_stolen(dev_priv, pctx_size); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7593 | if (!pctx) { |
| 7594 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
Tvrtko Ursulin | ee50489 | 2016-02-11 10:27:30 +0000 | [diff] [blame] | 7595 | goto out; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7596 | } |
| 7597 | |
Matthew Auld | 7789422 | 2017-12-11 15:18:18 +0000 | [diff] [blame] | 7598 | GEM_BUG_ON(range_overflows_t(u64, |
| 7599 | dev_priv->dsm.start, |
| 7600 | pctx->stolen->start, |
| 7601 | U32_MAX)); |
| 7602 | pctx_paddr = dev_priv->dsm.start + pctx->stolen->start; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7603 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 7604 | |
| 7605 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7606 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7607 | dev_priv->vlv_pctx = pctx; |
| 7608 | } |
| 7609 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7610 | static void valleyview_cleanup_pctx(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7611 | { |
Chris Wilson | 818fed4 | 2018-07-12 11:54:54 +0100 | [diff] [blame] | 7612 | struct drm_i915_gem_object *pctx; |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7613 | |
Chris Wilson | 818fed4 | 2018-07-12 11:54:54 +0100 | [diff] [blame] | 7614 | pctx = fetch_and_zero(&dev_priv->vlv_pctx); |
| 7615 | if (pctx) |
| 7616 | i915_gem_object_put(pctx); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7617 | } |
| 7618 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7619 | static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv) |
| 7620 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7621 | dev_priv->gt_pm.rps.gpll_ref_freq = |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7622 | vlv_get_cck_clock(dev_priv, "GPLL ref", |
| 7623 | CCK_GPLL_CLOCK_CONTROL, |
| 7624 | dev_priv->czclk_freq); |
| 7625 | |
| 7626 | DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7627 | dev_priv->gt_pm.rps.gpll_ref_freq); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7628 | } |
| 7629 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7630 | static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7631 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7632 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7633 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7634 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7635 | valleyview_setup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7636 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7637 | vlv_init_gpll_ref_freq(dev_priv); |
| 7638 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7639 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7640 | switch ((val >> 6) & 3) { |
| 7641 | case 0: |
| 7642 | case 1: |
| 7643 | dev_priv->mem_freq = 800; |
| 7644 | break; |
| 7645 | case 2: |
| 7646 | dev_priv->mem_freq = 1066; |
| 7647 | break; |
| 7648 | case 3: |
| 7649 | dev_priv->mem_freq = 1333; |
| 7650 | break; |
| 7651 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7652 | 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] | 7653 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7654 | rps->max_freq = valleyview_rps_max_freq(dev_priv); |
| 7655 | rps->rp0_freq = rps->max_freq; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7656 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7657 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7658 | rps->max_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7659 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7660 | rps->efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7661 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7662 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7663 | rps->efficient_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7664 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7665 | rps->rp1_freq = valleyview_rps_guar_freq(dev_priv); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7666 | 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] | 7667 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7668 | rps->rp1_freq); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7669 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7670 | rps->min_freq = valleyview_rps_min_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7671 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7672 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7673 | rps->min_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7674 | } |
| 7675 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7676 | static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7677 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7678 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7679 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7680 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7681 | cherryview_setup_pctx(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7682 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7683 | vlv_init_gpll_ref_freq(dev_priv); |
| 7684 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7685 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7686 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7687 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7688 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7689 | switch ((val >> 2) & 0x7) { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7690 | case 3: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7691 | dev_priv->mem_freq = 2000; |
| 7692 | break; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 7693 | default: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7694 | dev_priv->mem_freq = 1600; |
| 7695 | break; |
| 7696 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7697 | 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] | 7698 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7699 | rps->max_freq = cherryview_rps_max_freq(dev_priv); |
| 7700 | rps->rp0_freq = rps->max_freq; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7701 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7702 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7703 | rps->max_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7704 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7705 | rps->efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7706 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7707 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7708 | rps->efficient_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7709 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7710 | rps->rp1_freq = cherryview_rps_guar_freq(dev_priv); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7711 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7712 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7713 | rps->rp1_freq); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7714 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7715 | rps->min_freq = cherryview_rps_min_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7716 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7717 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7718 | rps->min_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7719 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7720 | WARN_ONCE((rps->max_freq | rps->efficient_freq | rps->rp1_freq | |
| 7721 | rps->min_freq) & 1, |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7722 | "Odd GPU freq values\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7723 | } |
| 7724 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7725 | static void valleyview_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7726 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7727 | valleyview_cleanup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7728 | } |
| 7729 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7730 | static void cherryview_enable_rc6(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7731 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7732 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7733 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7734 | u32 gtfifodbg, rc6_mode, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7735 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7736 | gtfifodbg = I915_READ(GTFIFODBG) & ~(GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV | |
| 7737 | GT_FIFO_FREE_ENTRIES_CHV); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7738 | if (gtfifodbg) { |
| 7739 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7740 | gtfifodbg); |
| 7741 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7742 | } |
| 7743 | |
| 7744 | cherryview_check_pctx(dev_priv); |
| 7745 | |
| 7746 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 7747 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7748 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7749 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7750 | /* Disable RC states. */ |
| 7751 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7752 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7753 | /* 2a: Program RC6 thresholds.*/ |
| 7754 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 7755 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7756 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 7757 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7758 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7759 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7760 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7761 | |
Deepak S | f4f71c7 | 2015-03-28 15:23:35 +0530 | [diff] [blame] | 7762 | /* TO threshold set to 500 us ( 0x186 * 1.28 us) */ |
| 7763 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x186); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7764 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7765 | /* Allows RC6 residency counter to work */ |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7766 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 7767 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7768 | VLV_MEDIA_RC6_COUNT_EN | |
| 7769 | VLV_RENDER_RC6_COUNT_EN)); |
| 7770 | |
| 7771 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 7772 | pcbr = I915_READ(VLV_PCBR); |
| 7773 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7774 | /* 3: Enable RC6 */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7775 | rc6_mode = 0; |
| 7776 | if (pcbr >> VLV_PCBR_ADDR_SHIFT) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 7777 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7778 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 7779 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7780 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 7781 | } |
| 7782 | |
| 7783 | static void cherryview_enable_rps(struct drm_i915_private *dev_priv) |
| 7784 | { |
| 7785 | u32 val; |
| 7786 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7787 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 7788 | |
| 7789 | /* 1: Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 7790 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7791 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7792 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7793 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7794 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7795 | |
| 7796 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7797 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7798 | /* 2: Enable RPS */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7799 | I915_WRITE(GEN6_RP_CONTROL, |
| 7800 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 7801 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7802 | GEN6_RP_ENABLE | |
| 7803 | GEN6_RP_UP_BUSY_AVG | |
| 7804 | GEN6_RP_DOWN_IDLE_AVG); |
| 7805 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7806 | /* Setting Fixed Bias */ |
| 7807 | val = VLV_OVERRIDE_EN | |
| 7808 | VLV_SOC_TDP_EN | |
| 7809 | CHV_BIAS_CPU_50_SOC_50; |
| 7810 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7811 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7812 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7813 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7814 | /* RPS code assumes GPLL is used */ |
| 7815 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7816 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7817 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7818 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7819 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7820 | reset_rps(dev_priv, valleyview_set_rps); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7821 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7822 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7823 | } |
| 7824 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7825 | static void valleyview_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7826 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7827 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7828 | enum intel_engine_id id; |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7829 | u32 gtfifodbg; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7830 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7831 | valleyview_check_pctx(dev_priv); |
| 7832 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7833 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7834 | if (gtfifodbg) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 7835 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7836 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7837 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7838 | } |
| 7839 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7840 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7841 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7842 | /* Disable RC states. */ |
| 7843 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7844 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7845 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 7846 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 7847 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 7848 | |
| 7849 | for_each_engine(engine, dev_priv, id) |
| 7850 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
| 7851 | |
| 7852 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
| 7853 | |
| 7854 | /* Allows RC6 residency counter to work */ |
| 7855 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 7856 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7857 | VLV_MEDIA_RC0_COUNT_EN | |
| 7858 | VLV_RENDER_RC0_COUNT_EN | |
| 7859 | VLV_MEDIA_RC6_COUNT_EN | |
| 7860 | VLV_RENDER_RC6_COUNT_EN)); |
| 7861 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 7862 | I915_WRITE(GEN6_RC_CONTROL, |
| 7863 | GEN7_RC_CTL_TO_MODE | VLV_RC_CTL_CTX_RST_PARALLEL); |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7864 | |
| 7865 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 7866 | } |
| 7867 | |
| 7868 | static void valleyview_enable_rps(struct drm_i915_private *dev_priv) |
| 7869 | { |
| 7870 | u32 val; |
| 7871 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7872 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 7873 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 7874 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7875 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7876 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7877 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7878 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7879 | |
| 7880 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7881 | |
| 7882 | I915_WRITE(GEN6_RP_CONTROL, |
| 7883 | GEN6_RP_MEDIA_TURBO | |
| 7884 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7885 | GEN6_RP_MEDIA_IS_GFX | |
| 7886 | GEN6_RP_ENABLE | |
| 7887 | GEN6_RP_UP_BUSY_AVG | |
| 7888 | GEN6_RP_DOWN_IDLE_CONT); |
| 7889 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7890 | /* Setting Fixed Bias */ |
| 7891 | val = VLV_OVERRIDE_EN | |
| 7892 | VLV_SOC_TDP_EN | |
| 7893 | VLV_BIAS_CPU_125_SOC_875; |
| 7894 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7895 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7896 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7897 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7898 | /* RPS code assumes GPLL is used */ |
| 7899 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7900 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7901 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7902 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7903 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7904 | reset_rps(dev_priv, valleyview_set_rps); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7905 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7906 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7907 | } |
| 7908 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7909 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 7910 | { |
| 7911 | unsigned long freq; |
| 7912 | int div = (vidfreq & 0x3f0000) >> 16; |
| 7913 | int post = (vidfreq & 0x3000) >> 12; |
| 7914 | int pre = (vidfreq & 0x7); |
| 7915 | |
| 7916 | if (!pre) |
| 7917 | return 0; |
| 7918 | |
| 7919 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 7920 | |
| 7921 | return freq; |
| 7922 | } |
| 7923 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7924 | static const struct cparams { |
| 7925 | u16 i; |
| 7926 | u16 t; |
| 7927 | u16 m; |
| 7928 | u16 c; |
| 7929 | } cparams[] = { |
| 7930 | { 1, 1333, 301, 28664 }, |
| 7931 | { 1, 1066, 294, 24460 }, |
| 7932 | { 1, 800, 294, 25192 }, |
| 7933 | { 0, 1333, 276, 27605 }, |
| 7934 | { 0, 1066, 276, 27605 }, |
| 7935 | { 0, 800, 231, 23784 }, |
| 7936 | }; |
| 7937 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7938 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7939 | { |
| 7940 | u64 total_count, diff, ret; |
| 7941 | u32 count1, count2, count3, m = 0, c = 0; |
| 7942 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 7943 | int i; |
| 7944 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7945 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7946 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7947 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7948 | |
| 7949 | /* Prevent division-by-zero if we are asking too fast. |
| 7950 | * Also, we don't get interesting results if we are polling |
| 7951 | * faster than once in 10ms, so just return the saved value |
| 7952 | * in such cases. |
| 7953 | */ |
| 7954 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7955 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7956 | |
| 7957 | count1 = I915_READ(DMIEC); |
| 7958 | count2 = I915_READ(DDREC); |
| 7959 | count3 = I915_READ(CSIEC); |
| 7960 | |
| 7961 | total_count = count1 + count2 + count3; |
| 7962 | |
| 7963 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7964 | if (total_count < dev_priv->ips.last_count1) { |
| 7965 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7966 | diff += total_count; |
| 7967 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7968 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7969 | } |
| 7970 | |
| 7971 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7972 | if (cparams[i].i == dev_priv->ips.c_m && |
| 7973 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7974 | m = cparams[i].m; |
| 7975 | c = cparams[i].c; |
| 7976 | break; |
| 7977 | } |
| 7978 | } |
| 7979 | |
| 7980 | diff = div_u64(diff, diff1); |
| 7981 | ret = ((m * diff) + c); |
| 7982 | ret = div_u64(ret, 10); |
| 7983 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7984 | dev_priv->ips.last_count1 = total_count; |
| 7985 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7986 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7987 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7988 | |
| 7989 | return ret; |
| 7990 | } |
| 7991 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7992 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 7993 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 7994 | intel_wakeref_t wakeref; |
| 7995 | unsigned long val = 0; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7996 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7997 | if (!IS_GEN(dev_priv, 5)) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7998 | return 0; |
| 7999 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8000 | with_intel_runtime_pm(dev_priv, wakeref) { |
| 8001 | spin_lock_irq(&mchdev_lock); |
| 8002 | val = __i915_chipset_val(dev_priv); |
| 8003 | spin_unlock_irq(&mchdev_lock); |
| 8004 | } |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8005 | |
| 8006 | return val; |
| 8007 | } |
| 8008 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8009 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 8010 | { |
| 8011 | unsigned long m, x, b; |
| 8012 | u32 tsfs; |
| 8013 | |
| 8014 | tsfs = I915_READ(TSFS); |
| 8015 | |
| 8016 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 8017 | x = I915_READ8(TR1); |
| 8018 | |
| 8019 | b = tsfs & TSFS_INTR_MASK; |
| 8020 | |
| 8021 | return ((m * x) / 127) - b; |
| 8022 | } |
| 8023 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8024 | static int _pxvid_to_vd(u8 pxvid) |
| 8025 | { |
| 8026 | if (pxvid == 0) |
| 8027 | return 0; |
| 8028 | |
| 8029 | if (pxvid >= 8 && pxvid < 31) |
| 8030 | pxvid = 31; |
| 8031 | |
| 8032 | return (pxvid + 2) * 125; |
| 8033 | } |
| 8034 | |
| 8035 | 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] | 8036 | { |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8037 | const int vd = _pxvid_to_vd(pxvid); |
| 8038 | const int vm = vd - 1125; |
| 8039 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8040 | if (INTEL_INFO(dev_priv)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 8041 | return vm > 0 ? vm : 0; |
| 8042 | |
| 8043 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8044 | } |
| 8045 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8046 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8047 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 8048 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8049 | u32 count; |
| 8050 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 8051 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8052 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 8053 | now = ktime_get_raw_ns(); |
| 8054 | diffms = now - dev_priv->ips.last_time2; |
| 8055 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8056 | |
| 8057 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8058 | if (!diffms) |
| 8059 | return; |
| 8060 | |
| 8061 | count = I915_READ(GFXEC); |
| 8062 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8063 | if (count < dev_priv->ips.last_count2) { |
| 8064 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8065 | diff += count; |
| 8066 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8067 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8068 | } |
| 8069 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8070 | dev_priv->ips.last_count2 = count; |
| 8071 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8072 | |
| 8073 | /* More magic constants... */ |
| 8074 | diff = diff * 1181; |
| 8075 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8076 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8077 | } |
| 8078 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8079 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 8080 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8081 | intel_wakeref_t wakeref; |
| 8082 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8083 | if (!IS_GEN(dev_priv, 5)) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8084 | return; |
| 8085 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8086 | with_intel_runtime_pm(dev_priv, wakeref) { |
| 8087 | spin_lock_irq(&mchdev_lock); |
| 8088 | __i915_update_gfx_val(dev_priv); |
| 8089 | spin_unlock_irq(&mchdev_lock); |
| 8090 | } |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8091 | } |
| 8092 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8093 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8094 | { |
| 8095 | unsigned long t, corr, state1, corr2, state2; |
| 8096 | u32 pxvid, ext_v; |
| 8097 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 8098 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8099 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8100 | pxvid = I915_READ(PXVFREQ(dev_priv->gt_pm.rps.cur_freq)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8101 | pxvid = (pxvid >> 24) & 0x7f; |
| 8102 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 8103 | |
| 8104 | state1 = ext_v; |
| 8105 | |
| 8106 | t = i915_mch_val(dev_priv); |
| 8107 | |
| 8108 | /* Revel in the empirically derived constants */ |
| 8109 | |
| 8110 | /* Correction factor in 1/100000 units */ |
| 8111 | if (t > 80) |
| 8112 | corr = ((t * 2349) + 135940); |
| 8113 | else if (t >= 50) |
| 8114 | corr = ((t * 964) + 29317); |
| 8115 | else /* < 50 */ |
| 8116 | corr = ((t * 301) + 1004); |
| 8117 | |
| 8118 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 8119 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8120 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8121 | |
| 8122 | state2 = (corr2 * state1) / 10000; |
| 8123 | state2 /= 100; /* convert to mW */ |
| 8124 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8125 | __i915_update_gfx_val(dev_priv); |
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 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8128 | } |
| 8129 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8130 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 8131 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8132 | intel_wakeref_t wakeref; |
| 8133 | unsigned long val = 0; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8134 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8135 | if (!IS_GEN(dev_priv, 5)) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8136 | return 0; |
| 8137 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8138 | with_intel_runtime_pm(dev_priv, wakeref) { |
| 8139 | spin_lock_irq(&mchdev_lock); |
| 8140 | val = __i915_gfx_val(dev_priv); |
| 8141 | spin_unlock_irq(&mchdev_lock); |
| 8142 | } |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 8143 | |
| 8144 | return val; |
| 8145 | } |
| 8146 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8147 | static struct drm_i915_private *i915_mch_dev; |
| 8148 | |
| 8149 | static struct drm_i915_private *mchdev_get(void) |
| 8150 | { |
| 8151 | struct drm_i915_private *i915; |
| 8152 | |
| 8153 | rcu_read_lock(); |
| 8154 | i915 = i915_mch_dev; |
| 8155 | if (!kref_get_unless_zero(&i915->drm.ref)) |
| 8156 | i915 = NULL; |
| 8157 | rcu_read_unlock(); |
| 8158 | |
| 8159 | return i915; |
| 8160 | } |
| 8161 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8162 | /** |
| 8163 | * i915_read_mch_val - return value for IPS use |
| 8164 | * |
| 8165 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 8166 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 8167 | */ |
| 8168 | unsigned long i915_read_mch_val(void) |
| 8169 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8170 | struct drm_i915_private *i915; |
| 8171 | unsigned long chipset_val = 0; |
| 8172 | unsigned long graphics_val = 0; |
| 8173 | intel_wakeref_t wakeref; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8174 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8175 | i915 = mchdev_get(); |
| 8176 | if (!i915) |
| 8177 | return 0; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8178 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8179 | with_intel_runtime_pm(i915, wakeref) { |
| 8180 | spin_lock_irq(&mchdev_lock); |
| 8181 | chipset_val = __i915_chipset_val(i915); |
| 8182 | graphics_val = __i915_gfx_val(i915); |
| 8183 | spin_unlock_irq(&mchdev_lock); |
| 8184 | } |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8185 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8186 | drm_dev_put(&i915->drm); |
| 8187 | return chipset_val + graphics_val; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8188 | } |
| 8189 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 8190 | |
| 8191 | /** |
| 8192 | * i915_gpu_raise - raise GPU frequency limit |
| 8193 | * |
| 8194 | * Raise the limit; IPS indicates we have thermal headroom. |
| 8195 | */ |
| 8196 | bool i915_gpu_raise(void) |
| 8197 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8198 | struct drm_i915_private *i915; |
| 8199 | |
| 8200 | i915 = mchdev_get(); |
| 8201 | if (!i915) |
| 8202 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8203 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8204 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8205 | if (i915->ips.max_delay > i915->ips.fmax) |
| 8206 | i915->ips.max_delay--; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8207 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8208 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8209 | drm_dev_put(&i915->drm); |
| 8210 | return true; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8211 | } |
| 8212 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 8213 | |
| 8214 | /** |
| 8215 | * i915_gpu_lower - lower GPU frequency limit |
| 8216 | * |
| 8217 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 8218 | * frequency maximum. |
| 8219 | */ |
| 8220 | bool i915_gpu_lower(void) |
| 8221 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8222 | struct drm_i915_private *i915; |
| 8223 | |
| 8224 | i915 = mchdev_get(); |
| 8225 | if (!i915) |
| 8226 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8227 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8228 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8229 | if (i915->ips.max_delay < i915->ips.min_delay) |
| 8230 | i915->ips.max_delay++; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8231 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8232 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8233 | drm_dev_put(&i915->drm); |
| 8234 | return true; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8235 | } |
| 8236 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 8237 | |
| 8238 | /** |
| 8239 | * i915_gpu_busy - indicate GPU business to IPS |
| 8240 | * |
| 8241 | * Tell the IPS driver whether or not the GPU is busy. |
| 8242 | */ |
| 8243 | bool i915_gpu_busy(void) |
| 8244 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8245 | struct drm_i915_private *i915; |
| 8246 | bool ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8247 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8248 | i915 = mchdev_get(); |
| 8249 | if (!i915) |
| 8250 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8251 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8252 | ret = i915->gt.awake; |
| 8253 | |
| 8254 | drm_dev_put(&i915->drm); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8255 | return ret; |
| 8256 | } |
| 8257 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 8258 | |
| 8259 | /** |
| 8260 | * i915_gpu_turbo_disable - disable graphics turbo |
| 8261 | * |
| 8262 | * Disable graphics turbo by resetting the max frequency and setting the |
| 8263 | * current frequency to the default. |
| 8264 | */ |
| 8265 | bool i915_gpu_turbo_disable(void) |
| 8266 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8267 | struct drm_i915_private *i915; |
| 8268 | bool ret; |
| 8269 | |
| 8270 | i915 = mchdev_get(); |
| 8271 | if (!i915) |
| 8272 | return false; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8273 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8274 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8275 | i915->ips.max_delay = i915->ips.fstart; |
| 8276 | ret = ironlake_set_drps(i915, i915->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 8277 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8278 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8279 | drm_dev_put(&i915->drm); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8280 | return ret; |
| 8281 | } |
| 8282 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 8283 | |
| 8284 | /** |
| 8285 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 8286 | * IPS got loaded first. |
| 8287 | * |
| 8288 | * This awkward dance is so that neither module has to depend on the |
| 8289 | * other in order for IPS to do the appropriate communication of |
| 8290 | * GPU turbo limits to i915. |
| 8291 | */ |
| 8292 | static void |
| 8293 | ips_ping_for_i915_load(void) |
| 8294 | { |
| 8295 | void (*link)(void); |
| 8296 | |
| 8297 | link = symbol_get(ips_link_to_i915_driver); |
| 8298 | if (link) { |
| 8299 | link(); |
| 8300 | symbol_put(ips_link_to_i915_driver); |
| 8301 | } |
| 8302 | } |
| 8303 | |
| 8304 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 8305 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 8306 | /* We only register the i915 ips part with intel-ips once everything is |
| 8307 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8308 | rcu_assign_pointer(i915_mch_dev, dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8309 | |
| 8310 | ips_ping_for_i915_load(); |
| 8311 | } |
| 8312 | |
| 8313 | void intel_gpu_ips_teardown(void) |
| 8314 | { |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 8315 | rcu_assign_pointer(i915_mch_dev, NULL); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 8316 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 8317 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8318 | static void intel_init_emon(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8319 | { |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8320 | u32 lcfuse; |
| 8321 | u8 pxw[16]; |
| 8322 | int i; |
| 8323 | |
| 8324 | /* Disable to program */ |
| 8325 | I915_WRITE(ECR, 0); |
| 8326 | POSTING_READ(ECR); |
| 8327 | |
| 8328 | /* Program energy weights for various events */ |
| 8329 | I915_WRITE(SDEW, 0x15040d00); |
| 8330 | I915_WRITE(CSIEW0, 0x007f0000); |
| 8331 | I915_WRITE(CSIEW1, 0x1e220004); |
| 8332 | I915_WRITE(CSIEW2, 0x04000004); |
| 8333 | |
| 8334 | for (i = 0; i < 5; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8335 | I915_WRITE(PEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8336 | for (i = 0; i < 3; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8337 | I915_WRITE(DEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8338 | |
| 8339 | /* Program P-state weights to account for frequency power adjustment */ |
| 8340 | for (i = 0; i < 16; i++) { |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8341 | u32 pxvidfreq = I915_READ(PXVFREQ(i)); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8342 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 8343 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 8344 | PXVFREQ_PX_SHIFT; |
| 8345 | unsigned long val; |
| 8346 | |
| 8347 | val = vid * vid; |
| 8348 | val *= (freq / 1000); |
| 8349 | val *= 255; |
| 8350 | val /= (127*127*900); |
| 8351 | if (val > 0xff) |
| 8352 | DRM_ERROR("bad pxval: %ld\n", val); |
| 8353 | pxw[i] = val; |
| 8354 | } |
| 8355 | /* Render standby states get 0 weight */ |
| 8356 | pxw[14] = 0; |
| 8357 | pxw[15] = 0; |
| 8358 | |
| 8359 | for (i = 0; i < 4; i++) { |
| 8360 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 8361 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8362 | I915_WRITE(PXW(i), val); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8363 | } |
| 8364 | |
| 8365 | /* Adjust magic regs to magic values (more experimental results) */ |
| 8366 | I915_WRITE(OGW0, 0); |
| 8367 | I915_WRITE(OGW1, 0); |
| 8368 | I915_WRITE(EG0, 0x00007f00); |
| 8369 | I915_WRITE(EG1, 0x0000000e); |
| 8370 | I915_WRITE(EG2, 0x000e0000); |
| 8371 | I915_WRITE(EG3, 0x68000300); |
| 8372 | I915_WRITE(EG4, 0x42000000); |
| 8373 | I915_WRITE(EG5, 0x00140031); |
| 8374 | I915_WRITE(EG6, 0); |
| 8375 | I915_WRITE(EG7, 0); |
| 8376 | |
| 8377 | for (i = 0; i < 8; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 8378 | I915_WRITE(PXWL(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8379 | |
| 8380 | /* Enable PMON + select events */ |
| 8381 | I915_WRITE(ECR, 0x80000019); |
| 8382 | |
| 8383 | lcfuse = I915_READ(LCFUSE02); |
| 8384 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 8385 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 8386 | } |
| 8387 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8388 | void intel_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8389 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8390 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8391 | |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8392 | /* |
| 8393 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 8394 | * requirement. |
| 8395 | */ |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8396 | if (!sanitize_rc6(dev_priv)) { |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8397 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 8398 | pm_runtime_get(&dev_priv->drm.pdev->dev); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8399 | } |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 8400 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8401 | mutex_lock(&dev_priv->pcu_lock); |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8402 | |
| 8403 | /* Initialize RPS limits (for userspace) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8404 | if (IS_CHERRYVIEW(dev_priv)) |
| 8405 | cherryview_init_gt_powersave(dev_priv); |
| 8406 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8407 | valleyview_init_gt_powersave(dev_priv); |
Chris Wilson | 2a13ae7 | 2016-08-02 11:15:27 +0100 | [diff] [blame] | 8408 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8409 | gen6_init_rps_frequencies(dev_priv); |
| 8410 | |
| 8411 | /* Derive initial user preferences/limits from the hardware limits */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8412 | rps->idle_freq = rps->min_freq; |
| 8413 | rps->cur_freq = rps->idle_freq; |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8414 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8415 | rps->max_freq_softlimit = rps->max_freq; |
| 8416 | rps->min_freq_softlimit = rps->min_freq; |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8417 | |
| 8418 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8419 | rps->min_freq_softlimit = |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8420 | max_t(int, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8421 | rps->efficient_freq, |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 8422 | intel_freq_opcode(dev_priv, 450)); |
| 8423 | |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8424 | /* After setting max-softlimit, find the overclock max freq */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 8425 | if (IS_GEN(dev_priv, 6) || |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8426 | IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
| 8427 | u32 params = 0; |
| 8428 | |
| 8429 | sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, ¶ms); |
| 8430 | if (params & BIT(31)) { /* OC supported */ |
| 8431 | DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8432 | (rps->max_freq & 0xff) * 50, |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8433 | (params & 0xff) * 50); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8434 | rps->max_freq = params & 0xff; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 8435 | } |
| 8436 | } |
| 8437 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 8438 | /* Finally allow us to boost to max by default */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 8439 | rps->boost_freq = rps->max_freq; |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 8440 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8441 | mutex_unlock(&dev_priv->pcu_lock); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8442 | } |
| 8443 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8444 | void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8445 | { |
Ville Syrjälä | 8dac1e1 | 2016-08-02 14:07:33 +0300 | [diff] [blame] | 8446 | if (IS_VALLEYVIEW(dev_priv)) |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8447 | valleyview_cleanup_gt_powersave(dev_priv); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 8448 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8449 | if (!HAS_RC6(dev_priv)) |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 8450 | pm_runtime_put(&dev_priv->drm.pdev->dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 8451 | } |
| 8452 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 8453 | /** |
| 8454 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 8455 | * @dev_priv: i915 device |
| 8456 | * |
| 8457 | * We don't want to disable RC6 or other features here, we just want |
| 8458 | * to make sure any work we've queued has finished and won't bother |
| 8459 | * us while we're suspended. |
| 8460 | */ |
| 8461 | void intel_suspend_gt_powersave(struct drm_i915_private *dev_priv) |
| 8462 | { |
| 8463 | if (INTEL_GEN(dev_priv) < 6) |
| 8464 | return; |
| 8465 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 8466 | /* gen6_rps_idle() will be called later to disable interrupts */ |
| 8467 | } |
| 8468 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8469 | void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv) |
| 8470 | { |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8471 | dev_priv->gt_pm.rps.enabled = true; /* force RPS disabling */ |
| 8472 | dev_priv->gt_pm.rc6.enabled = true; /* force RC6 disabling */ |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8473 | intel_disable_gt_powersave(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 8474 | |
Oscar Mateo | d02b98b | 2018-04-05 17:00:50 +0300 | [diff] [blame] | 8475 | if (INTEL_GEN(dev_priv) >= 11) |
| 8476 | gen11_reset_rps_interrupts(dev_priv); |
Chris Wilson | 61e1e37 | 2018-08-12 23:36:30 +0100 | [diff] [blame] | 8477 | else if (INTEL_GEN(dev_priv) >= 6) |
Oscar Mateo | d02b98b | 2018-04-05 17:00:50 +0300 | [diff] [blame] | 8478 | gen6_reset_rps_interrupts(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 8479 | } |
| 8480 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8481 | static inline void intel_disable_llc_pstate(struct drm_i915_private *i915) |
| 8482 | { |
| 8483 | lockdep_assert_held(&i915->pcu_lock); |
| 8484 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8485 | if (!i915->gt_pm.llc_pstate.enabled) |
| 8486 | return; |
| 8487 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8488 | /* Currently there is no HW configuration to be done to disable. */ |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8489 | |
| 8490 | i915->gt_pm.llc_pstate.enabled = false; |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8491 | } |
| 8492 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8493 | static void intel_disable_rc6(struct drm_i915_private *dev_priv) |
| 8494 | { |
| 8495 | lockdep_assert_held(&dev_priv->pcu_lock); |
| 8496 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8497 | if (!dev_priv->gt_pm.rc6.enabled) |
| 8498 | return; |
| 8499 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8500 | if (INTEL_GEN(dev_priv) >= 9) |
| 8501 | gen9_disable_rc6(dev_priv); |
| 8502 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8503 | cherryview_disable_rc6(dev_priv); |
| 8504 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8505 | valleyview_disable_rc6(dev_priv); |
| 8506 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8507 | gen6_disable_rc6(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8508 | |
| 8509 | dev_priv->gt_pm.rc6.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8510 | } |
| 8511 | |
| 8512 | static void intel_disable_rps(struct drm_i915_private *dev_priv) |
| 8513 | { |
| 8514 | lockdep_assert_held(&dev_priv->pcu_lock); |
| 8515 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8516 | if (!dev_priv->gt_pm.rps.enabled) |
| 8517 | return; |
| 8518 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8519 | if (INTEL_GEN(dev_priv) >= 9) |
| 8520 | gen9_disable_rps(dev_priv); |
| 8521 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8522 | cherryview_disable_rps(dev_priv); |
| 8523 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8524 | valleyview_disable_rps(dev_priv); |
| 8525 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8526 | gen6_disable_rps(dev_priv); |
| 8527 | else if (IS_IRONLAKE_M(dev_priv)) |
| 8528 | ironlake_disable_drps(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8529 | |
| 8530 | dev_priv->gt_pm.rps.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8531 | } |
| 8532 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8533 | void intel_disable_gt_powersave(struct drm_i915_private *dev_priv) |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 8534 | { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8535 | mutex_lock(&dev_priv->pcu_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8536 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8537 | intel_disable_rc6(dev_priv); |
| 8538 | intel_disable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8539 | if (HAS_LLC(dev_priv)) |
| 8540 | intel_disable_llc_pstate(dev_priv); |
| 8541 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8542 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8543 | } |
| 8544 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8545 | static inline void intel_enable_llc_pstate(struct drm_i915_private *i915) |
| 8546 | { |
| 8547 | lockdep_assert_held(&i915->pcu_lock); |
| 8548 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8549 | if (i915->gt_pm.llc_pstate.enabled) |
| 8550 | return; |
| 8551 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8552 | gen6_update_ring_freq(i915); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8553 | |
| 8554 | i915->gt_pm.llc_pstate.enabled = true; |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8555 | } |
| 8556 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8557 | static void intel_enable_rc6(struct drm_i915_private *dev_priv) |
| 8558 | { |
| 8559 | lockdep_assert_held(&dev_priv->pcu_lock); |
| 8560 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8561 | if (dev_priv->gt_pm.rc6.enabled) |
| 8562 | return; |
| 8563 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8564 | if (IS_CHERRYVIEW(dev_priv)) |
| 8565 | cherryview_enable_rc6(dev_priv); |
| 8566 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8567 | valleyview_enable_rc6(dev_priv); |
| 8568 | else if (INTEL_GEN(dev_priv) >= 9) |
| 8569 | gen9_enable_rc6(dev_priv); |
| 8570 | else if (IS_BROADWELL(dev_priv)) |
| 8571 | gen8_enable_rc6(dev_priv); |
| 8572 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8573 | gen6_enable_rc6(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8574 | |
| 8575 | dev_priv->gt_pm.rc6.enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8576 | } |
| 8577 | |
| 8578 | static void intel_enable_rps(struct drm_i915_private *dev_priv) |
| 8579 | { |
| 8580 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8581 | |
| 8582 | lockdep_assert_held(&dev_priv->pcu_lock); |
| 8583 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8584 | if (rps->enabled) |
| 8585 | return; |
| 8586 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8587 | if (IS_CHERRYVIEW(dev_priv)) { |
| 8588 | cherryview_enable_rps(dev_priv); |
| 8589 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 8590 | valleyview_enable_rps(dev_priv); |
| 8591 | } else if (INTEL_GEN(dev_priv) >= 9) { |
| 8592 | gen9_enable_rps(dev_priv); |
| 8593 | } else if (IS_BROADWELL(dev_priv)) { |
| 8594 | gen8_enable_rps(dev_priv); |
| 8595 | } else if (INTEL_GEN(dev_priv) >= 6) { |
| 8596 | gen6_enable_rps(dev_priv); |
| 8597 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 8598 | ironlake_enable_drps(dev_priv); |
| 8599 | intel_init_emon(dev_priv); |
| 8600 | } |
| 8601 | |
| 8602 | WARN_ON(rps->max_freq < rps->min_freq); |
| 8603 | WARN_ON(rps->idle_freq > rps->max_freq); |
| 8604 | |
| 8605 | WARN_ON(rps->efficient_freq < rps->min_freq); |
| 8606 | WARN_ON(rps->efficient_freq > rps->max_freq); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8607 | |
| 8608 | rps->enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8609 | } |
| 8610 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8611 | void intel_enable_gt_powersave(struct drm_i915_private *dev_priv) |
| 8612 | { |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8613 | /* Powersaving is controlled by the host when inside a VM */ |
| 8614 | if (intel_vgpu_active(dev_priv)) |
| 8615 | return; |
| 8616 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8617 | mutex_lock(&dev_priv->pcu_lock); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 8618 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 8619 | if (HAS_RC6(dev_priv)) |
| 8620 | intel_enable_rc6(dev_priv); |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8621 | intel_enable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8622 | if (HAS_LLC(dev_priv)) |
| 8623 | intel_enable_llc_pstate(dev_priv); |
| 8624 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8625 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8626 | } |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 8627 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8628 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8629 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8630 | /* |
| 8631 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8632 | * gating for the panel power sequencer or it will fail to |
| 8633 | * start up when no ports are active. |
| 8634 | */ |
| 8635 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 8636 | } |
| 8637 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8638 | 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] | 8639 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 8640 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8641 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8642 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8643 | I915_WRITE(DSPCNTR(pipe), |
| 8644 | I915_READ(DSPCNTR(pipe)) | |
| 8645 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 8646 | |
| 8647 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 8648 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8649 | } |
| 8650 | } |
| 8651 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8652 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8653 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8654 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8655 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 8656 | /* |
| 8657 | * Required for FBC |
| 8658 | * WaFbcDisableDpfcClockGating:ilk |
| 8659 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8660 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 8661 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 8662 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8663 | |
| 8664 | I915_WRITE(PCH_3DCGDIS0, |
| 8665 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 8666 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 8667 | I915_WRITE(PCH_3DCGDIS1, |
| 8668 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 8669 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8670 | /* |
| 8671 | * According to the spec the following bits should be set in |
| 8672 | * order to enable memory self-refresh |
| 8673 | * The bit 22/21 of 0x42004 |
| 8674 | * The bit 5 of 0x42020 |
| 8675 | * The bit 15 of 0x45000 |
| 8676 | */ |
| 8677 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8678 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8679 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8680 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8681 | I915_WRITE(DISP_ARB_CTL, |
| 8682 | (I915_READ(DISP_ARB_CTL) | |
| 8683 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 8684 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8685 | /* |
| 8686 | * Based on the document from hardware guys the following bits |
| 8687 | * should be set unconditionally in order to enable FBC. |
| 8688 | * The bit 22 of 0x42000 |
| 8689 | * The bit 22 of 0x42004 |
| 8690 | * The bit 7,8,9 of 0x42020. |
| 8691 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8692 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8693 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8694 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8695 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8696 | ILK_FBCQ_DIS); |
| 8697 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8698 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8699 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8700 | } |
| 8701 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8702 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 8703 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8704 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8705 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8706 | ILK_ELPIN_409_SELECT); |
| 8707 | I915_WRITE(_3D_CHICKEN2, |
| 8708 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 8709 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8710 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8711 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8712 | I915_WRITE(CACHE_MODE_0, |
| 8713 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8714 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8715 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 8716 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8717 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8718 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 8719 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8720 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8721 | } |
| 8722 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8723 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8724 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8725 | int pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8726 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8727 | |
| 8728 | /* |
| 8729 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8730 | * gating for the panel power sequencer or it will fail to |
| 8731 | * start up when no ports are active. |
| 8732 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 8733 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 8734 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 8735 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8736 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 8737 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 8738 | /* The below fixes the weird display corruption, a few pixels shifted |
| 8739 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 8740 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8741 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8742 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 8743 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 8744 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8745 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8746 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8747 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 8748 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 8749 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8750 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 8751 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8752 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8753 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8754 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 8755 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 8756 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8757 | } |
| 8758 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8759 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8760 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8761 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8762 | |
| 8763 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 8764 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 8765 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 8766 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8767 | } |
| 8768 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8769 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8770 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8771 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8772 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8773 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8774 | |
| 8775 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8776 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8777 | ILK_ELPIN_409_SELECT); |
| 8778 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8779 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 8780 | I915_WRITE(_3D_CHICKEN, |
| 8781 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 8782 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8783 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 8784 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8785 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8786 | /* |
| 8787 | * BSpec recoomends 8x4 when MSAA is used, |
| 8788 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8789 | * |
| 8790 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8791 | * disable bit, which we don't touch here, but it's good |
| 8792 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8793 | */ |
| 8794 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8795 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8796 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8797 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 8798 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8799 | |
| 8800 | I915_WRITE(GEN6_UCGCTL1, |
| 8801 | I915_READ(GEN6_UCGCTL1) | |
| 8802 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 8803 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 8804 | |
| 8805 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 8806 | * gating disable must be set. Failure to set it results in |
| 8807 | * flickering pixels due to Z write ordering failures after |
| 8808 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 8809 | * Sanctuary and Tropics, and apparently anything else with |
| 8810 | * alpha test or pixel discard. |
| 8811 | * |
| 8812 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 8813 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8814 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 8815 | * WaDisableRCCUnitClockGating:snb |
| 8816 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8817 | */ |
| 8818 | I915_WRITE(GEN6_UCGCTL2, |
| 8819 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 8820 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 8821 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 8822 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 8823 | I915_WRITE(_3D_CHICKEN3, |
| 8824 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8825 | |
| 8826 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 8827 | * Bspec says: |
| 8828 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 8829 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 8830 | */ |
| 8831 | I915_WRITE(_3D_CHICKEN3, |
| 8832 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 8833 | |
| 8834 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8835 | * According to the spec the following bits should be |
| 8836 | * set in order to enable memory self-refresh and fbc: |
| 8837 | * The bit21 and bit22 of 0x42000 |
| 8838 | * The bit21 and bit22 of 0x42004 |
| 8839 | * The bit5 and bit7 of 0x42020 |
| 8840 | * The bit14 of 0x70180 |
| 8841 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8842 | * |
| 8843 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8844 | */ |
| 8845 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8846 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8847 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 8848 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8849 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8850 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8851 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 8852 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 8853 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 8854 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8855 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8856 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 8857 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8858 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8859 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8860 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8861 | } |
| 8862 | |
| 8863 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 8864 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8865 | u32 reg = I915_READ(GEN7_FF_THREAD_MODE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8866 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8867 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8868 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8869 | * |
| 8870 | * This actually overrides the dispatch |
| 8871 | * mode for all thread types. |
| 8872 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8873 | reg &= ~GEN7_FF_SCHED_MASK; |
| 8874 | reg |= GEN7_FF_TS_SCHED_HW; |
| 8875 | reg |= GEN7_FF_VS_SCHED_HW; |
| 8876 | reg |= GEN7_FF_DS_SCHED_HW; |
| 8877 | |
| 8878 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 8879 | } |
| 8880 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8881 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8882 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8883 | /* |
| 8884 | * TODO: this bit should only be enabled when really needed, then |
| 8885 | * disabled when not needed anymore in order to save power. |
| 8886 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8887 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8888 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 8889 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 8890 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8891 | |
| 8892 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 8893 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 8894 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8895 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8896 | } |
| 8897 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8898 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8899 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8900 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 8901 | u32 val = I915_READ(SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8902 | |
| 8903 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8904 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8905 | } |
| 8906 | } |
| 8907 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8908 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 8909 | int general_prio_credits, |
| 8910 | int high_prio_credits) |
| 8911 | { |
| 8912 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 8913 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8914 | |
| 8915 | /* WaTempDisableDOPClkGating:bdw */ |
| 8916 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 8917 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 8918 | |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 8919 | val = I915_READ(GEN8_L3SQCREG1); |
| 8920 | val &= ~L3_PRIO_CREDITS_MASK; |
| 8921 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 8922 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
| 8923 | I915_WRITE(GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8924 | |
| 8925 | /* |
| 8926 | * Wait at least 100 clocks before re-enabling clock gating. |
| 8927 | * See the definition of L3SQCREG1 in BSpec. |
| 8928 | */ |
| 8929 | POSTING_READ(GEN8_L3SQCREG1); |
| 8930 | udelay(1); |
| 8931 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 8932 | } |
| 8933 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 8934 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8935 | { |
| 8936 | /* This is not an Wa. Enable to reduce Sampler power */ |
| 8937 | I915_WRITE(GEN10_DFR_RATIO_EN_AND_CHICKEN, |
| 8938 | I915_READ(GEN10_DFR_RATIO_EN_AND_CHICKEN) & ~DFR_DISABLE); |
Radhakrishna Sripada | 622b3f6 | 2018-10-30 01:45:01 -0700 | [diff] [blame] | 8939 | |
| 8940 | /* WaEnable32PlaneMode:icl */ |
| 8941 | I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, |
| 8942 | _MASKED_BIT_ENABLE(GEN11_ENABLE_32_PLANE_MODE)); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 8943 | } |
| 8944 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8945 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8946 | { |
| 8947 | if (!HAS_PCH_CNP(dev_priv)) |
| 8948 | return; |
| 8949 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 8950 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Rodrigo Vivi | 4cc6feb | 2017-09-08 16:45:33 -0700 | [diff] [blame] | 8951 | I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 8952 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8953 | } |
| 8954 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8955 | static void cnl_init_clock_gating(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8956 | { |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 8957 | u32 val; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8958 | cnp_init_clock_gating(dev_priv); |
| 8959 | |
Rodrigo Vivi | 1a25db6 | 2017-08-15 16:16:51 -0700 | [diff] [blame] | 8960 | /* This is not an Wa. Enable for better image quality */ |
| 8961 | I915_WRITE(_3D_CHICKEN3, |
| 8962 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE)); |
| 8963 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8964 | /* WaEnableChickenDCPR:cnl */ |
| 8965 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 8966 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
| 8967 | |
| 8968 | /* WaFbcWakeMemOn:cnl */ |
| 8969 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 8970 | DISP_FBC_MEMORY_WAKE); |
| 8971 | |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 8972 | val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE); |
| 8973 | /* ReadHitWriteOnlyDisable:cnl */ |
| 8974 | val |= RCCUNIT_CLKGATE_DIS; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8975 | /* WaSarbUnitClockGatingDisable:cnl (pre-prod) */ |
| 8976 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 8977 | val |= SARBUNIT_CLKGATE_DIS; |
| 8978 | I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val); |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 8979 | |
Rodrigo Vivi | a4713c5 | 2018-03-07 14:09:12 -0800 | [diff] [blame] | 8980 | /* Wa_2201832410:cnl */ |
| 8981 | val = I915_READ(SUBSLICE_UNIT_LEVEL_CLKGATE); |
| 8982 | val |= GWUNIT_CLKGATE_DIS; |
| 8983 | I915_WRITE(SUBSLICE_UNIT_LEVEL_CLKGATE, val); |
| 8984 | |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 8985 | /* WaDisableVFclkgate:cnl */ |
Rodrigo Vivi | 14941b6 | 2018-03-05 17:20:00 -0800 | [diff] [blame] | 8986 | /* WaVFUnitClockGatingDisable:cnl */ |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 8987 | val = I915_READ(UNSLICE_UNIT_LEVEL_CLKGATE); |
| 8988 | val |= VFUNIT_CLKGATE_DIS; |
| 8989 | I915_WRITE(UNSLICE_UNIT_LEVEL_CLKGATE, val); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8990 | } |
| 8991 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8992 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8993 | { |
| 8994 | cnp_init_clock_gating(dev_priv); |
| 8995 | gen9_init_clock_gating(dev_priv); |
| 8996 | |
| 8997 | /* WaFbcNukeOnHostModify:cfl */ |
| 8998 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8999 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 9000 | } |
| 9001 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9002 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9003 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9004 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9005 | |
| 9006 | /* WaDisableSDEUnitClockGating:kbl */ |
| 9007 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 9008 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9009 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 9010 | |
| 9011 | /* WaDisableGamClockGating:kbl */ |
| 9012 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 9013 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 9014 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9015 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9016 | /* WaFbcNukeOnHostModify:kbl */ |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9017 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 9018 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 9019 | } |
| 9020 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9021 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 9022 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9023 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 9024 | |
| 9025 | /* WAC6entrylatency:skl */ |
| 9026 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 9027 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 9028 | |
| 9029 | /* WaFbcNukeOnHostModify:skl */ |
| 9030 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 9031 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 9032 | } |
| 9033 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9034 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9035 | { |
Matthew Auld | 8cb0983 | 2017-10-06 23:18:23 +0100 | [diff] [blame] | 9036 | /* The GTT cache must be disabled if the system is using 2M pages. */ |
| 9037 | bool can_use_gtt_cache = !HAS_PAGE_SIZES(dev_priv, |
| 9038 | I915_GTT_PAGE_SIZE_2M); |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 9039 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9040 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9041 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 9042 | 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] | 9043 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9044 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 9045 | I915_WRITE(CHICKEN_PAR1_1, |
| 9046 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 9047 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9048 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 9049 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 9050 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 9051 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 9052 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 9053 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 9054 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 9055 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 9056 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 9057 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9058 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 9059 | ~(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] | 9060 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 9061 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 9062 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 9063 | |
| 9064 | /* WaDisableSDEUnitClockGating:bdw */ |
| 9065 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9066 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 9067 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9068 | /* WaProgramL3SqcReg1Default:bdw */ |
| 9069 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 9070 | |
Matthew Auld | 8cb0983 | 2017-10-06 23:18:23 +0100 | [diff] [blame] | 9071 | /* WaGttCachingOffByDefault:bdw */ |
| 9072 | 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] | 9073 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 9074 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 9075 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 9076 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 9077 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9078 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 9079 | |
| 9080 | /* WaDisableDopClockGating:bdw |
| 9081 | * |
| 9082 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 9083 | * clock gating. |
| 9084 | */ |
| 9085 | I915_WRITE(GEN6_UCGCTL1, |
| 9086 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 9087 | } |
| 9088 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9089 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9090 | { |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 9091 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 9092 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 9093 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 9094 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 9095 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9096 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9097 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9098 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9099 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9100 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 9101 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 9102 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9103 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9104 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9105 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 9106 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9107 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 9108 | /* enable HiZ Raw Stall Optimization */ |
| 9109 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 9110 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 9111 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9112 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9113 | I915_WRITE(CACHE_MODE_1, |
| 9114 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 9115 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9116 | /* |
| 9117 | * BSpec recommends 8x4 when MSAA is used, |
| 9118 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 9119 | * |
| 9120 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9121 | * disable bit, which we don't touch here, but it's good |
| 9122 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9123 | */ |
| 9124 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 9125 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 9126 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 9127 | /* WaSampleCChickenBitEnable:hsw */ |
| 9128 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 9129 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 9130 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9131 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 9132 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 9133 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9134 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 9135 | } |
| 9136 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9137 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9138 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9139 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9140 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 9141 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9142 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9143 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 9144 | I915_WRITE(_3D_CHICKEN3, |
| 9145 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 9146 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9147 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9148 | I915_WRITE(IVB_CHICKEN3, |
| 9149 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 9150 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 9151 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9152 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9153 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9154 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 9155 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9156 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9157 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 9158 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9159 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9160 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9161 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 9162 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 9163 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9164 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9165 | I915_WRITE(GEN7_L3CNTLREG1, |
| 9166 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 9167 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9168 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9169 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9170 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9171 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 9172 | else { |
| 9173 | /* must write both registers */ |
| 9174 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9175 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9176 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 9177 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 9178 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9179 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9180 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 9181 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 9182 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 9183 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 9184 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9185 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9186 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9187 | */ |
| 9188 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 9189 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9190 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9191 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9192 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9193 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9194 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9195 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9196 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9197 | |
| 9198 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 9199 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 9200 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 9201 | /* enable HiZ Raw Stall Optimization */ |
| 9202 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 9203 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 9204 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 9205 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9206 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 9207 | I915_WRITE(CACHE_MODE_1, |
| 9208 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 9209 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9210 | /* |
| 9211 | * BSpec recommends 8x4 when MSAA is used, |
| 9212 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 9213 | * |
| 9214 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9215 | * disable bit, which we don't touch here, but it's good |
| 9216 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9217 | */ |
| 9218 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 9219 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 9220 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 9221 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 9222 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 9223 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 9224 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 9225 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9226 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9227 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 9228 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9229 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9230 | } |
| 9231 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9232 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9233 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9234 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 9235 | I915_WRITE(_3D_CHICKEN3, |
| 9236 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 9237 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9238 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9239 | I915_WRITE(IVB_CHICKEN3, |
| 9240 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 9241 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 9242 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 9243 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9244 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9245 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 9246 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 9247 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 9248 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9249 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 9250 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9251 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9252 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 9253 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 9254 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 9255 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9256 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 9257 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 9258 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 9259 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9260 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9261 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 9262 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 9263 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 9264 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 9265 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 9266 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 9267 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9268 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9269 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9270 | */ |
| 9271 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 9272 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 9273 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 9274 | /* WaDisableL3Bank2xClockGate:vlv |
| 9275 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 9276 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 9277 | I915_WRITE(GEN7_UCGCTL4, |
| 9278 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 9279 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 9280 | /* |
| 9281 | * BSpec says this must be set, even though |
| 9282 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 9283 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 9284 | I915_WRITE(CACHE_MODE_1, |
| 9285 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 9286 | |
| 9287 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 9288 | * BSpec recommends 8x4 when MSAA is used, |
| 9289 | * however in practice 16x4 seems fastest. |
| 9290 | * |
| 9291 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 9292 | * disable bit, which we don't touch here, but it's good |
| 9293 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 9294 | */ |
| 9295 | I915_WRITE(GEN7_GT_MODE, |
| 9296 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 9297 | |
| 9298 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 9299 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 9300 | * This is the hardware default actually. |
| 9301 | */ |
| 9302 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 9303 | |
| 9304 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 9305 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 9306 | * Disable clock gating on th GCFG unit to prevent a delay |
| 9307 | * in the reporting of vblank events. |
| 9308 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 9309 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9310 | } |
| 9311 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9312 | 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] | 9313 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 9314 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 9315 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 9316 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 9317 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 9318 | ~(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] | 9319 | |
| 9320 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 9321 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 9322 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 9323 | |
| 9324 | /* WaDisableCSUnitClockGating:chv */ |
| 9325 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 9326 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 9327 | |
| 9328 | /* WaDisableSDEUnitClockGating:chv */ |
| 9329 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 9330 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 9331 | |
| 9332 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 9333 | * WaProgramL3SqcReg1Default:chv |
| 9334 | * See gfxspecs/Related Documents/Performance Guide/ |
| 9335 | * LSQC Setting Recommendations. |
| 9336 | */ |
| 9337 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
| 9338 | |
| 9339 | /* |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 9340 | * GTT cache may not work with big pages, so if those |
| 9341 | * are ever enabled GTT cache may need to be disabled. |
| 9342 | */ |
| 9343 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 9344 | } |
| 9345 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9346 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9347 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9348 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9349 | |
| 9350 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 9351 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 9352 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 9353 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 9354 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 9355 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 9356 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 9357 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9358 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9359 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 9360 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 9361 | |
| 9362 | /* WaDisableRenderCachePipelinedFlush */ |
| 9363 | I915_WRITE(CACHE_MODE_0, |
| 9364 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 9365 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9366 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 9367 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 9368 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9369 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9370 | } |
| 9371 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9372 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9373 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9374 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 9375 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 9376 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 9377 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 9378 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 9379 | I915_WRITE(MI_ARB_STATE, |
| 9380 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9381 | |
| 9382 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 9383 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9384 | } |
| 9385 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9386 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9387 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9388 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 9389 | I965_RCC_CLOCK_GATE_DISABLE | |
| 9390 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 9391 | I965_ISC_CLOCK_GATE_DISABLE | |
| 9392 | I965_FBC_CLOCK_GATE_DISABLE); |
| 9393 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 9394 | I915_WRITE(MI_ARB_STATE, |
| 9395 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 9396 | |
| 9397 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 9398 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9399 | } |
| 9400 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9401 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9402 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9403 | u32 dstate = I915_READ(D_STATE); |
| 9404 | |
| 9405 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 9406 | DSTATE_DOT_CLOCK_GATING; |
| 9407 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 9408 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9409 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 9410 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 9411 | |
| 9412 | /* IIR "flip pending" means done if this bit is set */ |
| 9413 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 9414 | |
| 9415 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 9416 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 9417 | |
| 9418 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 9419 | 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] | 9420 | |
| 9421 | I915_WRITE(MI_ARB_STATE, |
| 9422 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9423 | } |
| 9424 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9425 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9426 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9427 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 9428 | |
| 9429 | /* interrupts should cause a wake up from C3 */ |
| 9430 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 9431 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 9432 | |
| 9433 | I915_WRITE(MEM_MODE, |
| 9434 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9435 | } |
| 9436 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9437 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9438 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 9439 | I915_WRITE(MEM_MODE, |
| 9440 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 9441 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9442 | } |
| 9443 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9444 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9445 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9446 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 9447 | } |
| 9448 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 9449 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9450 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 9451 | if (HAS_PCH_LPT(dev_priv)) |
| 9452 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9453 | } |
| 9454 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 9455 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9456 | { |
| 9457 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 9458 | } |
| 9459 | |
| 9460 | /** |
| 9461 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 9462 | * @dev_priv: device private |
| 9463 | * |
| 9464 | * Setup the hooks that configure which clocks of a given platform can be |
| 9465 | * gated and also apply various GT and display specific workarounds for these |
| 9466 | * platforms. Note that some GT specific workarounds are applied separately |
| 9467 | * when GPU contexts or batchbuffers start their execution. |
| 9468 | */ |
| 9469 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 9470 | { |
Oscar Mateo | cc38cae | 2018-05-08 14:29:23 -0700 | [diff] [blame] | 9471 | if (IS_ICELAKE(dev_priv)) |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 9472 | dev_priv->display.init_clock_gating = icl_init_clock_gating; |
Oscar Mateo | cc38cae | 2018-05-08 14:29:23 -0700 | [diff] [blame] | 9473 | else if (IS_CANNONLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9474 | dev_priv->display.init_clock_gating = cnl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9475 | else if (IS_COFFEELAKE(dev_priv)) |
| 9476 | dev_priv->display.init_clock_gating = cfl_init_clock_gating; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 9477 | else if (IS_SKYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9478 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 9479 | else if (IS_KABYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9480 | dev_priv->display.init_clock_gating = kbl_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 9481 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9482 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 9483 | else if (IS_GEMINILAKE(dev_priv)) |
| 9484 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9485 | else if (IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9486 | dev_priv->display.init_clock_gating = bdw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9487 | else if (IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9488 | dev_priv->display.init_clock_gating = chv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9489 | else if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9490 | dev_priv->display.init_clock_gating = hsw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9491 | else if (IS_IVYBRIDGE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9492 | dev_priv->display.init_clock_gating = ivb_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9493 | else if (IS_VALLEYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9494 | dev_priv->display.init_clock_gating = vlv_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9495 | else if (IS_GEN(dev_priv, 6)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9496 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9497 | else if (IS_GEN(dev_priv, 5)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9498 | dev_priv->display.init_clock_gating = ilk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9499 | else if (IS_G4X(dev_priv)) |
| 9500 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 9501 | else if (IS_I965GM(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9502 | dev_priv->display.init_clock_gating = i965gm_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 9503 | else if (IS_I965G(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9504 | dev_priv->display.init_clock_gating = i965g_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9505 | else if (IS_GEN(dev_priv, 3)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9506 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 9507 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 9508 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9509 | else if (IS_GEN(dev_priv, 2)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9510 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 9511 | else { |
| 9512 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 9513 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 9514 | } |
| 9515 | } |
| 9516 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9517 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9518 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9519 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 9520 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9521 | if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 9522 | i915_pineview_get_mem_freq(dev_priv); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9523 | else if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 9524 | i915_ironlake_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 9525 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9526 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9527 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9528 | skl_setup_wm_latency(dev_priv); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 9529 | dev_priv->display.initial_watermarks = skl_initial_wm; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 9530 | dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 9531 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9532 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9533 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 9534 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9535 | 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] | 9536 | 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] | 9537 | (!IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9538 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 9539 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 9540 | dev_priv->display.compute_intermediate_wm = |
| 9541 | ilk_compute_intermediate_wm; |
| 9542 | dev_priv->display.initial_watermarks = |
| 9543 | ilk_initial_watermarks; |
| 9544 | dev_priv->display.optimize_watermarks = |
| 9545 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9546 | } else { |
| 9547 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 9548 | "Disable CxSR\n"); |
| 9549 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 9550 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9551 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9552 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 9553 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9554 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 9555 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9556 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 9557 | } else if (IS_G4X(dev_priv)) { |
| 9558 | g4x_setup_wm_latency(dev_priv); |
| 9559 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 9560 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 9561 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 9562 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9563 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9564 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9565 | dev_priv->is_ddr3, |
| 9566 | dev_priv->fsb_freq, |
| 9567 | dev_priv->mem_freq)) { |
| 9568 | DRM_INFO("failed to find known CxSR latency " |
| 9569 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 9570 | "disabling CxSR\n", |
| 9571 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 9572 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 9573 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 9574 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9575 | dev_priv->display.update_wm = NULL; |
| 9576 | } else |
| 9577 | dev_priv->display.update_wm = pineview_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9578 | } else if (IS_GEN(dev_priv, 4)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9579 | dev_priv->display.update_wm = i965_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9580 | } else if (IS_GEN(dev_priv, 3)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9581 | dev_priv->display.update_wm = i9xx_update_wm; |
| 9582 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9583 | } else if (IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9584 | if (INTEL_INFO(dev_priv)->num_pipes == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9585 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9586 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9587 | } else { |
| 9588 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9589 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9590 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9591 | } else { |
| 9592 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9593 | } |
| 9594 | } |
| 9595 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9596 | static inline int gen6_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 9597 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9598 | u32 flags = |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9599 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 9600 | |
| 9601 | switch (flags) { |
| 9602 | case GEN6_PCODE_SUCCESS: |
| 9603 | return 0; |
| 9604 | case GEN6_PCODE_UNIMPLEMENTED_CMD: |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9605 | return -ENODEV; |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9606 | case GEN6_PCODE_ILLEGAL_CMD: |
| 9607 | return -ENXIO; |
| 9608 | case GEN6_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Chris Wilson | 7850d1c | 2016-08-26 11:59:26 +0100 | [diff] [blame] | 9609 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9610 | return -EOVERFLOW; |
| 9611 | case GEN6_PCODE_TIMEOUT: |
| 9612 | return -ETIMEDOUT; |
| 9613 | default: |
Michal Wajdeczko | f0d6615 | 2017-03-28 08:45:12 +0000 | [diff] [blame] | 9614 | MISSING_CASE(flags); |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9615 | return 0; |
| 9616 | } |
| 9617 | } |
| 9618 | |
| 9619 | static inline int gen7_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 9620 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 9621 | u32 flags = |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9622 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 9623 | |
| 9624 | switch (flags) { |
| 9625 | case GEN6_PCODE_SUCCESS: |
| 9626 | return 0; |
| 9627 | case GEN6_PCODE_ILLEGAL_CMD: |
| 9628 | return -ENXIO; |
| 9629 | case GEN7_PCODE_TIMEOUT: |
| 9630 | return -ETIMEDOUT; |
| 9631 | case GEN7_PCODE_ILLEGAL_DATA: |
| 9632 | return -EINVAL; |
| 9633 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
| 9634 | return -EOVERFLOW; |
| 9635 | default: |
| 9636 | MISSING_CASE(flags); |
| 9637 | return 0; |
| 9638 | } |
| 9639 | } |
| 9640 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 9641 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9642 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9643 | int status; |
| 9644 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9645 | WARN_ON(!mutex_is_locked(&dev_priv->pcu_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9646 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9647 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 9648 | * use te fw I915_READ variants to reduce the amount of work |
| 9649 | * required when reading/writing. |
| 9650 | */ |
| 9651 | |
| 9652 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9653 | DRM_DEBUG_DRIVER("warning: pcode (read from mbox %x) mailbox access failed for %ps\n", |
| 9654 | mbox, __builtin_return_address(0)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9655 | return -EAGAIN; |
| 9656 | } |
| 9657 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9658 | I915_WRITE_FW(GEN6_PCODE_DATA, *val); |
| 9659 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
| 9660 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9661 | |
Chris Wilson | e09a303 | 2017-04-11 11:13:39 +0100 | [diff] [blame] | 9662 | if (__intel_wait_for_register_fw(dev_priv, |
| 9663 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 9664 | 500, 0, NULL)) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9665 | DRM_ERROR("timeout waiting for pcode read (from mbox %x) to finish for %ps\n", |
| 9666 | mbox, __builtin_return_address(0)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9667 | return -ETIMEDOUT; |
| 9668 | } |
| 9669 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9670 | *val = I915_READ_FW(GEN6_PCODE_DATA); |
| 9671 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9672 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9673 | if (INTEL_GEN(dev_priv) > 6) |
| 9674 | status = gen7_check_mailbox_status(dev_priv); |
| 9675 | else |
| 9676 | status = gen6_check_mailbox_status(dev_priv); |
| 9677 | |
| 9678 | if (status) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9679 | DRM_DEBUG_DRIVER("warning: pcode (read from mbox %x) mailbox access failed for %ps: %d\n", |
| 9680 | mbox, __builtin_return_address(0), status); |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9681 | return status; |
| 9682 | } |
| 9683 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9684 | return 0; |
| 9685 | } |
| 9686 | |
Imre Deak | e76019a | 2018-01-30 16:29:38 +0200 | [diff] [blame] | 9687 | int sandybridge_pcode_write_timeout(struct drm_i915_private *dev_priv, |
Imre Deak | 006bb4c | 2018-01-30 16:29:39 +0200 | [diff] [blame] | 9688 | u32 mbox, u32 val, |
| 9689 | int fast_timeout_us, int slow_timeout_ms) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9690 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9691 | int status; |
| 9692 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9693 | WARN_ON(!mutex_is_locked(&dev_priv->pcu_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9694 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9695 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 9696 | * use te fw I915_READ variants to reduce the amount of work |
| 9697 | * required when reading/writing. |
| 9698 | */ |
| 9699 | |
| 9700 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9701 | DRM_DEBUG_DRIVER("warning: pcode (write of 0x%08x to mbox %x) mailbox access failed for %ps\n", |
| 9702 | val, mbox, __builtin_return_address(0)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9703 | return -EAGAIN; |
| 9704 | } |
| 9705 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9706 | I915_WRITE_FW(GEN6_PCODE_DATA, val); |
Imre Deak | 8bf41b7 | 2016-11-28 17:29:27 +0200 | [diff] [blame] | 9707 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9708 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9709 | |
Chris Wilson | e09a303 | 2017-04-11 11:13:39 +0100 | [diff] [blame] | 9710 | if (__intel_wait_for_register_fw(dev_priv, |
| 9711 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
Imre Deak | 006bb4c | 2018-01-30 16:29:39 +0200 | [diff] [blame] | 9712 | fast_timeout_us, slow_timeout_ms, |
| 9713 | NULL)) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9714 | DRM_ERROR("timeout waiting for pcode write of 0x%08x to mbox %x to finish for %ps\n", |
| 9715 | val, mbox, __builtin_return_address(0)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9716 | return -ETIMEDOUT; |
| 9717 | } |
| 9718 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9719 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9720 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9721 | if (INTEL_GEN(dev_priv) > 6) |
| 9722 | status = gen7_check_mailbox_status(dev_priv); |
| 9723 | else |
| 9724 | status = gen6_check_mailbox_status(dev_priv); |
| 9725 | |
| 9726 | if (status) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9727 | DRM_DEBUG_DRIVER("warning: pcode (write of 0x%08x to mbox %x) mailbox access failed for %ps: %d\n", |
| 9728 | val, mbox, __builtin_return_address(0), status); |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9729 | return status; |
| 9730 | } |
| 9731 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9732 | return 0; |
| 9733 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 9734 | |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9735 | static bool skl_pcode_try_request(struct drm_i915_private *dev_priv, u32 mbox, |
| 9736 | u32 request, u32 reply_mask, u32 reply, |
| 9737 | u32 *status) |
| 9738 | { |
| 9739 | u32 val = request; |
| 9740 | |
| 9741 | *status = sandybridge_pcode_read(dev_priv, mbox, &val); |
| 9742 | |
| 9743 | return *status || ((val & reply_mask) == reply); |
| 9744 | } |
| 9745 | |
| 9746 | /** |
| 9747 | * skl_pcode_request - send PCODE request until acknowledgment |
| 9748 | * @dev_priv: device private |
| 9749 | * @mbox: PCODE mailbox ID the request is targeted for |
| 9750 | * @request: request ID |
| 9751 | * @reply_mask: mask used to check for request acknowledgment |
| 9752 | * @reply: value used to check for request acknowledgment |
| 9753 | * @timeout_base_ms: timeout for polling with preemption enabled |
| 9754 | * |
| 9755 | * Keep resending the @request to @mbox until PCODE acknowledges it, PCODE |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9756 | * reports an error or an overall timeout of @timeout_base_ms+50 ms expires. |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9757 | * The request is acknowledged once the PCODE reply dword equals @reply after |
| 9758 | * applying @reply_mask. Polling is first attempted with preemption enabled |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9759 | * for @timeout_base_ms and if this times out for another 50 ms with |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9760 | * preemption disabled. |
| 9761 | * |
| 9762 | * Returns 0 on success, %-ETIMEDOUT in case of a timeout, <0 in case of some |
| 9763 | * other error as reported by PCODE. |
| 9764 | */ |
| 9765 | int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request, |
| 9766 | u32 reply_mask, u32 reply, int timeout_base_ms) |
| 9767 | { |
| 9768 | u32 status; |
| 9769 | int ret; |
| 9770 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9771 | WARN_ON(!mutex_is_locked(&dev_priv->pcu_lock)); |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9772 | |
| 9773 | #define COND skl_pcode_try_request(dev_priv, mbox, request, reply_mask, reply, \ |
| 9774 | &status) |
| 9775 | |
| 9776 | /* |
| 9777 | * Prime the PCODE by doing a request first. Normally it guarantees |
| 9778 | * that a subsequent request, at most @timeout_base_ms later, succeeds. |
| 9779 | * _wait_for() doesn't guarantee when its passed condition is evaluated |
| 9780 | * first, so send the first request explicitly. |
| 9781 | */ |
| 9782 | if (COND) { |
| 9783 | ret = 0; |
| 9784 | goto out; |
| 9785 | } |
Chris Wilson | a54b187 | 2017-11-24 13:00:30 +0000 | [diff] [blame] | 9786 | ret = _wait_for(COND, timeout_base_ms * 1000, 10, 10); |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9787 | if (!ret) |
| 9788 | goto out; |
| 9789 | |
| 9790 | /* |
| 9791 | * The above can time out if the number of requests was low (2 in the |
| 9792 | * worst case) _and_ PCODE was busy for some reason even after a |
| 9793 | * (queued) request and @timeout_base_ms delay. As a workaround retry |
| 9794 | * the poll with preemption disabled to maximize the number of |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9795 | * requests. Increase the timeout from @timeout_base_ms to 50ms to |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9796 | * account for interrupts that could reduce the number of these |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9797 | * requests, and for any quirks of the PCODE firmware that delays |
| 9798 | * the request completion. |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9799 | */ |
| 9800 | DRM_DEBUG_KMS("PCODE timeout, retrying with preemption disabled\n"); |
| 9801 | WARN_ON_ONCE(timeout_base_ms > 3); |
| 9802 | preempt_disable(); |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9803 | ret = wait_for_atomic(COND, 50); |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9804 | preempt_enable(); |
| 9805 | |
| 9806 | out: |
| 9807 | return ret ? ret : status; |
| 9808 | #undef COND |
| 9809 | } |
| 9810 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 9811 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9812 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9813 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9814 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9815 | /* |
| 9816 | * N = val - 0xb7 |
| 9817 | * Slow = Fast = GPLL ref * N |
| 9818 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9819 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * (val - 0xb7), 1000); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 9820 | } |
| 9821 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9822 | 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] | 9823 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9824 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9825 | |
| 9826 | return DIV_ROUND_CLOSEST(1000 * val, rps->gpll_ref_freq) + 0xb7; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 9827 | } |
| 9828 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9829 | 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] | 9830 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9831 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9832 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9833 | /* |
| 9834 | * N = val / 2 |
| 9835 | * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2 |
| 9836 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9837 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * val, 2 * 2 * 1000); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9838 | } |
| 9839 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9840 | 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] | 9841 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9842 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9843 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 9844 | /* CHV needs even values */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9845 | return DIV_ROUND_CLOSEST(2 * 1000 * val, rps->gpll_ref_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9846 | } |
| 9847 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9848 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9849 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 9850 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9851 | return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, |
| 9852 | GEN9_FREQ_SCALER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9853 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9854 | return chv_gpu_freq(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9855 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9856 | return byt_gpu_freq(dev_priv, val); |
| 9857 | else |
| 9858 | return val * GT_FREQUENCY_MULTIPLIER; |
| 9859 | } |
| 9860 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9861 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 9862 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 9863 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9864 | return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, |
| 9865 | GT_FREQUENCY_MULTIPLIER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9866 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9867 | return chv_freq_opcode(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9868 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9869 | return byt_freq_opcode(dev_priv, val); |
| 9870 | else |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9871 | return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9872 | } |
| 9873 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 9874 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9875 | { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9876 | mutex_init(&dev_priv->pcu_lock); |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 9877 | mutex_init(&dev_priv->gt_pm.rps.power.mutex); |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9878 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9879 | atomic_set(&dev_priv->gt_pm.rps.num_waiters, 0); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 9880 | |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 9881 | dev_priv->runtime_pm.suspended = false; |
| 9882 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9883 | } |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9884 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9885 | static u64 vlv_residency_raw(struct drm_i915_private *dev_priv, |
| 9886 | const i915_reg_t reg) |
| 9887 | { |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9888 | u32 lower, upper, tmp; |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9889 | int loop = 2; |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9890 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9891 | /* |
| 9892 | * The register accessed do not need forcewake. We borrow |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9893 | * uncore lock to prevent concurrent access to range reg. |
| 9894 | */ |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9895 | lockdep_assert_held(&dev_priv->uncore.lock); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9896 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9897 | /* |
| 9898 | * vlv and chv residency counters are 40 bits in width. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9899 | * With a control bit, we can choose between upper or lower |
| 9900 | * 32bit window into this counter. |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9901 | * |
| 9902 | * Although we always use the counter in high-range mode elsewhere, |
| 9903 | * userspace may attempt to read the value before rc6 is initialised, |
| 9904 | * before we have set the default VLV_COUNTER_CONTROL value. So always |
| 9905 | * set the high bit to be safe. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9906 | */ |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9907 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9908 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9909 | upper = I915_READ_FW(reg); |
| 9910 | do { |
| 9911 | tmp = upper; |
| 9912 | |
| 9913 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9914 | _MASKED_BIT_DISABLE(VLV_COUNT_RANGE_HIGH)); |
| 9915 | lower = I915_READ_FW(reg); |
| 9916 | |
| 9917 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9918 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
| 9919 | upper = I915_READ_FW(reg); |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9920 | } while (upper != tmp && --loop); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9921 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9922 | /* |
| 9923 | * Everywhere else we always use VLV_COUNTER_CONTROL with the |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9924 | * VLV_COUNT_RANGE_HIGH bit set - so it is safe to leave it set |
| 9925 | * now. |
| 9926 | */ |
| 9927 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9928 | return lower | (u64)upper << 8; |
| 9929 | } |
| 9930 | |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9931 | u64 intel_rc6_residency_ns(struct drm_i915_private *dev_priv, |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9932 | const i915_reg_t reg) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9933 | { |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9934 | u64 time_hw, prev_hw, overflow_hw; |
| 9935 | unsigned int fw_domains; |
| 9936 | unsigned long flags; |
| 9937 | unsigned int i; |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9938 | u32 mul, div; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9939 | |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 9940 | if (!HAS_RC6(dev_priv)) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9941 | return 0; |
| 9942 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9943 | /* |
| 9944 | * Store previous hw counter values for counter wrap-around handling. |
| 9945 | * |
| 9946 | * There are only four interesting registers and they live next to each |
| 9947 | * other so we can use the relative address, compared to the smallest |
| 9948 | * one as the index into driver storage. |
| 9949 | */ |
| 9950 | i = (i915_mmio_reg_offset(reg) - |
| 9951 | i915_mmio_reg_offset(GEN6_GT_GFX_RC6_LOCKED)) / sizeof(u32); |
| 9952 | if (WARN_ON_ONCE(i >= ARRAY_SIZE(dev_priv->gt_pm.rc6.cur_residency))) |
| 9953 | return 0; |
| 9954 | |
| 9955 | fw_domains = intel_uncore_forcewake_for_reg(dev_priv, reg, FW_REG_READ); |
| 9956 | |
| 9957 | spin_lock_irqsave(&dev_priv->uncore.lock, flags); |
| 9958 | intel_uncore_forcewake_get__locked(dev_priv, fw_domains); |
| 9959 | |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9960 | /* On VLV and CHV, residency time is in CZ units rather than 1.28us */ |
| 9961 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9962 | mul = 1000000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9963 | div = dev_priv->czclk_freq; |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9964 | overflow_hw = BIT_ULL(40); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9965 | time_hw = vlv_residency_raw(dev_priv, reg); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9966 | } else { |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 9967 | /* 833.33ns units on Gen9LP, 1.28us elsewhere. */ |
| 9968 | if (IS_GEN9_LP(dev_priv)) { |
| 9969 | mul = 10000; |
| 9970 | div = 12; |
| 9971 | } else { |
| 9972 | mul = 1280; |
| 9973 | div = 1; |
| 9974 | } |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9975 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9976 | overflow_hw = BIT_ULL(32); |
| 9977 | time_hw = I915_READ_FW(reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9978 | } |
| 9979 | |
Tvrtko Ursulin | 817cc079 | 2018-02-08 16:00:36 +0000 | [diff] [blame] | 9980 | /* |
| 9981 | * Counter wrap handling. |
| 9982 | * |
| 9983 | * But relying on a sufficient frequency of queries otherwise counters |
| 9984 | * can still wrap. |
| 9985 | */ |
| 9986 | prev_hw = dev_priv->gt_pm.rc6.prev_hw_residency[i]; |
| 9987 | dev_priv->gt_pm.rc6.prev_hw_residency[i] = time_hw; |
| 9988 | |
| 9989 | /* RC6 delta from last sample. */ |
| 9990 | if (time_hw >= prev_hw) |
| 9991 | time_hw -= prev_hw; |
| 9992 | else |
| 9993 | time_hw += overflow_hw - prev_hw; |
| 9994 | |
| 9995 | /* Add delta to RC6 extended raw driver copy. */ |
| 9996 | time_hw += dev_priv->gt_pm.rc6.cur_residency[i]; |
| 9997 | dev_priv->gt_pm.rc6.cur_residency[i] = time_hw; |
| 9998 | |
| 9999 | intel_uncore_forcewake_put__locked(dev_priv, fw_domains); |
| 10000 | spin_unlock_irqrestore(&dev_priv->uncore.lock, flags); |
| 10001 | |
| 10002 | return mul_u64_u32_div(time_hw, mul, div); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 10003 | } |
Tvrtko Ursulin | c84b270 | 2017-11-21 18:18:44 +0000 | [diff] [blame] | 10004 | |
| 10005 | u32 intel_get_cagf(struct drm_i915_private *dev_priv, u32 rpstat) |
| 10006 | { |
| 10007 | u32 cagf; |
| 10008 | |
| 10009 | if (INTEL_GEN(dev_priv) >= 9) |
| 10010 | cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT; |
| 10011 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 10012 | cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT; |
| 10013 | else |
| 10014 | cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT; |
| 10015 | |
| 10016 | return cagf; |
| 10017 | } |