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> |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 29 | #include <drm/drm_plane_helper.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 30 | #include "i915_drv.h" |
| 31 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 32 | #include "../../../platform/x86/intel_ips.h" |
| 33 | #include <linux/module.h> |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 34 | #include <drm/drm_atomic_helper.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 35 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 36 | /** |
Jani Nikula | 18afd44 | 2016-01-18 09:19:48 +0200 | [diff] [blame] | 37 | * DOC: RC6 |
| 38 | * |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 39 | * RC6 is a special power stage which allows the GPU to enter an very |
| 40 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 41 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 42 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 43 | * |
| 44 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 45 | * among each other with the latency required to enter and leave RC6 and |
| 46 | * voltage consumed by the GPU in different states. |
| 47 | * |
| 48 | * The combination of the following flags define which states GPU is allowed |
| 49 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 50 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 51 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 52 | * which brings the most power savings; deeper states save more power, but |
| 53 | * require higher latency to switch to and wake up. |
| 54 | */ |
| 55 | #define INTEL_RC6_ENABLE (1<<0) |
| 56 | #define INTEL_RC6p_ENABLE (1<<1) |
| 57 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 58 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 59 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 60 | { |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 61 | if (HAS_LLC(dev_priv)) { |
| 62 | /* |
| 63 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
| 64 | * Display WA#0390: skl,kbl |
| 65 | * |
| 66 | * Must match Sampler, Pixel Back End, and Media. See |
| 67 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 68 | */ |
| 69 | I915_WRITE(CHICKEN_PAR1_1, |
| 70 | I915_READ(CHICKEN_PAR1_1) | |
| 71 | SKL_DE_COMPRESSED_HASH_MODE); |
| 72 | } |
| 73 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 74 | /* 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] | 75 | I915_WRITE(CHICKEN_PAR1_1, |
| 76 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 77 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 78 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 79 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 80 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 81 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 82 | /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl,cfl */ |
| 83 | /* WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 84 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 85 | DISP_FBC_WM_DIS | |
| 86 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 87 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 88 | /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl,cfl */ |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 89 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 90 | ILK_DPFC_DISABLE_DUMMY0); |
Praveen Paneri | 32087d1 | 2017-08-03 23:02:10 +0530 | [diff] [blame] | 91 | |
| 92 | if (IS_SKYLAKE(dev_priv)) { |
| 93 | /* WaDisableDopClockGating */ |
| 94 | I915_WRITE(GEN7_MISCCPCTL, I915_READ(GEN7_MISCCPCTL) |
| 95 | & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 96 | } |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 97 | } |
| 98 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 99 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 100 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 101 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 102 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 103 | /* WaDisableSDEUnitClockGating:bxt */ |
| 104 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 105 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 106 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 107 | /* |
| 108 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 109 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 110 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 111 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 112 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 116 | * to stay fully on. |
| 117 | */ |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 118 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 119 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 122 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 123 | { |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 124 | u32 val; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 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 | |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 144 | /* Display WA #1133: WaFbcSkipSegments:glk */ |
| 145 | val = I915_READ(ILK_DPFC_CHICKEN); |
| 146 | val &= ~GLK_SKIP_SEG_COUNT_MASK; |
| 147 | val |= GLK_SKIP_SEG_EN | GLK_SKIP_SEG_COUNT(1); |
| 148 | I915_WRITE(ILK_DPFC_CHICKEN, val); |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 151 | 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] | 152 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 153 | u32 tmp; |
| 154 | |
| 155 | tmp = I915_READ(CLKCFG); |
| 156 | |
| 157 | switch (tmp & CLKCFG_FSB_MASK) { |
| 158 | case CLKCFG_FSB_533: |
| 159 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 160 | break; |
| 161 | case CLKCFG_FSB_800: |
| 162 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 163 | break; |
| 164 | case CLKCFG_FSB_667: |
| 165 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 166 | break; |
| 167 | case CLKCFG_FSB_400: |
| 168 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 169 | break; |
| 170 | } |
| 171 | |
| 172 | switch (tmp & CLKCFG_MEM_MASK) { |
| 173 | case CLKCFG_MEM_533: |
| 174 | dev_priv->mem_freq = 533; |
| 175 | break; |
| 176 | case CLKCFG_MEM_667: |
| 177 | dev_priv->mem_freq = 667; |
| 178 | break; |
| 179 | case CLKCFG_MEM_800: |
| 180 | dev_priv->mem_freq = 800; |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | /* detect pineview DDR3 setting */ |
| 185 | tmp = I915_READ(CSHRDDR3CTL); |
| 186 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 187 | } |
| 188 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 189 | 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] | 190 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 191 | u16 ddrpll, csipll; |
| 192 | |
| 193 | ddrpll = I915_READ16(DDRMPLL1); |
| 194 | csipll = I915_READ16(CSIPLL0); |
| 195 | |
| 196 | switch (ddrpll & 0xff) { |
| 197 | case 0xc: |
| 198 | dev_priv->mem_freq = 800; |
| 199 | break; |
| 200 | case 0x10: |
| 201 | dev_priv->mem_freq = 1066; |
| 202 | break; |
| 203 | case 0x14: |
| 204 | dev_priv->mem_freq = 1333; |
| 205 | break; |
| 206 | case 0x18: |
| 207 | dev_priv->mem_freq = 1600; |
| 208 | break; |
| 209 | default: |
| 210 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 211 | ddrpll & 0xff); |
| 212 | dev_priv->mem_freq = 0; |
| 213 | break; |
| 214 | } |
| 215 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 216 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 217 | |
| 218 | switch (csipll & 0x3ff) { |
| 219 | case 0x00c: |
| 220 | dev_priv->fsb_freq = 3200; |
| 221 | break; |
| 222 | case 0x00e: |
| 223 | dev_priv->fsb_freq = 3733; |
| 224 | break; |
| 225 | case 0x010: |
| 226 | dev_priv->fsb_freq = 4266; |
| 227 | break; |
| 228 | case 0x012: |
| 229 | dev_priv->fsb_freq = 4800; |
| 230 | break; |
| 231 | case 0x014: |
| 232 | dev_priv->fsb_freq = 5333; |
| 233 | break; |
| 234 | case 0x016: |
| 235 | dev_priv->fsb_freq = 5866; |
| 236 | break; |
| 237 | case 0x018: |
| 238 | dev_priv->fsb_freq = 6400; |
| 239 | break; |
| 240 | default: |
| 241 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 242 | csipll & 0x3ff); |
| 243 | dev_priv->fsb_freq = 0; |
| 244 | break; |
| 245 | } |
| 246 | |
| 247 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 248 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 249 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 250 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 251 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 252 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 256 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 257 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 258 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 259 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 260 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 261 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 262 | |
| 263 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 264 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 265 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 266 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 267 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 268 | |
| 269 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 270 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 271 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 272 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 273 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 274 | |
| 275 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 276 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 277 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 278 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 279 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 280 | |
| 281 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 282 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 283 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 284 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 285 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 286 | |
| 287 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 288 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 289 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 290 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 291 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 292 | }; |
| 293 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 294 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 295 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 296 | int fsb, |
| 297 | int mem) |
| 298 | { |
| 299 | const struct cxsr_latency *latency; |
| 300 | int i; |
| 301 | |
| 302 | if (fsb == 0 || mem == 0) |
| 303 | return NULL; |
| 304 | |
| 305 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 306 | latency = &cxsr_latency_table[i]; |
| 307 | if (is_desktop == latency->is_desktop && |
| 308 | is_ddr3 == latency->is_ddr3 && |
| 309 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 310 | return latency; |
| 311 | } |
| 312 | |
| 313 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 314 | |
| 315 | return NULL; |
| 316 | } |
| 317 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 318 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 319 | { |
| 320 | u32 val; |
| 321 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 322 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 323 | |
| 324 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 325 | if (enable) |
| 326 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 327 | else |
| 328 | val |= FORCE_DDR_HIGH_FREQ; |
| 329 | val &= ~FORCE_DDR_LOW_FREQ; |
| 330 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 331 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 332 | |
| 333 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 334 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 335 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 336 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 337 | mutex_unlock(&dev_priv->pcu_lock); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 340 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 341 | { |
| 342 | u32 val; |
| 343 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 344 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 345 | |
| 346 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 347 | if (enable) |
| 348 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 349 | else |
| 350 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
| 351 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 352 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 353 | mutex_unlock(&dev_priv->pcu_lock); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 356 | #define FW_WM(value, plane) \ |
| 357 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 358 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 359 | 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] | 360 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 361 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 362 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 363 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 364 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 365 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 366 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 367 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 368 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 369 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 370 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 371 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 372 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 373 | val = I915_READ(DSPFW3); |
| 374 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 375 | if (enable) |
| 376 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 377 | else |
| 378 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 379 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 380 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 381 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 382 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 383 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 384 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 385 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 386 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 387 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 388 | /* |
| 389 | * FIXME can't find a bit like this for 915G, and |
| 390 | * and yet it does have the related watermark in |
| 391 | * FW_BLC_SELF. What's going on? |
| 392 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 393 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 394 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 395 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 396 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 397 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 398 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 399 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 400 | } |
| 401 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 402 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 403 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 404 | DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", |
| 405 | enableddisabled(enable), |
| 406 | enableddisabled(was_enabled)); |
| 407 | |
| 408 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 409 | } |
| 410 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 411 | /** |
| 412 | * intel_set_memory_cxsr - Configure CxSR state |
| 413 | * @dev_priv: i915 device |
| 414 | * @enable: Allow vs. disallow CxSR |
| 415 | * |
| 416 | * Allow or disallow the system to enter a special CxSR |
| 417 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 418 | * is that several display FIFOs may get combined into a single larger |
| 419 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 420 | * system to defer memory fetches longer, and the memory will enter |
| 421 | * self refresh. |
| 422 | * |
| 423 | * Note that enabling CxSR does not guarantee that the system enter |
| 424 | * this special mode, nor does it guarantee that the system stays |
| 425 | * in that mode once entered. So this just allows/disallows the system |
| 426 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 427 | * C-states will affect when/if the system actually enters/exits the |
| 428 | * CxSR mode. |
| 429 | * |
| 430 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 431 | * and the system is free to enter/exit memory self refresh at any time |
| 432 | * even when the use of CxSR has been disallowed. |
| 433 | * |
| 434 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 435 | * control registers will not get latched on vblank. Thus in order to |
| 436 | * guarantee the system will respond to changes in the plane registers |
| 437 | * we must always disallow CxSR prior to making changes to those registers. |
| 438 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 439 | * frame start which happens after vblank start (which is when the plane |
| 440 | * registers would get latched), so we can't proceed with the plane update |
| 441 | * during the same frame where we disallowed CxSR. |
| 442 | * |
| 443 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 444 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 445 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 446 | * Disallowing just CxSR is sufficient. |
| 447 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 448 | 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] | 449 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 450 | bool ret; |
| 451 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 452 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 453 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 454 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 455 | dev_priv->wm.vlv.cxsr = enable; |
| 456 | else if (IS_G4X(dev_priv)) |
| 457 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 458 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 459 | |
| 460 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 461 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 462 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 463 | /* |
| 464 | * Latency for FIFO fetches is dependent on several factors: |
| 465 | * - memory configuration (speed, channels) |
| 466 | * - chipset |
| 467 | * - current MCH state |
| 468 | * It can be fairly high in some situations, so here we assume a fairly |
| 469 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 470 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 471 | * and power consumption (set it too low to save power and we might see |
| 472 | * FIFO underruns and display "flicker"). |
| 473 | * |
| 474 | * A value of 5us seems to be a good balance; safe for very low end |
| 475 | * platforms but not overly aggressive on lower latency configs. |
| 476 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 477 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 478 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 479 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 480 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 481 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 482 | 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] | 483 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 484 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 485 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 486 | 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] | 487 | enum pipe pipe = crtc->pipe; |
| 488 | int sprite0_start, sprite1_start; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 489 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 490 | switch (pipe) { |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 491 | uint32_t dsparb, dsparb2, dsparb3; |
| 492 | case PIPE_A: |
| 493 | dsparb = I915_READ(DSPARB); |
| 494 | dsparb2 = I915_READ(DSPARB2); |
| 495 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 496 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 497 | break; |
| 498 | case PIPE_B: |
| 499 | dsparb = I915_READ(DSPARB); |
| 500 | dsparb2 = I915_READ(DSPARB2); |
| 501 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 502 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 503 | break; |
| 504 | case PIPE_C: |
| 505 | dsparb2 = I915_READ(DSPARB2); |
| 506 | dsparb3 = I915_READ(DSPARB3); |
| 507 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 508 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 509 | break; |
| 510 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 511 | MISSING_CASE(pipe); |
| 512 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 515 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 516 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 517 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 518 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 521 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 522 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 523 | uint32_t dsparb = I915_READ(DSPARB); |
| 524 | int size; |
| 525 | |
| 526 | size = dsparb & 0x7f; |
| 527 | if (plane) |
| 528 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 529 | |
| 530 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 531 | plane ? "B" : "A", size); |
| 532 | |
| 533 | return size; |
| 534 | } |
| 535 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 536 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 537 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 538 | uint32_t dsparb = I915_READ(DSPARB); |
| 539 | int size; |
| 540 | |
| 541 | size = dsparb & 0x1ff; |
| 542 | if (plane) |
| 543 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 544 | size >>= 1; /* Convert to cachelines */ |
| 545 | |
| 546 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 547 | plane ? "B" : "A", size); |
| 548 | |
| 549 | return size; |
| 550 | } |
| 551 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 552 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 553 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 554 | uint32_t dsparb = I915_READ(DSPARB); |
| 555 | int size; |
| 556 | |
| 557 | size = dsparb & 0x7f; |
| 558 | size >>= 2; /* Convert to cachelines */ |
| 559 | |
| 560 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 561 | plane ? "B" : "A", |
| 562 | size); |
| 563 | |
| 564 | return size; |
| 565 | } |
| 566 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 567 | /* Pineview has different values for various configs */ |
| 568 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 569 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 570 | .max_wm = PINEVIEW_MAX_WM, |
| 571 | .default_wm = PINEVIEW_DFT_WM, |
| 572 | .guard_size = PINEVIEW_GUARD_WM, |
| 573 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 574 | }; |
| 575 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 576 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 577 | .max_wm = PINEVIEW_MAX_WM, |
| 578 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 579 | .guard_size = PINEVIEW_GUARD_WM, |
| 580 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 581 | }; |
| 582 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 583 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 584 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 585 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 586 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 587 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 588 | }; |
| 589 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 590 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 591 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 592 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 593 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 594 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 595 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 596 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 597 | .fifo_size = I965_CURSOR_FIFO, |
| 598 | .max_wm = I965_CURSOR_MAX_WM, |
| 599 | .default_wm = I965_CURSOR_DFT_WM, |
| 600 | .guard_size = 2, |
| 601 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 602 | }; |
| 603 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 604 | .fifo_size = I945_FIFO_SIZE, |
| 605 | .max_wm = I915_MAX_WM, |
| 606 | .default_wm = 1, |
| 607 | .guard_size = 2, |
| 608 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 609 | }; |
| 610 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 611 | .fifo_size = I915_FIFO_SIZE, |
| 612 | .max_wm = I915_MAX_WM, |
| 613 | .default_wm = 1, |
| 614 | .guard_size = 2, |
| 615 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 616 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 617 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 618 | .fifo_size = I855GM_FIFO_SIZE, |
| 619 | .max_wm = I915_MAX_WM, |
| 620 | .default_wm = 1, |
| 621 | .guard_size = 2, |
| 622 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 623 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 624 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 625 | .fifo_size = I855GM_FIFO_SIZE, |
| 626 | .max_wm = I915_MAX_WM/2, |
| 627 | .default_wm = 1, |
| 628 | .guard_size = 2, |
| 629 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 630 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 631 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 632 | .fifo_size = I830_FIFO_SIZE, |
| 633 | .max_wm = I915_MAX_WM, |
| 634 | .default_wm = 1, |
| 635 | .guard_size = 2, |
| 636 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 637 | }; |
| 638 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 639 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 640 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 641 | * @pixel_rate: Pipe pixel rate in kHz |
| 642 | * @cpp: Plane bytes per pixel |
| 643 | * @latency: Memory wakeup latency in 0.1us units |
| 644 | * |
| 645 | * Compute the watermark using the method 1 or "small buffer" |
| 646 | * formula. The caller may additonally add extra cachelines |
| 647 | * to account for TLB misses and clock crossings. |
| 648 | * |
| 649 | * This method is concerned with the short term drain rate |
| 650 | * of the FIFO, ie. it does not account for blanking periods |
| 651 | * which would effectively reduce the average drain rate across |
| 652 | * a longer period. The name "small" refers to the fact the |
| 653 | * FIFO is relatively small compared to the amount of data |
| 654 | * fetched. |
| 655 | * |
| 656 | * The FIFO level vs. time graph might look something like: |
| 657 | * |
| 658 | * |\ |\ |
| 659 | * | \ | \ |
| 660 | * __---__---__ (- plane active, _ blanking) |
| 661 | * -> time |
| 662 | * |
| 663 | * or perhaps like this: |
| 664 | * |
| 665 | * |\|\ |\|\ |
| 666 | * __----__----__ (- plane active, _ blanking) |
| 667 | * -> time |
| 668 | * |
| 669 | * Returns: |
| 670 | * The watermark in bytes |
| 671 | */ |
| 672 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 673 | unsigned int cpp, |
| 674 | unsigned int latency) |
| 675 | { |
| 676 | uint64_t ret; |
| 677 | |
| 678 | ret = (uint64_t) pixel_rate * cpp * latency; |
| 679 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 680 | |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 686 | * @pixel_rate: Pipe pixel rate in kHz |
| 687 | * @htotal: Pipe horizontal total |
| 688 | * @width: Plane width in pixels |
| 689 | * @cpp: Plane bytes per pixel |
| 690 | * @latency: Memory wakeup latency in 0.1us units |
| 691 | * |
| 692 | * Compute the watermark using the method 2 or "large buffer" |
| 693 | * formula. The caller may additonally add extra cachelines |
| 694 | * to account for TLB misses and clock crossings. |
| 695 | * |
| 696 | * This method is concerned with the long term drain rate |
| 697 | * of the FIFO, ie. it does account for blanking periods |
| 698 | * which effectively reduce the average drain rate across |
| 699 | * a longer period. The name "large" refers to the fact the |
| 700 | * FIFO is relatively large compared to the amount of data |
| 701 | * fetched. |
| 702 | * |
| 703 | * The FIFO level vs. time graph might look something like: |
| 704 | * |
| 705 | * |\___ |\___ |
| 706 | * | \___ | \___ |
| 707 | * | \ | \ |
| 708 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 709 | * -> time |
| 710 | * |
| 711 | * Returns: |
| 712 | * The watermark in bytes |
| 713 | */ |
| 714 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 715 | unsigned int htotal, |
| 716 | unsigned int width, |
| 717 | unsigned int cpp, |
| 718 | unsigned int latency) |
| 719 | { |
| 720 | unsigned int ret; |
| 721 | |
| 722 | /* |
| 723 | * FIXME remove once all users are computing |
| 724 | * watermarks in the correct place. |
| 725 | */ |
| 726 | if (WARN_ON_ONCE(htotal == 0)) |
| 727 | htotal = 1; |
| 728 | |
| 729 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 730 | ret = (ret + 1) * width * cpp; |
| 731 | |
| 732 | return ret; |
| 733 | } |
| 734 | |
| 735 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 736 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 737 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 738 | * @wm: chip FIFO params |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 739 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 740 | * @latency_ns: memory latency for the platform |
| 741 | * |
| 742 | * Calculate the watermark level (the level at which the display plane will |
| 743 | * start fetching from memory again). Each chip has a different display |
| 744 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 745 | * in the correct intel_watermark_params structure. |
| 746 | * |
| 747 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 748 | * on the pixel size. When it reaches the watermark level, it'll start |
| 749 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 750 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 751 | * will occur, and a display engine hang could result. |
| 752 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 753 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 754 | const struct intel_watermark_params *wm, |
| 755 | int fifo_size, int cpp, |
| 756 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 757 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 758 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 759 | |
| 760 | /* |
| 761 | * Note: we need to make sure we don't overflow for various clock & |
| 762 | * latency values. |
| 763 | * clocks go from a few thousand to several hundred thousand. |
| 764 | * latency is usually a few thousand |
| 765 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 766 | entries = intel_wm_method1(pixel_rate, cpp, |
| 767 | latency_ns / 100); |
| 768 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 769 | wm->guard_size; |
| 770 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 771 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 772 | wm_size = fifo_size - entries; |
| 773 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 774 | |
| 775 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 776 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 777 | wm_size = wm->max_wm; |
| 778 | if (wm_size <= 0) |
| 779 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 780 | |
| 781 | /* |
| 782 | * Bspec seems to indicate that the value shouldn't be lower than |
| 783 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 784 | * Lets go for 8 which is the burst size since certain platforms |
| 785 | * already use a hardcoded 8 (which is what the spec says should be |
| 786 | * done). |
| 787 | */ |
| 788 | if (wm_size <= 8) |
| 789 | wm_size = 8; |
| 790 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 791 | return wm_size; |
| 792 | } |
| 793 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 794 | static bool is_disabling(int old, int new, int threshold) |
| 795 | { |
| 796 | return old >= threshold && new < threshold; |
| 797 | } |
| 798 | |
| 799 | static bool is_enabling(int old, int new, int threshold) |
| 800 | { |
| 801 | return old < threshold && new >= threshold; |
| 802 | } |
| 803 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 804 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 805 | { |
| 806 | return dev_priv->wm.max_level + 1; |
| 807 | } |
| 808 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 809 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 810 | const struct intel_plane_state *plane_state) |
| 811 | { |
| 812 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 813 | |
| 814 | /* FIXME check the 'enable' instead */ |
| 815 | if (!crtc_state->base.active) |
| 816 | return false; |
| 817 | |
| 818 | /* |
| 819 | * Treat cursor with fb as always visible since cursor updates |
| 820 | * can happen faster than the vrefresh rate, and the current |
| 821 | * watermark code doesn't handle that correctly. Cursor updates |
| 822 | * which set/clear the fb or change the cursor size are going |
| 823 | * to get throttled by intel_legacy_cursor_update() to work |
| 824 | * around this problem with the watermark code. |
| 825 | */ |
| 826 | if (plane->id == PLANE_CURSOR) |
| 827 | return plane_state->base.fb != NULL; |
| 828 | else |
| 829 | return plane_state->base.visible; |
| 830 | } |
| 831 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 832 | 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] | 833 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 834 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 835 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 836 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 837 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 838 | if (enabled) |
| 839 | return NULL; |
| 840 | enabled = crtc; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | return enabled; |
| 845 | } |
| 846 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 847 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 848 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 849 | 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] | 850 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 851 | const struct cxsr_latency *latency; |
| 852 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 853 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 854 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 855 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
| 856 | dev_priv->is_ddr3, |
| 857 | dev_priv->fsb_freq, |
| 858 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 859 | if (!latency) { |
| 860 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 861 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 862 | return; |
| 863 | } |
| 864 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 865 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 866 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 867 | const struct drm_display_mode *adjusted_mode = |
| 868 | &crtc->config->base.adjusted_mode; |
| 869 | const struct drm_framebuffer *fb = |
| 870 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 871 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 872 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 873 | |
| 874 | /* Display SR */ |
| 875 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 876 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 877 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 878 | reg = I915_READ(DSPFW1); |
| 879 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 880 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 881 | I915_WRITE(DSPFW1, reg); |
| 882 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 883 | |
| 884 | /* cursor SR */ |
| 885 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 886 | pineview_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 887 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 888 | reg = I915_READ(DSPFW3); |
| 889 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 890 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 891 | I915_WRITE(DSPFW3, reg); |
| 892 | |
| 893 | /* Display HPLL off SR */ |
| 894 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 895 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 896 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 897 | reg = I915_READ(DSPFW3); |
| 898 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 899 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 900 | I915_WRITE(DSPFW3, reg); |
| 901 | |
| 902 | /* cursor HPLL off SR */ |
| 903 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 904 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 905 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 906 | reg = I915_READ(DSPFW3); |
| 907 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 908 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 909 | I915_WRITE(DSPFW3, reg); |
| 910 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 911 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 912 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 913 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 914 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 918 | /* |
| 919 | * Documentation says: |
| 920 | * "If the line size is small, the TLB fetches can get in the way of the |
| 921 | * data fetches, causing some lag in the pixel data return which is not |
| 922 | * accounted for in the above formulas. The following adjustment only |
| 923 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 924 | * The WM is adjusted upwards by the difference between the FIFO size |
| 925 | * and the size of 8 whole lines. This adjustment is always performed |
| 926 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 927 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 928 | 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] | 929 | { |
| 930 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 931 | |
| 932 | return max(0, tlb_miss); |
| 933 | } |
| 934 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 935 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 936 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 937 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 938 | enum pipe pipe; |
| 939 | |
| 940 | for_each_pipe(dev_priv, pipe) |
| 941 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 942 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 943 | I915_WRITE(DSPFW1, |
| 944 | FW_WM(wm->sr.plane, SR) | |
| 945 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 946 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 947 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 948 | I915_WRITE(DSPFW2, |
| 949 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 950 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 951 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 952 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 953 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 954 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 955 | I915_WRITE(DSPFW3, |
| 956 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 957 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 958 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 959 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 960 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 961 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 962 | } |
| 963 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 964 | #define FW_WM_VLV(value, plane) \ |
| 965 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 966 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 967 | 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] | 968 | const struct vlv_wm_values *wm) |
| 969 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 970 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 971 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 972 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 973 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 974 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 975 | I915_WRITE(VLV_DDL(pipe), |
| 976 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 977 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 978 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 979 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 980 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 981 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 982 | /* |
| 983 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 984 | * high order bits so that there are no out of bounds values |
| 985 | * present in the registers during the reprogramming. |
| 986 | */ |
| 987 | I915_WRITE(DSPHOWM, 0); |
| 988 | I915_WRITE(DSPHOWM1, 0); |
| 989 | I915_WRITE(DSPFW4, 0); |
| 990 | I915_WRITE(DSPFW5, 0); |
| 991 | I915_WRITE(DSPFW6, 0); |
| 992 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 993 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 994 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 995 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 996 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 997 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 998 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 999 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 1000 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1001 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1002 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1003 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1004 | |
| 1005 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1006 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1007 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1008 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1009 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1010 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 1011 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1012 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1013 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1014 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1015 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1016 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1017 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1018 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1019 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 1020 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1021 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1022 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1023 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1024 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1025 | 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] | 1026 | } else { |
| 1027 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1028 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1029 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1030 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1031 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1032 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1033 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1034 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1035 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1036 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1037 | 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] | 1038 | } |
| 1039 | |
| 1040 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1043 | #undef FW_WM_VLV |
| 1044 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1045 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1046 | { |
| 1047 | /* all latencies in usec */ |
| 1048 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1049 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1050 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1051 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1052 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1056 | { |
| 1057 | /* |
| 1058 | * DSPCNTR[13] supposedly controls whether the |
| 1059 | * primary plane can use the FIFO space otherwise |
| 1060 | * reserved for the sprite plane. It's not 100% clear |
| 1061 | * what the actual FIFO size is, but it looks like we |
| 1062 | * can happily set both primary and sprite watermarks |
| 1063 | * up to 127 cachelines. So that would seem to mean |
| 1064 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1065 | * the total FIFO is >= 256 cachelines in size. Either |
| 1066 | * way, we don't seem to have to worry about this |
| 1067 | * repartitioning as the maximum watermark value the |
| 1068 | * register can hold for each plane is lower than the |
| 1069 | * minimum FIFO size. |
| 1070 | */ |
| 1071 | switch (plane_id) { |
| 1072 | case PLANE_CURSOR: |
| 1073 | return 63; |
| 1074 | case PLANE_PRIMARY: |
| 1075 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1076 | case PLANE_SPRITE0: |
| 1077 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1078 | default: |
| 1079 | MISSING_CASE(plane_id); |
| 1080 | return 0; |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | static int g4x_fbc_fifo_size(int level) |
| 1085 | { |
| 1086 | switch (level) { |
| 1087 | case G4X_WM_LEVEL_SR: |
| 1088 | return 7; |
| 1089 | case G4X_WM_LEVEL_HPLL: |
| 1090 | return 15; |
| 1091 | default: |
| 1092 | MISSING_CASE(level); |
| 1093 | return 0; |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | static uint16_t g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1098 | const struct intel_plane_state *plane_state, |
| 1099 | int level) |
| 1100 | { |
| 1101 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1102 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 1103 | const struct drm_display_mode *adjusted_mode = |
| 1104 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1105 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1106 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1107 | |
| 1108 | if (latency == 0) |
| 1109 | return USHRT_MAX; |
| 1110 | |
| 1111 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1112 | return 0; |
| 1113 | |
| 1114 | /* |
| 1115 | * Not 100% sure which way ELK should go here as the |
| 1116 | * spec only says CL/CTG should assume 32bpp and BW |
| 1117 | * doesn't need to. But as these things followed the |
| 1118 | * mobile vs. desktop lines on gen3 as well, let's |
| 1119 | * assume ELK doesn't need this. |
| 1120 | * |
| 1121 | * The spec also fails to list such a restriction for |
| 1122 | * the HPLL watermark, which seems a little strange. |
| 1123 | * Let's use 32bpp for the HPLL watermark as well. |
| 1124 | */ |
| 1125 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1126 | level != G4X_WM_LEVEL_NORMAL) |
| 1127 | cpp = 4; |
| 1128 | else |
| 1129 | cpp = plane_state->base.fb->format->cpp[0]; |
| 1130 | |
| 1131 | clock = adjusted_mode->crtc_clock; |
| 1132 | htotal = adjusted_mode->crtc_htotal; |
| 1133 | |
| 1134 | if (plane->id == PLANE_CURSOR) |
| 1135 | width = plane_state->base.crtc_w; |
| 1136 | else |
| 1137 | width = drm_rect_width(&plane_state->base.dst); |
| 1138 | |
| 1139 | if (plane->id == PLANE_CURSOR) { |
| 1140 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1141 | } else if (plane->id == PLANE_PRIMARY && |
| 1142 | level == G4X_WM_LEVEL_NORMAL) { |
| 1143 | wm = intel_wm_method1(clock, cpp, latency); |
| 1144 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1145 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1146 | |
| 1147 | small = intel_wm_method1(clock, cpp, latency); |
| 1148 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1149 | |
| 1150 | wm = min(small, large); |
| 1151 | } |
| 1152 | |
| 1153 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1154 | width, cpp); |
| 1155 | |
| 1156 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1157 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1158 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1162 | int level, enum plane_id plane_id, u16 value) |
| 1163 | { |
| 1164 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1165 | bool dirty = false; |
| 1166 | |
| 1167 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1168 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1169 | |
| 1170 | dirty |= raw->plane[plane_id] != value; |
| 1171 | raw->plane[plane_id] = value; |
| 1172 | } |
| 1173 | |
| 1174 | return dirty; |
| 1175 | } |
| 1176 | |
| 1177 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1178 | int level, u16 value) |
| 1179 | { |
| 1180 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1181 | bool dirty = false; |
| 1182 | |
| 1183 | /* NORMAL level doesn't have an FBC watermark */ |
| 1184 | level = max(level, G4X_WM_LEVEL_SR); |
| 1185 | |
| 1186 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1187 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1188 | |
| 1189 | dirty |= raw->fbc != value; |
| 1190 | raw->fbc = value; |
| 1191 | } |
| 1192 | |
| 1193 | return dirty; |
| 1194 | } |
| 1195 | |
| 1196 | static uint32_t ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
| 1197 | const struct intel_plane_state *pstate, |
| 1198 | uint32_t pri_val); |
| 1199 | |
| 1200 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1201 | const struct intel_plane_state *plane_state) |
| 1202 | { |
| 1203 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1204 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1205 | enum plane_id plane_id = plane->id; |
| 1206 | bool dirty = false; |
| 1207 | int level; |
| 1208 | |
| 1209 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1210 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1211 | if (plane_id == PLANE_PRIMARY) |
| 1212 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1213 | goto out; |
| 1214 | } |
| 1215 | |
| 1216 | for (level = 0; level < num_levels; level++) { |
| 1217 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1218 | int wm, max_wm; |
| 1219 | |
| 1220 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1221 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1222 | |
| 1223 | if (wm > max_wm) |
| 1224 | break; |
| 1225 | |
| 1226 | dirty |= raw->plane[plane_id] != wm; |
| 1227 | raw->plane[plane_id] = wm; |
| 1228 | |
| 1229 | if (plane_id != PLANE_PRIMARY || |
| 1230 | level == G4X_WM_LEVEL_NORMAL) |
| 1231 | continue; |
| 1232 | |
| 1233 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1234 | raw->plane[plane_id]); |
| 1235 | max_wm = g4x_fbc_fifo_size(level); |
| 1236 | |
| 1237 | /* |
| 1238 | * FBC wm is not mandatory as we |
| 1239 | * can always just disable its use. |
| 1240 | */ |
| 1241 | if (wm > max_wm) |
| 1242 | wm = USHRT_MAX; |
| 1243 | |
| 1244 | dirty |= raw->fbc != wm; |
| 1245 | raw->fbc = wm; |
| 1246 | } |
| 1247 | |
| 1248 | /* mark watermarks as invalid */ |
| 1249 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1250 | |
| 1251 | if (plane_id == PLANE_PRIMARY) |
| 1252 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1253 | |
| 1254 | out: |
| 1255 | if (dirty) { |
| 1256 | DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1257 | plane->base.name, |
| 1258 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1259 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1260 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
| 1261 | |
| 1262 | if (plane_id == PLANE_PRIMARY) |
| 1263 | DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", |
| 1264 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1265 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
| 1266 | } |
| 1267 | |
| 1268 | return dirty; |
| 1269 | } |
| 1270 | |
| 1271 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1272 | enum plane_id plane_id, int level) |
| 1273 | { |
| 1274 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1275 | |
| 1276 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1277 | } |
| 1278 | |
| 1279 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1280 | int level) |
| 1281 | { |
| 1282 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1283 | |
| 1284 | if (level > dev_priv->wm.max_level) |
| 1285 | return false; |
| 1286 | |
| 1287 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1288 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1289 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1290 | } |
| 1291 | |
| 1292 | /* mark all levels starting from 'level' as invalid */ |
| 1293 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1294 | struct g4x_wm_state *wm_state, int level) |
| 1295 | { |
| 1296 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1297 | enum plane_id plane_id; |
| 1298 | |
| 1299 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1300 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1301 | } |
| 1302 | |
| 1303 | if (level <= G4X_WM_LEVEL_SR) { |
| 1304 | wm_state->cxsr = false; |
| 1305 | wm_state->sr.cursor = USHRT_MAX; |
| 1306 | wm_state->sr.plane = USHRT_MAX; |
| 1307 | wm_state->sr.fbc = USHRT_MAX; |
| 1308 | } |
| 1309 | |
| 1310 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1311 | wm_state->hpll_en = false; |
| 1312 | wm_state->hpll.cursor = USHRT_MAX; |
| 1313 | wm_state->hpll.plane = USHRT_MAX; |
| 1314 | wm_state->hpll.fbc = USHRT_MAX; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1319 | { |
| 1320 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1321 | struct intel_atomic_state *state = |
| 1322 | to_intel_atomic_state(crtc_state->base.state); |
| 1323 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 1324 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1325 | ~BIT(PLANE_CURSOR)); |
| 1326 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1327 | const struct intel_plane_state *old_plane_state; |
| 1328 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1329 | struct intel_plane *plane; |
| 1330 | enum plane_id plane_id; |
| 1331 | int i, level; |
| 1332 | unsigned int dirty = 0; |
| 1333 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1334 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1335 | old_plane_state, |
| 1336 | new_plane_state, i) { |
| 1337 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1338 | old_plane_state->base.crtc != &crtc->base) |
| 1339 | continue; |
| 1340 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1341 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1342 | dirty |= BIT(plane->id); |
| 1343 | } |
| 1344 | |
| 1345 | if (!dirty) |
| 1346 | return 0; |
| 1347 | |
| 1348 | level = G4X_WM_LEVEL_NORMAL; |
| 1349 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1350 | goto out; |
| 1351 | |
| 1352 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1353 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1354 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1355 | |
| 1356 | level = G4X_WM_LEVEL_SR; |
| 1357 | |
| 1358 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1359 | goto out; |
| 1360 | |
| 1361 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1362 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1363 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1364 | wm_state->sr.fbc = raw->fbc; |
| 1365 | |
| 1366 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1367 | |
| 1368 | level = G4X_WM_LEVEL_HPLL; |
| 1369 | |
| 1370 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1371 | goto out; |
| 1372 | |
| 1373 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1374 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1375 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1376 | wm_state->hpll.fbc = raw->fbc; |
| 1377 | |
| 1378 | wm_state->hpll_en = wm_state->cxsr; |
| 1379 | |
| 1380 | level++; |
| 1381 | |
| 1382 | out: |
| 1383 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1384 | return -EINVAL; |
| 1385 | |
| 1386 | /* invalidate the higher levels */ |
| 1387 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1388 | |
| 1389 | /* |
| 1390 | * Determine if the FBC watermark(s) can be used. IF |
| 1391 | * this isn't the case we prefer to disable the FBC |
| 1392 | ( watermark(s) rather than disable the SR/HPLL |
| 1393 | * level(s) entirely. |
| 1394 | */ |
| 1395 | wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL; |
| 1396 | |
| 1397 | if (level >= G4X_WM_LEVEL_SR && |
| 1398 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1399 | wm_state->fbc_en = false; |
| 1400 | else if (level >= G4X_WM_LEVEL_HPLL && |
| 1401 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1402 | wm_state->fbc_en = false; |
| 1403 | |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | static int g4x_compute_intermediate_wm(struct drm_device *dev, |
| 1408 | struct intel_crtc *crtc, |
| 1409 | struct intel_crtc_state *crtc_state) |
| 1410 | { |
| 1411 | struct g4x_wm_state *intermediate = &crtc_state->wm.g4x.intermediate; |
| 1412 | const struct g4x_wm_state *optimal = &crtc_state->wm.g4x.optimal; |
| 1413 | const struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 1414 | enum plane_id plane_id; |
| 1415 | |
| 1416 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
| 1417 | !crtc_state->disable_cxsr; |
| 1418 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
| 1419 | !crtc_state->disable_cxsr; |
| 1420 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1421 | |
| 1422 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1423 | intermediate->wm.plane[plane_id] = |
| 1424 | max(optimal->wm.plane[plane_id], |
| 1425 | active->wm.plane[plane_id]); |
| 1426 | |
| 1427 | WARN_ON(intermediate->wm.plane[plane_id] > |
| 1428 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
| 1429 | } |
| 1430 | |
| 1431 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1432 | active->sr.plane); |
| 1433 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1434 | active->sr.cursor); |
| 1435 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1436 | active->sr.fbc); |
| 1437 | |
| 1438 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1439 | active->hpll.plane); |
| 1440 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1441 | active->hpll.cursor); |
| 1442 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1443 | active->hpll.fbc); |
| 1444 | |
| 1445 | WARN_ON((intermediate->sr.plane > |
| 1446 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1447 | intermediate->sr.cursor > |
| 1448 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1449 | intermediate->cxsr); |
| 1450 | WARN_ON((intermediate->sr.plane > |
| 1451 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1452 | intermediate->sr.cursor > |
| 1453 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1454 | intermediate->hpll_en); |
| 1455 | |
| 1456 | WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1457 | intermediate->fbc_en && intermediate->cxsr); |
| 1458 | WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1459 | intermediate->fbc_en && intermediate->hpll_en); |
| 1460 | |
| 1461 | /* |
| 1462 | * If our intermediate WM are identical to the final WM, then we can |
| 1463 | * omit the post-vblank programming; only update if it's different. |
| 1464 | */ |
| 1465 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
| 1466 | crtc_state->wm.need_postvbl_update = true; |
| 1467 | |
| 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1472 | struct g4x_wm_values *wm) |
| 1473 | { |
| 1474 | struct intel_crtc *crtc; |
| 1475 | int num_active_crtcs = 0; |
| 1476 | |
| 1477 | wm->cxsr = true; |
| 1478 | wm->hpll_en = true; |
| 1479 | wm->fbc_en = true; |
| 1480 | |
| 1481 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1482 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1483 | |
| 1484 | if (!crtc->active) |
| 1485 | continue; |
| 1486 | |
| 1487 | if (!wm_state->cxsr) |
| 1488 | wm->cxsr = false; |
| 1489 | if (!wm_state->hpll_en) |
| 1490 | wm->hpll_en = false; |
| 1491 | if (!wm_state->fbc_en) |
| 1492 | wm->fbc_en = false; |
| 1493 | |
| 1494 | num_active_crtcs++; |
| 1495 | } |
| 1496 | |
| 1497 | if (num_active_crtcs != 1) { |
| 1498 | wm->cxsr = false; |
| 1499 | wm->hpll_en = false; |
| 1500 | wm->fbc_en = false; |
| 1501 | } |
| 1502 | |
| 1503 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1504 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1505 | enum pipe pipe = crtc->pipe; |
| 1506 | |
| 1507 | wm->pipe[pipe] = wm_state->wm; |
| 1508 | if (crtc->active && wm->cxsr) |
| 1509 | wm->sr = wm_state->sr; |
| 1510 | if (crtc->active && wm->hpll_en) |
| 1511 | wm->hpll = wm_state->hpll; |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1516 | { |
| 1517 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1518 | struct g4x_wm_values new_wm = {}; |
| 1519 | |
| 1520 | g4x_merge_wm(dev_priv, &new_wm); |
| 1521 | |
| 1522 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1523 | return; |
| 1524 | |
| 1525 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1526 | _intel_set_memory_cxsr(dev_priv, false); |
| 1527 | |
| 1528 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1529 | |
| 1530 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1531 | _intel_set_memory_cxsr(dev_priv, true); |
| 1532 | |
| 1533 | *old_wm = new_wm; |
| 1534 | } |
| 1535 | |
| 1536 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
| 1537 | struct intel_crtc_state *crtc_state) |
| 1538 | { |
| 1539 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1540 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1541 | |
| 1542 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1543 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1544 | g4x_program_watermarks(dev_priv); |
| 1545 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1546 | } |
| 1547 | |
| 1548 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
| 1549 | struct intel_crtc_state *crtc_state) |
| 1550 | { |
| 1551 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1552 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1553 | |
| 1554 | if (!crtc_state->wm.need_postvbl_update) |
| 1555 | return; |
| 1556 | |
| 1557 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1558 | intel_crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 1559 | g4x_program_watermarks(dev_priv); |
| 1560 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1561 | } |
| 1562 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1563 | /* latency must be in 0.1us units. */ |
| 1564 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1565 | unsigned int htotal, |
| 1566 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1567 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1568 | unsigned int latency) |
| 1569 | { |
| 1570 | unsigned int ret; |
| 1571 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1572 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1573 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1574 | ret = DIV_ROUND_UP(ret, 64); |
| 1575 | |
| 1576 | return ret; |
| 1577 | } |
| 1578 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1579 | 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] | 1580 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1581 | /* all latencies in usec */ |
| 1582 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1583 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1584 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1585 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1586 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1587 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1588 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1589 | |
| 1590 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1591 | } |
| 1592 | } |
| 1593 | |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1594 | static uint16_t vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1595 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1596 | int level) |
| 1597 | { |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1598 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1599 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1600 | const struct drm_display_mode *adjusted_mode = |
| 1601 | &crtc_state->base.adjusted_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1602 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1603 | |
| 1604 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1605 | return USHRT_MAX; |
| 1606 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1607 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1608 | return 0; |
| 1609 | |
Daniel Vetter | ef426c1 | 2017-01-04 11:41:10 +0100 | [diff] [blame] | 1610 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1611 | clock = adjusted_mode->crtc_clock; |
| 1612 | htotal = adjusted_mode->crtc_htotal; |
| 1613 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1614 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1615 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1616 | /* |
| 1617 | * FIXME the formula gives values that are |
| 1618 | * too big for the cursor FIFO, and hence we |
| 1619 | * would never be able to use cursors. For |
| 1620 | * now just hardcode the watermark. |
| 1621 | */ |
| 1622 | wm = 63; |
| 1623 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1624 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1625 | dev_priv->wm.pri_latency[level] * 10); |
| 1626 | } |
| 1627 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1628 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1629 | } |
| 1630 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1631 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1632 | { |
| 1633 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1634 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1635 | } |
| 1636 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1637 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1638 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1639 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1640 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1641 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1642 | 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] | 1643 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1644 | int num_active_planes = hweight32(active_planes); |
| 1645 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1646 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1647 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1648 | unsigned int total_rate; |
| 1649 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1650 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1651 | /* |
| 1652 | * When enabling sprite0 after sprite1 has already been enabled |
| 1653 | * we tend to get an underrun unless sprite0 already has some |
| 1654 | * FIFO space allcoated. Hence we always allocate at least one |
| 1655 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1656 | * |
| 1657 | * All other plane enable sequences appear immune to this problem. |
| 1658 | */ |
| 1659 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1660 | sprite0_fifo_extra = 1; |
| 1661 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1662 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1663 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1664 | raw->plane[PLANE_SPRITE1] + |
| 1665 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1666 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1667 | if (total_rate > fifo_size) |
| 1668 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1669 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1670 | if (total_rate == 0) |
| 1671 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1672 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1673 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1674 | unsigned int rate; |
| 1675 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1676 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1677 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1678 | continue; |
| 1679 | } |
| 1680 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1681 | rate = raw->plane[plane_id]; |
| 1682 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1683 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1684 | } |
| 1685 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1686 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1687 | fifo_left -= sprite0_fifo_extra; |
| 1688 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1689 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1690 | |
| 1691 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1692 | |
| 1693 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1694 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1695 | int plane_extra; |
| 1696 | |
| 1697 | if (fifo_left == 0) |
| 1698 | break; |
| 1699 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1700 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1701 | continue; |
| 1702 | |
| 1703 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1704 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1705 | fifo_left -= plane_extra; |
| 1706 | } |
| 1707 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1708 | WARN_ON(active_planes != 0 && fifo_left != 0); |
| 1709 | |
| 1710 | /* give it all to the first plane if none are active */ |
| 1711 | if (active_planes == 0) { |
| 1712 | WARN_ON(fifo_left != fifo_size); |
| 1713 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1714 | } |
| 1715 | |
| 1716 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1717 | } |
| 1718 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1719 | /* mark all levels starting from 'level' as invalid */ |
| 1720 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1721 | struct vlv_wm_state *wm_state, int level) |
| 1722 | { |
| 1723 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1724 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1725 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1726 | enum plane_id plane_id; |
| 1727 | |
| 1728 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1729 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1730 | |
| 1731 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1732 | wm_state->sr[level].plane = USHRT_MAX; |
| 1733 | } |
| 1734 | } |
| 1735 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1736 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1737 | { |
| 1738 | if (wm > fifo_size) |
| 1739 | return USHRT_MAX; |
| 1740 | else |
| 1741 | return fifo_size - wm; |
| 1742 | } |
| 1743 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1744 | /* |
| 1745 | * Starting from 'level' set all higher |
| 1746 | * levels to 'value' in the "raw" watermarks. |
| 1747 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1748 | 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] | 1749 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1750 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1751 | 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] | 1752 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1753 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1754 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1755 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1756 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1757 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1758 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1759 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1760 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1761 | |
| 1762 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1763 | } |
| 1764 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1765 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1766 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1767 | { |
| 1768 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1769 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1770 | 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] | 1771 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1772 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1773 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1774 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1775 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1776 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1780 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1781 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1782 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1783 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1784 | if (wm > max_wm) |
| 1785 | break; |
| 1786 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1787 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1788 | raw->plane[plane_id] = wm; |
| 1789 | } |
| 1790 | |
| 1791 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1792 | 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] | 1793 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1794 | out: |
| 1795 | if (dirty) |
Ville Syrjälä | 57a6528 | 2017-04-21 21:14:22 +0300 | [diff] [blame] | 1796 | 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] | 1797 | plane->base.name, |
| 1798 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1799 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1800 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
| 1801 | |
| 1802 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1803 | } |
| 1804 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1805 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1806 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1807 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1808 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1809 | &crtc_state->wm.vlv.raw[level]; |
| 1810 | const struct vlv_fifo_state *fifo_state = |
| 1811 | &crtc_state->wm.vlv.fifo_state; |
| 1812 | |
| 1813 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1814 | } |
| 1815 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1816 | 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] | 1817 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1818 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1819 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1820 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1821 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | 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] | 1825 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1826 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1827 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1828 | struct intel_atomic_state *state = |
| 1829 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1830 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1831 | const struct vlv_fifo_state *fifo_state = |
| 1832 | &crtc_state->wm.vlv.fifo_state; |
| 1833 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1834 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1835 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->base); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1836 | const struct intel_plane_state *old_plane_state; |
| 1837 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1838 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1839 | enum plane_id plane_id; |
| 1840 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1841 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1842 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1843 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1844 | old_plane_state, |
| 1845 | new_plane_state, i) { |
| 1846 | if (new_plane_state->base.crtc != &crtc->base && |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1847 | old_plane_state->base.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1848 | continue; |
| 1849 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1850 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1851 | dirty |= BIT(plane->id); |
| 1852 | } |
| 1853 | |
| 1854 | /* |
| 1855 | * DSPARB registers may have been reset due to the |
| 1856 | * power well being turned off. Make sure we restore |
| 1857 | * them to a consistent state even if no primary/sprite |
| 1858 | * planes are initially active. |
| 1859 | */ |
| 1860 | if (needs_modeset) |
| 1861 | crtc_state->fifo_changed = true; |
| 1862 | |
| 1863 | if (!dirty) |
| 1864 | return 0; |
| 1865 | |
| 1866 | /* cursor changes don't warrant a FIFO recompute */ |
| 1867 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1868 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1869 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1870 | const struct vlv_fifo_state *old_fifo_state = |
| 1871 | &old_crtc_state->wm.vlv.fifo_state; |
| 1872 | |
| 1873 | ret = vlv_compute_fifo(crtc_state); |
| 1874 | if (ret) |
| 1875 | return ret; |
| 1876 | |
| 1877 | if (needs_modeset || |
| 1878 | memcmp(old_fifo_state, fifo_state, |
| 1879 | sizeof(*fifo_state)) != 0) |
| 1880 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1881 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1882 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1883 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1884 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1885 | /* |
| 1886 | * Note that enabling cxsr with no primary/sprite planes |
| 1887 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1888 | * with exactly one enabled primary/sprite plane. |
| 1889 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1890 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1891 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1892 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1893 | 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] | 1894 | 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] | 1895 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1896 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1897 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1898 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1899 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1900 | wm_state->wm[level].plane[plane_id] = |
| 1901 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1902 | fifo_state->plane[plane_id]); |
| 1903 | } |
| 1904 | |
| 1905 | wm_state->sr[level].plane = |
| 1906 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1907 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1908 | raw->plane[PLANE_SPRITE1]), |
| 1909 | sr_fifo_size); |
| 1910 | |
| 1911 | wm_state->sr[level].cursor = |
| 1912 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1913 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1914 | } |
| 1915 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1916 | if (level == 0) |
| 1917 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1918 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1919 | /* limit to only levels we can actually handle */ |
| 1920 | wm_state->num_levels = level; |
| 1921 | |
| 1922 | /* invalidate the higher levels */ |
| 1923 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1924 | |
| 1925 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1926 | } |
| 1927 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1928 | #define VLV_FIFO(plane, value) \ |
| 1929 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1930 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1931 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
| 1932 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1933 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1934 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1935 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1936 | const struct vlv_fifo_state *fifo_state = |
| 1937 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1938 | int sprite0_start, sprite1_start, fifo_size; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1939 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1940 | if (!crtc_state->fifo_changed) |
| 1941 | return; |
| 1942 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1943 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 1944 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 1945 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1946 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1947 | WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63); |
| 1948 | WARN_ON(fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1949 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1950 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 1951 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1952 | /* |
| 1953 | * uncore.lock serves a double purpose here. It allows us to |
| 1954 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 1955 | * it protects the DSPARB registers from getting clobbered by |
| 1956 | * parallel updates from multiple pipes. |
| 1957 | * |
| 1958 | * intel_pipe_update_start() has already disabled interrupts |
| 1959 | * for us, so a plain spin_lock() is sufficient here. |
| 1960 | */ |
| 1961 | spin_lock(&dev_priv->uncore.lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1962 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1963 | switch (crtc->pipe) { |
| 1964 | uint32_t dsparb, dsparb2, dsparb3; |
| 1965 | case PIPE_A: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1966 | dsparb = I915_READ_FW(DSPARB); |
| 1967 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1968 | |
| 1969 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1970 | VLV_FIFO(SPRITEB, 0xff)); |
| 1971 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1972 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1973 | |
| 1974 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1975 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1976 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1977 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1978 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1979 | I915_WRITE_FW(DSPARB, dsparb); |
| 1980 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1981 | break; |
| 1982 | case PIPE_B: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1983 | dsparb = I915_READ_FW(DSPARB); |
| 1984 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1985 | |
| 1986 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 1987 | VLV_FIFO(SPRITED, 0xff)); |
| 1988 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 1989 | VLV_FIFO(SPRITED, sprite1_start)); |
| 1990 | |
| 1991 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 1992 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 1993 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 1994 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 1995 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1996 | I915_WRITE_FW(DSPARB, dsparb); |
| 1997 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1998 | break; |
| 1999 | case PIPE_C: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2000 | dsparb3 = I915_READ_FW(DSPARB3); |
| 2001 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2002 | |
| 2003 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2004 | VLV_FIFO(SPRITEF, 0xff)); |
| 2005 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2006 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2007 | |
| 2008 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2009 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2010 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2011 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2012 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2013 | I915_WRITE_FW(DSPARB3, dsparb3); |
| 2014 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2015 | break; |
| 2016 | default: |
| 2017 | break; |
| 2018 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2019 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2020 | POSTING_READ_FW(DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2021 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2022 | spin_unlock(&dev_priv->uncore.lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | #undef VLV_FIFO |
| 2026 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2027 | static int vlv_compute_intermediate_wm(struct drm_device *dev, |
| 2028 | struct intel_crtc *crtc, |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame^] | 2029 | struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2030 | { |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame^] | 2031 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2032 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
| 2033 | struct intel_atomic_state *intel_state = |
| 2034 | to_intel_atomic_state(new_crtc_state->base.state); |
| 2035 | const struct intel_crtc_state *old_crtc_state = |
| 2036 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 2037 | 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] | 2038 | int level; |
| 2039 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame^] | 2040 | if (!new_crtc_state->base.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->base)) { |
| 2041 | *intermediate = *optimal; |
| 2042 | |
| 2043 | intermediate->cxsr = false; |
| 2044 | goto out; |
| 2045 | } |
| 2046 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2047 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2048 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame^] | 2049 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2050 | |
| 2051 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2052 | enum plane_id plane_id; |
| 2053 | |
| 2054 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2055 | intermediate->wm[level].plane[plane_id] = |
| 2056 | min(optimal->wm[level].plane[plane_id], |
| 2057 | active->wm[level].plane[plane_id]); |
| 2058 | } |
| 2059 | |
| 2060 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2061 | active->sr[level].plane); |
| 2062 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2063 | active->sr[level].cursor); |
| 2064 | } |
| 2065 | |
| 2066 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2067 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame^] | 2068 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2069 | /* |
| 2070 | * If our intermediate WM are identical to the final WM, then we can |
| 2071 | * omit the post-vblank programming; only update if it's different. |
| 2072 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2073 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame^] | 2074 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2075 | |
| 2076 | return 0; |
| 2077 | } |
| 2078 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2079 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2080 | struct vlv_wm_values *wm) |
| 2081 | { |
| 2082 | struct intel_crtc *crtc; |
| 2083 | int num_active_crtcs = 0; |
| 2084 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2085 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2086 | wm->cxsr = true; |
| 2087 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2088 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2089 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2090 | |
| 2091 | if (!crtc->active) |
| 2092 | continue; |
| 2093 | |
| 2094 | if (!wm_state->cxsr) |
| 2095 | wm->cxsr = false; |
| 2096 | |
| 2097 | num_active_crtcs++; |
| 2098 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2099 | } |
| 2100 | |
| 2101 | if (num_active_crtcs != 1) |
| 2102 | wm->cxsr = false; |
| 2103 | |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2104 | if (num_active_crtcs > 1) |
| 2105 | wm->level = VLV_WM_LEVEL_PM2; |
| 2106 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2107 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2108 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2109 | enum pipe pipe = crtc->pipe; |
| 2110 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2111 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2112 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2113 | wm->sr = wm_state->sr[wm->level]; |
| 2114 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2115 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2116 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2117 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2118 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2122 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2123 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2124 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2125 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2126 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2127 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2128 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2129 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2130 | return; |
| 2131 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2132 | 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] | 2133 | chv_set_memory_dvfs(dev_priv, false); |
| 2134 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2135 | 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] | 2136 | chv_set_memory_pm5(dev_priv, false); |
| 2137 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2138 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2139 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2140 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2141 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2142 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2143 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2144 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2145 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2146 | 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] | 2147 | chv_set_memory_pm5(dev_priv, true); |
| 2148 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2149 | 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] | 2150 | chv_set_memory_dvfs(dev_priv, true); |
| 2151 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2152 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2153 | } |
| 2154 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2155 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
| 2156 | struct intel_crtc_state *crtc_state) |
| 2157 | { |
| 2158 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2159 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2160 | |
| 2161 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2162 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2163 | vlv_program_watermarks(dev_priv); |
| 2164 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2165 | } |
| 2166 | |
| 2167 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
| 2168 | struct intel_crtc_state *crtc_state) |
| 2169 | { |
| 2170 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2171 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2172 | |
| 2173 | if (!crtc_state->wm.need_postvbl_update) |
| 2174 | return; |
| 2175 | |
| 2176 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 2177 | intel_crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2178 | vlv_program_watermarks(dev_priv); |
| 2179 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2180 | } |
| 2181 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2182 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2183 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2184 | 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] | 2185 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2186 | int srwm = 1; |
| 2187 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2188 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2189 | |
| 2190 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2191 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2192 | if (crtc) { |
| 2193 | /* self-refresh has much higher latency */ |
| 2194 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2195 | const struct drm_display_mode *adjusted_mode = |
| 2196 | &crtc->config->base.adjusted_mode; |
| 2197 | const struct drm_framebuffer *fb = |
| 2198 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2199 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2200 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2201 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2202 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2203 | int entries; |
| 2204 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2205 | entries = intel_wm_method2(clock, htotal, |
| 2206 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2207 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2208 | srwm = I965_FIFO_SIZE - entries; |
| 2209 | if (srwm < 0) |
| 2210 | srwm = 1; |
| 2211 | srwm &= 0x1ff; |
| 2212 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 2213 | entries, srwm); |
| 2214 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2215 | entries = intel_wm_method2(clock, htotal, |
| 2216 | crtc->base.cursor->state->crtc_w, 4, |
| 2217 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2218 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2219 | i965_cursor_wm_info.cacheline_size) + |
| 2220 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2221 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2222 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2223 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2224 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2225 | |
| 2226 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 2227 | "cursor %d\n", srwm, cursor_sr); |
| 2228 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2229 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2230 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2231 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2232 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2233 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2237 | srwm); |
| 2238 | |
| 2239 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2240 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2241 | FW_WM(8, CURSORB) | |
| 2242 | FW_WM(8, PLANEB) | |
| 2243 | FW_WM(8, PLANEA)); |
| 2244 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2245 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2246 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2247 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2248 | |
| 2249 | if (cxsr_enabled) |
| 2250 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2251 | } |
| 2252 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2253 | #undef FW_WM |
| 2254 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2255 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2256 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2257 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2258 | const struct intel_watermark_params *wm_info; |
| 2259 | uint32_t fwater_lo; |
| 2260 | uint32_t fwater_hi; |
| 2261 | int cwm, srwm = 1; |
| 2262 | int fifo_size; |
| 2263 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2264 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2265 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2266 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2267 | wm_info = &i945_wm_info; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2268 | else if (!IS_GEN2(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2269 | wm_info = &i915_wm_info; |
| 2270 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2271 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2272 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2273 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, 0); |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 2274 | crtc = intel_get_crtc_for_plane(dev_priv, 0); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2275 | if (intel_crtc_active(crtc)) { |
| 2276 | const struct drm_display_mode *adjusted_mode = |
| 2277 | &crtc->config->base.adjusted_mode; |
| 2278 | const struct drm_framebuffer *fb = |
| 2279 | crtc->base.primary->state->fb; |
| 2280 | int cpp; |
| 2281 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2282 | if (IS_GEN2(dev_priv)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2283 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2284 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2285 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2286 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2287 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2288 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2289 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2290 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2291 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2292 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2293 | if (planea_wm > (long)wm_info->max_wm) |
| 2294 | planea_wm = wm_info->max_wm; |
| 2295 | } |
| 2296 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2297 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2298 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2299 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2300 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, 1); |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 2301 | crtc = intel_get_crtc_for_plane(dev_priv, 1); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2302 | if (intel_crtc_active(crtc)) { |
| 2303 | const struct drm_display_mode *adjusted_mode = |
| 2304 | &crtc->config->base.adjusted_mode; |
| 2305 | const struct drm_framebuffer *fb = |
| 2306 | crtc->base.primary->state->fb; |
| 2307 | int cpp; |
| 2308 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2309 | if (IS_GEN2(dev_priv)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2310 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2311 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2312 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2313 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2314 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2315 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2316 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2317 | if (enabled == NULL) |
| 2318 | enabled = crtc; |
| 2319 | else |
| 2320 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2321 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2322 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2323 | if (planeb_wm > (long)wm_info->max_wm) |
| 2324 | planeb_wm = wm_info->max_wm; |
| 2325 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2326 | |
| 2327 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2328 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2329 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2330 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2331 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2332 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2333 | |
| 2334 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2335 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2336 | enabled = NULL; |
| 2337 | } |
| 2338 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2339 | /* |
| 2340 | * Overlay gets an aggressive default since video jitter is bad. |
| 2341 | */ |
| 2342 | cwm = 2; |
| 2343 | |
| 2344 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2345 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2346 | |
| 2347 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2348 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2349 | /* self-refresh has much higher latency */ |
| 2350 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2351 | const struct drm_display_mode *adjusted_mode = |
| 2352 | &enabled->config->base.adjusted_mode; |
| 2353 | const struct drm_framebuffer *fb = |
| 2354 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2355 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2356 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2357 | int hdisplay = enabled->config->pipe_src_w; |
| 2358 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2359 | int entries; |
| 2360 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2361 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2362 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2363 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2364 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2365 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2366 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2367 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2368 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 2369 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 2370 | srwm = wm_info->fifo_size - entries; |
| 2371 | if (srwm < 0) |
| 2372 | srwm = 1; |
| 2373 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2374 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2375 | I915_WRITE(FW_BLC_SELF, |
| 2376 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2377 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2378 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2379 | } |
| 2380 | |
| 2381 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2382 | planea_wm, planeb_wm, cwm, srwm); |
| 2383 | |
| 2384 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2385 | fwater_hi = (cwm & 0x1f); |
| 2386 | |
| 2387 | /* Set request length to 8 cachelines per fetch */ |
| 2388 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2389 | fwater_hi = fwater_hi | (1 << 8); |
| 2390 | |
| 2391 | I915_WRITE(FW_BLC, fwater_lo); |
| 2392 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2393 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2394 | if (enabled) |
| 2395 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2396 | } |
| 2397 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2398 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2399 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2400 | 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] | 2401 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2402 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2403 | uint32_t fwater_lo; |
| 2404 | int planea_wm; |
| 2405 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2406 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2407 | if (crtc == NULL) |
| 2408 | return; |
| 2409 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2410 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2411 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2412 | &i845_wm_info, |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2413 | dev_priv->display.get_fifo_size(dev_priv, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2414 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2415 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2416 | fwater_lo |= (3<<8) | planea_wm; |
| 2417 | |
| 2418 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 2419 | |
| 2420 | I915_WRITE(FW_BLC, fwater_lo); |
| 2421 | } |
| 2422 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2423 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2424 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2425 | unsigned int cpp, |
| 2426 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2427 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2428 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2429 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2430 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2431 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2432 | |
| 2433 | return ret; |
| 2434 | } |
| 2435 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2436 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2437 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2438 | unsigned int htotal, |
| 2439 | unsigned int width, |
| 2440 | unsigned int cpp, |
| 2441 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2442 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2443 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2444 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2445 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2446 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2447 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2448 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2449 | return ret; |
| 2450 | } |
| 2451 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2452 | static uint32_t ilk_wm_fbc(uint32_t pri_val, uint32_t horiz_pixels, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2453 | uint8_t cpp) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2454 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2455 | /* |
| 2456 | * Neither of these should be possible since this function shouldn't be |
| 2457 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2458 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2459 | * elsewhere in the driver. |
| 2460 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2461 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2462 | return 0; |
| 2463 | if (WARN_ON(!horiz_pixels)) |
| 2464 | return 0; |
| 2465 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2466 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2467 | } |
| 2468 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2469 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2470 | uint16_t pri; |
| 2471 | uint16_t spr; |
| 2472 | uint16_t cur; |
| 2473 | uint16_t fbc; |
| 2474 | }; |
| 2475 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2476 | /* |
| 2477 | * For both WM_PIPE and WM_LP. |
| 2478 | * mem_value must be in 0.1us units. |
| 2479 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2480 | static uint32_t ilk_compute_pri_wm(const struct intel_crtc_state *cstate, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2481 | const struct intel_plane_state *pstate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2482 | uint32_t mem_value, |
| 2483 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2484 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2485 | uint32_t method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2486 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2487 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2488 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2489 | return 0; |
| 2490 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2491 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2492 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2493 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2494 | |
| 2495 | if (!is_lp) |
| 2496 | return method1; |
| 2497 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2498 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2499 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2500 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2501 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2502 | |
| 2503 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2504 | } |
| 2505 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2506 | /* |
| 2507 | * For both WM_PIPE and WM_LP. |
| 2508 | * mem_value must be in 0.1us units. |
| 2509 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2510 | static uint32_t ilk_compute_spr_wm(const struct intel_crtc_state *cstate, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2511 | const struct intel_plane_state *pstate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2512 | uint32_t mem_value) |
| 2513 | { |
| 2514 | uint32_t method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2515 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2516 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2517 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2518 | return 0; |
| 2519 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2520 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2521 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2522 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
| 2523 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2524 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2525 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2526 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2527 | return min(method1, method2); |
| 2528 | } |
| 2529 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2530 | /* |
| 2531 | * For both WM_PIPE and WM_LP. |
| 2532 | * mem_value must be in 0.1us units. |
| 2533 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2534 | static uint32_t ilk_compute_cur_wm(const struct intel_crtc_state *cstate, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2535 | const struct intel_plane_state *pstate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2536 | uint32_t mem_value) |
| 2537 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2538 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2539 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2540 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2541 | return 0; |
| 2542 | |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2543 | cpp = pstate->base.fb->format->cpp[0]; |
| 2544 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2545 | return ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2546 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2547 | pstate->base.crtc_w, cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2548 | } |
| 2549 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2550 | /* Only for WM_LP. */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2551 | static uint32_t ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2552 | const struct intel_plane_state *pstate, |
Ville Syrjälä | 1fda988 | 2013-07-05 11:57:19 +0300 | [diff] [blame] | 2553 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2554 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2555 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2556 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2557 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2558 | return 0; |
| 2559 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2560 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2561 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2562 | 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] | 2563 | } |
| 2564 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2565 | static unsigned int |
| 2566 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2567 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2568 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2569 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2570 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2571 | return 768; |
| 2572 | else |
| 2573 | return 512; |
| 2574 | } |
| 2575 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2576 | static unsigned int |
| 2577 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2578 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2579 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2580 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2581 | /* BDW primary/sprite plane watermarks */ |
| 2582 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2583 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2584 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2585 | return level == 0 ? 127 : 1023; |
| 2586 | else if (!is_sprite) |
| 2587 | /* ILK/SNB primary plane watermarks */ |
| 2588 | return level == 0 ? 127 : 511; |
| 2589 | else |
| 2590 | /* ILK/SNB sprite plane watermarks */ |
| 2591 | return level == 0 ? 63 : 255; |
| 2592 | } |
| 2593 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2594 | static unsigned int |
| 2595 | 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] | 2596 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2597 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2598 | return level == 0 ? 63 : 255; |
| 2599 | else |
| 2600 | return level == 0 ? 31 : 63; |
| 2601 | } |
| 2602 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2603 | 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] | 2604 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2605 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2606 | return 31; |
| 2607 | else |
| 2608 | return 15; |
| 2609 | } |
| 2610 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2611 | /* Calculate the maximum primary/sprite plane watermark */ |
| 2612 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 2613 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2614 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2615 | enum intel_ddb_partitioning ddb_partitioning, |
| 2616 | bool is_sprite) |
| 2617 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2618 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 2619 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2620 | |
| 2621 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2622 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2623 | return 0; |
| 2624 | |
| 2625 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2626 | if (level == 0 || config->num_pipes_active > 1) { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2627 | fifo_size /= INTEL_INFO(dev_priv)->num_pipes; |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2628 | |
| 2629 | /* |
| 2630 | * For some reason the non self refresh |
| 2631 | * FIFO size is only half of the self |
| 2632 | * refresh FIFO size on ILK/SNB. |
| 2633 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2634 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2635 | fifo_size /= 2; |
| 2636 | } |
| 2637 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2638 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2639 | /* level 0 is always calculated with 1:1 split */ |
| 2640 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2641 | if (is_sprite) |
| 2642 | fifo_size *= 5; |
| 2643 | fifo_size /= 6; |
| 2644 | } else { |
| 2645 | fifo_size /= 2; |
| 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2650 | 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] | 2651 | } |
| 2652 | |
| 2653 | /* Calculate the maximum cursor plane watermark */ |
| 2654 | static unsigned int ilk_cursor_wm_max(const struct drm_device *dev, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2655 | int level, |
| 2656 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2657 | { |
| 2658 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2659 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2660 | return 64; |
| 2661 | |
| 2662 | /* otherwise just report max that registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2663 | return ilk_cursor_wm_reg_max(to_i915(dev), level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2664 | } |
| 2665 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2666 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2667 | int level, |
| 2668 | const struct intel_wm_config *config, |
| 2669 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2670 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2671 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2672 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 2673 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 2674 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2675 | max->fbc = ilk_fbc_wm_reg_max(to_i915(dev)); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2676 | } |
| 2677 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2678 | 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] | 2679 | int level, |
| 2680 | struct ilk_wm_maximums *max) |
| 2681 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2682 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2683 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2684 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2685 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2686 | } |
| 2687 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2688 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2689 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2690 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2691 | { |
| 2692 | bool ret; |
| 2693 | |
| 2694 | /* already determined to be invalid? */ |
| 2695 | if (!result->enable) |
| 2696 | return false; |
| 2697 | |
| 2698 | result->enable = result->pri_val <= max->pri && |
| 2699 | result->spr_val <= max->spr && |
| 2700 | result->cur_val <= max->cur; |
| 2701 | |
| 2702 | ret = result->enable; |
| 2703 | |
| 2704 | /* |
| 2705 | * HACK until we can pre-compute everything, |
| 2706 | * and thus fail gracefully if LP0 watermarks |
| 2707 | * are exceeded... |
| 2708 | */ |
| 2709 | if (level == 0 && !result->enable) { |
| 2710 | if (result->pri_val > max->pri) |
| 2711 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2712 | level, result->pri_val, max->pri); |
| 2713 | if (result->spr_val > max->spr) |
| 2714 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2715 | level, result->spr_val, max->spr); |
| 2716 | if (result->cur_val > max->cur) |
| 2717 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2718 | level, result->cur_val, max->cur); |
| 2719 | |
| 2720 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2721 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2722 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2723 | result->enable = true; |
| 2724 | } |
| 2725 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2726 | return ret; |
| 2727 | } |
| 2728 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2729 | 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] | 2730 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2731 | int level, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2732 | struct intel_crtc_state *cstate, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2733 | const struct intel_plane_state *pristate, |
| 2734 | const struct intel_plane_state *sprstate, |
| 2735 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2736 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2737 | { |
| 2738 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2739 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2740 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2741 | |
| 2742 | /* WM1+ latency values stored in 0.5us units */ |
| 2743 | if (level > 0) { |
| 2744 | pri_latency *= 5; |
| 2745 | spr_latency *= 5; |
| 2746 | cur_latency *= 5; |
| 2747 | } |
| 2748 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2749 | if (pristate) { |
| 2750 | result->pri_val = ilk_compute_pri_wm(cstate, pristate, |
| 2751 | pri_latency, level); |
| 2752 | result->fbc_val = ilk_compute_fbc_wm(cstate, pristate, result->pri_val); |
| 2753 | } |
| 2754 | |
| 2755 | if (sprstate) |
| 2756 | result->spr_val = ilk_compute_spr_wm(cstate, sprstate, spr_latency); |
| 2757 | |
| 2758 | if (curstate) |
| 2759 | result->cur_val = ilk_compute_cur_wm(cstate, curstate, cur_latency); |
| 2760 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2761 | result->enable = true; |
| 2762 | } |
| 2763 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2764 | static uint32_t |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2765 | hsw_compute_linetime_wm(const struct intel_crtc_state *cstate) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2766 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2767 | const struct intel_atomic_state *intel_state = |
| 2768 | to_intel_atomic_state(cstate->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2769 | const struct drm_display_mode *adjusted_mode = |
| 2770 | &cstate->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2771 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2772 | |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2773 | if (!cstate->base.active) |
| 2774 | return 0; |
| 2775 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2776 | return 0; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2777 | if (WARN_ON(intel_state->cdclk.logical.cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2778 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2779 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2780 | /* The WM are computed with base on how long it takes to fill a single |
| 2781 | * row at the given clock rate, multiplied by 8. |
| 2782 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2783 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2784 | adjusted_mode->crtc_clock); |
| 2785 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2786 | intel_state->cdclk.logical.cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2787 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2788 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2789 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2790 | } |
| 2791 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2792 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
| 2793 | uint16_t wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2794 | { |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2795 | if (INTEL_GEN(dev_priv) >= 9) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2796 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2797 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2798 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2799 | |
| 2800 | /* read the first set of memory latencies[0:3] */ |
| 2801 | val = 0; /* data0 to be programmed to 0 for first set */ |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 2802 | mutex_lock(&dev_priv->pcu_lock); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2803 | ret = sandybridge_pcode_read(dev_priv, |
| 2804 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2805 | &val); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 2806 | mutex_unlock(&dev_priv->pcu_lock); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2807 | |
| 2808 | if (ret) { |
| 2809 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2810 | return; |
| 2811 | } |
| 2812 | |
| 2813 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2814 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2815 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2816 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2817 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2818 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2819 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2820 | |
| 2821 | /* read the second set of memory latencies[4:7] */ |
| 2822 | val = 1; /* data0 to be programmed to 1 for second set */ |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 2823 | mutex_lock(&dev_priv->pcu_lock); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2824 | ret = sandybridge_pcode_read(dev_priv, |
| 2825 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2826 | &val); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 2827 | mutex_unlock(&dev_priv->pcu_lock); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2828 | if (ret) { |
| 2829 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2830 | return; |
| 2831 | } |
| 2832 | |
| 2833 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2834 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2835 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2836 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2837 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2838 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2839 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2840 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2841 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2842 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2843 | * need to be disabled. We make sure to sanitize the values out |
| 2844 | * of the punit to satisfy this requirement. |
| 2845 | */ |
| 2846 | for (level = 1; level <= max_level; level++) { |
| 2847 | if (wm[level] == 0) { |
| 2848 | for (i = level + 1; i <= max_level; i++) |
| 2849 | wm[i] = 0; |
| 2850 | break; |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | /* |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2855 | * WaWmMemoryReadLatency:skl+,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2856 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2857 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2858 | * to add 2us to the various latency levels we retrieve from the |
| 2859 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2860 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2861 | if (wm[0] == 0) { |
| 2862 | wm[0] += 2; |
| 2863 | for (level = 1; level <= max_level; level++) { |
| 2864 | if (wm[level] == 0) |
| 2865 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2866 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2867 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2868 | } |
| 2869 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2870 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2871 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2872 | |
| 2873 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2874 | if (wm[0] == 0) |
| 2875 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2876 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2877 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2878 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2879 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2880 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2881 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2882 | |
| 2883 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2884 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2885 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2886 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2887 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2888 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2889 | |
| 2890 | /* ILK primary LP0 latency is 700 ns */ |
| 2891 | wm[0] = 7; |
| 2892 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2893 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2894 | } else { |
| 2895 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2899 | static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv, |
| 2900 | uint16_t wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2901 | { |
| 2902 | /* ILK sprite LP0 latency is 1300 ns */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2903 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2904 | wm[0] = 13; |
| 2905 | } |
| 2906 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2907 | static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv, |
| 2908 | uint16_t wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2909 | { |
| 2910 | /* ILK cursor LP0 latency is 1300 ns */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2911 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2912 | wm[0] = 13; |
| 2913 | |
| 2914 | /* WaDoubleCursorLP3Latency:ivb */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2915 | if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2916 | wm[3] *= 2; |
| 2917 | } |
| 2918 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2919 | 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] | 2920 | { |
| 2921 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2922 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2923 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2924 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2925 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2926 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2927 | return 3; |
| 2928 | else |
| 2929 | return 2; |
| 2930 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2931 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2932 | 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] | 2933 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2934 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2935 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2936 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2937 | |
| 2938 | for (level = 0; level <= max_level; level++) { |
| 2939 | unsigned int latency = wm[level]; |
| 2940 | |
| 2941 | if (latency == 0) { |
| 2942 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2943 | name, level); |
| 2944 | continue; |
| 2945 | } |
| 2946 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2947 | /* |
| 2948 | * - latencies are in us on gen9. |
| 2949 | * - before then, WM1+ latency values are in 0.5us units |
| 2950 | */ |
Paulo Zanoni | dfc267a | 2017-08-09 13:52:46 -0700 | [diff] [blame] | 2951 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2952 | latency *= 10; |
| 2953 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2954 | latency *= 5; |
| 2955 | |
| 2956 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2957 | name, level, wm[level], |
| 2958 | latency / 10, latency % 10); |
| 2959 | } |
| 2960 | } |
| 2961 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2962 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2963 | uint16_t wm[5], uint16_t min) |
| 2964 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2965 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2966 | |
| 2967 | if (wm[0] >= min) |
| 2968 | return false; |
| 2969 | |
| 2970 | wm[0] = max(wm[0], min); |
| 2971 | for (level = 1; level <= max_level; level++) |
| 2972 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2973 | |
| 2974 | return true; |
| 2975 | } |
| 2976 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2977 | 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] | 2978 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2979 | bool changed; |
| 2980 | |
| 2981 | /* |
| 2982 | * The BIOS provided WM memory latency values are often |
| 2983 | * inadequate for high resolution displays. Adjust them. |
| 2984 | */ |
| 2985 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2986 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2987 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2988 | |
| 2989 | if (!changed) |
| 2990 | return; |
| 2991 | |
| 2992 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2993 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 2994 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 2995 | 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] | 2996 | } |
| 2997 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2998 | 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] | 2999 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3000 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3001 | |
| 3002 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3003 | sizeof(dev_priv->wm.pri_latency)); |
| 3004 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3005 | sizeof(dev_priv->wm.pri_latency)); |
| 3006 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3007 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3008 | 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] | 3009 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3010 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3011 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3012 | 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] | 3013 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3014 | if (IS_GEN6(dev_priv)) |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3015 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3016 | } |
| 3017 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3018 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3019 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3020 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3021 | 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] | 3022 | } |
| 3023 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3024 | static bool ilk_validate_pipe_wm(struct drm_device *dev, |
| 3025 | struct intel_pipe_wm *pipe_wm) |
| 3026 | { |
| 3027 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3028 | const struct intel_wm_config config = { |
| 3029 | .num_pipes_active = 1, |
| 3030 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3031 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3032 | }; |
| 3033 | struct ilk_wm_maximums max; |
| 3034 | |
| 3035 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 3036 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 3037 | |
| 3038 | /* At least LP0 must be valid */ |
| 3039 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 3040 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 3041 | return false; |
| 3042 | } |
| 3043 | |
| 3044 | return true; |
| 3045 | } |
| 3046 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3047 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3048 | static int ilk_compute_pipe_wm(struct intel_crtc_state *cstate) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3049 | { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3050 | struct drm_atomic_state *state = cstate->base.state; |
| 3051 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3052 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3053 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3054 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3055 | struct drm_plane *plane; |
| 3056 | const struct drm_plane_state *plane_state; |
| 3057 | const struct intel_plane_state *pristate = NULL; |
| 3058 | const struct intel_plane_state *sprstate = NULL; |
| 3059 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3060 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3061 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3062 | |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3063 | pipe_wm = &cstate->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3064 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3065 | drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, &cstate->base) { |
| 3066 | const struct intel_plane_state *ps = to_intel_plane_state(plane_state); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3067 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3068 | if (plane->type == DRM_PLANE_TYPE_PRIMARY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3069 | pristate = ps; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3070 | else if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3071 | sprstate = ps; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3072 | else if (plane->type == DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3073 | curstate = ps; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3074 | } |
| 3075 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3076 | pipe_wm->pipe_enabled = cstate->base.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3077 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3078 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 3079 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 3080 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 3081 | 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] | 3082 | } |
| 3083 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3084 | usable_level = max_level; |
| 3085 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3086 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3087 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3088 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3089 | |
| 3090 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3091 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3092 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3093 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3094 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3095 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, cstate, |
| 3096 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3097 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3098 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 3099 | pipe_wm->linetime = hsw_compute_linetime_wm(cstate); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3100 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3101 | if (!ilk_validate_pipe_wm(dev, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3102 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3103 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3104 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3105 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3106 | for (level = 1; level <= usable_level; level++) { |
| 3107 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3108 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3109 | ilk_compute_wm_level(dev_priv, intel_crtc, level, cstate, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3110 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3111 | |
| 3112 | /* |
| 3113 | * Disable any watermark level that exceeds the |
| 3114 | * register maximums since such watermarks are |
| 3115 | * always invalid. |
| 3116 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3117 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3118 | memset(wm, 0, sizeof(*wm)); |
| 3119 | break; |
| 3120 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3121 | } |
| 3122 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3123 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3127 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3128 | * state and the new state. These can be programmed to the hardware |
| 3129 | * immediately. |
| 3130 | */ |
| 3131 | static int ilk_compute_intermediate_wm(struct drm_device *dev, |
| 3132 | struct intel_crtc *intel_crtc, |
| 3133 | struct intel_crtc_state *newstate) |
| 3134 | { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3135 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3136 | struct intel_atomic_state *intel_state = |
| 3137 | to_intel_atomic_state(newstate->base.state); |
| 3138 | const struct intel_crtc_state *oldstate = |
| 3139 | intel_atomic_get_old_crtc_state(intel_state, intel_crtc); |
| 3140 | const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3141 | int level, max_level = ilk_wm_max_level(to_i915(dev)); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3142 | |
| 3143 | /* |
| 3144 | * Start with the final, target watermarks, then combine with the |
| 3145 | * currently active watermarks to get values that are safe both before |
| 3146 | * and after the vblank. |
| 3147 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3148 | *a = newstate->wm.ilk.optimal; |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3149 | if (!newstate->base.active || drm_atomic_crtc_needs_modeset(&newstate->base)) |
| 3150 | return 0; |
| 3151 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3152 | a->pipe_enabled |= b->pipe_enabled; |
| 3153 | a->sprites_enabled |= b->sprites_enabled; |
| 3154 | a->sprites_scaled |= b->sprites_scaled; |
| 3155 | |
| 3156 | for (level = 0; level <= max_level; level++) { |
| 3157 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3158 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3159 | |
| 3160 | a_wm->enable &= b_wm->enable; |
| 3161 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3162 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3163 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3164 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3165 | } |
| 3166 | |
| 3167 | /* |
| 3168 | * We need to make sure that these merged watermark values are |
| 3169 | * actually a valid configuration themselves. If they're not, |
| 3170 | * there's no safe way to transition from the old state to |
| 3171 | * the new state, so we need to fail the atomic transaction. |
| 3172 | */ |
| 3173 | if (!ilk_validate_pipe_wm(dev, a)) |
| 3174 | return -EINVAL; |
| 3175 | |
| 3176 | /* |
| 3177 | * If our intermediate WM are identical to the final WM, then we can |
| 3178 | * omit the post-vblank programming; only update if it's different. |
| 3179 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3180 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3181 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3182 | |
| 3183 | return 0; |
| 3184 | } |
| 3185 | |
| 3186 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3187 | * Merge the watermarks from all active pipes for a specific level. |
| 3188 | */ |
| 3189 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 3190 | int level, |
| 3191 | struct intel_wm_level *ret_wm) |
| 3192 | { |
| 3193 | const struct intel_crtc *intel_crtc; |
| 3194 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3195 | ret_wm->enable = true; |
| 3196 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3197 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3198 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3199 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3200 | |
| 3201 | if (!active->pipe_enabled) |
| 3202 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3203 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3204 | /* |
| 3205 | * The watermark values may have been used in the past, |
| 3206 | * so we must maintain them in the registers for some |
| 3207 | * time even if the level is now disabled. |
| 3208 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3209 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3210 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3211 | |
| 3212 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3213 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3214 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3215 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3216 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | /* |
| 3220 | * Merge all low power watermarks for all active pipes. |
| 3221 | */ |
| 3222 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3223 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3224 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3225 | struct intel_pipe_wm *merged) |
| 3226 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3227 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3228 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3229 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3230 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3231 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3232 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3233 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3234 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3235 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3236 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3237 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3238 | |
| 3239 | /* merge each WM1+ level */ |
| 3240 | for (level = 1; level <= max_level; level++) { |
| 3241 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3242 | |
| 3243 | ilk_merge_wm_level(dev, level, wm); |
| 3244 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3245 | if (level > last_enabled_level) |
| 3246 | wm->enable = false; |
| 3247 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3248 | /* make sure all following levels get disabled */ |
| 3249 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3250 | |
| 3251 | /* |
| 3252 | * The spec says it is preferred to disable |
| 3253 | * FBC WMs instead of disabling a WM level. |
| 3254 | */ |
| 3255 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3256 | if (wm->enable) |
| 3257 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3258 | wm->fbc_val = 0; |
| 3259 | } |
| 3260 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3261 | |
| 3262 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3263 | /* |
| 3264 | * FIXME this is racy. FBC might get enabled later. |
| 3265 | * What we should check here is whether FBC can be |
| 3266 | * enabled sometime later. |
| 3267 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3268 | if (IS_GEN5(dev_priv) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3269 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3270 | for (level = 2; level <= max_level; level++) { |
| 3271 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3272 | |
| 3273 | wm->enable = false; |
| 3274 | } |
| 3275 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3276 | } |
| 3277 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3278 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3279 | { |
| 3280 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3281 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3282 | } |
| 3283 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3284 | /* The value we need to program into the WM_LPx latency field */ |
| 3285 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 3286 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3287 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3288 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3289 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3290 | return 2 * level; |
| 3291 | else |
| 3292 | return dev_priv->wm.pri_latency[level]; |
| 3293 | } |
| 3294 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3295 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3296 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3297 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3298 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3299 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3300 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3301 | struct intel_crtc *intel_crtc; |
| 3302 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3303 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3304 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3305 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3306 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3307 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3308 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3309 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3310 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3311 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3312 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3313 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3314 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3315 | /* |
| 3316 | * Maintain the watermark values even if the level is |
| 3317 | * disabled. Doing otherwise could cause underruns. |
| 3318 | */ |
| 3319 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3320 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3321 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3322 | r->cur_val; |
| 3323 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3324 | if (r->enable) |
| 3325 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3326 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3327 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3328 | results->wm_lp[wm_lp - 1] |= |
| 3329 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3330 | else |
| 3331 | results->wm_lp[wm_lp - 1] |= |
| 3332 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3333 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3334 | /* |
| 3335 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3336 | * level is disabled. Doing otherwise could cause underruns. |
| 3337 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3338 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3339 | WARN_ON(wm_lp != 1); |
| 3340 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3341 | } else |
| 3342 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3343 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3344 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3345 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3346 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3347 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3348 | const struct intel_wm_level *r = |
| 3349 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3350 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3351 | if (WARN_ON(!r->enable)) |
| 3352 | continue; |
| 3353 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3354 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3355 | |
| 3356 | results->wm_pipe[pipe] = |
| 3357 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3358 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3359 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3360 | } |
| 3361 | } |
| 3362 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3363 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3364 | * case both are at the same level. Prefer r1 in case they're the same. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3365 | static struct intel_pipe_wm *ilk_find_best_result(struct drm_device *dev, |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3366 | struct intel_pipe_wm *r1, |
| 3367 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3368 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3369 | int level, max_level = ilk_wm_max_level(to_i915(dev)); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3370 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3371 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3372 | for (level = 1; level <= max_level; level++) { |
| 3373 | if (r1->wm[level].enable) |
| 3374 | level1 = level; |
| 3375 | if (r2->wm[level].enable) |
| 3376 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3377 | } |
| 3378 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3379 | if (level1 == level2) { |
| 3380 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3381 | return r2; |
| 3382 | else |
| 3383 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3384 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3385 | return r1; |
| 3386 | } else { |
| 3387 | return r2; |
| 3388 | } |
| 3389 | } |
| 3390 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3391 | /* dirty bits used to track which watermarks need changes */ |
| 3392 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 3393 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 3394 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3395 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3396 | #define WM_DIRTY_FBC (1 << 24) |
| 3397 | #define WM_DIRTY_DDB (1 << 25) |
| 3398 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3399 | 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] | 3400 | const struct ilk_wm_values *old, |
| 3401 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3402 | { |
| 3403 | unsigned int dirty = 0; |
| 3404 | enum pipe pipe; |
| 3405 | int wm_lp; |
| 3406 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3407 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3408 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 3409 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 3410 | /* Must disable LP1+ watermarks too */ |
| 3411 | dirty |= WM_DIRTY_LP_ALL; |
| 3412 | } |
| 3413 | |
| 3414 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3415 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3416 | /* Must disable LP1+ watermarks too */ |
| 3417 | dirty |= WM_DIRTY_LP_ALL; |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3422 | dirty |= WM_DIRTY_FBC; |
| 3423 | /* Must disable LP1+ watermarks too */ |
| 3424 | dirty |= WM_DIRTY_LP_ALL; |
| 3425 | } |
| 3426 | |
| 3427 | if (old->partitioning != new->partitioning) { |
| 3428 | dirty |= WM_DIRTY_DDB; |
| 3429 | /* Must disable LP1+ watermarks too */ |
| 3430 | dirty |= WM_DIRTY_LP_ALL; |
| 3431 | } |
| 3432 | |
| 3433 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3434 | if (dirty & WM_DIRTY_LP_ALL) |
| 3435 | return dirty; |
| 3436 | |
| 3437 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3438 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3439 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3440 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3441 | break; |
| 3442 | } |
| 3443 | |
| 3444 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3445 | for (; wm_lp <= 3; wm_lp++) |
| 3446 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3447 | |
| 3448 | return dirty; |
| 3449 | } |
| 3450 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3451 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3452 | unsigned int dirty) |
| 3453 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3454 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3455 | bool changed = false; |
| 3456 | |
| 3457 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3458 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3459 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3460 | changed = true; |
| 3461 | } |
| 3462 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3463 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3464 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3465 | changed = true; |
| 3466 | } |
| 3467 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3468 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3469 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3470 | changed = true; |
| 3471 | } |
| 3472 | |
| 3473 | /* |
| 3474 | * Don't touch WM1S_LP_EN here. |
| 3475 | * Doing so could cause underruns. |
| 3476 | */ |
| 3477 | |
| 3478 | return changed; |
| 3479 | } |
| 3480 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3481 | /* |
| 3482 | * The spec says we shouldn't write when we don't need, because every write |
| 3483 | * causes WMs to be re-evaluated, expending some power. |
| 3484 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3485 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3486 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3487 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3488 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3489 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3490 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3491 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3492 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3493 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3494 | return; |
| 3495 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3496 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3497 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3498 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3499 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3500 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3501 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3502 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3503 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 3504 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3505 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3506 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3507 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3508 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3509 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3510 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 3511 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3512 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3513 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3514 | val = I915_READ(WM_MISC); |
| 3515 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3516 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3517 | else |
| 3518 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3519 | I915_WRITE(WM_MISC, val); |
| 3520 | } else { |
| 3521 | val = I915_READ(DISP_ARB_CTL2); |
| 3522 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3523 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3524 | else |
| 3525 | val |= DISP_DATA_PARTITION_5_6; |
| 3526 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3527 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3528 | } |
| 3529 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3530 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3531 | val = I915_READ(DISP_ARB_CTL); |
| 3532 | if (results->enable_fbc_wm) |
| 3533 | val &= ~DISP_FBC_WM_DIS; |
| 3534 | else |
| 3535 | val |= DISP_FBC_WM_DIS; |
| 3536 | I915_WRITE(DISP_ARB_CTL, val); |
| 3537 | } |
| 3538 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3539 | if (dirty & WM_DIRTY_LP(1) && |
| 3540 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3541 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3542 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3543 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3544 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3545 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3546 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3547 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3548 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3549 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3550 | 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] | 3551 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3552 | 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] | 3553 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3554 | 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] | 3555 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3556 | |
| 3557 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3558 | } |
| 3559 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3560 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3561 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3562 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3563 | |
| 3564 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3565 | } |
| 3566 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3567 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3568 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3569 | * so assume we'll always need it in order to avoid underruns. |
| 3570 | */ |
| 3571 | static bool skl_needs_memory_bw_wa(struct intel_atomic_state *state) |
| 3572 | { |
| 3573 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 3574 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 3575 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3576 | return true; |
| 3577 | |
| 3578 | return false; |
| 3579 | } |
| 3580 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3581 | static bool |
| 3582 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3583 | { |
Rodrigo Vivi | 0197181 | 2017-08-09 13:52:44 -0700 | [diff] [blame] | 3584 | if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || |
| 3585 | IS_CANNONLAKE(dev_priv)) |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3586 | return true; |
| 3587 | |
| 3588 | if (IS_SKYLAKE(dev_priv) && |
| 3589 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED) |
| 3590 | return true; |
| 3591 | |
| 3592 | return false; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3593 | } |
| 3594 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3595 | /* |
| 3596 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3597 | * depending on power and performance requirements. The display engine access |
| 3598 | * to system memory is blocked during the adjustment time. Because of the |
| 3599 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3600 | * underruns if we don't meet all of the following requirements: |
| 3601 | * |
| 3602 | * - <= 1 pipe enabled |
| 3603 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3604 | * - We're not using an interlaced display configuration |
| 3605 | */ |
| 3606 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3607 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3608 | { |
| 3609 | int ret; |
| 3610 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3611 | if (!intel_has_sagv(dev_priv)) |
| 3612 | return 0; |
| 3613 | |
| 3614 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3615 | return 0; |
| 3616 | |
| 3617 | DRM_DEBUG_KMS("Enabling the SAGV\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 3618 | mutex_lock(&dev_priv->pcu_lock); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3619 | |
| 3620 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3621 | GEN9_SAGV_ENABLE); |
| 3622 | |
| 3623 | /* We don't need to wait for the SAGV when enabling */ |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 3624 | mutex_unlock(&dev_priv->pcu_lock); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3625 | |
| 3626 | /* |
| 3627 | * Some skl systems, pre-release machines in particular, |
| 3628 | * don't actually have an SAGV. |
| 3629 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3630 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3631 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3632 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3633 | return 0; |
| 3634 | } else if (ret < 0) { |
| 3635 | DRM_ERROR("Failed to enable the SAGV\n"); |
| 3636 | return ret; |
| 3637 | } |
| 3638 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3639 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3640 | return 0; |
| 3641 | } |
| 3642 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3643 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3644 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3645 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3646 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3647 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3648 | if (!intel_has_sagv(dev_priv)) |
| 3649 | return 0; |
| 3650 | |
| 3651 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3652 | return 0; |
| 3653 | |
| 3654 | DRM_DEBUG_KMS("Disabling the SAGV\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 3655 | mutex_lock(&dev_priv->pcu_lock); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3656 | |
| 3657 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3658 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3659 | GEN9_SAGV_DISABLE, |
| 3660 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3661 | 1); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 3662 | mutex_unlock(&dev_priv->pcu_lock); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3663 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3664 | /* |
| 3665 | * Some skl systems, pre-release machines in particular, |
| 3666 | * don't actually have an SAGV. |
| 3667 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3668 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3669 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3670 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3671 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3672 | } else if (ret < 0) { |
| 3673 | DRM_ERROR("Failed to disable the SAGV (%d)\n", ret); |
| 3674 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3675 | } |
| 3676 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3677 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3678 | return 0; |
| 3679 | } |
| 3680 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3681 | bool intel_can_enable_sagv(struct drm_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3682 | { |
| 3683 | struct drm_device *dev = state->dev; |
| 3684 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3685 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3686 | struct intel_crtc *crtc; |
| 3687 | struct intel_plane *plane; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3688 | struct intel_crtc_state *cstate; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3689 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3690 | int level, latency; |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3691 | int sagv_block_time_us = IS_GEN9(dev_priv) ? 30 : 20; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3692 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3693 | if (!intel_has_sagv(dev_priv)) |
| 3694 | return false; |
| 3695 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3696 | /* |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3697 | * SKL+ workaround: bspec recommends we disable the SAGV when we have |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3698 | * more then one pipe enabled |
| 3699 | * |
| 3700 | * If there are no active CRTCs, no additional checks need be performed |
| 3701 | */ |
| 3702 | if (hweight32(intel_state->active_crtcs) == 0) |
| 3703 | return true; |
| 3704 | else if (hweight32(intel_state->active_crtcs) > 1) |
| 3705 | return false; |
| 3706 | |
| 3707 | /* Since we're now guaranteed to only have one active CRTC... */ |
| 3708 | pipe = ffs(intel_state->active_crtcs) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 3709 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3710 | cstate = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3711 | |
Paulo Zanoni | c89cadd | 2016-10-10 17:30:59 -0300 | [diff] [blame] | 3712 | if (crtc->base.state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3713 | return false; |
| 3714 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3715 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3716 | struct skl_plane_wm *wm = |
| 3717 | &cstate->wm.skl.optimal.planes[plane->id]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3718 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3719 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3720 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3721 | continue; |
| 3722 | |
| 3723 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3724 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3725 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3726 | { } |
| 3727 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3728 | latency = dev_priv->wm.skl_latency[level]; |
| 3729 | |
| 3730 | if (skl_needs_memory_bw_wa(intel_state) && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3731 | plane->base.state->fb->modifier == |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3732 | I915_FORMAT_MOD_X_TILED) |
| 3733 | latency += 15; |
| 3734 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3735 | /* |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3736 | * If any of the planes on this pipe don't enable wm levels that |
| 3737 | * incur memory latencies higher than sagv_block_time_us we |
| 3738 | * can't enable the SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3739 | */ |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3740 | if (latency < sagv_block_time_us) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3741 | return false; |
| 3742 | } |
| 3743 | |
| 3744 | return true; |
| 3745 | } |
| 3746 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3747 | static void |
| 3748 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3749 | const struct intel_crtc_state *cstate, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3750 | struct skl_ddb_entry *alloc, /* out */ |
| 3751 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3752 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3753 | struct drm_atomic_state *state = cstate->base.state; |
| 3754 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 3755 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3756 | struct drm_crtc *for_crtc = cstate->base.crtc; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3757 | unsigned int pipe_size, ddb_size; |
| 3758 | int nth_active_pipe; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3759 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3760 | if (WARN_ON(!state) || !cstate->base.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3761 | alloc->start = 0; |
| 3762 | alloc->end = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3763 | *num_active = hweight32(dev_priv->active_crtcs); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3764 | return; |
| 3765 | } |
| 3766 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3767 | if (intel_state->active_pipe_changes) |
| 3768 | *num_active = hweight32(intel_state->active_crtcs); |
| 3769 | else |
| 3770 | *num_active = hweight32(dev_priv->active_crtcs); |
| 3771 | |
Deepak M | 6f3fff6 | 2016-09-15 15:01:10 +0530 | [diff] [blame] | 3772 | ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3773 | WARN_ON(ddb_size == 0); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3774 | |
| 3775 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 3776 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3777 | /* |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3778 | * If the state doesn't change the active CRTC's, then there's |
| 3779 | * no need to recalculate; the existing pipe allocation limits |
| 3780 | * should remain unchanged. Note that we're safe from racing |
| 3781 | * commits since any racing commit that changes the active CRTC |
| 3782 | * list would need to grab _all_ crtc locks, including the one |
| 3783 | * we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3784 | */ |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3785 | if (!intel_state->active_pipe_changes) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 3786 | /* |
| 3787 | * alloc may be cleared by clear_intel_crtc_state, |
| 3788 | * copy from old state to be sure |
| 3789 | */ |
| 3790 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3791 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3792 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3793 | |
| 3794 | nth_active_pipe = hweight32(intel_state->active_crtcs & |
| 3795 | (drm_crtc_mask(for_crtc) - 1)); |
| 3796 | pipe_size = ddb_size / hweight32(intel_state->active_crtcs); |
| 3797 | alloc->start = nth_active_pipe * ddb_size / *num_active; |
| 3798 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3799 | } |
| 3800 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3801 | static unsigned int skl_cursor_allocation(int num_active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3802 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3803 | if (num_active == 1) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3804 | return 32; |
| 3805 | |
| 3806 | return 8; |
| 3807 | } |
| 3808 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3809 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 3810 | { |
| 3811 | entry->start = reg & 0x3ff; |
| 3812 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3813 | if (entry->end) |
| 3814 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3815 | } |
| 3816 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 3817 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 3818 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3819 | { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3820 | struct intel_crtc *crtc; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3821 | |
Maarten Lankhorst | b10f1b2 | 2015-10-22 13:56:34 +0200 | [diff] [blame] | 3822 | memset(ddb, 0, sizeof(*ddb)); |
| 3823 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3824 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3825 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3826 | enum plane_id plane_id; |
| 3827 | enum pipe pipe = crtc->pipe; |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3828 | |
| 3829 | power_domain = POWER_DOMAIN_PIPE(pipe); |
| 3830 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Maarten Lankhorst | b10f1b2 | 2015-10-22 13:56:34 +0200 | [diff] [blame] | 3831 | continue; |
| 3832 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3833 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 3834 | u32 val; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3835 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3836 | if (plane_id != PLANE_CURSOR) |
| 3837 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 3838 | else |
| 3839 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 3840 | |
| 3841 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane_id], val); |
| 3842 | } |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3843 | |
| 3844 | intel_display_power_put(dev_priv, power_domain); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3845 | } |
| 3846 | } |
| 3847 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3848 | /* |
| 3849 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 3850 | * The bspec defines downscale amount as: |
| 3851 | * |
| 3852 | * """ |
| 3853 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 3854 | * Horizontal destination size] |
| 3855 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 3856 | * Vertical destination size] |
| 3857 | * Total down scale amount = Horizontal down scale amount * |
| 3858 | * Vertical down scale amount |
| 3859 | * """ |
| 3860 | * |
| 3861 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 3862 | * Caller should take care of dividing & rounding off the value. |
| 3863 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3864 | static uint_fixed_16_16_t |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3865 | skl_plane_downscale_amount(const struct intel_crtc_state *cstate, |
| 3866 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3867 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3868 | struct intel_plane *plane = to_intel_plane(pstate->base.plane); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3869 | uint32_t src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3870 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 3871 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3872 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3873 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 3874 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3875 | |
| 3876 | /* 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] | 3877 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 3878 | /* |
| 3879 | * Cursors only support 0/180 degree rotation, |
| 3880 | * hence no need to account for rotation here. |
| 3881 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3882 | src_w = pstate->base.src_w >> 16; |
| 3883 | src_h = pstate->base.src_h >> 16; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3884 | dst_w = pstate->base.crtc_w; |
| 3885 | dst_h = pstate->base.crtc_h; |
| 3886 | } else { |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 3887 | /* |
| 3888 | * Src coordinates are already rotated by 270 degrees for |
| 3889 | * the 90/270 degree plane rotation cases (to match the |
| 3890 | * GTT mapping), hence no need to account for rotation here. |
| 3891 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3892 | src_w = drm_rect_width(&pstate->base.src) >> 16; |
| 3893 | src_h = drm_rect_height(&pstate->base.src) >> 16; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3894 | dst_w = drm_rect_width(&pstate->base.dst); |
| 3895 | dst_h = drm_rect_height(&pstate->base.dst); |
| 3896 | } |
| 3897 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 3898 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 3899 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 3900 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 3901 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3902 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 3903 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3904 | } |
| 3905 | |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3906 | static uint_fixed_16_16_t |
| 3907 | skl_pipe_downscale_amount(const struct intel_crtc_state *crtc_state) |
| 3908 | { |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 3909 | uint_fixed_16_16_t pipe_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3910 | |
| 3911 | if (!crtc_state->base.enable) |
| 3912 | return pipe_downscale; |
| 3913 | |
| 3914 | if (crtc_state->pch_pfit.enabled) { |
| 3915 | uint32_t src_w, src_h, dst_w, dst_h; |
| 3916 | uint32_t pfit_size = crtc_state->pch_pfit.size; |
| 3917 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 3918 | uint_fixed_16_16_t downscale_h, downscale_w; |
| 3919 | |
| 3920 | src_w = crtc_state->pipe_src_w; |
| 3921 | src_h = crtc_state->pipe_src_h; |
| 3922 | dst_w = pfit_size >> 16; |
| 3923 | dst_h = pfit_size & 0xffff; |
| 3924 | |
| 3925 | if (!dst_w || !dst_h) |
| 3926 | return pipe_downscale; |
| 3927 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 3928 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 3929 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 3930 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 3931 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3932 | |
| 3933 | pipe_downscale = mul_fixed16(downscale_w, downscale_h); |
| 3934 | } |
| 3935 | |
| 3936 | return pipe_downscale; |
| 3937 | } |
| 3938 | |
| 3939 | int skl_check_pipe_max_pixel_rate(struct intel_crtc *intel_crtc, |
| 3940 | struct intel_crtc_state *cstate) |
| 3941 | { |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 3942 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3943 | struct drm_crtc_state *crtc_state = &cstate->base; |
| 3944 | struct drm_atomic_state *state = crtc_state->state; |
| 3945 | struct drm_plane *plane; |
| 3946 | const struct drm_plane_state *pstate; |
| 3947 | struct intel_plane_state *intel_pstate; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 3948 | int crtc_clock, dotclk; |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3949 | uint32_t pipe_max_pixel_rate; |
| 3950 | uint_fixed_16_16_t pipe_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 3951 | uint_fixed_16_16_t max_downscale = u32_to_fixed16(1); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3952 | |
| 3953 | if (!cstate->base.enable) |
| 3954 | return 0; |
| 3955 | |
| 3956 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { |
| 3957 | uint_fixed_16_16_t plane_downscale; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 3958 | 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] | 3959 | int bpp; |
| 3960 | |
| 3961 | if (!intel_wm_plane_visible(cstate, |
| 3962 | to_intel_plane_state(pstate))) |
| 3963 | continue; |
| 3964 | |
| 3965 | if (WARN_ON(!pstate->fb)) |
| 3966 | return -EINVAL; |
| 3967 | |
| 3968 | intel_pstate = to_intel_plane_state(pstate); |
| 3969 | plane_downscale = skl_plane_downscale_amount(cstate, |
| 3970 | intel_pstate); |
| 3971 | bpp = pstate->fb->format->cpp[0] * 8; |
| 3972 | if (bpp == 64) |
| 3973 | plane_downscale = mul_fixed16(plane_downscale, |
| 3974 | fp_9_div_8); |
| 3975 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 3976 | max_downscale = max_fixed16(plane_downscale, max_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3977 | } |
| 3978 | pipe_downscale = skl_pipe_downscale_amount(cstate); |
| 3979 | |
| 3980 | pipe_downscale = mul_fixed16(pipe_downscale, max_downscale); |
| 3981 | |
| 3982 | crtc_clock = crtc_state->adjusted_mode.crtc_clock; |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 3983 | dotclk = to_intel_atomic_state(state)->cdclk.logical.cdclk; |
| 3984 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 3985 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 3986 | dotclk *= 2; |
| 3987 | |
| 3988 | pipe_max_pixel_rate = div_round_up_u32_fixed16(dotclk, pipe_downscale); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3989 | |
| 3990 | if (pipe_max_pixel_rate < crtc_clock) { |
Maarten Lankhorst | 789f35d | 2017-06-01 12:34:13 +0200 | [diff] [blame] | 3991 | DRM_DEBUG_KMS("Max supported pixel clock with scaling exceeded\n"); |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 3992 | return -EINVAL; |
| 3993 | } |
| 3994 | |
| 3995 | return 0; |
| 3996 | } |
| 3997 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3998 | static unsigned int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3999 | skl_plane_relative_data_rate(const struct intel_crtc_state *cstate, |
| 4000 | const struct drm_plane_state *pstate, |
| 4001 | int y) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4002 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4003 | struct intel_plane *plane = to_intel_plane(pstate->plane); |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4004 | struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate); |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4005 | uint32_t data_rate; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4006 | uint32_t width = 0, height = 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4007 | struct drm_framebuffer *fb; |
| 4008 | u32 format; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4009 | uint_fixed_16_16_t down_scale_amount; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4010 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4011 | if (!intel_pstate->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4012 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4013 | |
| 4014 | fb = pstate->fb; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4015 | format = fb->format->format; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4016 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4017 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4018 | return 0; |
| 4019 | if (y && format != DRM_FORMAT_NV12) |
| 4020 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4021 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4022 | /* |
| 4023 | * Src coordinates are already rotated by 270 degrees for |
| 4024 | * the 90/270 degree plane rotation cases (to match the |
| 4025 | * GTT mapping), hence no need to account for rotation here. |
| 4026 | */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4027 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4028 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4029 | |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4030 | /* for planar format */ |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4031 | if (format == DRM_FORMAT_NV12) { |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4032 | if (y) /* y-plane data rate */ |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4033 | data_rate = width * height * |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4034 | fb->format->cpp[0]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4035 | else /* uv-plane data rate */ |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4036 | data_rate = (width / 2) * (height / 2) * |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4037 | fb->format->cpp[1]; |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4038 | } else { |
| 4039 | /* for packed formats */ |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4040 | data_rate = width * height * fb->format->cpp[0]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4043 | down_scale_amount = skl_plane_downscale_amount(cstate, intel_pstate); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4044 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4045 | return mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | /* |
| 4049 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 4050 | * a 8192x4096@32bpp framebuffer: |
| 4051 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 4052 | */ |
| 4053 | static unsigned int |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4054 | skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate, |
| 4055 | unsigned *plane_data_rate, |
| 4056 | unsigned *plane_y_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4057 | { |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4058 | struct drm_crtc_state *cstate = &intel_cstate->base; |
| 4059 | struct drm_atomic_state *state = cstate->state; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4060 | struct drm_plane *plane; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4061 | const struct drm_plane_state *pstate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4062 | unsigned int total_data_rate = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4063 | |
| 4064 | if (WARN_ON(!state)) |
| 4065 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4066 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4067 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 4068 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, cstate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4069 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 4070 | unsigned int rate; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4071 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4072 | /* packed/uv */ |
| 4073 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4074 | pstate, 0); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4075 | plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4076 | |
| 4077 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4078 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4079 | /* y-plane */ |
| 4080 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 4081 | pstate, 1); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4082 | plane_y_data_rate[plane_id] = rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4083 | |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4084 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | return total_data_rate; |
| 4088 | } |
| 4089 | |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4090 | static uint16_t |
| 4091 | skl_ddb_min_alloc(const struct drm_plane_state *pstate, |
| 4092 | const int y) |
| 4093 | { |
| 4094 | struct drm_framebuffer *fb = pstate->fb; |
| 4095 | struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate); |
| 4096 | uint32_t src_w, src_h; |
| 4097 | uint32_t min_scanlines = 8; |
| 4098 | uint8_t plane_bpp; |
| 4099 | |
| 4100 | if (WARN_ON(!fb)) |
| 4101 | return 0; |
| 4102 | |
| 4103 | /* For packed formats, no y-plane, return 0 */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4104 | if (y && fb->format->format != DRM_FORMAT_NV12) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4105 | return 0; |
| 4106 | |
| 4107 | /* For Non Y-tile return 8-blocks */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 4108 | if (fb->modifier != I915_FORMAT_MOD_Y_TILED && |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 4109 | fb->modifier != I915_FORMAT_MOD_Yf_TILED && |
| 4110 | fb->modifier != I915_FORMAT_MOD_Y_TILED_CCS && |
| 4111 | fb->modifier != I915_FORMAT_MOD_Yf_TILED_CCS) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4112 | return 8; |
| 4113 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4114 | /* |
| 4115 | * Src coordinates are already rotated by 270 degrees for |
| 4116 | * the 90/270 degree plane rotation cases (to match the |
| 4117 | * GTT mapping), hence no need to account for rotation here. |
| 4118 | */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4119 | src_w = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4120 | src_h = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4121 | |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4122 | /* Halve UV plane width and height for NV12 */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4123 | if (fb->format->format == DRM_FORMAT_NV12 && !y) { |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4124 | src_w /= 2; |
| 4125 | src_h /= 2; |
| 4126 | } |
| 4127 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4128 | if (fb->format->format == DRM_FORMAT_NV12 && !y) |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4129 | plane_bpp = fb->format->cpp[1]; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4130 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4131 | plane_bpp = fb->format->cpp[0]; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4132 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 4133 | if (drm_rotation_90_or_270(pstate->rotation)) { |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 4134 | switch (plane_bpp) { |
| 4135 | case 1: |
| 4136 | min_scanlines = 32; |
| 4137 | break; |
| 4138 | case 2: |
| 4139 | min_scanlines = 16; |
| 4140 | break; |
| 4141 | case 4: |
| 4142 | min_scanlines = 8; |
| 4143 | break; |
| 4144 | case 8: |
| 4145 | min_scanlines = 4; |
| 4146 | break; |
| 4147 | default: |
| 4148 | WARN(1, "Unsupported pixel depth %u for rotation", |
| 4149 | plane_bpp); |
| 4150 | min_scanlines = 32; |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | return DIV_ROUND_UP((4 * src_w * plane_bpp), 512) * min_scanlines/4 + 3; |
| 4155 | } |
| 4156 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4157 | static void |
| 4158 | skl_ddb_calc_min(const struct intel_crtc_state *cstate, int num_active, |
| 4159 | uint16_t *minimum, uint16_t *y_minimum) |
| 4160 | { |
| 4161 | const struct drm_plane_state *pstate; |
| 4162 | struct drm_plane *plane; |
| 4163 | |
| 4164 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, &cstate->base) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4165 | enum plane_id plane_id = to_intel_plane(plane)->id; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4166 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4167 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4168 | continue; |
| 4169 | |
| 4170 | if (!pstate->visible) |
| 4171 | continue; |
| 4172 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4173 | minimum[plane_id] = skl_ddb_min_alloc(pstate, 0); |
| 4174 | y_minimum[plane_id] = skl_ddb_min_alloc(pstate, 1); |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | minimum[PLANE_CURSOR] = skl_cursor_allocation(num_active); |
| 4178 | } |
| 4179 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4180 | static int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4181 | skl_allocate_pipe_ddb(struct intel_crtc_state *cstate, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4182 | struct skl_ddb_allocation *ddb /* out */) |
| 4183 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4184 | struct drm_atomic_state *state = cstate->base.state; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4185 | struct drm_crtc *crtc = cstate->base.crtc; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4186 | struct drm_device *dev = crtc->dev; |
| 4187 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4188 | enum pipe pipe = intel_crtc->pipe; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4189 | struct skl_ddb_entry *alloc = &cstate->wm.skl.ddb; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4190 | uint16_t alloc_size, start; |
Maarten Lankhorst | fefdd81 | 2016-10-26 15:41:33 +0200 | [diff] [blame] | 4191 | uint16_t minimum[I915_MAX_PLANES] = {}; |
| 4192 | uint16_t y_minimum[I915_MAX_PLANES] = {}; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4193 | unsigned int total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4194 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4195 | int num_active; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4196 | unsigned plane_data_rate[I915_MAX_PLANES] = {}; |
| 4197 | unsigned plane_y_data_rate[I915_MAX_PLANES] = {}; |
Kumar, Mahesh | 5ba6faa | 2017-05-17 17:28:26 +0530 | [diff] [blame] | 4198 | uint16_t total_min_blocks = 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4199 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4200 | /* Clear the partitioning for disabled planes. */ |
| 4201 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 4202 | memset(ddb->y_plane[pipe], 0, sizeof(ddb->y_plane[pipe])); |
| 4203 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4204 | if (WARN_ON(!state)) |
| 4205 | return 0; |
| 4206 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4207 | if (!cstate->base.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4208 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4209 | return 0; |
| 4210 | } |
| 4211 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4212 | skl_ddb_get_pipe_allocation_limits(dev, cstate, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4213 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 4214 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4215 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4216 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4217 | skl_ddb_calc_min(cstate, num_active, minimum, y_minimum); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4218 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4219 | /* |
| 4220 | * 1. Allocate the mininum required blocks for each active plane |
| 4221 | * and allocate the cursor, it doesn't require extra allocation |
| 4222 | * proportional to the data rate. |
| 4223 | */ |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4224 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4225 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Kumar, Mahesh | 5ba6faa | 2017-05-17 17:28:26 +0530 | [diff] [blame] | 4226 | total_min_blocks += minimum[plane_id]; |
| 4227 | total_min_blocks += y_minimum[plane_id]; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 4228 | } |
| 4229 | |
Kumar, Mahesh | 5ba6faa | 2017-05-17 17:28:26 +0530 | [diff] [blame] | 4230 | if (total_min_blocks > alloc_size) { |
| 4231 | DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); |
| 4232 | DRM_DEBUG_KMS("minimum required %d/%d\n", total_min_blocks, |
| 4233 | alloc_size); |
| 4234 | return -EINVAL; |
| 4235 | } |
| 4236 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4237 | alloc_size -= total_min_blocks; |
| 4238 | ddb->plane[pipe][PLANE_CURSOR].start = alloc->end - minimum[PLANE_CURSOR]; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4239 | ddb->plane[pipe][PLANE_CURSOR].end = alloc->end; |
| 4240 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4241 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 4242 | * 2. Distribute the remaining space in proportion to the amount of |
| 4243 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4244 | * |
| 4245 | * FIXME: we may not allocate every single block here. |
| 4246 | */ |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4247 | total_data_rate = skl_get_total_relative_data_rate(cstate, |
| 4248 | plane_data_rate, |
| 4249 | plane_y_data_rate); |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4250 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4251 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4252 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4253 | start = alloc->start; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4254 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4255 | unsigned int data_rate, y_data_rate; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4256 | uint16_t plane_blocks, y_plane_blocks = 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4257 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4258 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4259 | continue; |
| 4260 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4261 | data_rate = plane_data_rate[plane_id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4262 | |
| 4263 | /* |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4264 | * allocation for (packed formats) or (uv-plane part of planar format): |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4265 | * promote the expression to 64 bits to avoid overflowing, the |
| 4266 | * result is < available as data_rate / total_data_rate < 1 |
| 4267 | */ |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4268 | plane_blocks = minimum[plane_id]; |
| 4269 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 4270 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4271 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4272 | /* Leave disabled planes at (0,0) */ |
| 4273 | if (data_rate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4274 | ddb->plane[pipe][plane_id].start = start; |
| 4275 | ddb->plane[pipe][plane_id].end = start + plane_blocks; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4276 | } |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4277 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4278 | start += plane_blocks; |
| 4279 | |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4280 | /* |
| 4281 | * allocation for y_plane part of planar format: |
| 4282 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4283 | y_data_rate = plane_y_data_rate[plane_id]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4284 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4285 | y_plane_blocks = y_minimum[plane_id]; |
| 4286 | y_plane_blocks += div_u64((uint64_t)alloc_size * y_data_rate, |
| 4287 | total_data_rate); |
| 4288 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4289 | if (y_data_rate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4290 | ddb->y_plane[pipe][plane_id].start = start; |
| 4291 | ddb->y_plane[pipe][plane_id].end = start + y_plane_blocks; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4292 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4293 | |
| 4294 | start += y_plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4295 | } |
| 4296 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4297 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4298 | } |
| 4299 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4300 | /* |
| 4301 | * 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] | 4302 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4303 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 4304 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 4305 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4306 | static uint_fixed_16_16_t |
| 4307 | skl_wm_method1(const struct drm_i915_private *dev_priv, uint32_t pixel_rate, |
| 4308 | uint8_t cpp, uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4309 | { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4310 | uint32_t wm_intermediate_val; |
| 4311 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4312 | |
| 4313 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4314 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4315 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4316 | wm_intermediate_val = latency * pixel_rate * cpp; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4317 | ret = div_fixed16(wm_intermediate_val, 1000 * 512); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 4318 | |
| 4319 | if (INTEL_GEN(dev_priv) >= 10) |
| 4320 | ret = add_fixed16_u32(ret, 1); |
| 4321 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4322 | return ret; |
| 4323 | } |
| 4324 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4325 | static uint_fixed_16_16_t skl_wm_method2(uint32_t pixel_rate, |
| 4326 | uint32_t pipe_htotal, |
| 4327 | uint32_t latency, |
| 4328 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4329 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4330 | uint32_t wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4331 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4332 | |
| 4333 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4334 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4335 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4336 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4337 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 4338 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4339 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4340 | return ret; |
| 4341 | } |
| 4342 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4343 | static uint_fixed_16_16_t |
| 4344 | intel_get_linetime_us(struct intel_crtc_state *cstate) |
| 4345 | { |
| 4346 | uint32_t pixel_rate; |
| 4347 | uint32_t crtc_htotal; |
| 4348 | uint_fixed_16_16_t linetime_us; |
| 4349 | |
| 4350 | if (!cstate->base.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4351 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4352 | |
| 4353 | pixel_rate = cstate->pixel_rate; |
| 4354 | |
| 4355 | if (WARN_ON(pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4356 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4357 | |
| 4358 | crtc_htotal = cstate->base.adjusted_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4359 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4360 | |
| 4361 | return linetime_us; |
| 4362 | } |
| 4363 | |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4364 | static uint32_t |
| 4365 | skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *cstate, |
| 4366 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4367 | { |
| 4368 | uint64_t adjusted_pixel_rate; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4369 | uint_fixed_16_16_t downscale_amount; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4370 | |
| 4371 | /* Shouldn't reach here on disabled planes... */ |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4372 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4373 | return 0; |
| 4374 | |
| 4375 | /* |
| 4376 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 4377 | * with additional adjustments for plane-specific scaling. |
| 4378 | */ |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 4379 | adjusted_pixel_rate = cstate->pixel_rate; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4380 | downscale_amount = skl_plane_downscale_amount(cstate, pstate); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4381 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4382 | return mul_round_up_u32_fixed16(adjusted_pixel_rate, |
| 4383 | downscale_amount); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4386 | static int |
| 4387 | skl_compute_plane_wm_params(const struct drm_i915_private *dev_priv, |
| 4388 | struct intel_crtc_state *cstate, |
| 4389 | const struct intel_plane_state *intel_pstate, |
| 4390 | struct skl_wm_params *wp) |
| 4391 | { |
| 4392 | struct intel_plane *plane = to_intel_plane(intel_pstate->base.plane); |
| 4393 | const struct drm_plane_state *pstate = &intel_pstate->base; |
| 4394 | const struct drm_framebuffer *fb = pstate->fb; |
| 4395 | uint32_t interm_pbpl; |
| 4396 | struct intel_atomic_state *state = |
| 4397 | to_intel_atomic_state(cstate->base.state); |
| 4398 | bool apply_memory_bw_wa = skl_needs_memory_bw_wa(state); |
| 4399 | |
| 4400 | if (!intel_wm_plane_visible(cstate, intel_pstate)) |
| 4401 | return 0; |
| 4402 | |
| 4403 | wp->y_tiled = fb->modifier == I915_FORMAT_MOD_Y_TILED || |
| 4404 | fb->modifier == I915_FORMAT_MOD_Yf_TILED || |
| 4405 | fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4406 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4407 | wp->x_tiled = fb->modifier == I915_FORMAT_MOD_X_TILED; |
| 4408 | wp->rc_surface = fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 4409 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 4410 | |
| 4411 | if (plane->id == PLANE_CURSOR) { |
| 4412 | wp->width = intel_pstate->base.crtc_w; |
| 4413 | } else { |
| 4414 | /* |
| 4415 | * Src coordinates are already rotated by 270 degrees for |
| 4416 | * the 90/270 degree plane rotation cases (to match the |
| 4417 | * GTT mapping), hence no need to account for rotation here. |
| 4418 | */ |
| 4419 | wp->width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4420 | } |
| 4421 | |
| 4422 | wp->cpp = (fb->format->format == DRM_FORMAT_NV12) ? fb->format->cpp[1] : |
| 4423 | fb->format->cpp[0]; |
| 4424 | wp->plane_pixel_rate = skl_adjusted_plane_pixel_rate(cstate, |
| 4425 | intel_pstate); |
| 4426 | |
| 4427 | if (drm_rotation_90_or_270(pstate->rotation)) { |
| 4428 | |
| 4429 | switch (wp->cpp) { |
| 4430 | case 1: |
| 4431 | wp->y_min_scanlines = 16; |
| 4432 | break; |
| 4433 | case 2: |
| 4434 | wp->y_min_scanlines = 8; |
| 4435 | break; |
| 4436 | case 4: |
| 4437 | wp->y_min_scanlines = 4; |
| 4438 | break; |
| 4439 | default: |
| 4440 | MISSING_CASE(wp->cpp); |
| 4441 | return -EINVAL; |
| 4442 | } |
| 4443 | } else { |
| 4444 | wp->y_min_scanlines = 4; |
| 4445 | } |
| 4446 | |
| 4447 | if (apply_memory_bw_wa) |
| 4448 | wp->y_min_scanlines *= 2; |
| 4449 | |
| 4450 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 4451 | if (wp->y_tiled) { |
| 4452 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
| 4453 | wp->y_min_scanlines, 512); |
| 4454 | |
| 4455 | if (INTEL_GEN(dev_priv) >= 10) |
| 4456 | interm_pbpl++; |
| 4457 | |
| 4458 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 4459 | wp->y_min_scanlines); |
| 4460 | } else if (wp->x_tiled && IS_GEN9(dev_priv)) { |
| 4461 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, 512); |
| 4462 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4463 | } else { |
| 4464 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, 512) + 1; |
| 4465 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 4466 | } |
| 4467 | |
| 4468 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 4469 | wp->plane_blocks_per_line); |
| 4470 | wp->linetime_us = fixed16_to_u32_round_up( |
| 4471 | intel_get_linetime_us(cstate)); |
| 4472 | |
| 4473 | return 0; |
| 4474 | } |
| 4475 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4476 | static int skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 4477 | struct intel_crtc_state *cstate, |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4478 | const struct intel_plane_state *intel_pstate, |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4479 | uint16_t ddb_allocation, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4480 | int level, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4481 | const struct skl_wm_params *wp, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4482 | uint16_t *out_blocks, /* out */ |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4483 | uint8_t *out_lines, /* out */ |
| 4484 | bool *enabled /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4485 | { |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4486 | const struct drm_plane_state *pstate = &intel_pstate->base; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4487 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4488 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4489 | uint_fixed_16_16_t selected_result; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4490 | uint32_t res_blocks, res_lines; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4491 | struct intel_atomic_state *state = |
| 4492 | to_intel_atomic_state(cstate->base.state); |
| 4493 | bool apply_memory_bw_wa = skl_needs_memory_bw_wa(state); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4494 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4495 | if (latency == 0 || |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4496 | !intel_wm_plane_visible(cstate, intel_pstate)) { |
| 4497 | *enabled = false; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4498 | return 0; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4499 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4500 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4501 | /* Display WA #1141: kbl,cfl */ |
Kumar, Mahesh | d86ba62 | 2017-08-17 19:15:26 +0530 | [diff] [blame] | 4502 | if ((IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || |
| 4503 | IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) && |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 4504 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 4505 | latency += 4; |
| 4506 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4507 | if (apply_memory_bw_wa && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4508 | latency += 15; |
| 4509 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4510 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
| 4511 | wp->cpp, latency); |
| 4512 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4513 | cstate->base.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4514 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4515 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4516 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4517 | if (wp->y_tiled) { |
| 4518 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4519 | } else { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4520 | if ((wp->cpp * cstate->base.adjusted_mode.crtc_htotal / |
| 4521 | 512 < 1) && (wp->plane_bytes_per_line / 512 < 1)) |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 4522 | selected_result = method2; |
Maarten Lankhorst | 54d20ed | 2017-07-17 14:02:30 +0200 | [diff] [blame] | 4523 | else if (ddb_allocation >= |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4524 | fixed16_to_u32_round_up(wp->plane_blocks_per_line)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4525 | selected_result = min_fixed16(method1, method2); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4526 | else if (latency >= wp->linetime_us) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4527 | selected_result = min_fixed16(method1, method2); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4528 | else |
| 4529 | selected_result = method1; |
| 4530 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4531 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4532 | res_blocks = fixed16_to_u32_round_up(selected_result) + 1; |
Kumar, Mahesh | d273ecc | 2017-05-17 17:28:22 +0530 | [diff] [blame] | 4533 | res_lines = div_round_up_fixed16(selected_result, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4534 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4535 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 4536 | /* Display WA #1125: skl,bxt,kbl,glk */ |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4537 | if (level == 0 && wp->rc_surface) |
| 4538 | res_blocks += fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 4539 | |
| 4540 | /* Display WA #1126: skl,bxt,kbl,glk */ |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4541 | if (level >= 1 && level <= 7) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4542 | if (wp->y_tiled) { |
| 4543 | res_blocks += fixed16_to_u32_round_up( |
| 4544 | wp->y_tile_minimum); |
| 4545 | res_lines += wp->y_min_scanlines; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4546 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4547 | res_blocks++; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4548 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4549 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4550 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4551 | if (res_blocks >= ddb_allocation || res_lines > 31) { |
| 4552 | *enabled = false; |
Matt Roper | 6b6bada | 2016-05-12 07:06:10 -0700 | [diff] [blame] | 4553 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4554 | /* |
| 4555 | * If there are no valid level 0 watermarks, then we can't |
| 4556 | * support this display configuration. |
| 4557 | */ |
| 4558 | if (level) { |
| 4559 | return 0; |
| 4560 | } else { |
| 4561 | struct drm_plane *plane = pstate->plane; |
| 4562 | |
| 4563 | DRM_DEBUG_KMS("Requested display configuration exceeds system watermark limitations\n"); |
| 4564 | DRM_DEBUG_KMS("[PLANE:%d:%s] blocks required = %u/%u, lines required = %u/31\n", |
| 4565 | plane->base.id, plane->name, |
| 4566 | res_blocks, ddb_allocation, res_lines); |
| 4567 | return -EINVAL; |
| 4568 | } |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4569 | } |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4570 | |
| 4571 | *out_blocks = res_blocks; |
| 4572 | *out_lines = res_lines; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4573 | *enabled = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4574 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4575 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4576 | } |
| 4577 | |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4578 | static int |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4579 | skl_compute_wm_levels(const struct drm_i915_private *dev_priv, |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4580 | struct skl_ddb_allocation *ddb, |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4581 | struct intel_crtc_state *cstate, |
| 4582 | const struct intel_plane_state *intel_pstate, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4583 | const struct skl_wm_params *wm_params, |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4584 | struct skl_plane_wm *wm) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4585 | { |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4586 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
| 4587 | struct drm_plane *plane = intel_pstate->base.plane; |
| 4588 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 4589 | uint16_t ddb_blocks; |
| 4590 | enum pipe pipe = intel_crtc->pipe; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4591 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4592 | int ret; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4593 | |
Kumar, Mahesh | 7b75119 | 2017-05-17 17:28:24 +0530 | [diff] [blame] | 4594 | if (WARN_ON(!intel_pstate->base.fb)) |
| 4595 | return -EINVAL; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4596 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4597 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][intel_plane->id]); |
| 4598 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4599 | for (level = 0; level <= max_level; level++) { |
| 4600 | struct skl_wm_level *result = &wm->wm[level]; |
| 4601 | |
| 4602 | ret = skl_compute_plane_wm(dev_priv, |
| 4603 | cstate, |
| 4604 | intel_pstate, |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4605 | ddb_blocks, |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4606 | level, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4607 | wm_params, |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4608 | &result->plane_res_b, |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4609 | &result->plane_res_l, |
| 4610 | &result->plane_en); |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4611 | if (ret) |
| 4612 | return ret; |
| 4613 | } |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4614 | |
| 4615 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4616 | } |
| 4617 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4618 | static uint32_t |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4619 | skl_compute_linetime_wm(struct intel_crtc_state *cstate) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4620 | { |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4621 | struct drm_atomic_state *state = cstate->base.state; |
| 4622 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4623 | uint_fixed_16_16_t linetime_us; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4624 | uint32_t linetime_wm; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4625 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 4626 | linetime_us = intel_get_linetime_us(cstate); |
| 4627 | |
| 4628 | if (is_fixed16_zero(linetime_us)) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4629 | return 0; |
| 4630 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4631 | 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] | 4632 | |
Kumar, Mahesh | 446e850 | 2017-08-17 19:15:25 +0530 | [diff] [blame] | 4633 | /* Display WA #1135: bxt:ALL GLK:ALL */ |
| 4634 | if ((IS_BROXTON(dev_priv) || IS_GEMINILAKE(dev_priv)) && |
| 4635 | dev_priv->ipc_enabled) |
| 4636 | linetime_wm /= 2; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4637 | |
| 4638 | return linetime_wm; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4641 | static void skl_compute_transition_wm(struct intel_crtc_state *cstate, |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4642 | struct skl_wm_params *wp, |
| 4643 | struct skl_wm_level *wm_l0, |
| 4644 | uint16_t ddb_allocation, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4645 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4646 | { |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4647 | struct drm_device *dev = cstate->base.crtc->dev; |
| 4648 | const struct drm_i915_private *dev_priv = to_i915(dev); |
| 4649 | uint16_t trans_min, trans_y_tile_min; |
| 4650 | const uint16_t trans_amount = 10; /* This is configurable amount */ |
| 4651 | uint16_t trans_offset_b, res_blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4652 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4653 | if (!cstate->base.active) |
| 4654 | goto exit; |
| 4655 | |
| 4656 | /* Transition WM are not recommended by HW team for GEN9 */ |
| 4657 | if (INTEL_GEN(dev_priv) <= 9) |
| 4658 | goto exit; |
| 4659 | |
| 4660 | /* Transition WM don't make any sense if ipc is disabled */ |
| 4661 | if (!dev_priv->ipc_enabled) |
| 4662 | goto exit; |
| 4663 | |
| 4664 | if (INTEL_GEN(dev_priv) >= 10) |
| 4665 | trans_min = 4; |
| 4666 | |
| 4667 | trans_offset_b = trans_min + trans_amount; |
| 4668 | |
| 4669 | if (wp->y_tiled) { |
| 4670 | trans_y_tile_min = (uint16_t) mul_round_up_u32_fixed16(2, |
| 4671 | wp->y_tile_minimum); |
| 4672 | res_blocks = max(wm_l0->plane_res_b, trans_y_tile_min) + |
| 4673 | trans_offset_b; |
| 4674 | } else { |
| 4675 | res_blocks = wm_l0->plane_res_b + trans_offset_b; |
| 4676 | |
| 4677 | /* WA BUG:1938466 add one block for non y-tile planes */ |
| 4678 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_A0)) |
| 4679 | res_blocks += 1; |
| 4680 | |
| 4681 | } |
| 4682 | |
| 4683 | res_blocks += 1; |
| 4684 | |
| 4685 | if (res_blocks < ddb_allocation) { |
| 4686 | trans_wm->plane_res_b = res_blocks; |
| 4687 | trans_wm->plane_en = true; |
| 4688 | return; |
| 4689 | } |
| 4690 | |
| 4691 | exit: |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4692 | trans_wm->plane_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4693 | } |
| 4694 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4695 | static int skl_build_pipe_wm(struct intel_crtc_state *cstate, |
| 4696 | struct skl_ddb_allocation *ddb, |
| 4697 | struct skl_pipe_wm *pipe_wm) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4698 | { |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4699 | struct drm_device *dev = cstate->base.crtc->dev; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4700 | struct drm_crtc_state *crtc_state = &cstate->base; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4701 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4702 | struct drm_plane *plane; |
| 4703 | const struct drm_plane_state *pstate; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4704 | struct skl_plane_wm *wm; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4705 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4706 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4707 | /* |
| 4708 | * We'll only calculate watermarks for planes that are actually |
| 4709 | * enabled, so make sure all other planes are set as disabled. |
| 4710 | */ |
| 4711 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 4712 | |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4713 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { |
| 4714 | const struct intel_plane_state *intel_pstate = |
| 4715 | to_intel_plane_state(pstate); |
| 4716 | enum plane_id plane_id = to_intel_plane(plane)->id; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4717 | struct skl_wm_params wm_params; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4718 | enum pipe pipe = to_intel_crtc(cstate->base.crtc)->pipe; |
| 4719 | uint16_t ddb_blocks; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 4720 | |
| 4721 | wm = &pipe_wm->planes[plane_id]; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4722 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][plane_id]); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4723 | memset(&wm_params, 0, sizeof(struct skl_wm_params)); |
| 4724 | |
| 4725 | ret = skl_compute_plane_wm_params(dev_priv, cstate, |
| 4726 | intel_pstate, &wm_params); |
| 4727 | if (ret) |
| 4728 | return ret; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4729 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4730 | ret = skl_compute_wm_levels(dev_priv, ddb, cstate, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 4731 | intel_pstate, &wm_params, wm); |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 4732 | if (ret) |
| 4733 | return ret; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 4734 | skl_compute_transition_wm(cstate, &wm_params, &wm->wm[0], |
| 4735 | ddb_blocks, &wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4736 | } |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4737 | pipe_wm->linetime = skl_compute_linetime_wm(cstate); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4738 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4739 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4740 | } |
| 4741 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4742 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 4743 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 4744 | const struct skl_ddb_entry *entry) |
| 4745 | { |
| 4746 | if (entry->end) |
| 4747 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 4748 | else |
| 4749 | I915_WRITE(reg, 0); |
| 4750 | } |
| 4751 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4752 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 4753 | i915_reg_t reg, |
| 4754 | const struct skl_wm_level *level) |
| 4755 | { |
| 4756 | uint32_t val = 0; |
| 4757 | |
| 4758 | if (level->plane_en) { |
| 4759 | val |= PLANE_WM_EN; |
| 4760 | val |= level->plane_res_b; |
| 4761 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
| 4762 | } |
| 4763 | |
| 4764 | I915_WRITE(reg, val); |
| 4765 | } |
| 4766 | |
Ville Syrjälä | d9348de | 2016-11-22 22:21:53 +0200 | [diff] [blame] | 4767 | static void skl_write_plane_wm(struct intel_crtc *intel_crtc, |
| 4768 | const struct skl_plane_wm *wm, |
| 4769 | const struct skl_ddb_allocation *ddb, |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4770 | enum plane_id plane_id) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4771 | { |
| 4772 | struct drm_crtc *crtc = &intel_crtc->base; |
| 4773 | struct drm_device *dev = crtc->dev; |
| 4774 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4775 | int level, max_level = ilk_wm_max_level(dev_priv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4776 | enum pipe pipe = intel_crtc->pipe; |
| 4777 | |
| 4778 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4779 | 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] | 4780 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4781 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4782 | 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] | 4783 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4784 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4785 | skl_ddb_entry_write(dev_priv, PLANE_BUF_CFG(pipe, plane_id), |
| 4786 | &ddb->plane[pipe][plane_id]); |
| 4787 | skl_ddb_entry_write(dev_priv, PLANE_NV12_BUF_CFG(pipe, plane_id), |
| 4788 | &ddb->y_plane[pipe][plane_id]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4789 | } |
| 4790 | |
Ville Syrjälä | d9348de | 2016-11-22 22:21:53 +0200 | [diff] [blame] | 4791 | static void skl_write_cursor_wm(struct intel_crtc *intel_crtc, |
| 4792 | const struct skl_plane_wm *wm, |
| 4793 | const struct skl_ddb_allocation *ddb) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4794 | { |
| 4795 | struct drm_crtc *crtc = &intel_crtc->base; |
| 4796 | struct drm_device *dev = crtc->dev; |
| 4797 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4798 | int level, max_level = ilk_wm_max_level(dev_priv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4799 | enum pipe pipe = intel_crtc->pipe; |
| 4800 | |
| 4801 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4802 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 4803 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4804 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4805 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4806 | |
| 4807 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4808 | &ddb->plane[pipe][PLANE_CURSOR]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4809 | } |
| 4810 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 4811 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 4812 | const struct skl_wm_level *l2) |
| 4813 | { |
| 4814 | if (l1->plane_en != l2->plane_en) |
| 4815 | return false; |
| 4816 | |
| 4817 | /* If both planes aren't enabled, the rest shouldn't matter */ |
| 4818 | if (!l1->plane_en) |
| 4819 | return true; |
| 4820 | |
| 4821 | return (l1->plane_res_l == l2->plane_res_l && |
| 4822 | l1->plane_res_b == l2->plane_res_b); |
| 4823 | } |
| 4824 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4825 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 4826 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4827 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4828 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4829 | } |
| 4830 | |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 4831 | bool skl_ddb_allocation_overlaps(struct drm_i915_private *dev_priv, |
| 4832 | const struct skl_ddb_entry **entries, |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 4833 | const struct skl_ddb_entry *ddb, |
| 4834 | int ignore) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4835 | { |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 4836 | enum pipe pipe; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4837 | |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 4838 | for_each_pipe(dev_priv, pipe) { |
| 4839 | if (pipe != ignore && entries[pipe] && |
| 4840 | skl_ddb_entries_overlap(ddb, entries[pipe])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4841 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 4842 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4843 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4844 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4845 | } |
| 4846 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4847 | static int skl_update_pipe_wm(struct drm_crtc_state *cstate, |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4848 | const struct skl_pipe_wm *old_pipe_wm, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4849 | struct skl_pipe_wm *pipe_wm, /* out */ |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4850 | struct skl_ddb_allocation *ddb, /* out */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4851 | bool *changed /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4852 | { |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4853 | struct intel_crtc_state *intel_cstate = to_intel_crtc_state(cstate); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4854 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4855 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4856 | ret = skl_build_pipe_wm(intel_cstate, ddb, pipe_wm); |
| 4857 | if (ret) |
| 4858 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4859 | |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4860 | if (!memcmp(old_pipe_wm, pipe_wm, sizeof(*pipe_wm))) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4861 | *changed = false; |
| 4862 | else |
| 4863 | *changed = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4864 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4865 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4868 | static uint32_t |
| 4869 | pipes_modified(struct drm_atomic_state *state) |
| 4870 | { |
| 4871 | struct drm_crtc *crtc; |
| 4872 | struct drm_crtc_state *cstate; |
| 4873 | uint32_t i, ret = 0; |
| 4874 | |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 4875 | for_each_new_crtc_in_state(state, crtc, cstate, i) |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4876 | ret |= drm_crtc_mask(crtc); |
| 4877 | |
| 4878 | return ret; |
| 4879 | } |
| 4880 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 4881 | static int |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4882 | skl_ddb_add_affected_planes(struct intel_crtc_state *cstate) |
| 4883 | { |
| 4884 | struct drm_atomic_state *state = cstate->base.state; |
| 4885 | struct drm_device *dev = state->dev; |
| 4886 | struct drm_crtc *crtc = cstate->base.crtc; |
| 4887 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4888 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 4889 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4890 | struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb; |
| 4891 | struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 4892 | struct drm_plane_state *plane_state; |
| 4893 | struct drm_plane *plane; |
| 4894 | enum pipe pipe = intel_crtc->pipe; |
| 4895 | |
| 4896 | WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc)); |
| 4897 | |
| 4898 | drm_for_each_plane_mask(plane, dev, cstate->base.plane_mask) { |
| 4899 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 4900 | |
| 4901 | if (skl_ddb_entry_equal(&cur_ddb->plane[pipe][plane_id], |
| 4902 | &new_ddb->plane[pipe][plane_id]) && |
| 4903 | skl_ddb_entry_equal(&cur_ddb->y_plane[pipe][plane_id], |
| 4904 | &new_ddb->y_plane[pipe][plane_id])) |
| 4905 | continue; |
| 4906 | |
| 4907 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 4908 | if (IS_ERR(plane_state)) |
| 4909 | return PTR_ERR(plane_state); |
| 4910 | } |
| 4911 | |
| 4912 | return 0; |
| 4913 | } |
| 4914 | |
| 4915 | static int |
| 4916 | skl_compute_ddb(struct drm_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4917 | { |
| 4918 | struct drm_device *dev = state->dev; |
| 4919 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 4920 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4921 | struct intel_crtc *intel_crtc; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4922 | struct skl_ddb_allocation *ddb = &intel_state->wm_results.ddb; |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4923 | uint32_t realloc_pipes = pipes_modified(state); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4924 | int ret; |
| 4925 | |
| 4926 | /* |
| 4927 | * If this is our first atomic update following hardware readout, |
| 4928 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 4929 | * pretend that all pipes switched active status so that we'll |
| 4930 | * ensure a full DDB recompute. |
| 4931 | */ |
Matt Roper | 1b54a88 | 2016-06-17 13:42:18 -0700 | [diff] [blame] | 4932 | if (dev_priv->wm.distrust_bios_wm) { |
| 4933 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
| 4934 | state->acquire_ctx); |
| 4935 | if (ret) |
| 4936 | return ret; |
| 4937 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4938 | intel_state->active_pipe_changes = ~0; |
| 4939 | |
Matt Roper | 1b54a88 | 2016-06-17 13:42:18 -0700 | [diff] [blame] | 4940 | /* |
| 4941 | * We usually only initialize intel_state->active_crtcs if we |
| 4942 | * we're doing a modeset; make sure this field is always |
| 4943 | * initialized during the sanitization process that happens |
| 4944 | * on the first commit too. |
| 4945 | */ |
| 4946 | if (!intel_state->modeset) |
| 4947 | intel_state->active_crtcs = dev_priv->active_crtcs; |
| 4948 | } |
| 4949 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4950 | /* |
| 4951 | * If the modeset changes which CRTC's are active, we need to |
| 4952 | * recompute the DDB allocation for *all* active pipes, even |
| 4953 | * those that weren't otherwise being modified in any way by this |
| 4954 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 4955 | * when new active CRTC's are added, it's possible for a pipe that |
| 4956 | * we were already using and aren't changing at all here to suddenly |
| 4957 | * become invalid if its DDB needs exceeds its new allocation. |
| 4958 | * |
| 4959 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 4960 | * any other display updates race with this transaction, so we need |
| 4961 | * to grab the lock on *all* CRTC's. |
| 4962 | */ |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4963 | if (intel_state->active_pipe_changes) { |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4964 | realloc_pipes = ~0; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4965 | intel_state->wm_results.dirty_pipes = ~0; |
| 4966 | } |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4967 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4968 | /* |
| 4969 | * We're not recomputing for the pipes not included in the commit, so |
| 4970 | * make sure we start with the current state. |
| 4971 | */ |
| 4972 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 4973 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4974 | for_each_intel_crtc_mask(dev, intel_crtc, realloc_pipes) { |
| 4975 | struct intel_crtc_state *cstate; |
| 4976 | |
| 4977 | cstate = intel_atomic_get_crtc_state(state, intel_crtc); |
| 4978 | if (IS_ERR(cstate)) |
| 4979 | return PTR_ERR(cstate); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4980 | |
| 4981 | ret = skl_allocate_pipe_ddb(cstate, ddb); |
| 4982 | if (ret) |
| 4983 | return ret; |
| 4984 | |
| 4985 | ret = skl_ddb_add_affected_planes(cstate); |
| 4986 | if (ret) |
| 4987 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | return 0; |
| 4991 | } |
| 4992 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4993 | static void |
| 4994 | skl_copy_wm_for_pipe(struct skl_wm_values *dst, |
| 4995 | struct skl_wm_values *src, |
| 4996 | enum pipe pipe) |
| 4997 | { |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4998 | memcpy(dst->ddb.y_plane[pipe], src->ddb.y_plane[pipe], |
| 4999 | sizeof(dst->ddb.y_plane[pipe])); |
| 5000 | memcpy(dst->ddb.plane[pipe], src->ddb.plane[pipe], |
| 5001 | sizeof(dst->ddb.plane[pipe])); |
| 5002 | } |
| 5003 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5004 | static void |
| 5005 | skl_print_wm_changes(const struct drm_atomic_state *state) |
| 5006 | { |
| 5007 | const struct drm_device *dev = state->dev; |
| 5008 | const struct drm_i915_private *dev_priv = to_i915(dev); |
| 5009 | const struct intel_atomic_state *intel_state = |
| 5010 | to_intel_atomic_state(state); |
| 5011 | const struct drm_crtc *crtc; |
| 5012 | const struct drm_crtc_state *cstate; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5013 | const struct intel_plane *intel_plane; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5014 | const struct skl_ddb_allocation *old_ddb = &dev_priv->wm.skl_hw.ddb; |
| 5015 | const struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5016 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5017 | |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 5018 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5019 | const struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5020 | enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5021 | |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5022 | for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5023 | enum plane_id plane_id = intel_plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5024 | const struct skl_ddb_entry *old, *new; |
| 5025 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5026 | old = &old_ddb->plane[pipe][plane_id]; |
| 5027 | new = &new_ddb->plane[pipe][plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5028 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5029 | if (skl_ddb_entry_equal(old, new)) |
| 5030 | continue; |
| 5031 | |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5032 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] ddb (%d - %d) -> (%d - %d)\n", |
| 5033 | intel_plane->base.base.id, |
| 5034 | intel_plane->base.name, |
| 5035 | old->start, old->end, |
| 5036 | new->start, new->end); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5037 | } |
| 5038 | } |
| 5039 | } |
| 5040 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5041 | static int |
| 5042 | skl_compute_wm(struct drm_atomic_state *state) |
| 5043 | { |
| 5044 | struct drm_crtc *crtc; |
| 5045 | struct drm_crtc_state *cstate; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5046 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 5047 | struct skl_wm_values *results = &intel_state->wm_results; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5048 | struct drm_device *dev = state->dev; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5049 | struct skl_pipe_wm *pipe_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5050 | bool changed = false; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5051 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5052 | |
| 5053 | /* |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5054 | * When we distrust bios wm we always need to recompute to set the |
| 5055 | * expected DDB allocations for each CRTC. |
| 5056 | */ |
| 5057 | if (to_i915(dev)->wm.distrust_bios_wm) |
| 5058 | changed = true; |
| 5059 | |
| 5060 | /* |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5061 | * If this transaction isn't actually touching any CRTC's, don't |
| 5062 | * bother with watermark calculation. Note that if we pass this |
| 5063 | * test, we're guaranteed to hold at least one CRTC state mutex, |
| 5064 | * which means we can safely use values like dev_priv->active_crtcs |
| 5065 | * since any racing commits that want to update them would need to |
| 5066 | * hold _all_ CRTC state mutexes. |
| 5067 | */ |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 5068 | for_each_new_crtc_in_state(state, crtc, cstate, i) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5069 | changed = true; |
Maarten Lankhorst | 367d73d | 2017-05-31 17:42:36 +0200 | [diff] [blame] | 5070 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5071 | if (!changed) |
| 5072 | return 0; |
| 5073 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5074 | /* Clear all dirty flags */ |
| 5075 | results->dirty_pipes = 0; |
| 5076 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5077 | ret = skl_compute_ddb(state); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5078 | if (ret) |
| 5079 | return ret; |
| 5080 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5081 | /* |
| 5082 | * Calculate WM's for all pipes that are part of this transaction. |
| 5083 | * Note that the DDB allocation above may have added more CRTC's that |
| 5084 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 5085 | * pipe allocations had to change. |
| 5086 | * |
| 5087 | * FIXME: Now that we're doing this in the atomic check phase, we |
| 5088 | * should allow skl_update_pipe_wm() to return failure in cases where |
| 5089 | * no suitable watermark values can be found. |
| 5090 | */ |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 5091 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5092 | struct intel_crtc_state *intel_cstate = |
| 5093 | to_intel_crtc_state(cstate); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5094 | const struct skl_pipe_wm *old_pipe_wm = |
| 5095 | &to_intel_crtc_state(crtc->state)->wm.skl.optimal; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5096 | |
| 5097 | pipe_wm = &intel_cstate->wm.skl.optimal; |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5098 | ret = skl_update_pipe_wm(cstate, old_pipe_wm, pipe_wm, |
| 5099 | &results->ddb, &changed); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5100 | if (ret) |
| 5101 | return ret; |
| 5102 | |
| 5103 | if (changed) |
| 5104 | results->dirty_pipes |= drm_crtc_mask(crtc); |
| 5105 | |
| 5106 | if ((results->dirty_pipes & drm_crtc_mask(crtc)) == 0) |
| 5107 | /* This pipe's WM's did not change */ |
| 5108 | continue; |
| 5109 | |
| 5110 | intel_cstate->update_wm_pre = true; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5111 | } |
| 5112 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5113 | skl_print_wm_changes(state); |
| 5114 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5115 | return 0; |
| 5116 | } |
| 5117 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5118 | static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state, |
| 5119 | struct intel_crtc_state *cstate) |
| 5120 | { |
| 5121 | struct intel_crtc *crtc = to_intel_crtc(cstate->base.crtc); |
| 5122 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5123 | struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5124 | const struct skl_ddb_allocation *ddb = &state->wm_results.ddb; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5125 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5126 | enum plane_id plane_id; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5127 | |
| 5128 | if (!(state->wm_results.dirty_pipes & drm_crtc_mask(&crtc->base))) |
| 5129 | return; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5130 | |
| 5131 | I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5132 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5133 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5134 | if (plane_id != PLANE_CURSOR) |
| 5135 | skl_write_plane_wm(crtc, &pipe_wm->planes[plane_id], |
| 5136 | ddb, plane_id); |
| 5137 | else |
| 5138 | skl_write_cursor_wm(crtc, &pipe_wm->planes[plane_id], |
| 5139 | ddb); |
| 5140 | } |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5141 | } |
| 5142 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5143 | static void skl_initial_wm(struct intel_atomic_state *state, |
| 5144 | struct intel_crtc_state *cstate) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5145 | { |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5146 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5147 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5148 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5149 | struct skl_wm_values *results = &state->wm_results; |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 5150 | struct skl_wm_values *hw_vals = &dev_priv->wm.skl_hw; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5151 | enum pipe pipe = intel_crtc->pipe; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 5152 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5153 | if ((results->dirty_pipes & drm_crtc_mask(&intel_crtc->base)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5154 | return; |
| 5155 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5156 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5157 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 5158 | if (cstate->base.active_changed) |
| 5159 | skl_atomic_update_crtc_wm(state, cstate); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5160 | |
| 5161 | skl_copy_wm_for_pipe(hw_vals, results, pipe); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 5162 | |
| 5163 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5166 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 5167 | struct intel_wm_config *config) |
| 5168 | { |
| 5169 | struct intel_crtc *crtc; |
| 5170 | |
| 5171 | /* Compute the currently _active_ config */ |
| 5172 | for_each_intel_crtc(dev, crtc) { |
| 5173 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 5174 | |
| 5175 | if (!wm->pipe_enabled) |
| 5176 | continue; |
| 5177 | |
| 5178 | config->sprites_enabled |= wm->sprites_enabled; |
| 5179 | config->sprites_scaled |= wm->sprites_scaled; |
| 5180 | config->num_pipes_active++; |
| 5181 | } |
| 5182 | } |
| 5183 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5184 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 5185 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 5186 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5187 | 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] | 5188 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5189 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5190 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5191 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 5192 | |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5193 | ilk_compute_wm_config(dev, &config); |
| 5194 | |
| 5195 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 5196 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 5197 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5198 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5199 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 5200 | config.num_pipes_active == 1 && config.sprites_enabled) { |
| 5201 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 5202 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 5203 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5204 | best_lp_wm = ilk_find_best_result(dev, &lp_wm_1_2, &lp_wm_5_6); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5205 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5206 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5207 | } |
| 5208 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 5209 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 5210 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 5211 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5212 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 5213 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5214 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 5215 | } |
| 5216 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5217 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
| 5218 | struct intel_crtc_state *cstate) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5219 | { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5220 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 5221 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5222 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5223 | mutex_lock(&dev_priv->wm.wm_mutex); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5224 | intel_crtc->wm.active.ilk = cstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5225 | ilk_program_watermarks(dev_priv); |
| 5226 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5227 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5228 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5229 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
| 5230 | struct intel_crtc_state *cstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5231 | { |
| 5232 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 5233 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
| 5234 | |
| 5235 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5236 | if (cstate->wm.need_postvbl_update) { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5237 | intel_crtc->wm.active.ilk = cstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5238 | ilk_program_watermarks(dev_priv); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5239 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5240 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5243 | static inline void skl_wm_level_from_reg_val(uint32_t val, |
| 5244 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5245 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5246 | level->plane_en = val & PLANE_WM_EN; |
| 5247 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 5248 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 5249 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5250 | } |
| 5251 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5252 | void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc, |
| 5253 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5254 | { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5255 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5256 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5257 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5258 | int level, max_level; |
| 5259 | enum plane_id plane_id; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5260 | uint32_t val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5261 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5262 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5263 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5264 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 5265 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5266 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5267 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5268 | if (plane_id != PLANE_CURSOR) |
| 5269 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5270 | else |
| 5271 | val = I915_READ(CUR_WM(pipe, level)); |
| 5272 | |
| 5273 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 5274 | } |
| 5275 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5276 | if (plane_id != PLANE_CURSOR) |
| 5277 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5278 | else |
| 5279 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 5280 | |
| 5281 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 5282 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5283 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 5284 | if (!intel_crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5285 | return; |
| 5286 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5287 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 5291 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5292 | struct drm_i915_private *dev_priv = to_i915(dev); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5293 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5294 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5295 | struct drm_crtc *crtc; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5296 | struct intel_crtc *intel_crtc; |
| 5297 | struct intel_crtc_state *cstate; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5298 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5299 | skl_ddb_get_hw_state(dev_priv, ddb); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5300 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 5301 | intel_crtc = to_intel_crtc(crtc); |
| 5302 | cstate = to_intel_crtc_state(crtc->state); |
| 5303 | |
| 5304 | skl_pipe_wm_get_hw_state(crtc, &cstate->wm.skl.optimal); |
| 5305 | |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5306 | if (intel_crtc->active) |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5307 | hw->dirty_pipes |= drm_crtc_mask(crtc); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5308 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5309 | |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5310 | if (dev_priv->active_crtcs) { |
| 5311 | /* Fully recompute DDB on first atomic commit */ |
| 5312 | dev_priv->wm.distrust_bios_wm = true; |
| 5313 | } else { |
| 5314 | /* Easy/common case; just sanitize DDB now if everything off */ |
| 5315 | memset(ddb, 0, sizeof(*ddb)); |
| 5316 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5319 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 5320 | { |
| 5321 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5322 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5323 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5324 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5325 | struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5326 | struct intel_pipe_wm *active = &cstate->wm.ilk.optimal; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5327 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5328 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5329 | [PIPE_A] = WM0_PIPEA_ILK, |
| 5330 | [PIPE_B] = WM0_PIPEB_ILK, |
| 5331 | [PIPE_C] = WM0_PIPEC_IVB, |
| 5332 | }; |
| 5333 | |
| 5334 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5335 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 5336 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5337 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 5338 | memset(active, 0, sizeof(*active)); |
| 5339 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 5340 | active->pipe_enabled = intel_crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 5341 | |
| 5342 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5343 | u32 tmp = hw->wm_pipe[pipe]; |
| 5344 | |
| 5345 | /* |
| 5346 | * For active pipes LP0 watermark is marked as |
| 5347 | * enabled, and LP1+ watermaks as disabled since |
| 5348 | * we can't really reverse compute them in case |
| 5349 | * multiple pipes are active. |
| 5350 | */ |
| 5351 | active->wm[0].enable = true; |
| 5352 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 5353 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 5354 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 5355 | active->linetime = hw->wm_linetime[pipe]; |
| 5356 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5357 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5358 | |
| 5359 | /* |
| 5360 | * For inactive pipes, all watermark levels |
| 5361 | * should be marked as enabled but zeroed, |
| 5362 | * which is what we'd compute them to. |
| 5363 | */ |
| 5364 | for (level = 0; level <= max_level; level++) |
| 5365 | active->wm[level].enable = true; |
| 5366 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5367 | |
| 5368 | intel_crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5369 | } |
| 5370 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5371 | #define _FW_WM(value, plane) \ |
| 5372 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 5373 | #define _FW_WM_VLV(value, plane) \ |
| 5374 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 5375 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5376 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 5377 | struct g4x_wm_values *wm) |
| 5378 | { |
| 5379 | uint32_t tmp; |
| 5380 | |
| 5381 | tmp = I915_READ(DSPFW1); |
| 5382 | wm->sr.plane = _FW_WM(tmp, SR); |
| 5383 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5384 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 5385 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 5386 | |
| 5387 | tmp = I915_READ(DSPFW2); |
| 5388 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 5389 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 5390 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 5391 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 5392 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5393 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 5394 | |
| 5395 | tmp = I915_READ(DSPFW3); |
| 5396 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 5397 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5398 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 5399 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 5400 | } |
| 5401 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5402 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 5403 | struct vlv_wm_values *wm) |
| 5404 | { |
| 5405 | enum pipe pipe; |
| 5406 | uint32_t tmp; |
| 5407 | |
| 5408 | for_each_pipe(dev_priv, pipe) { |
| 5409 | tmp = I915_READ(VLV_DDL(pipe)); |
| 5410 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5411 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5412 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5413 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5414 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5415 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5416 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5417 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5418 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 5419 | } |
| 5420 | |
| 5421 | tmp = I915_READ(DSPFW1); |
| 5422 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5423 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5424 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 5425 | 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] | 5426 | |
| 5427 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5428 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 5429 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5430 | 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] | 5431 | |
| 5432 | tmp = I915_READ(DSPFW3); |
| 5433 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5434 | |
| 5435 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5436 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5437 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5438 | 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] | 5439 | |
| 5440 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5441 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 5442 | 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] | 5443 | |
| 5444 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5445 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 5446 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5447 | |
| 5448 | tmp = I915_READ(DSPHOWM); |
| 5449 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5450 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 5451 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 5452 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 5453 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5454 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5455 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5456 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5457 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5458 | 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] | 5459 | } else { |
| 5460 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5461 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5462 | 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] | 5463 | |
| 5464 | tmp = I915_READ(DSPHOWM); |
| 5465 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5466 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5467 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5468 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5469 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5470 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5471 | 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] | 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | #undef _FW_WM |
| 5476 | #undef _FW_WM_VLV |
| 5477 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5478 | void g4x_wm_get_hw_state(struct drm_device *dev) |
| 5479 | { |
| 5480 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5481 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 5482 | struct intel_crtc *crtc; |
| 5483 | |
| 5484 | g4x_read_wm_values(dev_priv, wm); |
| 5485 | |
| 5486 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 5487 | |
| 5488 | for_each_intel_crtc(dev, crtc) { |
| 5489 | struct intel_crtc_state *crtc_state = |
| 5490 | to_intel_crtc_state(crtc->base.state); |
| 5491 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 5492 | struct g4x_pipe_wm *raw; |
| 5493 | enum pipe pipe = crtc->pipe; |
| 5494 | enum plane_id plane_id; |
| 5495 | int level, max_level; |
| 5496 | |
| 5497 | active->cxsr = wm->cxsr; |
| 5498 | active->hpll_en = wm->hpll_en; |
| 5499 | active->fbc_en = wm->fbc_en; |
| 5500 | |
| 5501 | active->sr = wm->sr; |
| 5502 | active->hpll = wm->hpll; |
| 5503 | |
| 5504 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5505 | active->wm.plane[plane_id] = |
| 5506 | wm->pipe[pipe].plane[plane_id]; |
| 5507 | } |
| 5508 | |
| 5509 | if (wm->cxsr && wm->hpll_en) |
| 5510 | max_level = G4X_WM_LEVEL_HPLL; |
| 5511 | else if (wm->cxsr) |
| 5512 | max_level = G4X_WM_LEVEL_SR; |
| 5513 | else |
| 5514 | max_level = G4X_WM_LEVEL_NORMAL; |
| 5515 | |
| 5516 | level = G4X_WM_LEVEL_NORMAL; |
| 5517 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5518 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5519 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 5520 | |
| 5521 | if (++level > max_level) |
| 5522 | goto out; |
| 5523 | |
| 5524 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5525 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 5526 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 5527 | raw->plane[PLANE_SPRITE0] = 0; |
| 5528 | raw->fbc = active->sr.fbc; |
| 5529 | |
| 5530 | if (++level > max_level) |
| 5531 | goto out; |
| 5532 | |
| 5533 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5534 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 5535 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 5536 | raw->plane[PLANE_SPRITE0] = 0; |
| 5537 | raw->fbc = active->hpll.fbc; |
| 5538 | |
| 5539 | out: |
| 5540 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5541 | g4x_raw_plane_wm_set(crtc_state, level, |
| 5542 | plane_id, USHRT_MAX); |
| 5543 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 5544 | |
| 5545 | crtc_state->wm.g4x.optimal = *active; |
| 5546 | crtc_state->wm.g4x.intermediate = *active; |
| 5547 | |
| 5548 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 5549 | pipe_name(pipe), |
| 5550 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 5551 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 5552 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
| 5553 | } |
| 5554 | |
| 5555 | DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 5556 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 5557 | DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 5558 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 5559 | DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", |
| 5560 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
| 5561 | } |
| 5562 | |
| 5563 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 5564 | { |
| 5565 | struct intel_plane *plane; |
| 5566 | struct intel_crtc *crtc; |
| 5567 | |
| 5568 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5569 | |
| 5570 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 5571 | struct intel_crtc *crtc = |
| 5572 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 5573 | struct intel_crtc_state *crtc_state = |
| 5574 | to_intel_crtc_state(crtc->base.state); |
| 5575 | struct intel_plane_state *plane_state = |
| 5576 | to_intel_plane_state(plane->base.state); |
| 5577 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 5578 | enum plane_id plane_id = plane->id; |
| 5579 | int level; |
| 5580 | |
| 5581 | if (plane_state->base.visible) |
| 5582 | continue; |
| 5583 | |
| 5584 | for (level = 0; level < 3; level++) { |
| 5585 | struct g4x_pipe_wm *raw = |
| 5586 | &crtc_state->wm.g4x.raw[level]; |
| 5587 | |
| 5588 | raw->plane[plane_id] = 0; |
| 5589 | wm_state->wm.plane[plane_id] = 0; |
| 5590 | } |
| 5591 | |
| 5592 | if (plane_id == PLANE_PRIMARY) { |
| 5593 | for (level = 0; level < 3; level++) { |
| 5594 | struct g4x_pipe_wm *raw = |
| 5595 | &crtc_state->wm.g4x.raw[level]; |
| 5596 | raw->fbc = 0; |
| 5597 | } |
| 5598 | |
| 5599 | wm_state->sr.fbc = 0; |
| 5600 | wm_state->hpll.fbc = 0; |
| 5601 | wm_state->fbc_en = false; |
| 5602 | } |
| 5603 | } |
| 5604 | |
| 5605 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5606 | struct intel_crtc_state *crtc_state = |
| 5607 | to_intel_crtc_state(crtc->base.state); |
| 5608 | |
| 5609 | crtc_state->wm.g4x.intermediate = |
| 5610 | crtc_state->wm.g4x.optimal; |
| 5611 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 5612 | } |
| 5613 | |
| 5614 | g4x_program_watermarks(dev_priv); |
| 5615 | |
| 5616 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5617 | } |
| 5618 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5619 | void vlv_wm_get_hw_state(struct drm_device *dev) |
| 5620 | { |
| 5621 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5622 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 5623 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5624 | u32 val; |
| 5625 | |
| 5626 | vlv_read_wm_values(dev_priv, wm); |
| 5627 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5628 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 5629 | wm->level = VLV_WM_LEVEL_PM2; |
| 5630 | |
| 5631 | if (IS_CHERRYVIEW(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5632 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5633 | |
| 5634 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5635 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 5636 | wm->level = VLV_WM_LEVEL_PM5; |
| 5637 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 5638 | /* |
| 5639 | * If DDR DVFS is disabled in the BIOS, Punit |
| 5640 | * will never ack the request. So if that happens |
| 5641 | * assume we don't have to enable/disable DDR DVFS |
| 5642 | * dynamically. To test that just set the REQ_ACK |
| 5643 | * bit to poke the Punit, but don't change the |
| 5644 | * HIGH/LOW bits so that we don't actually change |
| 5645 | * the current state. |
| 5646 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5647 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 5648 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 5649 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 5650 | |
| 5651 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 5652 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 5653 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 5654 | "assuming DDR DVFS is disabled\n"); |
| 5655 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 5656 | } else { |
| 5657 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 5658 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 5659 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 5660 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5661 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5662 | mutex_unlock(&dev_priv->pcu_lock); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5663 | } |
| 5664 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5665 | for_each_intel_crtc(dev, crtc) { |
| 5666 | struct intel_crtc_state *crtc_state = |
| 5667 | to_intel_crtc_state(crtc->base.state); |
| 5668 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 5669 | const struct vlv_fifo_state *fifo_state = |
| 5670 | &crtc_state->wm.vlv.fifo_state; |
| 5671 | enum pipe pipe = crtc->pipe; |
| 5672 | enum plane_id plane_id; |
| 5673 | int level; |
| 5674 | |
| 5675 | vlv_get_fifo_size(crtc_state); |
| 5676 | |
| 5677 | active->num_levels = wm->level + 1; |
| 5678 | active->cxsr = wm->cxsr; |
| 5679 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5680 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 5681 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5682 | &crtc_state->wm.vlv.raw[level]; |
| 5683 | |
| 5684 | active->sr[level].plane = wm->sr.plane; |
| 5685 | active->sr[level].cursor = wm->sr.cursor; |
| 5686 | |
| 5687 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5688 | active->wm[level].plane[plane_id] = |
| 5689 | wm->pipe[pipe].plane[plane_id]; |
| 5690 | |
| 5691 | raw->plane[plane_id] = |
| 5692 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 5693 | fifo_state->plane[plane_id]); |
| 5694 | } |
| 5695 | } |
| 5696 | |
| 5697 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5698 | vlv_raw_plane_wm_set(crtc_state, level, |
| 5699 | plane_id, USHRT_MAX); |
| 5700 | vlv_invalidate_wms(crtc, active, level); |
| 5701 | |
| 5702 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 5703 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5704 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5705 | 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] | 5706 | pipe_name(pipe), |
| 5707 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 5708 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 5709 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 5710 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5711 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5712 | |
| 5713 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 5714 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 5715 | } |
| 5716 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 5717 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 5718 | { |
| 5719 | struct intel_plane *plane; |
| 5720 | struct intel_crtc *crtc; |
| 5721 | |
| 5722 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5723 | |
| 5724 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 5725 | struct intel_crtc *crtc = |
| 5726 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 5727 | struct intel_crtc_state *crtc_state = |
| 5728 | to_intel_crtc_state(crtc->base.state); |
| 5729 | struct intel_plane_state *plane_state = |
| 5730 | to_intel_plane_state(plane->base.state); |
| 5731 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 5732 | const struct vlv_fifo_state *fifo_state = |
| 5733 | &crtc_state->wm.vlv.fifo_state; |
| 5734 | enum plane_id plane_id = plane->id; |
| 5735 | int level; |
| 5736 | |
| 5737 | if (plane_state->base.visible) |
| 5738 | continue; |
| 5739 | |
| 5740 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 5741 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 5742 | &crtc_state->wm.vlv.raw[level]; |
| 5743 | |
| 5744 | raw->plane[plane_id] = 0; |
| 5745 | |
| 5746 | wm_state->wm[level].plane[plane_id] = |
| 5747 | vlv_invert_wm_value(raw->plane[plane_id], |
| 5748 | fifo_state->plane[plane_id]); |
| 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5753 | struct intel_crtc_state *crtc_state = |
| 5754 | to_intel_crtc_state(crtc->base.state); |
| 5755 | |
| 5756 | crtc_state->wm.vlv.intermediate = |
| 5757 | crtc_state->wm.vlv.optimal; |
| 5758 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 5759 | } |
| 5760 | |
| 5761 | vlv_program_watermarks(dev_priv); |
| 5762 | |
| 5763 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5764 | } |
| 5765 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 5766 | /* |
| 5767 | * FIXME should probably kill this and improve |
| 5768 | * the real watermark readout/sanitation instead |
| 5769 | */ |
| 5770 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 5771 | { |
| 5772 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5773 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5774 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5775 | |
| 5776 | /* |
| 5777 | * Don't touch WM1S_LP_EN here. |
| 5778 | * Doing so could cause underruns. |
| 5779 | */ |
| 5780 | } |
| 5781 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5782 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 5783 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5784 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5785 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5786 | struct drm_crtc *crtc; |
| 5787 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 5788 | ilk_init_lp_watermarks(dev_priv); |
| 5789 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 5790 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5791 | ilk_pipe_wm_get_hw_state(crtc); |
| 5792 | |
| 5793 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 5794 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 5795 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 5796 | |
| 5797 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5798 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 5799 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 5800 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 5801 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5802 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5803 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 5804 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 5805 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5806 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 5807 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 5808 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5809 | |
| 5810 | hw->enable_fbc_wm = |
| 5811 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 5812 | } |
| 5813 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5814 | /** |
| 5815 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 5816 | * |
| 5817 | * Calculate watermark values for the various WM regs based on current mode |
| 5818 | * and plane configuration. |
| 5819 | * |
| 5820 | * There are several cases to deal with here: |
| 5821 | * - normal (i.e. non-self-refresh) |
| 5822 | * - self-refresh (SR) mode |
| 5823 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 5824 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 5825 | * lines), so need to account for TLB latency |
| 5826 | * |
| 5827 | * The normal calculation is: |
| 5828 | * watermark = dotclock * bytes per pixel * latency |
| 5829 | * where latency is platform & configuration dependent (we assume pessimal |
| 5830 | * values here). |
| 5831 | * |
| 5832 | * The SR calculation is: |
| 5833 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 5834 | * bytes per pixel |
| 5835 | * where |
| 5836 | * line time = htotal / dotclock |
| 5837 | * surface width = hdisplay for normal plane and 64 for cursor |
| 5838 | * and latency is assumed to be high, as above. |
| 5839 | * |
| 5840 | * The final value programmed to the register should always be rounded up, |
| 5841 | * and include an extra 2 entries to account for clock crossings. |
| 5842 | * |
| 5843 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 5844 | * to set the non-SR watermarks to 8. |
| 5845 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5846 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5847 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5848 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5849 | |
| 5850 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 5851 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5852 | } |
| 5853 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 5854 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 5855 | { |
| 5856 | u32 val; |
| 5857 | |
Rodrigo Vivi | 4d6ef0d | 2017-10-02 23:36:50 -0700 | [diff] [blame] | 5858 | /* Display WA #0477 WaDisableIPC: skl */ |
| 5859 | if (IS_SKYLAKE(dev_priv)) { |
| 5860 | dev_priv->ipc_enabled = false; |
| 5861 | return; |
| 5862 | } |
| 5863 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 5864 | val = I915_READ(DISP_ARB_CTL2); |
| 5865 | |
| 5866 | if (dev_priv->ipc_enabled) |
| 5867 | val |= DISP_IPC_ENABLE; |
| 5868 | else |
| 5869 | val &= ~DISP_IPC_ENABLE; |
| 5870 | |
| 5871 | I915_WRITE(DISP_ARB_CTL2, val); |
| 5872 | } |
| 5873 | |
| 5874 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 5875 | { |
| 5876 | dev_priv->ipc_enabled = false; |
| 5877 | if (!HAS_IPC(dev_priv)) |
| 5878 | return; |
| 5879 | |
| 5880 | dev_priv->ipc_enabled = true; |
| 5881 | intel_enable_ipc(dev_priv); |
| 5882 | } |
| 5883 | |
Jani Nikula | e282891 | 2016-01-18 09:19:47 +0200 | [diff] [blame] | 5884 | /* |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5885 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5886 | */ |
| 5887 | DEFINE_SPINLOCK(mchdev_lock); |
| 5888 | |
| 5889 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 5890 | * mchdev_lock. */ |
| 5891 | static struct drm_i915_private *i915_mch_dev; |
| 5892 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5893 | bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5894 | { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5895 | u16 rgvswctl; |
| 5896 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 5897 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5898 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5899 | rgvswctl = I915_READ16(MEMSWCTL); |
| 5900 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 5901 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 5902 | return false; /* still busy with another command */ |
| 5903 | } |
| 5904 | |
| 5905 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 5906 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 5907 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 5908 | POSTING_READ16(MEMSWCTL); |
| 5909 | |
| 5910 | rgvswctl |= MEMCTL_CMD_STS; |
| 5911 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 5912 | |
| 5913 | return true; |
| 5914 | } |
| 5915 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5916 | static void ironlake_enable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5917 | { |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 5918 | u32 rgvmodectl; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5919 | u8 fmax, fmin, fstart, vstart; |
| 5920 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5921 | spin_lock_irq(&mchdev_lock); |
| 5922 | |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 5923 | rgvmodectl = I915_READ(MEMMODECTL); |
| 5924 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5925 | /* Enable temp reporting */ |
| 5926 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 5927 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 5928 | |
| 5929 | /* 100ms RC evaluation intervals */ |
| 5930 | I915_WRITE(RCUPEI, 100000); |
| 5931 | I915_WRITE(RCDNEI, 100000); |
| 5932 | |
| 5933 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 5934 | I915_WRITE(RCBMAXAVG, 90000); |
| 5935 | I915_WRITE(RCBMINAVG, 80000); |
| 5936 | |
| 5937 | I915_WRITE(MEMIHYST, 1); |
| 5938 | |
| 5939 | /* Set up min, max, and cur for interrupt handling */ |
| 5940 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 5941 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 5942 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 5943 | MEMMODE_FSTART_SHIFT; |
| 5944 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 5945 | vstart = (I915_READ(PXVFREQ(fstart)) & PXVFREQ_PX_MASK) >> |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5946 | PXVFREQ_PX_SHIFT; |
| 5947 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5948 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 5949 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5950 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5951 | dev_priv->ips.max_delay = fstart; |
| 5952 | dev_priv->ips.min_delay = fmin; |
| 5953 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5954 | |
| 5955 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 5956 | fmax, fmin, fstart); |
| 5957 | |
| 5958 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 5959 | |
| 5960 | /* |
| 5961 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 5962 | */ |
| 5963 | |
| 5964 | I915_WRITE(VIDSTART, vstart); |
| 5965 | POSTING_READ(VIDSTART); |
| 5966 | |
| 5967 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 5968 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 5969 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5970 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5971 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 5972 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5973 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5974 | ironlake_set_drps(dev_priv, fstart); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5975 | |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 5976 | dev_priv->ips.last_count1 = I915_READ(DMIEC) + |
| 5977 | I915_READ(DDREC) + I915_READ(CSIEC); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5978 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 5979 | dev_priv->ips.last_count2 = I915_READ(GFXEC); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5980 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5981 | |
| 5982 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5983 | } |
| 5984 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5985 | static void ironlake_disable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5986 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5987 | u16 rgvswctl; |
| 5988 | |
| 5989 | spin_lock_irq(&mchdev_lock); |
| 5990 | |
| 5991 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5992 | |
| 5993 | /* Ack interrupts, disable EFC interrupt */ |
| 5994 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 5995 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 5996 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 5997 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 5998 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 5999 | |
| 6000 | /* Go back to the starting frequency */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 6001 | ironlake_set_drps(dev_priv, dev_priv->ips.fstart); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6002 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6003 | rgvswctl |= MEMCTL_CMD_STS; |
| 6004 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 6005 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6006 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 6007 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6008 | } |
| 6009 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 6010 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 6011 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 6012 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 6013 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 6014 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6015 | 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] | 6016 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6017 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6018 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6019 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6020 | /* Only set the down limit when we've reached the lowest level to avoid |
| 6021 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 6022 | * race in the hw when coming out of rc6: There's a tiny window where |
| 6023 | * the hw runs at the minimal clock before selecting the desired |
| 6024 | * frequency, if the down threshold expires in that window we will not |
| 6025 | * receive a down interrupt. */ |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6026 | if (INTEL_GEN(dev_priv) >= 9) { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6027 | limits = (rps->max_freq_softlimit) << 23; |
| 6028 | if (val <= rps->min_freq_softlimit) |
| 6029 | limits |= (rps->min_freq_softlimit) << 14; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6030 | } else { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6031 | limits = rps->max_freq_softlimit << 24; |
| 6032 | if (val <= rps->min_freq_softlimit) |
| 6033 | limits |= rps->min_freq_softlimit << 16; |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6034 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 6035 | |
| 6036 | return limits; |
| 6037 | } |
| 6038 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6039 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 6040 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6041 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6042 | int new_power; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6043 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 6044 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6045 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6046 | new_power = rps->power; |
| 6047 | switch (rps->power) { |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6048 | case LOW_POWER: |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6049 | if (val > rps->efficient_freq + 1 && |
| 6050 | val > rps->cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6051 | new_power = BETWEEN; |
| 6052 | break; |
| 6053 | |
| 6054 | case BETWEEN: |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6055 | if (val <= rps->efficient_freq && |
| 6056 | val < rps->cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6057 | new_power = LOW_POWER; |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6058 | else if (val >= rps->rp0_freq && |
| 6059 | val > rps->cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6060 | new_power = HIGH_POWER; |
| 6061 | break; |
| 6062 | |
| 6063 | case HIGH_POWER: |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6064 | if (val < (rps->rp1_freq + rps->rp0_freq) >> 1 && |
| 6065 | val < rps->cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6066 | new_power = BETWEEN; |
| 6067 | break; |
| 6068 | } |
| 6069 | /* Max/min bins are special */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6070 | if (val <= rps->min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6071 | new_power = LOW_POWER; |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6072 | if (val >= rps->max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6073 | new_power = HIGH_POWER; |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6074 | if (new_power == rps->power) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6075 | return; |
| 6076 | |
| 6077 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 6078 | switch (new_power) { |
| 6079 | case LOW_POWER: |
| 6080 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6081 | ei_up = 16000; |
| 6082 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6083 | |
| 6084 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6085 | ei_down = 32000; |
| 6086 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6087 | break; |
| 6088 | |
| 6089 | case BETWEEN: |
| 6090 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6091 | ei_up = 13000; |
| 6092 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6093 | |
| 6094 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6095 | ei_down = 32000; |
| 6096 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6097 | break; |
| 6098 | |
| 6099 | case HIGH_POWER: |
| 6100 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6101 | ei_up = 10000; |
| 6102 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6103 | |
| 6104 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6105 | ei_down = 32000; |
| 6106 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6107 | break; |
| 6108 | } |
| 6109 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6110 | /* When byt can survive without system hang with dynamic |
| 6111 | * sw freq adjustments, this restriction can be lifted. |
| 6112 | */ |
| 6113 | if (IS_VALLEYVIEW(dev_priv)) |
| 6114 | goto skip_hw_write; |
| 6115 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6116 | I915_WRITE(GEN6_RP_UP_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6117 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6118 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6119 | GT_INTERVAL_FROM_US(dev_priv, |
| 6120 | ei_up * threshold_up / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6121 | |
| 6122 | I915_WRITE(GEN6_RP_DOWN_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6123 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6124 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6125 | GT_INTERVAL_FROM_US(dev_priv, |
| 6126 | ei_down * threshold_down / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6127 | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 6128 | I915_WRITE(GEN6_RP_CONTROL, |
| 6129 | GEN6_RP_MEDIA_TURBO | |
| 6130 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6131 | GEN6_RP_MEDIA_IS_GFX | |
| 6132 | GEN6_RP_ENABLE | |
| 6133 | GEN6_RP_UP_BUSY_AVG | |
| 6134 | GEN6_RP_DOWN_IDLE_AVG); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 6135 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 6136 | skip_hw_write: |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6137 | rps->power = new_power; |
| 6138 | rps->up_threshold = threshold_up; |
| 6139 | rps->down_threshold = threshold_down; |
| 6140 | rps->last_adj = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6141 | } |
| 6142 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6143 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 6144 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6145 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6146 | u32 mask = 0; |
| 6147 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6148 | /* 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] | 6149 | if (val > rps->min_freq_softlimit) |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6150 | 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] | 6151 | if (val < rps->max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 6152 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6153 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 6154 | mask &= dev_priv->pm_rps_events; |
| 6155 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 6156 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6157 | } |
| 6158 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6159 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 6160 | * called when the range (min_delay and max_delay) is modified so that we can |
| 6161 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6162 | 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] | 6163 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6164 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6165 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6166 | /* min/max delay may still have been modified so be sure to |
| 6167 | * write the limits value. |
| 6168 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6169 | if (val != rps->cur_freq) { |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6170 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6171 | |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6172 | if (INTEL_GEN(dev_priv) >= 9) |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 6173 | I915_WRITE(GEN6_RPNSWREQ, |
| 6174 | GEN9_FREQUENCY(val)); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6175 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 6176 | I915_WRITE(GEN6_RPNSWREQ, |
| 6177 | HSW_FREQUENCY(val)); |
| 6178 | else |
| 6179 | I915_WRITE(GEN6_RPNSWREQ, |
| 6180 | GEN6_FREQUENCY(val) | |
| 6181 | GEN6_OFFSET(0) | |
| 6182 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 6183 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6184 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6185 | /* Make sure we continue to get interrupts |
| 6186 | * until we hit the minimum or maximum frequencies. |
| 6187 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 6188 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 6189 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 6190 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6191 | rps->cur_freq = val; |
Mika Kuoppala | 0f94592 | 2015-11-17 18:14:26 +0200 | [diff] [blame] | 6192 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6193 | |
| 6194 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6195 | } |
| 6196 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6197 | 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] | 6198 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6199 | int err; |
| 6200 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6201 | if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1), |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6202 | "Odd GPU freq value\n")) |
| 6203 | val &= ~1; |
| 6204 | |
Deepak S | cd25dd5 | 2015-07-10 18:31:40 +0530 | [diff] [blame] | 6205 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 6206 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6207 | if (val != dev_priv->gt_pm.rps.cur_freq) { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6208 | err = vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 6209 | if (err) |
| 6210 | return err; |
| 6211 | |
Chris Wilson | db4c5e0 | 2017-02-10 15:03:46 +0000 | [diff] [blame] | 6212 | gen6_set_rps_thresholds(dev_priv, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 6213 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6214 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6215 | dev_priv->gt_pm.rps.cur_freq = val; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6216 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6217 | |
| 6218 | return 0; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6219 | } |
| 6220 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6221 | /* 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] | 6222 | * |
| 6223 | * * If Gfx is Idle, then |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6224 | * 1. Forcewake Media well. |
| 6225 | * 2. Request idle freq. |
| 6226 | * 3. Release Forcewake of Media well. |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6227 | */ |
| 6228 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 6229 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6230 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6231 | u32 val = rps->idle_freq; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6232 | int err; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 6233 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6234 | if (rps->cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6235 | return; |
| 6236 | |
Chris Wilson | c9efef7 | 2017-01-02 15:28:45 +0000 | [diff] [blame] | 6237 | /* The punit delays the write of the frequency and voltage until it |
| 6238 | * determines the GPU is awake. During normal usage we don't want to |
| 6239 | * waste power changing the frequency if the GPU is sleeping (rc6). |
| 6240 | * However, the GPU and driver is now idle and we do not want to delay |
| 6241 | * switching to minimum voltage (reducing power whilst idle) as we do |
| 6242 | * not expect to be woken in the near future and so must flush the |
| 6243 | * change by waking the device. |
| 6244 | * |
| 6245 | * We choose to take the media powerwell (either would do to trick the |
| 6246 | * punit into committing the voltage change) as that takes a lot less |
| 6247 | * power than the render powerwell. |
| 6248 | */ |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6249 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6250 | err = valleyview_set_rps(dev_priv, val); |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 6251 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6252 | |
| 6253 | if (err) |
| 6254 | DRM_ERROR("Failed to set RPS for idle\n"); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6255 | } |
| 6256 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6257 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 6258 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6259 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6260 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6261 | mutex_lock(&dev_priv->pcu_lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6262 | if (rps->enabled) { |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6263 | u8 freq; |
| 6264 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 6265 | if (dev_priv->pm_rps_events & GEN6_PM_RP_UP_EI_EXPIRED) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6266 | gen6_rps_reset_ei(dev_priv); |
| 6267 | I915_WRITE(GEN6_PMINTRMSK, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6268 | gen6_rps_pm_mask(dev_priv, rps->cur_freq)); |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 6269 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6270 | gen6_enable_rps_interrupts(dev_priv); |
| 6271 | |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6272 | /* Use the user's desired frequency as a guide, but for better |
| 6273 | * performance, jump directly to RPe as our starting frequency. |
| 6274 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6275 | freq = max(rps->cur_freq, |
| 6276 | rps->efficient_freq); |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6277 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6278 | if (intel_set_rps(dev_priv, |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 6279 | clamp(freq, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6280 | rps->min_freq_softlimit, |
| 6281 | rps->max_freq_softlimit))) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6282 | DRM_DEBUG_DRIVER("Failed to set idle frequency\n"); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6283 | } |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6284 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6285 | } |
| 6286 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6287 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 6288 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6289 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6290 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6291 | /* Flush our bottom-half so that it does not race with us |
| 6292 | * setting the idle frequency and so that it is bounded by |
| 6293 | * our rpm wakeref. And then disable the interrupts to stop any |
| 6294 | * futher RPS reclocking whilst we are asleep. |
| 6295 | */ |
| 6296 | gen6_disable_rps_interrupts(dev_priv); |
| 6297 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6298 | mutex_lock(&dev_priv->pcu_lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6299 | if (rps->enabled) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6300 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 6301 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6302 | else |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6303 | gen6_set_rps(dev_priv, rps->idle_freq); |
| 6304 | rps->last_adj = 0; |
Ville Syrjälä | 12c100b | 2016-05-23 17:42:48 +0300 | [diff] [blame] | 6305 | I915_WRITE(GEN6_PMINTRMSK, |
| 6306 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6307 | } |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6308 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6309 | } |
| 6310 | |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6311 | void gen6_rps_boost(struct drm_i915_gem_request *rq, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6312 | struct intel_rps_client *rps_client) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6313 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6314 | struct intel_rps *rps = &rq->i915->gt_pm.rps; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6315 | unsigned long flags; |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6316 | bool boost; |
| 6317 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6318 | /* This is intentionally racy! We peek at the state here, then |
| 6319 | * validate inside the RPS worker. |
| 6320 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6321 | if (!rps->enabled) |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6322 | return; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6323 | |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6324 | boost = false; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6325 | spin_lock_irqsave(&rq->lock, flags); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6326 | if (!rq->waitboost && !i915_gem_request_completed(rq)) { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6327 | atomic_inc(&rps->num_waiters); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6328 | rq->waitboost = true; |
| 6329 | boost = true; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6330 | } |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 6331 | spin_unlock_irqrestore(&rq->lock, flags); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6332 | if (!boost) |
| 6333 | return; |
| 6334 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6335 | if (READ_ONCE(rps->cur_freq) < rps->boost_freq) |
| 6336 | schedule_work(&rps->work); |
Chris Wilson | 7b92c1b | 2017-06-28 13:35:48 +0100 | [diff] [blame] | 6337 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6338 | atomic_inc(rps_client ? &rps_client->boosts : &rps->boosts); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6339 | } |
| 6340 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6341 | int intel_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6342 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6343 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6344 | int err; |
| 6345 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6346 | lockdep_assert_held(&dev_priv->pcu_lock); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6347 | GEM_BUG_ON(val > rps->max_freq); |
| 6348 | GEM_BUG_ON(val < rps->min_freq); |
Chris Wilson | cfd1c48 | 2017-02-20 09:47:07 +0000 | [diff] [blame] | 6349 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6350 | if (!rps->enabled) { |
| 6351 | rps->cur_freq = val; |
Chris Wilson | 76e4e4b | 2017-02-20 09:47:08 +0000 | [diff] [blame] | 6352 | return 0; |
| 6353 | } |
| 6354 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6355 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6356 | err = valleyview_set_rps(dev_priv, val); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6357 | else |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6358 | err = gen6_set_rps(dev_priv, val); |
| 6359 | |
| 6360 | return err; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6361 | } |
| 6362 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6363 | static void gen9_disable_rc6(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6364 | { |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6365 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6366 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6369 | static void gen9_disable_rps(struct drm_i915_private *dev_priv) |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6370 | { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6371 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6372 | } |
| 6373 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6374 | static void gen6_disable_rc6(struct drm_i915_private *dev_priv) |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6375 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6376 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | static void gen6_disable_rps(struct drm_i915_private *dev_priv) |
| 6380 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6381 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6382 | I915_WRITE(GEN6_RP_CONTROL, 0); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6383 | } |
| 6384 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6385 | static void cherryview_disable_rc6(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6386 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6387 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6388 | } |
| 6389 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 6390 | static void cherryview_disable_rps(struct drm_i915_private *dev_priv) |
| 6391 | { |
| 6392 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6393 | } |
| 6394 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6395 | static void valleyview_disable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6396 | { |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6397 | /* We're doing forcewake before Disabling RC6, |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6398 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6399 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6400 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6401 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6402 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6403 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6404 | } |
| 6405 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 6406 | static void valleyview_disable_rps(struct drm_i915_private *dev_priv) |
| 6407 | { |
| 6408 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6409 | } |
| 6410 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6411 | static void intel_print_rc6_info(struct drm_i915_private *dev_priv, u32 mode) |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 6412 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6413 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 6414 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 6415 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 6416 | else |
| 6417 | mode = 0; |
| 6418 | } |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6419 | if (HAS_RC6p(dev_priv)) |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6420 | DRM_DEBUG_DRIVER("Enabling RC6 states: " |
| 6421 | "RC6 %s RC6p %s RC6pp %s\n", |
| 6422 | onoff(mode & GEN6_RC_CTL_RC6_ENABLE), |
| 6423 | onoff(mode & GEN6_RC_CTL_RC6p_ENABLE), |
| 6424 | onoff(mode & GEN6_RC_CTL_RC6pp_ENABLE)); |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 6425 | |
| 6426 | else |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6427 | DRM_DEBUG_DRIVER("Enabling RC6 states: RC6 %s\n", |
| 6428 | onoff(mode & GEN6_RC_CTL_RC6_ENABLE)); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 6429 | } |
| 6430 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6431 | 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] | 6432 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 6433 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6434 | bool enable_rc6 = true; |
| 6435 | unsigned long rc6_ctx_base; |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6436 | u32 rc_ctl; |
| 6437 | int rc_sw_target; |
| 6438 | |
| 6439 | rc_ctl = I915_READ(GEN6_RC_CONTROL); |
| 6440 | rc_sw_target = (I915_READ(GEN6_RC_STATE) & RC_SW_TARGET_STATE_MASK) >> |
| 6441 | RC_SW_TARGET_STATE_SHIFT; |
| 6442 | DRM_DEBUG_DRIVER("BIOS enabled RC states: " |
| 6443 | "HW_CTRL %s HW_RC6 %s SW_TARGET_STATE %x\n", |
| 6444 | onoff(rc_ctl & GEN6_RC_CTL_HW_ENABLE), |
| 6445 | onoff(rc_ctl & GEN6_RC_CTL_RC6_ENABLE), |
| 6446 | rc_sw_target); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6447 | |
| 6448 | if (!(I915_READ(RC6_LOCATION) & RC6_CTX_IN_DRAM)) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6449 | DRM_DEBUG_DRIVER("RC6 Base location not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6450 | enable_rc6 = false; |
| 6451 | } |
| 6452 | |
| 6453 | /* |
| 6454 | * The exact context size is not known for BXT, so assume a page size |
| 6455 | * for this check. |
| 6456 | */ |
| 6457 | rc6_ctx_base = I915_READ(RC6_CTX_BASE) & RC6_CTX_BASE_MASK; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 6458 | if (!((rc6_ctx_base >= ggtt->stolen_reserved_base) && |
| 6459 | (rc6_ctx_base + PAGE_SIZE <= ggtt->stolen_reserved_base + |
| 6460 | ggtt->stolen_reserved_size))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6461 | DRM_DEBUG_DRIVER("RC6 Base address not as expected.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6462 | enable_rc6 = false; |
| 6463 | } |
| 6464 | |
| 6465 | if (!(((I915_READ(PWRCTX_MAXCNT_RCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6466 | ((I915_READ(PWRCTX_MAXCNT_VCSUNIT0) & IDLE_TIME_MASK) > 1) && |
| 6467 | ((I915_READ(PWRCTX_MAXCNT_BCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6468 | ((I915_READ(PWRCTX_MAXCNT_VECSUNIT) & IDLE_TIME_MASK) > 1))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6469 | DRM_DEBUG_DRIVER("Engine Idle wait time not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6470 | enable_rc6 = false; |
| 6471 | } |
| 6472 | |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6473 | if (!I915_READ(GEN8_PUSHBUS_CONTROL) || |
| 6474 | !I915_READ(GEN8_PUSHBUS_ENABLE) || |
| 6475 | !I915_READ(GEN8_PUSHBUS_SHIFT)) { |
| 6476 | DRM_DEBUG_DRIVER("Pushbus not setup properly.\n"); |
| 6477 | enable_rc6 = false; |
| 6478 | } |
| 6479 | |
| 6480 | if (!I915_READ(GEN6_GFXPAUSE)) { |
| 6481 | DRM_DEBUG_DRIVER("GFX pause not setup properly.\n"); |
| 6482 | enable_rc6 = false; |
| 6483 | } |
| 6484 | |
| 6485 | if (!I915_READ(GEN8_MISC_CTRL0)) { |
| 6486 | DRM_DEBUG_DRIVER("GPM control not setup properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6487 | enable_rc6 = false; |
| 6488 | } |
| 6489 | |
| 6490 | return enable_rc6; |
| 6491 | } |
| 6492 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6493 | int sanitize_rc6_option(struct drm_i915_private *dev_priv, int enable_rc6) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6494 | { |
Daniel Vetter | e7d66d8 | 2015-06-15 23:23:54 +0200 | [diff] [blame] | 6495 | /* No RC6 before Ironlake and code is gone for ilk. */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6496 | if (INTEL_INFO(dev_priv)->gen < 6) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6497 | return 0; |
| 6498 | |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6499 | if (!enable_rc6) |
| 6500 | return 0; |
| 6501 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 6502 | if (IS_GEN9_LP(dev_priv) && !bxt_check_bios_rc6_setup(dev_priv)) { |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6503 | DRM_INFO("RC6 disabled by BIOS\n"); |
| 6504 | return 0; |
| 6505 | } |
| 6506 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 6507 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6508 | if (enable_rc6 >= 0) { |
| 6509 | int mask; |
| 6510 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6511 | if (HAS_RC6p(dev_priv)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6512 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 6513 | INTEL_RC6pp_ENABLE; |
| 6514 | else |
| 6515 | mask = INTEL_RC6_ENABLE; |
| 6516 | |
| 6517 | if ((enable_rc6 & mask) != enable_rc6) |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6518 | DRM_DEBUG_DRIVER("Adjusting RC6 mask to %d " |
| 6519 | "(requested %d, valid %d)\n", |
| 6520 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6521 | |
| 6522 | return enable_rc6 & mask; |
| 6523 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6524 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6525 | if (IS_IVYBRIDGE(dev_priv)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 6526 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 6527 | |
| 6528 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6529 | } |
| 6530 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6531 | static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6532 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6533 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6534 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6535 | /* All of these values are in units of 50MHz */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6536 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6537 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 6538 | if (IS_GEN9_LP(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6539 | u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6540 | rps->rp0_freq = (rp_state_cap >> 16) & 0xff; |
| 6541 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 6542 | rps->min_freq = (rp_state_cap >> 0) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 6543 | } else { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6544 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6545 | rps->rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 6546 | rps->rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 6547 | rps->min_freq = (rp_state_cap >> 16) & 0xff; |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 6548 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6549 | /* hw_max = RP0 until we check for overclocking */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6550 | rps->max_freq = rps->rp0_freq; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6551 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6552 | rps->efficient_freq = rps->rp1_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6553 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) || |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6554 | IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6555 | u32 ddcc_status = 0; |
| 6556 | |
| 6557 | if (sandybridge_pcode_read(dev_priv, |
| 6558 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 6559 | &ddcc_status) == 0) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6560 | rps->efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 6561 | clamp_t(u8, |
| 6562 | ((ddcc_status >> 8) & 0xff), |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6563 | rps->min_freq, |
| 6564 | rps->max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6565 | } |
| 6566 | |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6567 | if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) { |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 6568 | /* Store the frequency values in 16.66 MHZ units, which is |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6569 | * the natural hardware unit for SKL |
| 6570 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6571 | rps->rp0_freq *= GEN9_FREQ_SCALER; |
| 6572 | rps->rp1_freq *= GEN9_FREQ_SCALER; |
| 6573 | rps->min_freq *= GEN9_FREQ_SCALER; |
| 6574 | rps->max_freq *= GEN9_FREQ_SCALER; |
| 6575 | rps->efficient_freq *= GEN9_FREQ_SCALER; |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 6576 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6577 | } |
| 6578 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6579 | static void reset_rps(struct drm_i915_private *dev_priv, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6580 | int (*set)(struct drm_i915_private *, u8)) |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6581 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6582 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6583 | u8 freq = rps->cur_freq; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6584 | |
| 6585 | /* force a reset */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6586 | rps->power = -1; |
| 6587 | rps->cur_freq = -1; |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6588 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6589 | if (set(dev_priv, freq)) |
| 6590 | DRM_ERROR("Failed to reset RPS to initial values\n"); |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6591 | } |
| 6592 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6593 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6594 | static void gen9_enable_rps(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6595 | { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6596 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 6597 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6598 | /* Program defaults and thresholds for RPS*/ |
| 6599 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6600 | GEN9_FREQUENCY(dev_priv->gt_pm.rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6601 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6602 | /* 1 second timeout*/ |
| 6603 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 6604 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 6605 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6606 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6607 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6608 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 6609 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 6610 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6611 | reset_rps(dev_priv, gen6_set_rps); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6612 | |
| 6613 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 6614 | } |
| 6615 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6616 | static void gen9_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6617 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6618 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6619 | enum intel_engine_id id; |
Rodrigo Vivi | e4ffc83 | 2017-08-22 16:58:28 -0700 | [diff] [blame] | 6620 | u32 rc6_mode, rc6_mask = 0; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6621 | |
| 6622 | /* 1a: Software RC state - RC0 */ |
| 6623 | I915_WRITE(GEN6_RC_STATE, 0); |
| 6624 | |
| 6625 | /* 1b: Get forcewake during program sequence. Although the driver |
| 6626 | * 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] | 6627 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6628 | |
| 6629 | /* 2a: Disable RC states. */ |
| 6630 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6631 | |
| 6632 | /* 2b: Program RC6 thresholds.*/ |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 6633 | if (INTEL_GEN(dev_priv) >= 10) { |
| 6634 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16 | 85); |
| 6635 | I915_WRITE(GEN10_MEDIA_WAKE_RATE_LIMIT, 150); |
| 6636 | } else if (IS_SKYLAKE(dev_priv)) { |
| 6637 | /* |
| 6638 | * WaRsDoubleRc6WrlWithCoarsePowerGating:skl Doubling WRL only |
| 6639 | * when CPG is enabled |
| 6640 | */ |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 6641 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 108 << 16); |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 6642 | } else { |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 6643 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
Rodrigo Vivi | 0aab201 | 2017-10-23 15:46:12 -0700 | [diff] [blame] | 6644 | } |
| 6645 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6646 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 6647 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6648 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6649 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 6650 | |
Dave Gordon | 1a3d189 | 2016-05-13 15:36:30 +0100 | [diff] [blame] | 6651 | if (HAS_GUC(dev_priv)) |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 6652 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 6653 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6654 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6655 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6656 | /* 2c: Program Coarse Power Gating Policies. */ |
| 6657 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 6658 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 6659 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6660 | /* 3a: Enable RC6 */ |
Sagar Arun Kamble | 771decb | 2017-10-10 22:30:07 +0100 | [diff] [blame] | 6661 | if (intel_rc6_enabled() & INTEL_RC6_ENABLE) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6662 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 6663 | DRM_INFO("RC6 %s\n", onoff(rc6_mask & GEN6_RC_CTL_RC6_ENABLE)); |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 6664 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
Rodrigo Vivi | e4ffc83 | 2017-08-22 16:58:28 -0700 | [diff] [blame] | 6665 | |
| 6666 | /* WaRsUseTimeoutMode:cnl (pre-prod) */ |
| 6667 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_C0)) |
| 6668 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
| 6669 | else |
| 6670 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 6671 | |
Chris Wilson | 1c044f9 | 2017-01-25 17:26:01 +0000 | [diff] [blame] | 6672 | I915_WRITE(GEN6_RC_CONTROL, |
Rodrigo Vivi | e4ffc83 | 2017-08-22 16:58:28 -0700 | [diff] [blame] | 6673 | GEN6_RC_CTL_HW_ENABLE | rc6_mode | rc6_mask); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6674 | |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 6675 | /* |
| 6676 | * 3b: Enable Coarse Power Gating only when RC6 is enabled. |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 6677 | * WaRsDisableCoarsePowerGating:skl,bxt - Render/Media PG need to be disabled with RC6. |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 6678 | */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6679 | if (NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 6680 | I915_WRITE(GEN9_PG_ENABLE, 0); |
| 6681 | else |
| 6682 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 6683 | (GEN9_RENDER_PG_ENABLE | GEN9_MEDIA_PG_ENABLE) : 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6684 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6685 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6686 | } |
| 6687 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 6688 | static void gen8_enable_rc6(struct drm_i915_private *dev_priv) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6689 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6690 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6691 | enum intel_engine_id id; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6692 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6693 | |
| 6694 | /* 1a: Software RC state - RC0 */ |
| 6695 | I915_WRITE(GEN6_RC_STATE, 0); |
| 6696 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 6697 | /* 1b: Get forcewake during program sequence. Although the driver |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6698 | * 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] | 6699 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6700 | |
| 6701 | /* 2a: Disable RC states. */ |
| 6702 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6703 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6704 | /* 2b: Program RC6 thresholds.*/ |
| 6705 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 6706 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 6707 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6708 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6709 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6710 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Sagar Arun Kamble | 415544d | 2017-10-10 22:30:00 +0100 | [diff] [blame] | 6711 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6712 | |
| 6713 | /* 3: Enable RC6 */ |
Sagar Arun Kamble | 771decb | 2017-10-10 22:30:07 +0100 | [diff] [blame] | 6714 | if (intel_rc6_enabled() & INTEL_RC6_ENABLE) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6715 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6716 | intel_print_rc6_info(dev_priv, rc6_mask); |
Sagar Arun Kamble | 415544d | 2017-10-10 22:30:00 +0100 | [diff] [blame] | 6717 | |
| 6718 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 6719 | GEN7_RC_CTL_TO_MODE | |
| 6720 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6721 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 6722 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 6723 | } |
| 6724 | |
| 6725 | static void gen8_enable_rps(struct drm_i915_private *dev_priv) |
| 6726 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6727 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 6728 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 6729 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 6730 | |
| 6731 | /* 1 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 6732 | I915_WRITE(GEN6_RPNSWREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6733 | HSW_FREQUENCY(rps->rp1_freq)); |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 6734 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6735 | HSW_FREQUENCY(rps->rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6736 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 6737 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6738 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6739 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 6740 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6741 | rps->max_freq_softlimit << 24 | |
| 6742 | rps->min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6743 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6744 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 6745 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 6746 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 6747 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6748 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6749 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6750 | |
Sagar Arun Kamble | 3a85392 | 2017-10-10 22:30:01 +0100 | [diff] [blame] | 6751 | /* 2: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6752 | I915_WRITE(GEN6_RP_CONTROL, |
| 6753 | GEN6_RP_MEDIA_TURBO | |
| 6754 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6755 | GEN6_RP_MEDIA_IS_GFX | |
| 6756 | GEN6_RP_ENABLE | |
| 6757 | GEN6_RP_UP_BUSY_AVG | |
| 6758 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6759 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6760 | reset_rps(dev_priv, gen6_set_rps); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6761 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6762 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6763 | } |
| 6764 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6765 | static void gen6_enable_rc6(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6766 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6767 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6768 | enum intel_engine_id id; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 6769 | u32 rc6vids, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6770 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6771 | int rc6_mode; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 6772 | int ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6773 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6774 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6775 | |
| 6776 | /* Clear the DBG now so we don't confuse earlier errors */ |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 6777 | gtfifodbg = I915_READ(GTFIFODBG); |
| 6778 | if (gtfifodbg) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6779 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 6780 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 6781 | } |
| 6782 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6783 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6784 | |
| 6785 | /* disable the counters and set deterministic thresholds */ |
| 6786 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6787 | |
| 6788 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 6789 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 6790 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 6791 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 6792 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 6793 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6794 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6795 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6796 | |
| 6797 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 6798 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6799 | if (IS_IVYBRIDGE(dev_priv)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 6800 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 6801 | else |
| 6802 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 6803 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6804 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 6805 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6806 | /* Check if we are enabling RC6 */ |
Sagar Arun Kamble | 771decb | 2017-10-10 22:30:07 +0100 | [diff] [blame] | 6807 | rc6_mode = intel_rc6_enabled(); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6808 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 6809 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 6810 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6811 | /* We don't use those on Haswell */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6812 | if (!IS_HASWELL(dev_priv)) { |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6813 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 6814 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6815 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6816 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 6817 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 6818 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6819 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6820 | intel_print_rc6_info(dev_priv, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6821 | |
| 6822 | I915_WRITE(GEN6_RC_CONTROL, |
| 6823 | rc6_mask | |
| 6824 | GEN6_RC_CTL_EI_MODE(1) | |
| 6825 | GEN6_RC_CTL_HW_ENABLE); |
| 6826 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 6827 | rc6vids = 0; |
| 6828 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6829 | if (IS_GEN6(dev_priv) && ret) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 6830 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6831 | } else if (IS_GEN6(dev_priv) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 6832 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 6833 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 6834 | rc6vids &= 0xffff00; |
| 6835 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 6836 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 6837 | if (ret) |
| 6838 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 6839 | } |
| 6840 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6841 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6842 | } |
| 6843 | |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6844 | static void gen6_enable_rps(struct drm_i915_private *dev_priv) |
| 6845 | { |
Sagar Arun Kamble | 960e546 | 2017-10-10 22:29:59 +0100 | [diff] [blame] | 6846 | /* Here begins a magic sequence of register writes to enable |
| 6847 | * auto-downclocking. |
| 6848 | * |
| 6849 | * Perhaps there might be some value in exposing these to |
| 6850 | * userspace... |
| 6851 | */ |
| 6852 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 6853 | |
| 6854 | /* Power down if completely idle for over 50ms */ |
| 6855 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
| 6856 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 6857 | |
| 6858 | reset_rps(dev_priv, gen6_set_rps); |
| 6859 | |
| 6860 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 6861 | } |
| 6862 | |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 6863 | static void gen6_update_ring_freq(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6864 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6865 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6866 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6867 | unsigned int gpu_freq; |
| 6868 | unsigned int max_ia_freq, min_ring_freq; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6869 | unsigned int max_gpu_freq, min_gpu_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6870 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6871 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6872 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 6873 | WARN_ON(!mutex_is_locked(&dev_priv->pcu_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 6874 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6875 | policy = cpufreq_cpu_get(0); |
| 6876 | if (policy) { |
| 6877 | max_ia_freq = policy->cpuinfo.max_freq; |
| 6878 | cpufreq_cpu_put(policy); |
| 6879 | } else { |
| 6880 | /* |
| 6881 | * Default to measured freq if none found, PCU will ensure we |
| 6882 | * don't go over |
| 6883 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6884 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6885 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6886 | |
| 6887 | /* Convert from kHz to MHz */ |
| 6888 | max_ia_freq /= 1000; |
| 6889 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 6890 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 6891 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 6892 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6893 | |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6894 | if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6895 | /* Convert GT frequency to 50 HZ units */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6896 | min_gpu_freq = rps->min_freq / GEN9_FREQ_SCALER; |
| 6897 | max_gpu_freq = rps->max_freq / GEN9_FREQ_SCALER; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6898 | } else { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 6899 | min_gpu_freq = rps->min_freq; |
| 6900 | max_gpu_freq = rps->max_freq; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6901 | } |
| 6902 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6903 | /* |
| 6904 | * For each potential GPU frequency, load a ring frequency we'd like |
| 6905 | * to use for memory access. We do this by specifying the IA frequency |
| 6906 | * the PCU should use as a reference to determine the ring frequency. |
| 6907 | */ |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6908 | for (gpu_freq = max_gpu_freq; gpu_freq >= min_gpu_freq; gpu_freq--) { |
| 6909 | int diff = max_gpu_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6910 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6911 | |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 6912 | if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6913 | /* |
| 6914 | * ring_freq = 2 * GT. ring_freq is in 100MHz units |
| 6915 | * No floor required for ring frequency on SKL. |
| 6916 | */ |
| 6917 | ring_freq = gpu_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6918 | } else if (INTEL_INFO(dev_priv)->gen >= 8) { |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 6919 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 6920 | ring_freq = max(min_ring_freq, gpu_freq); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6921 | } else if (IS_HASWELL(dev_priv)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 6922 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6923 | ring_freq = max(min_ring_freq, ring_freq); |
| 6924 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 6925 | } else { |
| 6926 | /* On older processors, there is no separate ring |
| 6927 | * clock domain, so in order to boost the bandwidth |
| 6928 | * of the ring, we need to upclock the CPU (ia_freq). |
| 6929 | * |
| 6930 | * For GPU frequencies less than 750MHz, |
| 6931 | * just use the lowest ring freq. |
| 6932 | */ |
| 6933 | if (gpu_freq < min_freq) |
| 6934 | ia_freq = 800; |
| 6935 | else |
| 6936 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 6937 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 6938 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6939 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6940 | sandybridge_pcode_write(dev_priv, |
| 6941 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6942 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 6943 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 6944 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6945 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6946 | } |
| 6947 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 6948 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6949 | { |
| 6950 | u32 val, rp0; |
| 6951 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6952 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6953 | |
Imre Deak | 43b6799 | 2016-08-31 19:13:02 +0300 | [diff] [blame] | 6954 | switch (INTEL_INFO(dev_priv)->sseu.eu_total) { |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6955 | case 8: |
| 6956 | /* (2 * 4) config */ |
| 6957 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 6958 | break; |
| 6959 | case 12: |
| 6960 | /* (2 * 6) config */ |
| 6961 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 6962 | break; |
| 6963 | case 16: |
| 6964 | /* (2 * 8) config */ |
| 6965 | default: |
| 6966 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 6967 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 6968 | break; |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 6969 | } |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6970 | |
| 6971 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 6972 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6973 | return rp0; |
| 6974 | } |
| 6975 | |
| 6976 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 6977 | { |
| 6978 | u32 val, rpe; |
| 6979 | |
| 6980 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 6981 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 6982 | |
| 6983 | return rpe; |
| 6984 | } |
| 6985 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 6986 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 6987 | { |
| 6988 | u32 val, rp1; |
| 6989 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6990 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 6991 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 6992 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 6993 | return rp1; |
| 6994 | } |
| 6995 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 6996 | static u32 cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 6997 | { |
| 6998 | u32 val, rpn; |
| 6999 | |
| 7000 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 7001 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 7002 | FB_GFX_FREQ_FUSE_MASK); |
| 7003 | |
| 7004 | return rpn; |
| 7005 | } |
| 7006 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7007 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 7008 | { |
| 7009 | u32 val, rp1; |
| 7010 | |
| 7011 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 7012 | |
| 7013 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 7014 | |
| 7015 | return rp1; |
| 7016 | } |
| 7017 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7018 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7019 | { |
| 7020 | u32 val, rp0; |
| 7021 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7022 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7023 | |
| 7024 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 7025 | /* Clamp to max */ |
| 7026 | rp0 = min_t(u32, rp0, 0xea); |
| 7027 | |
| 7028 | return rp0; |
| 7029 | } |
| 7030 | |
| 7031 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 7032 | { |
| 7033 | u32 val, rpe; |
| 7034 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7035 | 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] | 7036 | 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] | 7037 | 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] | 7038 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 7039 | |
| 7040 | return rpe; |
| 7041 | } |
| 7042 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 7043 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7044 | { |
Imre Deak | 3614603 | 2014-12-04 18:39:35 +0200 | [diff] [blame] | 7045 | u32 val; |
| 7046 | |
| 7047 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
| 7048 | /* |
| 7049 | * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value |
| 7050 | * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on |
| 7051 | * a BYT-M B0 the above register contains 0xbf. Moreover when setting |
| 7052 | * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0 |
| 7053 | * to make sure it matches what Punit accepts. |
| 7054 | */ |
| 7055 | return max_t(u32, val, 0xc0); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7056 | } |
| 7057 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7058 | /* Check that the pctx buffer wasn't move under us. */ |
| 7059 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 7060 | { |
| 7061 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 7062 | |
| 7063 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 7064 | dev_priv->vlv_pctx->stolen->start); |
| 7065 | } |
| 7066 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7067 | |
| 7068 | /* Check that the pcbr address is not empty. */ |
| 7069 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 7070 | { |
| 7071 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 7072 | |
| 7073 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 7074 | } |
| 7075 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7076 | static void cherryview_setup_pctx(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7077 | { |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 7078 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 7079 | unsigned long pctx_paddr, paddr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7080 | u32 pcbr; |
| 7081 | int pctx_size = 32*1024; |
| 7082 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7083 | pcbr = I915_READ(VLV_PCBR); |
| 7084 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7085 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7086 | paddr = (dev_priv->mm.stolen_base + |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 7087 | (ggtt->stolen_size - pctx_size)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7088 | |
| 7089 | pctx_paddr = (paddr & (~4095)); |
| 7090 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 7091 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7092 | |
| 7093 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7094 | } |
| 7095 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7096 | static void valleyview_setup_pctx(struct drm_i915_private *dev_priv) |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7097 | { |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7098 | struct drm_i915_gem_object *pctx; |
| 7099 | unsigned long pctx_paddr; |
| 7100 | u32 pcbr; |
| 7101 | int pctx_size = 24*1024; |
| 7102 | |
| 7103 | pcbr = I915_READ(VLV_PCBR); |
| 7104 | if (pcbr) { |
| 7105 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 7106 | int pcbr_offset; |
| 7107 | |
| 7108 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 7109 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7110 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 7111 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7112 | pctx_size); |
| 7113 | goto out; |
| 7114 | } |
| 7115 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7116 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 7117 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7118 | /* |
| 7119 | * From the Gunit register HAS: |
| 7120 | * The Gfx driver is expected to program this register and ensure |
| 7121 | * proper allocation within Gfx stolen memory. For example, this |
| 7122 | * register should be programmed such than the PCBR range does not |
| 7123 | * overlap with other ranges, such as the frame buffer, protected |
| 7124 | * memory, or any other relevant ranges. |
| 7125 | */ |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 7126 | pctx = i915_gem_object_create_stolen(dev_priv, pctx_size); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7127 | if (!pctx) { |
| 7128 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
Tvrtko Ursulin | ee50489 | 2016-02-11 10:27:30 +0000 | [diff] [blame] | 7129 | goto out; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7130 | } |
| 7131 | |
| 7132 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 7133 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 7134 | |
| 7135 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 7136 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 7137 | dev_priv->vlv_pctx = pctx; |
| 7138 | } |
| 7139 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7140 | static void valleyview_cleanup_pctx(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7141 | { |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7142 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 7143 | return; |
| 7144 | |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 7145 | i915_gem_object_put(dev_priv->vlv_pctx); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7146 | dev_priv->vlv_pctx = NULL; |
| 7147 | } |
| 7148 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7149 | static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv) |
| 7150 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7151 | dev_priv->gt_pm.rps.gpll_ref_freq = |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7152 | vlv_get_cck_clock(dev_priv, "GPLL ref", |
| 7153 | CCK_GPLL_CLOCK_CONTROL, |
| 7154 | dev_priv->czclk_freq); |
| 7155 | |
| 7156 | DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7157 | dev_priv->gt_pm.rps.gpll_ref_freq); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7158 | } |
| 7159 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7160 | static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7161 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7162 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7163 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7164 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7165 | valleyview_setup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7166 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7167 | vlv_init_gpll_ref_freq(dev_priv); |
| 7168 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7169 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7170 | switch ((val >> 6) & 3) { |
| 7171 | case 0: |
| 7172 | case 1: |
| 7173 | dev_priv->mem_freq = 800; |
| 7174 | break; |
| 7175 | case 2: |
| 7176 | dev_priv->mem_freq = 1066; |
| 7177 | break; |
| 7178 | case 3: |
| 7179 | dev_priv->mem_freq = 1333; |
| 7180 | break; |
| 7181 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7182 | 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] | 7183 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7184 | rps->max_freq = valleyview_rps_max_freq(dev_priv); |
| 7185 | rps->rp0_freq = rps->max_freq; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7186 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7187 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7188 | rps->max_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7189 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7190 | rps->efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7191 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7192 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7193 | rps->efficient_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7194 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7195 | rps->rp1_freq = valleyview_rps_guar_freq(dev_priv); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7196 | 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] | 7197 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7198 | rps->rp1_freq); |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 7199 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7200 | rps->min_freq = valleyview_rps_min_freq(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7201 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7202 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7203 | rps->min_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7204 | } |
| 7205 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7206 | static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7207 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7208 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7209 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7210 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7211 | cherryview_setup_pctx(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7212 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 7213 | vlv_init_gpll_ref_freq(dev_priv); |
| 7214 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7215 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7216 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7217 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 7218 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7219 | switch ((val >> 2) & 0x7) { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7220 | case 3: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7221 | dev_priv->mem_freq = 2000; |
| 7222 | break; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 7223 | default: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 7224 | dev_priv->mem_freq = 1600; |
| 7225 | break; |
| 7226 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 7227 | 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] | 7228 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7229 | rps->max_freq = cherryview_rps_max_freq(dev_priv); |
| 7230 | rps->rp0_freq = rps->max_freq; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7231 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7232 | intel_gpu_freq(dev_priv, rps->max_freq), |
| 7233 | rps->max_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7234 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7235 | rps->efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7236 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7237 | intel_gpu_freq(dev_priv, rps->efficient_freq), |
| 7238 | rps->efficient_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7239 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7240 | rps->rp1_freq = cherryview_rps_guar_freq(dev_priv); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7241 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7242 | intel_gpu_freq(dev_priv, rps->rp1_freq), |
| 7243 | rps->rp1_freq); |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 7244 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7245 | rps->min_freq = cherryview_rps_min_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7246 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7247 | intel_gpu_freq(dev_priv, rps->min_freq), |
| 7248 | rps->min_freq); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7249 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7250 | WARN_ONCE((rps->max_freq | rps->efficient_freq | rps->rp1_freq | |
| 7251 | rps->min_freq) & 1, |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7252 | "Odd GPU freq values\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7253 | } |
| 7254 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7255 | static void valleyview_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7256 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7257 | valleyview_cleanup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 7258 | } |
| 7259 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7260 | static void cherryview_enable_rc6(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7261 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7262 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7263 | enum intel_engine_id id; |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7264 | u32 gtfifodbg, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7265 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7266 | gtfifodbg = I915_READ(GTFIFODBG) & ~(GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV | |
| 7267 | GT_FIFO_FREE_ENTRIES_CHV); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7268 | if (gtfifodbg) { |
| 7269 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7270 | gtfifodbg); |
| 7271 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7272 | } |
| 7273 | |
| 7274 | cherryview_check_pctx(dev_priv); |
| 7275 | |
| 7276 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 7277 | * 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] | 7278 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7279 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7280 | /* Disable RC states. */ |
| 7281 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7282 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7283 | /* 2a: Program RC6 thresholds.*/ |
| 7284 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 7285 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 7286 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 7287 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7288 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7289 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7290 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 7291 | |
Deepak S | f4f71c7 | 2015-03-28 15:23:35 +0530 | [diff] [blame] | 7292 | /* TO threshold set to 500 us ( 0x186 * 1.28 us) */ |
| 7293 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x186); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7294 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7295 | /* Allows RC6 residency counter to work */ |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7296 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 7297 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7298 | VLV_MEDIA_RC6_COUNT_EN | |
| 7299 | VLV_RENDER_RC6_COUNT_EN)); |
| 7300 | |
| 7301 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 7302 | pcbr = I915_READ(VLV_PCBR); |
| 7303 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7304 | /* 3: Enable RC6 */ |
Sagar Arun Kamble | 771decb | 2017-10-10 22:30:07 +0100 | [diff] [blame] | 7305 | if ((intel_rc6_enabled() & INTEL_RC6_ENABLE) && |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7306 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 7307 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7308 | |
| 7309 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 7310 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7311 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 7312 | } |
| 7313 | |
| 7314 | static void cherryview_enable_rps(struct drm_i915_private *dev_priv) |
| 7315 | { |
| 7316 | u32 val; |
| 7317 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7318 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 7319 | |
| 7320 | /* 1: Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 7321 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7322 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7323 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7324 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7325 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7326 | |
| 7327 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7328 | |
Sagar Arun Kamble | d46b00d | 2017-10-10 22:30:03 +0100 | [diff] [blame] | 7329 | /* 2: Enable RPS */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7330 | I915_WRITE(GEN6_RP_CONTROL, |
| 7331 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 7332 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7333 | GEN6_RP_ENABLE | |
| 7334 | GEN6_RP_UP_BUSY_AVG | |
| 7335 | GEN6_RP_DOWN_IDLE_AVG); |
| 7336 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7337 | /* Setting Fixed Bias */ |
| 7338 | val = VLV_OVERRIDE_EN | |
| 7339 | VLV_SOC_TDP_EN | |
| 7340 | CHV_BIAS_CPU_50_SOC_50; |
| 7341 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7342 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7343 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 7344 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7345 | /* RPS code assumes GPLL is used */ |
| 7346 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7347 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7348 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7349 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7350 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7351 | reset_rps(dev_priv, valleyview_set_rps); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7352 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7353 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7354 | } |
| 7355 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7356 | static void valleyview_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7357 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7358 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7359 | enum intel_engine_id id; |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7360 | u32 gtfifodbg, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7361 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7362 | valleyview_check_pctx(dev_priv); |
| 7363 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7364 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7365 | if (gtfifodbg) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 7366 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7367 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7368 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7369 | } |
| 7370 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7371 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7372 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7373 | /* Disable RC states. */ |
| 7374 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7375 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7376 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 7377 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 7378 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 7379 | |
| 7380 | for_each_engine(engine, dev_priv, id) |
| 7381 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
| 7382 | |
| 7383 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
| 7384 | |
| 7385 | /* Allows RC6 residency counter to work */ |
| 7386 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 7387 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7388 | VLV_MEDIA_RC0_COUNT_EN | |
| 7389 | VLV_RENDER_RC0_COUNT_EN | |
| 7390 | VLV_MEDIA_RC6_COUNT_EN | |
| 7391 | VLV_RENDER_RC6_COUNT_EN)); |
| 7392 | |
Sagar Arun Kamble | 771decb | 2017-10-10 22:30:07 +0100 | [diff] [blame] | 7393 | if (intel_rc6_enabled() & INTEL_RC6_ENABLE) |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7394 | rc6_mode = GEN7_RC_CTL_TO_MODE | VLV_RC_CTL_CTX_RST_PARALLEL; |
| 7395 | |
| 7396 | intel_print_rc6_info(dev_priv, rc6_mode); |
| 7397 | |
| 7398 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 7399 | |
| 7400 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 7401 | } |
| 7402 | |
| 7403 | static void valleyview_enable_rps(struct drm_i915_private *dev_priv) |
| 7404 | { |
| 7405 | u32 val; |
| 7406 | |
Sagar Arun Kamble | 0d6fc92 | 2017-10-10 22:30:02 +0100 | [diff] [blame] | 7407 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 7408 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 7409 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7410 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7411 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7412 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7413 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7414 | |
| 7415 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7416 | |
| 7417 | I915_WRITE(GEN6_RP_CONTROL, |
| 7418 | GEN6_RP_MEDIA_TURBO | |
| 7419 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7420 | GEN6_RP_MEDIA_IS_GFX | |
| 7421 | GEN6_RP_ENABLE | |
| 7422 | GEN6_RP_UP_BUSY_AVG | |
| 7423 | GEN6_RP_DOWN_IDLE_CONT); |
| 7424 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7425 | /* Setting Fixed Bias */ |
| 7426 | val = VLV_OVERRIDE_EN | |
| 7427 | VLV_SOC_TDP_EN | |
| 7428 | VLV_BIAS_CPU_125_SOC_875; |
| 7429 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7430 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7431 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7432 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7433 | /* RPS code assumes GPLL is used */ |
| 7434 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7435 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7436 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7437 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7438 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7439 | reset_rps(dev_priv, valleyview_set_rps); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7440 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7441 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7442 | } |
| 7443 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7444 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 7445 | { |
| 7446 | unsigned long freq; |
| 7447 | int div = (vidfreq & 0x3f0000) >> 16; |
| 7448 | int post = (vidfreq & 0x3000) >> 12; |
| 7449 | int pre = (vidfreq & 0x7); |
| 7450 | |
| 7451 | if (!pre) |
| 7452 | return 0; |
| 7453 | |
| 7454 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 7455 | |
| 7456 | return freq; |
| 7457 | } |
| 7458 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7459 | static const struct cparams { |
| 7460 | u16 i; |
| 7461 | u16 t; |
| 7462 | u16 m; |
| 7463 | u16 c; |
| 7464 | } cparams[] = { |
| 7465 | { 1, 1333, 301, 28664 }, |
| 7466 | { 1, 1066, 294, 24460 }, |
| 7467 | { 1, 800, 294, 25192 }, |
| 7468 | { 0, 1333, 276, 27605 }, |
| 7469 | { 0, 1066, 276, 27605 }, |
| 7470 | { 0, 800, 231, 23784 }, |
| 7471 | }; |
| 7472 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7473 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7474 | { |
| 7475 | u64 total_count, diff, ret; |
| 7476 | u32 count1, count2, count3, m = 0, c = 0; |
| 7477 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 7478 | int i; |
| 7479 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7480 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7481 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7482 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7483 | |
| 7484 | /* Prevent division-by-zero if we are asking too fast. |
| 7485 | * Also, we don't get interesting results if we are polling |
| 7486 | * faster than once in 10ms, so just return the saved value |
| 7487 | * in such cases. |
| 7488 | */ |
| 7489 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7490 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7491 | |
| 7492 | count1 = I915_READ(DMIEC); |
| 7493 | count2 = I915_READ(DDREC); |
| 7494 | count3 = I915_READ(CSIEC); |
| 7495 | |
| 7496 | total_count = count1 + count2 + count3; |
| 7497 | |
| 7498 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7499 | if (total_count < dev_priv->ips.last_count1) { |
| 7500 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7501 | diff += total_count; |
| 7502 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7503 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7504 | } |
| 7505 | |
| 7506 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7507 | if (cparams[i].i == dev_priv->ips.c_m && |
| 7508 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7509 | m = cparams[i].m; |
| 7510 | c = cparams[i].c; |
| 7511 | break; |
| 7512 | } |
| 7513 | } |
| 7514 | |
| 7515 | diff = div_u64(diff, diff1); |
| 7516 | ret = ((m * diff) + c); |
| 7517 | ret = div_u64(ret, 10); |
| 7518 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7519 | dev_priv->ips.last_count1 = total_count; |
| 7520 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7521 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7522 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7523 | |
| 7524 | return ret; |
| 7525 | } |
| 7526 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7527 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 7528 | { |
| 7529 | unsigned long val; |
| 7530 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7531 | if (INTEL_INFO(dev_priv)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7532 | return 0; |
| 7533 | |
| 7534 | spin_lock_irq(&mchdev_lock); |
| 7535 | |
| 7536 | val = __i915_chipset_val(dev_priv); |
| 7537 | |
| 7538 | spin_unlock_irq(&mchdev_lock); |
| 7539 | |
| 7540 | return val; |
| 7541 | } |
| 7542 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7543 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 7544 | { |
| 7545 | unsigned long m, x, b; |
| 7546 | u32 tsfs; |
| 7547 | |
| 7548 | tsfs = I915_READ(TSFS); |
| 7549 | |
| 7550 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 7551 | x = I915_READ8(TR1); |
| 7552 | |
| 7553 | b = tsfs & TSFS_INTR_MASK; |
| 7554 | |
| 7555 | return ((m * x) / 127) - b; |
| 7556 | } |
| 7557 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7558 | static int _pxvid_to_vd(u8 pxvid) |
| 7559 | { |
| 7560 | if (pxvid == 0) |
| 7561 | return 0; |
| 7562 | |
| 7563 | if (pxvid >= 8 && pxvid < 31) |
| 7564 | pxvid = 31; |
| 7565 | |
| 7566 | return (pxvid + 2) * 125; |
| 7567 | } |
| 7568 | |
| 7569 | 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] | 7570 | { |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7571 | const int vd = _pxvid_to_vd(pxvid); |
| 7572 | const int vm = vd - 1125; |
| 7573 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7574 | if (INTEL_INFO(dev_priv)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7575 | return vm > 0 ? vm : 0; |
| 7576 | |
| 7577 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7578 | } |
| 7579 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7580 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7581 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 7582 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7583 | u32 count; |
| 7584 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7585 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7586 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 7587 | now = ktime_get_raw_ns(); |
| 7588 | diffms = now - dev_priv->ips.last_time2; |
| 7589 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7590 | |
| 7591 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7592 | if (!diffms) |
| 7593 | return; |
| 7594 | |
| 7595 | count = I915_READ(GFXEC); |
| 7596 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7597 | if (count < dev_priv->ips.last_count2) { |
| 7598 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7599 | diff += count; |
| 7600 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7601 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7602 | } |
| 7603 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7604 | dev_priv->ips.last_count2 = count; |
| 7605 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7606 | |
| 7607 | /* More magic constants... */ |
| 7608 | diff = diff * 1181; |
| 7609 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7610 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7611 | } |
| 7612 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7613 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 7614 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7615 | if (INTEL_INFO(dev_priv)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7616 | return; |
| 7617 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7618 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7619 | |
| 7620 | __i915_update_gfx_val(dev_priv); |
| 7621 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7622 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7623 | } |
| 7624 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7625 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7626 | { |
| 7627 | unsigned long t, corr, state1, corr2, state2; |
| 7628 | u32 pxvid, ext_v; |
| 7629 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7630 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7631 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7632 | pxvid = I915_READ(PXVFREQ(dev_priv->gt_pm.rps.cur_freq)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7633 | pxvid = (pxvid >> 24) & 0x7f; |
| 7634 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 7635 | |
| 7636 | state1 = ext_v; |
| 7637 | |
| 7638 | t = i915_mch_val(dev_priv); |
| 7639 | |
| 7640 | /* Revel in the empirically derived constants */ |
| 7641 | |
| 7642 | /* Correction factor in 1/100000 units */ |
| 7643 | if (t > 80) |
| 7644 | corr = ((t * 2349) + 135940); |
| 7645 | else if (t >= 50) |
| 7646 | corr = ((t * 964) + 29317); |
| 7647 | else /* < 50 */ |
| 7648 | corr = ((t * 301) + 1004); |
| 7649 | |
| 7650 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 7651 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7652 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7653 | |
| 7654 | state2 = (corr2 * state1) / 10000; |
| 7655 | state2 /= 100; /* convert to mW */ |
| 7656 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7657 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7658 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7659 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7660 | } |
| 7661 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7662 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 7663 | { |
| 7664 | unsigned long val; |
| 7665 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7666 | if (INTEL_INFO(dev_priv)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7667 | return 0; |
| 7668 | |
| 7669 | spin_lock_irq(&mchdev_lock); |
| 7670 | |
| 7671 | val = __i915_gfx_val(dev_priv); |
| 7672 | |
| 7673 | spin_unlock_irq(&mchdev_lock); |
| 7674 | |
| 7675 | return val; |
| 7676 | } |
| 7677 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7678 | /** |
| 7679 | * i915_read_mch_val - return value for IPS use |
| 7680 | * |
| 7681 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 7682 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 7683 | */ |
| 7684 | unsigned long i915_read_mch_val(void) |
| 7685 | { |
| 7686 | struct drm_i915_private *dev_priv; |
| 7687 | unsigned long chipset_val, graphics_val, ret = 0; |
| 7688 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7689 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7690 | if (!i915_mch_dev) |
| 7691 | goto out_unlock; |
| 7692 | dev_priv = i915_mch_dev; |
| 7693 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7694 | chipset_val = __i915_chipset_val(dev_priv); |
| 7695 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7696 | |
| 7697 | ret = chipset_val + graphics_val; |
| 7698 | |
| 7699 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7700 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7701 | |
| 7702 | return ret; |
| 7703 | } |
| 7704 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 7705 | |
| 7706 | /** |
| 7707 | * i915_gpu_raise - raise GPU frequency limit |
| 7708 | * |
| 7709 | * Raise the limit; IPS indicates we have thermal headroom. |
| 7710 | */ |
| 7711 | bool i915_gpu_raise(void) |
| 7712 | { |
| 7713 | struct drm_i915_private *dev_priv; |
| 7714 | bool ret = true; |
| 7715 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7716 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7717 | if (!i915_mch_dev) { |
| 7718 | ret = false; |
| 7719 | goto out_unlock; |
| 7720 | } |
| 7721 | dev_priv = i915_mch_dev; |
| 7722 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7723 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 7724 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7725 | |
| 7726 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7727 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7728 | |
| 7729 | return ret; |
| 7730 | } |
| 7731 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 7732 | |
| 7733 | /** |
| 7734 | * i915_gpu_lower - lower GPU frequency limit |
| 7735 | * |
| 7736 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 7737 | * frequency maximum. |
| 7738 | */ |
| 7739 | bool i915_gpu_lower(void) |
| 7740 | { |
| 7741 | struct drm_i915_private *dev_priv; |
| 7742 | bool ret = true; |
| 7743 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7744 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7745 | if (!i915_mch_dev) { |
| 7746 | ret = false; |
| 7747 | goto out_unlock; |
| 7748 | } |
| 7749 | dev_priv = i915_mch_dev; |
| 7750 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7751 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 7752 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7753 | |
| 7754 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7755 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7756 | |
| 7757 | return ret; |
| 7758 | } |
| 7759 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 7760 | |
| 7761 | /** |
| 7762 | * i915_gpu_busy - indicate GPU business to IPS |
| 7763 | * |
| 7764 | * Tell the IPS driver whether or not the GPU is busy. |
| 7765 | */ |
| 7766 | bool i915_gpu_busy(void) |
| 7767 | { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7768 | bool ret = false; |
| 7769 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7770 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | dcff85c | 2016-08-05 10:14:11 +0100 | [diff] [blame] | 7771 | if (i915_mch_dev) |
| 7772 | ret = i915_mch_dev->gt.awake; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7773 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7774 | |
| 7775 | return ret; |
| 7776 | } |
| 7777 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 7778 | |
| 7779 | /** |
| 7780 | * i915_gpu_turbo_disable - disable graphics turbo |
| 7781 | * |
| 7782 | * Disable graphics turbo by resetting the max frequency and setting the |
| 7783 | * current frequency to the default. |
| 7784 | */ |
| 7785 | bool i915_gpu_turbo_disable(void) |
| 7786 | { |
| 7787 | struct drm_i915_private *dev_priv; |
| 7788 | bool ret = true; |
| 7789 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7790 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7791 | if (!i915_mch_dev) { |
| 7792 | ret = false; |
| 7793 | goto out_unlock; |
| 7794 | } |
| 7795 | dev_priv = i915_mch_dev; |
| 7796 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7797 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7798 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 7799 | if (!ironlake_set_drps(dev_priv, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7800 | ret = false; |
| 7801 | |
| 7802 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7803 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7804 | |
| 7805 | return ret; |
| 7806 | } |
| 7807 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 7808 | |
| 7809 | /** |
| 7810 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 7811 | * IPS got loaded first. |
| 7812 | * |
| 7813 | * This awkward dance is so that neither module has to depend on the |
| 7814 | * other in order for IPS to do the appropriate communication of |
| 7815 | * GPU turbo limits to i915. |
| 7816 | */ |
| 7817 | static void |
| 7818 | ips_ping_for_i915_load(void) |
| 7819 | { |
| 7820 | void (*link)(void); |
| 7821 | |
| 7822 | link = symbol_get(ips_link_to_i915_driver); |
| 7823 | if (link) { |
| 7824 | link(); |
| 7825 | symbol_put(ips_link_to_i915_driver); |
| 7826 | } |
| 7827 | } |
| 7828 | |
| 7829 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 7830 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7831 | /* We only register the i915 ips part with intel-ips once everything is |
| 7832 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7833 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7834 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7835 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7836 | |
| 7837 | ips_ping_for_i915_load(); |
| 7838 | } |
| 7839 | |
| 7840 | void intel_gpu_ips_teardown(void) |
| 7841 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7842 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7843 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7844 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7845 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 7846 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7847 | static void intel_init_emon(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7848 | { |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7849 | u32 lcfuse; |
| 7850 | u8 pxw[16]; |
| 7851 | int i; |
| 7852 | |
| 7853 | /* Disable to program */ |
| 7854 | I915_WRITE(ECR, 0); |
| 7855 | POSTING_READ(ECR); |
| 7856 | |
| 7857 | /* Program energy weights for various events */ |
| 7858 | I915_WRITE(SDEW, 0x15040d00); |
| 7859 | I915_WRITE(CSIEW0, 0x007f0000); |
| 7860 | I915_WRITE(CSIEW1, 0x1e220004); |
| 7861 | I915_WRITE(CSIEW2, 0x04000004); |
| 7862 | |
| 7863 | for (i = 0; i < 5; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7864 | I915_WRITE(PEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7865 | for (i = 0; i < 3; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7866 | I915_WRITE(DEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7867 | |
| 7868 | /* Program P-state weights to account for frequency power adjustment */ |
| 7869 | for (i = 0; i < 16; i++) { |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7870 | u32 pxvidfreq = I915_READ(PXVFREQ(i)); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7871 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 7872 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 7873 | PXVFREQ_PX_SHIFT; |
| 7874 | unsigned long val; |
| 7875 | |
| 7876 | val = vid * vid; |
| 7877 | val *= (freq / 1000); |
| 7878 | val *= 255; |
| 7879 | val /= (127*127*900); |
| 7880 | if (val > 0xff) |
| 7881 | DRM_ERROR("bad pxval: %ld\n", val); |
| 7882 | pxw[i] = val; |
| 7883 | } |
| 7884 | /* Render standby states get 0 weight */ |
| 7885 | pxw[14] = 0; |
| 7886 | pxw[15] = 0; |
| 7887 | |
| 7888 | for (i = 0; i < 4; i++) { |
| 7889 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 7890 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7891 | I915_WRITE(PXW(i), val); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7892 | } |
| 7893 | |
| 7894 | /* Adjust magic regs to magic values (more experimental results) */ |
| 7895 | I915_WRITE(OGW0, 0); |
| 7896 | I915_WRITE(OGW1, 0); |
| 7897 | I915_WRITE(EG0, 0x00007f00); |
| 7898 | I915_WRITE(EG1, 0x0000000e); |
| 7899 | I915_WRITE(EG2, 0x000e0000); |
| 7900 | I915_WRITE(EG3, 0x68000300); |
| 7901 | I915_WRITE(EG4, 0x42000000); |
| 7902 | I915_WRITE(EG5, 0x00140031); |
| 7903 | I915_WRITE(EG6, 0); |
| 7904 | I915_WRITE(EG7, 0); |
| 7905 | |
| 7906 | for (i = 0; i < 8; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7907 | I915_WRITE(PXWL(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7908 | |
| 7909 | /* Enable PMON + select events */ |
| 7910 | I915_WRITE(ECR, 0x80000019); |
| 7911 | |
| 7912 | lcfuse = I915_READ(LCFUSE02); |
| 7913 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7914 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7915 | } |
| 7916 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7917 | void intel_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7918 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7919 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 7920 | |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 7921 | /* |
| 7922 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 7923 | * requirement. |
| 7924 | */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 7925 | if (!i915_modparams.enable_rc6) { |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 7926 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 7927 | intel_runtime_pm_get(dev_priv); |
| 7928 | } |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7929 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 7930 | mutex_lock(&dev_priv->pcu_lock); |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7931 | |
| 7932 | /* Initialize RPS limits (for userspace) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7933 | if (IS_CHERRYVIEW(dev_priv)) |
| 7934 | cherryview_init_gt_powersave(dev_priv); |
| 7935 | else if (IS_VALLEYVIEW(dev_priv)) |
| 7936 | valleyview_init_gt_powersave(dev_priv); |
Chris Wilson | 2a13ae7 | 2016-08-02 11:15:27 +0100 | [diff] [blame] | 7937 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7938 | gen6_init_rps_frequencies(dev_priv); |
| 7939 | |
| 7940 | /* Derive initial user preferences/limits from the hardware limits */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7941 | rps->idle_freq = rps->min_freq; |
| 7942 | rps->cur_freq = rps->idle_freq; |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7943 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7944 | rps->max_freq_softlimit = rps->max_freq; |
| 7945 | rps->min_freq_softlimit = rps->min_freq; |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7946 | |
| 7947 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7948 | rps->min_freq_softlimit = |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7949 | max_t(int, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7950 | rps->efficient_freq, |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7951 | intel_freq_opcode(dev_priv, 450)); |
| 7952 | |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7953 | /* After setting max-softlimit, find the overclock max freq */ |
| 7954 | if (IS_GEN6(dev_priv) || |
| 7955 | IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
| 7956 | u32 params = 0; |
| 7957 | |
| 7958 | sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, ¶ms); |
| 7959 | if (params & BIT(31)) { /* OC supported */ |
| 7960 | DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n", |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7961 | (rps->max_freq & 0xff) * 50, |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7962 | (params & 0xff) * 50); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7963 | rps->max_freq = params & 0xff; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7964 | } |
| 7965 | } |
| 7966 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 7967 | /* Finally allow us to boost to max by default */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 7968 | rps->boost_freq = rps->max_freq; |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 7969 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 7970 | mutex_unlock(&dev_priv->pcu_lock); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7971 | } |
| 7972 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7973 | void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7974 | { |
Ville Syrjälä | 8dac1e1 | 2016-08-02 14:07:33 +0300 | [diff] [blame] | 7975 | if (IS_VALLEYVIEW(dev_priv)) |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7976 | valleyview_cleanup_gt_powersave(dev_priv); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 7977 | |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 7978 | if (!i915_modparams.enable_rc6) |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 7979 | intel_runtime_pm_put(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7980 | } |
| 7981 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7982 | /** |
| 7983 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 7984 | * @dev_priv: i915 device |
| 7985 | * |
| 7986 | * We don't want to disable RC6 or other features here, we just want |
| 7987 | * to make sure any work we've queued has finished and won't bother |
| 7988 | * us while we're suspended. |
| 7989 | */ |
| 7990 | void intel_suspend_gt_powersave(struct drm_i915_private *dev_priv) |
| 7991 | { |
| 7992 | if (INTEL_GEN(dev_priv) < 6) |
| 7993 | return; |
| 7994 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7995 | /* gen6_rps_idle() will be called later to disable interrupts */ |
| 7996 | } |
| 7997 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7998 | void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv) |
| 7999 | { |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8000 | dev_priv->gt_pm.rps.enabled = true; /* force RPS disabling */ |
| 8001 | dev_priv->gt_pm.rc6.enabled = true; /* force RC6 disabling */ |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8002 | intel_disable_gt_powersave(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 8003 | |
| 8004 | gen6_reset_rps_interrupts(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 8005 | } |
| 8006 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8007 | static inline void intel_disable_llc_pstate(struct drm_i915_private *i915) |
| 8008 | { |
| 8009 | lockdep_assert_held(&i915->pcu_lock); |
| 8010 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8011 | if (!i915->gt_pm.llc_pstate.enabled) |
| 8012 | return; |
| 8013 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8014 | /* Currently there is no HW configuration to be done to disable. */ |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8015 | |
| 8016 | i915->gt_pm.llc_pstate.enabled = false; |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8017 | } |
| 8018 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8019 | static void intel_disable_rc6(struct drm_i915_private *dev_priv) |
| 8020 | { |
| 8021 | lockdep_assert_held(&dev_priv->pcu_lock); |
| 8022 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8023 | if (!dev_priv->gt_pm.rc6.enabled) |
| 8024 | return; |
| 8025 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8026 | if (INTEL_GEN(dev_priv) >= 9) |
| 8027 | gen9_disable_rc6(dev_priv); |
| 8028 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8029 | cherryview_disable_rc6(dev_priv); |
| 8030 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8031 | valleyview_disable_rc6(dev_priv); |
| 8032 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8033 | gen6_disable_rc6(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8034 | |
| 8035 | dev_priv->gt_pm.rc6.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8036 | } |
| 8037 | |
| 8038 | static void intel_disable_rps(struct drm_i915_private *dev_priv) |
| 8039 | { |
| 8040 | lockdep_assert_held(&dev_priv->pcu_lock); |
| 8041 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8042 | if (!dev_priv->gt_pm.rps.enabled) |
| 8043 | return; |
| 8044 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8045 | if (INTEL_GEN(dev_priv) >= 9) |
| 8046 | gen9_disable_rps(dev_priv); |
| 8047 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8048 | cherryview_disable_rps(dev_priv); |
| 8049 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8050 | valleyview_disable_rps(dev_priv); |
| 8051 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8052 | gen6_disable_rps(dev_priv); |
| 8053 | else if (IS_IRONLAKE_M(dev_priv)) |
| 8054 | ironlake_disable_drps(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8055 | |
| 8056 | dev_priv->gt_pm.rps.enabled = false; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8057 | } |
| 8058 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 8059 | void intel_disable_gt_powersave(struct drm_i915_private *dev_priv) |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 8060 | { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8061 | mutex_lock(&dev_priv->pcu_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 8062 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8063 | intel_disable_rc6(dev_priv); |
| 8064 | intel_disable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8065 | if (HAS_LLC(dev_priv)) |
| 8066 | intel_disable_llc_pstate(dev_priv); |
| 8067 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8068 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8069 | } |
| 8070 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8071 | static inline void intel_enable_llc_pstate(struct drm_i915_private *i915) |
| 8072 | { |
| 8073 | lockdep_assert_held(&i915->pcu_lock); |
| 8074 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8075 | if (i915->gt_pm.llc_pstate.enabled) |
| 8076 | return; |
| 8077 | |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8078 | gen6_update_ring_freq(i915); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8079 | |
| 8080 | i915->gt_pm.llc_pstate.enabled = true; |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8081 | } |
| 8082 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8083 | static void intel_enable_rc6(struct drm_i915_private *dev_priv) |
| 8084 | { |
| 8085 | lockdep_assert_held(&dev_priv->pcu_lock); |
| 8086 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8087 | if (dev_priv->gt_pm.rc6.enabled) |
| 8088 | return; |
| 8089 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8090 | if (IS_CHERRYVIEW(dev_priv)) |
| 8091 | cherryview_enable_rc6(dev_priv); |
| 8092 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8093 | valleyview_enable_rc6(dev_priv); |
| 8094 | else if (INTEL_GEN(dev_priv) >= 9) |
| 8095 | gen9_enable_rc6(dev_priv); |
| 8096 | else if (IS_BROADWELL(dev_priv)) |
| 8097 | gen8_enable_rc6(dev_priv); |
| 8098 | else if (INTEL_GEN(dev_priv) >= 6) |
| 8099 | gen6_enable_rc6(dev_priv); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8100 | |
| 8101 | dev_priv->gt_pm.rc6.enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8102 | } |
| 8103 | |
| 8104 | static void intel_enable_rps(struct drm_i915_private *dev_priv) |
| 8105 | { |
| 8106 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 8107 | |
| 8108 | lockdep_assert_held(&dev_priv->pcu_lock); |
| 8109 | |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8110 | if (rps->enabled) |
| 8111 | return; |
| 8112 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8113 | if (IS_CHERRYVIEW(dev_priv)) { |
| 8114 | cherryview_enable_rps(dev_priv); |
| 8115 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 8116 | valleyview_enable_rps(dev_priv); |
| 8117 | } else if (INTEL_GEN(dev_priv) >= 9) { |
| 8118 | gen9_enable_rps(dev_priv); |
| 8119 | } else if (IS_BROADWELL(dev_priv)) { |
| 8120 | gen8_enable_rps(dev_priv); |
| 8121 | } else if (INTEL_GEN(dev_priv) >= 6) { |
| 8122 | gen6_enable_rps(dev_priv); |
| 8123 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 8124 | ironlake_enable_drps(dev_priv); |
| 8125 | intel_init_emon(dev_priv); |
| 8126 | } |
| 8127 | |
| 8128 | WARN_ON(rps->max_freq < rps->min_freq); |
| 8129 | WARN_ON(rps->idle_freq > rps->max_freq); |
| 8130 | |
| 8131 | WARN_ON(rps->efficient_freq < rps->min_freq); |
| 8132 | WARN_ON(rps->efficient_freq > rps->max_freq); |
Sagar Arun Kamble | 37d933f | 2017-10-10 22:30:10 +0100 | [diff] [blame] | 8133 | |
| 8134 | rps->enabled = true; |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8135 | } |
| 8136 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8137 | void intel_enable_gt_powersave(struct drm_i915_private *dev_priv) |
| 8138 | { |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8139 | /* Powersaving is controlled by the host when inside a VM */ |
| 8140 | if (intel_vgpu_active(dev_priv)) |
| 8141 | return; |
| 8142 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8143 | mutex_lock(&dev_priv->pcu_lock); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 8144 | |
Sagar Arun Kamble | fc77426 | 2017-10-10 22:30:09 +0100 | [diff] [blame] | 8145 | intel_enable_rc6(dev_priv); |
| 8146 | intel_enable_rps(dev_priv); |
Sagar Arun Kamble | 0870a2a | 2017-10-10 22:30:08 +0100 | [diff] [blame] | 8147 | if (HAS_LLC(dev_priv)) |
| 8148 | intel_enable_llc_pstate(dev_priv); |
| 8149 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8150 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 8151 | } |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 8152 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8153 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8154 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8155 | /* |
| 8156 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8157 | * gating for the panel power sequencer or it will fail to |
| 8158 | * start up when no ports are active. |
| 8159 | */ |
| 8160 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 8161 | } |
| 8162 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8163 | 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] | 8164 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 8165 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8166 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8167 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8168 | I915_WRITE(DSPCNTR(pipe), |
| 8169 | I915_READ(DSPCNTR(pipe)) | |
| 8170 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 8171 | |
| 8172 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 8173 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 8174 | } |
| 8175 | } |
| 8176 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8177 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8178 | { |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8179 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8180 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 8181 | /* |
| 8182 | * Required for FBC |
| 8183 | * WaFbcDisableDpfcClockGating:ilk |
| 8184 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8185 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 8186 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 8187 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8188 | |
| 8189 | I915_WRITE(PCH_3DCGDIS0, |
| 8190 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 8191 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 8192 | I915_WRITE(PCH_3DCGDIS1, |
| 8193 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 8194 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8195 | /* |
| 8196 | * According to the spec the following bits should be set in |
| 8197 | * order to enable memory self-refresh |
| 8198 | * The bit 22/21 of 0x42004 |
| 8199 | * The bit 5 of 0x42020 |
| 8200 | * The bit 15 of 0x45000 |
| 8201 | */ |
| 8202 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8203 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8204 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8205 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8206 | I915_WRITE(DISP_ARB_CTL, |
| 8207 | (I915_READ(DISP_ARB_CTL) | |
| 8208 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 8209 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8210 | /* |
| 8211 | * Based on the document from hardware guys the following bits |
| 8212 | * should be set unconditionally in order to enable FBC. |
| 8213 | * The bit 22 of 0x42000 |
| 8214 | * The bit 22 of 0x42004 |
| 8215 | * The bit 7,8,9 of 0x42020. |
| 8216 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8217 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8218 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8219 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8220 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8221 | ILK_FBCQ_DIS); |
| 8222 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8223 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8224 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8225 | } |
| 8226 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 8227 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 8228 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8229 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8230 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8231 | ILK_ELPIN_409_SELECT); |
| 8232 | I915_WRITE(_3D_CHICKEN2, |
| 8233 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 8234 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8235 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8236 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8237 | I915_WRITE(CACHE_MODE_0, |
| 8238 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8239 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8240 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 8241 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8242 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8243 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 8244 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8245 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8246 | } |
| 8247 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8248 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8249 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8250 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8251 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8252 | |
| 8253 | /* |
| 8254 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 8255 | * gating for the panel power sequencer or it will fail to |
| 8256 | * start up when no ports are active. |
| 8257 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 8258 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 8259 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 8260 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8261 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 8262 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 8263 | /* The below fixes the weird display corruption, a few pixels shifted |
| 8264 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 8265 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8266 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8267 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 8268 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 8269 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8270 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8271 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 8272 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 8273 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 8274 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 8275 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 8276 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8277 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8278 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8279 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 8280 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 8281 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8282 | } |
| 8283 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8284 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8285 | { |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8286 | uint32_t tmp; |
| 8287 | |
| 8288 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 8289 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 8290 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 8291 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8292 | } |
| 8293 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8294 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8295 | { |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8296 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8297 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8298 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8299 | |
| 8300 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8301 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8302 | ILK_ELPIN_409_SELECT); |
| 8303 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8304 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 8305 | I915_WRITE(_3D_CHICKEN, |
| 8306 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 8307 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8308 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 8309 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8310 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8311 | /* |
| 8312 | * BSpec recoomends 8x4 when MSAA is used, |
| 8313 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8314 | * |
| 8315 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8316 | * disable bit, which we don't touch here, but it's good |
| 8317 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8318 | */ |
| 8319 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8320 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 8321 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8322 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 8323 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8324 | |
| 8325 | I915_WRITE(GEN6_UCGCTL1, |
| 8326 | I915_READ(GEN6_UCGCTL1) | |
| 8327 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 8328 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 8329 | |
| 8330 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 8331 | * gating disable must be set. Failure to set it results in |
| 8332 | * flickering pixels due to Z write ordering failures after |
| 8333 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 8334 | * Sanctuary and Tropics, and apparently anything else with |
| 8335 | * alpha test or pixel discard. |
| 8336 | * |
| 8337 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 8338 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8339 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 8340 | * WaDisableRCCUnitClockGating:snb |
| 8341 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8342 | */ |
| 8343 | I915_WRITE(GEN6_UCGCTL2, |
| 8344 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 8345 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 8346 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 8347 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 8348 | I915_WRITE(_3D_CHICKEN3, |
| 8349 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8350 | |
| 8351 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 8352 | * Bspec says: |
| 8353 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 8354 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 8355 | */ |
| 8356 | I915_WRITE(_3D_CHICKEN3, |
| 8357 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 8358 | |
| 8359 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8360 | * According to the spec the following bits should be |
| 8361 | * set in order to enable memory self-refresh and fbc: |
| 8362 | * The bit21 and bit22 of 0x42000 |
| 8363 | * The bit21 and bit22 of 0x42004 |
| 8364 | * The bit5 and bit7 of 0x42020 |
| 8365 | * The bit14 of 0x70180 |
| 8366 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8367 | * |
| 8368 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8369 | */ |
| 8370 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8371 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8372 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 8373 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8374 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8375 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8376 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 8377 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 8378 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 8379 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8380 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8381 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 8382 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8383 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8384 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8385 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8386 | } |
| 8387 | |
| 8388 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 8389 | { |
| 8390 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 8391 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8392 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8393 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8394 | * |
| 8395 | * This actually overrides the dispatch |
| 8396 | * mode for all thread types. |
| 8397 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8398 | reg &= ~GEN7_FF_SCHED_MASK; |
| 8399 | reg |= GEN7_FF_TS_SCHED_HW; |
| 8400 | reg |= GEN7_FF_VS_SCHED_HW; |
| 8401 | reg |= GEN7_FF_DS_SCHED_HW; |
| 8402 | |
| 8403 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 8404 | } |
| 8405 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8406 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8407 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8408 | /* |
| 8409 | * TODO: this bit should only be enabled when really needed, then |
| 8410 | * disabled when not needed anymore in order to save power. |
| 8411 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8412 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8413 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 8414 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 8415 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8416 | |
| 8417 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 8418 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 8419 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8420 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8421 | } |
| 8422 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8423 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8424 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8425 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8426 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8427 | |
| 8428 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8429 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8430 | } |
| 8431 | } |
| 8432 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8433 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 8434 | int general_prio_credits, |
| 8435 | int high_prio_credits) |
| 8436 | { |
| 8437 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 8438 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8439 | |
| 8440 | /* WaTempDisableDOPClkGating:bdw */ |
| 8441 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 8442 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 8443 | |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 8444 | val = I915_READ(GEN8_L3SQCREG1); |
| 8445 | val &= ~L3_PRIO_CREDITS_MASK; |
| 8446 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 8447 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
| 8448 | I915_WRITE(GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8449 | |
| 8450 | /* |
| 8451 | * Wait at least 100 clocks before re-enabling clock gating. |
| 8452 | * See the definition of L3SQCREG1 in BSpec. |
| 8453 | */ |
| 8454 | POSTING_READ(GEN8_L3SQCREG1); |
| 8455 | udelay(1); |
| 8456 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 8457 | } |
| 8458 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8459 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8460 | { |
| 8461 | if (!HAS_PCH_CNP(dev_priv)) |
| 8462 | return; |
| 8463 | |
| 8464 | /* Wa #1181 */ |
Rodrigo Vivi | 4cc6feb | 2017-09-08 16:45:33 -0700 | [diff] [blame] | 8465 | I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 8466 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8467 | } |
| 8468 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8469 | static void cnl_init_clock_gating(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8470 | { |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 8471 | u32 val; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8472 | cnp_init_clock_gating(dev_priv); |
| 8473 | |
Rodrigo Vivi | 1a25db6 | 2017-08-15 16:16:51 -0700 | [diff] [blame] | 8474 | /* This is not an Wa. Enable for better image quality */ |
| 8475 | I915_WRITE(_3D_CHICKEN3, |
| 8476 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE)); |
| 8477 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8478 | /* WaEnableChickenDCPR:cnl */ |
| 8479 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 8480 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
| 8481 | |
| 8482 | /* WaFbcWakeMemOn:cnl */ |
| 8483 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 8484 | DISP_FBC_MEMORY_WAKE); |
| 8485 | |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 8486 | val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE); |
| 8487 | /* ReadHitWriteOnlyDisable:cnl */ |
| 8488 | val |= RCCUNIT_CLKGATE_DIS; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8489 | /* WaSarbUnitClockGatingDisable:cnl (pre-prod) */ |
| 8490 | if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0)) |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 8491 | val |= SARBUNIT_CLKGATE_DIS; |
| 8492 | I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val); |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 8493 | |
| 8494 | /* Display WA #1133: WaFbcSkipSegments:cnl */ |
| 8495 | val = I915_READ(ILK_DPFC_CHICKEN); |
| 8496 | val &= ~GLK_SKIP_SEG_COUNT_MASK; |
| 8497 | val |= GLK_SKIP_SEG_EN | GLK_SKIP_SEG_COUNT(1); |
| 8498 | I915_WRITE(ILK_DPFC_CHICKEN, val); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8499 | } |
| 8500 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8501 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 8502 | { |
| 8503 | cnp_init_clock_gating(dev_priv); |
| 8504 | gen9_init_clock_gating(dev_priv); |
| 8505 | |
| 8506 | /* WaFbcNukeOnHostModify:cfl */ |
| 8507 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8508 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 8509 | } |
| 8510 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8511 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8512 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8513 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8514 | |
| 8515 | /* WaDisableSDEUnitClockGating:kbl */ |
| 8516 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 8517 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8518 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 8519 | |
| 8520 | /* WaDisableGamClockGating:kbl */ |
| 8521 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 8522 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 8523 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8524 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8525 | /* WaFbcNukeOnHostModify:kbl */ |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8526 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8527 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8528 | } |
| 8529 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8530 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8531 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8532 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 8533 | |
| 8534 | /* WAC6entrylatency:skl */ |
| 8535 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 8536 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8537 | |
| 8538 | /* WaFbcNukeOnHostModify:skl */ |
| 8539 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8540 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8541 | } |
| 8542 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8543 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8544 | { |
Matthew Auld | 8cb0983 | 2017-10-06 23:18:23 +0100 | [diff] [blame] | 8545 | /* The GTT cache must be disabled if the system is using 2M pages. */ |
| 8546 | bool can_use_gtt_cache = !HAS_PAGE_SIZES(dev_priv, |
| 8547 | I915_GTT_PAGE_SIZE_2M); |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 8548 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8549 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8550 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 8551 | 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] | 8552 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8553 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 8554 | I915_WRITE(CHICKEN_PAR1_1, |
| 8555 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 8556 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8557 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8558 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 8559 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 8560 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 8561 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 8562 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 8563 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8564 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 8565 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 8566 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8567 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 8568 | ~(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] | 8569 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 8570 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 8571 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 8572 | |
| 8573 | /* WaDisableSDEUnitClockGating:bdw */ |
| 8574 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8575 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 8576 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8577 | /* WaProgramL3SqcReg1Default:bdw */ |
| 8578 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 8579 | |
Matthew Auld | 8cb0983 | 2017-10-06 23:18:23 +0100 | [diff] [blame] | 8580 | /* WaGttCachingOffByDefault:bdw */ |
| 8581 | 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] | 8582 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 8583 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 8584 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 8585 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 8586 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8587 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 8588 | |
| 8589 | /* WaDisableDopClockGating:bdw |
| 8590 | * |
| 8591 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 8592 | * clock gating. |
| 8593 | */ |
| 8594 | I915_WRITE(GEN6_UCGCTL1, |
| 8595 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8596 | } |
| 8597 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8598 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8599 | { |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 8600 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 8601 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 8602 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 8603 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 8604 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8605 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8606 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8607 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8608 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8609 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 8610 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 8611 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8612 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8613 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8614 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 8615 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8616 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 8617 | /* enable HiZ Raw Stall Optimization */ |
| 8618 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 8619 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 8620 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8621 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8622 | I915_WRITE(CACHE_MODE_1, |
| 8623 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 8624 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8625 | /* |
| 8626 | * BSpec recommends 8x4 when MSAA is used, |
| 8627 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8628 | * |
| 8629 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8630 | * disable bit, which we don't touch here, but it's good |
| 8631 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8632 | */ |
| 8633 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8634 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8635 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 8636 | /* WaSampleCChickenBitEnable:hsw */ |
| 8637 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 8638 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 8639 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8640 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 8641 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 8642 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8643 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8644 | } |
| 8645 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8646 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8647 | { |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8648 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8649 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8650 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8651 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8652 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 8653 | I915_WRITE(_3D_CHICKEN3, |
| 8654 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 8655 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8656 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8657 | I915_WRITE(IVB_CHICKEN3, |
| 8658 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 8659 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 8660 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8661 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8662 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8663 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 8664 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8665 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8666 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 8667 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8668 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8669 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8670 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 8671 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 8672 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8673 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8674 | I915_WRITE(GEN7_L3CNTLREG1, |
| 8675 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 8676 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8677 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8678 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8679 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8680 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 8681 | else { |
| 8682 | /* must write both registers */ |
| 8683 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8684 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8685 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 8686 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 8687 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8688 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8689 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 8690 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 8691 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 8692 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 8693 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8694 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8695 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8696 | */ |
| 8697 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 8698 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8699 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8700 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8701 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8702 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8703 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8704 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8705 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8706 | |
| 8707 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 8708 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 8709 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 8710 | /* enable HiZ Raw Stall Optimization */ |
| 8711 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 8712 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 8713 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 8714 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8715 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 8716 | I915_WRITE(CACHE_MODE_1, |
| 8717 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8718 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8719 | /* |
| 8720 | * BSpec recommends 8x4 when MSAA is used, |
| 8721 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8722 | * |
| 8723 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8724 | * disable bit, which we don't touch here, but it's good |
| 8725 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8726 | */ |
| 8727 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8728 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8729 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8730 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 8731 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 8732 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 8733 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8734 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8735 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8736 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8737 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8738 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8739 | } |
| 8740 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8741 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8742 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8743 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 8744 | I915_WRITE(_3D_CHICKEN3, |
| 8745 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 8746 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8747 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8748 | I915_WRITE(IVB_CHICKEN3, |
| 8749 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 8750 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 8751 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 8752 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8753 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8754 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 8755 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 8756 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8757 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8758 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 8759 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8760 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8761 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 8762 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 8763 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 8764 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8765 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8766 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8767 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 8768 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8769 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8770 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8771 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8772 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8773 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8774 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 8775 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 8776 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8777 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8778 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8779 | */ |
| 8780 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 8781 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8782 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 8783 | /* WaDisableL3Bank2xClockGate:vlv |
| 8784 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 8785 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 8786 | I915_WRITE(GEN7_UCGCTL4, |
| 8787 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 8788 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 8789 | /* |
| 8790 | * BSpec says this must be set, even though |
| 8791 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 8792 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 8793 | I915_WRITE(CACHE_MODE_1, |
| 8794 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 8795 | |
| 8796 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 8797 | * BSpec recommends 8x4 when MSAA is used, |
| 8798 | * however in practice 16x4 seems fastest. |
| 8799 | * |
| 8800 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8801 | * disable bit, which we don't touch here, but it's good |
| 8802 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 8803 | */ |
| 8804 | I915_WRITE(GEN7_GT_MODE, |
| 8805 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 8806 | |
| 8807 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 8808 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 8809 | * This is the hardware default actually. |
| 8810 | */ |
| 8811 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 8812 | |
| 8813 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8814 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 8815 | * Disable clock gating on th GCFG unit to prevent a delay |
| 8816 | * in the reporting of vblank events. |
| 8817 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 8818 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8819 | } |
| 8820 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8821 | 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] | 8822 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 8823 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 8824 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 8825 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8826 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 8827 | ~(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] | 8828 | |
| 8829 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 8830 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 8831 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 8832 | |
| 8833 | /* WaDisableCSUnitClockGating:chv */ |
| 8834 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 8835 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 8836 | |
| 8837 | /* WaDisableSDEUnitClockGating:chv */ |
| 8838 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8839 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8840 | |
| 8841 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8842 | * WaProgramL3SqcReg1Default:chv |
| 8843 | * See gfxspecs/Related Documents/Performance Guide/ |
| 8844 | * LSQC Setting Recommendations. |
| 8845 | */ |
| 8846 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
| 8847 | |
| 8848 | /* |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8849 | * GTT cache may not work with big pages, so if those |
| 8850 | * are ever enabled GTT cache may need to be disabled. |
| 8851 | */ |
| 8852 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 8853 | } |
| 8854 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8855 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8856 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8857 | uint32_t dspclk_gate; |
| 8858 | |
| 8859 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 8860 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 8861 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 8862 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 8863 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 8864 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 8865 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 8866 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8867 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8868 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 8869 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8870 | |
| 8871 | /* WaDisableRenderCachePipelinedFlush */ |
| 8872 | I915_WRITE(CACHE_MODE_0, |
| 8873 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 8874 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8875 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 8876 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8877 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8878 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8879 | } |
| 8880 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8881 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8882 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8883 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 8884 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 8885 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 8886 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 8887 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 8888 | I915_WRITE(MI_ARB_STATE, |
| 8889 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8890 | |
| 8891 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 8892 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8893 | } |
| 8894 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8895 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8896 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8897 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 8898 | I965_RCC_CLOCK_GATE_DISABLE | |
| 8899 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 8900 | I965_ISC_CLOCK_GATE_DISABLE | |
| 8901 | I965_FBC_CLOCK_GATE_DISABLE); |
| 8902 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 8903 | I915_WRITE(MI_ARB_STATE, |
| 8904 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8905 | |
| 8906 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 8907 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8908 | } |
| 8909 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8910 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8911 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8912 | u32 dstate = I915_READ(D_STATE); |
| 8913 | |
| 8914 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 8915 | DSTATE_DOT_CLOCK_GATING; |
| 8916 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 8917 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8918 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 8919 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 8920 | |
| 8921 | /* IIR "flip pending" means done if this bit is set */ |
| 8922 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 8923 | |
| 8924 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 8925 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 8926 | |
| 8927 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 8928 | 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] | 8929 | |
| 8930 | I915_WRITE(MI_ARB_STATE, |
| 8931 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8932 | } |
| 8933 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8934 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8935 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8936 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 8937 | |
| 8938 | /* interrupts should cause a wake up from C3 */ |
| 8939 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 8940 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 8941 | |
| 8942 | I915_WRITE(MEM_MODE, |
| 8943 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8944 | } |
| 8945 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8946 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8947 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 8948 | I915_WRITE(MEM_MODE, |
| 8949 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 8950 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8951 | } |
| 8952 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8953 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8954 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8955 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8956 | } |
| 8957 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8958 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8959 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8960 | if (HAS_PCH_LPT(dev_priv)) |
| 8961 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8962 | } |
| 8963 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8964 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8965 | { |
| 8966 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 8967 | } |
| 8968 | |
| 8969 | /** |
| 8970 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 8971 | * @dev_priv: device private |
| 8972 | * |
| 8973 | * Setup the hooks that configure which clocks of a given platform can be |
| 8974 | * gated and also apply various GT and display specific workarounds for these |
| 8975 | * platforms. Note that some GT specific workarounds are applied separately |
| 8976 | * when GPU contexts or batchbuffers start their execution. |
| 8977 | */ |
| 8978 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 8979 | { |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8980 | if (IS_CANNONLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8981 | dev_priv->display.init_clock_gating = cnl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8982 | else if (IS_COFFEELAKE(dev_priv)) |
| 8983 | dev_priv->display.init_clock_gating = cfl_init_clock_gating; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 8984 | else if (IS_SKYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8985 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 8986 | else if (IS_KABYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8987 | dev_priv->display.init_clock_gating = kbl_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 8988 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8989 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 8990 | else if (IS_GEMINILAKE(dev_priv)) |
| 8991 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8992 | else if (IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8993 | dev_priv->display.init_clock_gating = bdw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8994 | else if (IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8995 | dev_priv->display.init_clock_gating = chv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8996 | else if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8997 | dev_priv->display.init_clock_gating = hsw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8998 | else if (IS_IVYBRIDGE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 8999 | dev_priv->display.init_clock_gating = ivb_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9000 | else if (IS_VALLEYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9001 | dev_priv->display.init_clock_gating = vlv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9002 | else if (IS_GEN6(dev_priv)) |
| 9003 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
| 9004 | else if (IS_GEN5(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9005 | dev_priv->display.init_clock_gating = ilk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9006 | else if (IS_G4X(dev_priv)) |
| 9007 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 9008 | else if (IS_I965GM(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9009 | dev_priv->display.init_clock_gating = i965gm_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 9010 | else if (IS_I965G(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 9011 | dev_priv->display.init_clock_gating = i965g_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 9012 | else if (IS_GEN3(dev_priv)) |
| 9013 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 9014 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 9015 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 9016 | else if (IS_GEN2(dev_priv)) |
| 9017 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 9018 | else { |
| 9019 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 9020 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 9021 | } |
| 9022 | } |
| 9023 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9024 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9025 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9026 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 9027 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9028 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 9029 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9030 | if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 9031 | i915_pineview_get_mem_freq(dev_priv); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 9032 | else if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 9033 | i915_ironlake_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 9034 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9035 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9036 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9037 | skl_setup_wm_latency(dev_priv); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 9038 | dev_priv->display.initial_watermarks = skl_initial_wm; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 9039 | dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 9040 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9041 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9042 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 9043 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 9044 | if ((IS_GEN5(dev_priv) && dev_priv->wm.pri_latency[1] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9045 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 9046 | (!IS_GEN5(dev_priv) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9047 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 9048 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 9049 | dev_priv->display.compute_intermediate_wm = |
| 9050 | ilk_compute_intermediate_wm; |
| 9051 | dev_priv->display.initial_watermarks = |
| 9052 | ilk_initial_watermarks; |
| 9053 | dev_priv->display.optimize_watermarks = |
| 9054 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 9055 | } else { |
| 9056 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 9057 | "Disable CxSR\n"); |
| 9058 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 9059 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 9060 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9061 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 9062 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9063 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 9064 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 9065 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 9066 | } else if (IS_G4X(dev_priv)) { |
| 9067 | g4x_setup_wm_latency(dev_priv); |
| 9068 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 9069 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 9070 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 9071 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 9072 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 9073 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9074 | dev_priv->is_ddr3, |
| 9075 | dev_priv->fsb_freq, |
| 9076 | dev_priv->mem_freq)) { |
| 9077 | DRM_INFO("failed to find known CxSR latency " |
| 9078 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 9079 | "disabling CxSR\n", |
| 9080 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 9081 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 9082 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 9083 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9084 | dev_priv->display.update_wm = NULL; |
| 9085 | } else |
| 9086 | dev_priv->display.update_wm = pineview_update_wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 9087 | } else if (IS_GEN4(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9088 | dev_priv->display.update_wm = i965_update_wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 9089 | } else if (IS_GEN3(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9090 | dev_priv->display.update_wm = i9xx_update_wm; |
| 9091 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 9092 | } else if (IS_GEN2(dev_priv)) { |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 9093 | if (INTEL_INFO(dev_priv)->num_pipes == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9094 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9095 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9096 | } else { |
| 9097 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9098 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9099 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 9100 | } else { |
| 9101 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9102 | } |
| 9103 | } |
| 9104 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9105 | static inline int gen6_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 9106 | { |
| 9107 | uint32_t flags = |
| 9108 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 9109 | |
| 9110 | switch (flags) { |
| 9111 | case GEN6_PCODE_SUCCESS: |
| 9112 | return 0; |
| 9113 | case GEN6_PCODE_UNIMPLEMENTED_CMD: |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9114 | return -ENODEV; |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9115 | case GEN6_PCODE_ILLEGAL_CMD: |
| 9116 | return -ENXIO; |
| 9117 | case GEN6_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Chris Wilson | 7850d1c | 2016-08-26 11:59:26 +0100 | [diff] [blame] | 9118 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9119 | return -EOVERFLOW; |
| 9120 | case GEN6_PCODE_TIMEOUT: |
| 9121 | return -ETIMEDOUT; |
| 9122 | default: |
Michal Wajdeczko | f0d6615 | 2017-03-28 08:45:12 +0000 | [diff] [blame] | 9123 | MISSING_CASE(flags); |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9124 | return 0; |
| 9125 | } |
| 9126 | } |
| 9127 | |
| 9128 | static inline int gen7_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 9129 | { |
| 9130 | uint32_t flags = |
| 9131 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 9132 | |
| 9133 | switch (flags) { |
| 9134 | case GEN6_PCODE_SUCCESS: |
| 9135 | return 0; |
| 9136 | case GEN6_PCODE_ILLEGAL_CMD: |
| 9137 | return -ENXIO; |
| 9138 | case GEN7_PCODE_TIMEOUT: |
| 9139 | return -ETIMEDOUT; |
| 9140 | case GEN7_PCODE_ILLEGAL_DATA: |
| 9141 | return -EINVAL; |
| 9142 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
| 9143 | return -EOVERFLOW; |
| 9144 | default: |
| 9145 | MISSING_CASE(flags); |
| 9146 | return 0; |
| 9147 | } |
| 9148 | } |
| 9149 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 9150 | 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] | 9151 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9152 | int status; |
| 9153 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9154 | WARN_ON(!mutex_is_locked(&dev_priv->pcu_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9155 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9156 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 9157 | * use te fw I915_READ variants to reduce the amount of work |
| 9158 | * required when reading/writing. |
| 9159 | */ |
| 9160 | |
| 9161 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9162 | DRM_DEBUG_DRIVER("warning: pcode (read from mbox %x) mailbox access failed for %ps\n", |
| 9163 | mbox, __builtin_return_address(0)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9164 | return -EAGAIN; |
| 9165 | } |
| 9166 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9167 | I915_WRITE_FW(GEN6_PCODE_DATA, *val); |
| 9168 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
| 9169 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9170 | |
Chris Wilson | e09a303 | 2017-04-11 11:13:39 +0100 | [diff] [blame] | 9171 | if (__intel_wait_for_register_fw(dev_priv, |
| 9172 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 9173 | 500, 0, NULL)) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9174 | DRM_ERROR("timeout waiting for pcode read (from mbox %x) to finish for %ps\n", |
| 9175 | mbox, __builtin_return_address(0)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9176 | return -ETIMEDOUT; |
| 9177 | } |
| 9178 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9179 | *val = I915_READ_FW(GEN6_PCODE_DATA); |
| 9180 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9181 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9182 | if (INTEL_GEN(dev_priv) > 6) |
| 9183 | status = gen7_check_mailbox_status(dev_priv); |
| 9184 | else |
| 9185 | status = gen6_check_mailbox_status(dev_priv); |
| 9186 | |
| 9187 | if (status) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9188 | DRM_DEBUG_DRIVER("warning: pcode (read from mbox %x) mailbox access failed for %ps: %d\n", |
| 9189 | mbox, __builtin_return_address(0), status); |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9190 | return status; |
| 9191 | } |
| 9192 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9193 | return 0; |
| 9194 | } |
| 9195 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9196 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9197 | u32 mbox, u32 val) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9198 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9199 | int status; |
| 9200 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9201 | WARN_ON(!mutex_is_locked(&dev_priv->pcu_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9202 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9203 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 9204 | * use te fw I915_READ variants to reduce the amount of work |
| 9205 | * required when reading/writing. |
| 9206 | */ |
| 9207 | |
| 9208 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9209 | DRM_DEBUG_DRIVER("warning: pcode (write of 0x%08x to mbox %x) mailbox access failed for %ps\n", |
| 9210 | val, mbox, __builtin_return_address(0)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9211 | return -EAGAIN; |
| 9212 | } |
| 9213 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9214 | I915_WRITE_FW(GEN6_PCODE_DATA, val); |
Imre Deak | 8bf41b7 | 2016-11-28 17:29:27 +0200 | [diff] [blame] | 9215 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9216 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9217 | |
Chris Wilson | e09a303 | 2017-04-11 11:13:39 +0100 | [diff] [blame] | 9218 | if (__intel_wait_for_register_fw(dev_priv, |
| 9219 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 9220 | 500, 0, NULL)) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9221 | DRM_ERROR("timeout waiting for pcode write of 0x%08x to mbox %x to finish for %ps\n", |
| 9222 | val, mbox, __builtin_return_address(0)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9223 | return -ETIMEDOUT; |
| 9224 | } |
| 9225 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 9226 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9227 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9228 | if (INTEL_GEN(dev_priv) > 6) |
| 9229 | status = gen7_check_mailbox_status(dev_priv); |
| 9230 | else |
| 9231 | status = gen6_check_mailbox_status(dev_priv); |
| 9232 | |
| 9233 | if (status) { |
Chris Wilson | 5a9cfff | 2017-07-28 09:50:22 +0100 | [diff] [blame] | 9234 | DRM_DEBUG_DRIVER("warning: pcode (write of 0x%08x to mbox %x) mailbox access failed for %ps: %d\n", |
| 9235 | val, mbox, __builtin_return_address(0), status); |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 9236 | return status; |
| 9237 | } |
| 9238 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 9239 | return 0; |
| 9240 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 9241 | |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9242 | static bool skl_pcode_try_request(struct drm_i915_private *dev_priv, u32 mbox, |
| 9243 | u32 request, u32 reply_mask, u32 reply, |
| 9244 | u32 *status) |
| 9245 | { |
| 9246 | u32 val = request; |
| 9247 | |
| 9248 | *status = sandybridge_pcode_read(dev_priv, mbox, &val); |
| 9249 | |
| 9250 | return *status || ((val & reply_mask) == reply); |
| 9251 | } |
| 9252 | |
| 9253 | /** |
| 9254 | * skl_pcode_request - send PCODE request until acknowledgment |
| 9255 | * @dev_priv: device private |
| 9256 | * @mbox: PCODE mailbox ID the request is targeted for |
| 9257 | * @request: request ID |
| 9258 | * @reply_mask: mask used to check for request acknowledgment |
| 9259 | * @reply: value used to check for request acknowledgment |
| 9260 | * @timeout_base_ms: timeout for polling with preemption enabled |
| 9261 | * |
| 9262 | * Keep resending the @request to @mbox until PCODE acknowledges it, PCODE |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9263 | * 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] | 9264 | * The request is acknowledged once the PCODE reply dword equals @reply after |
| 9265 | * applying @reply_mask. Polling is first attempted with preemption enabled |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9266 | * 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] | 9267 | * preemption disabled. |
| 9268 | * |
| 9269 | * Returns 0 on success, %-ETIMEDOUT in case of a timeout, <0 in case of some |
| 9270 | * other error as reported by PCODE. |
| 9271 | */ |
| 9272 | int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request, |
| 9273 | u32 reply_mask, u32 reply, int timeout_base_ms) |
| 9274 | { |
| 9275 | u32 status; |
| 9276 | int ret; |
| 9277 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9278 | WARN_ON(!mutex_is_locked(&dev_priv->pcu_lock)); |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9279 | |
| 9280 | #define COND skl_pcode_try_request(dev_priv, mbox, request, reply_mask, reply, \ |
| 9281 | &status) |
| 9282 | |
| 9283 | /* |
| 9284 | * Prime the PCODE by doing a request first. Normally it guarantees |
| 9285 | * that a subsequent request, at most @timeout_base_ms later, succeeds. |
| 9286 | * _wait_for() doesn't guarantee when its passed condition is evaluated |
| 9287 | * first, so send the first request explicitly. |
| 9288 | */ |
| 9289 | if (COND) { |
| 9290 | ret = 0; |
| 9291 | goto out; |
| 9292 | } |
| 9293 | ret = _wait_for(COND, timeout_base_ms * 1000, 10); |
| 9294 | if (!ret) |
| 9295 | goto out; |
| 9296 | |
| 9297 | /* |
| 9298 | * The above can time out if the number of requests was low (2 in the |
| 9299 | * worst case) _and_ PCODE was busy for some reason even after a |
| 9300 | * (queued) request and @timeout_base_ms delay. As a workaround retry |
| 9301 | * the poll with preemption disabled to maximize the number of |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9302 | * requests. Increase the timeout from @timeout_base_ms to 50ms to |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9303 | * account for interrupts that could reduce the number of these |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9304 | * requests, and for any quirks of the PCODE firmware that delays |
| 9305 | * the request completion. |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9306 | */ |
| 9307 | DRM_DEBUG_KMS("PCODE timeout, retrying with preemption disabled\n"); |
| 9308 | WARN_ON_ONCE(timeout_base_ms > 3); |
| 9309 | preempt_disable(); |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 9310 | ret = wait_for_atomic(COND, 50); |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 9311 | preempt_enable(); |
| 9312 | |
| 9313 | out: |
| 9314 | return ret ? ret : status; |
| 9315 | #undef COND |
| 9316 | } |
| 9317 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 9318 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9319 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9320 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9321 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9322 | /* |
| 9323 | * N = val - 0xb7 |
| 9324 | * Slow = Fast = GPLL ref * N |
| 9325 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9326 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * (val - 0xb7), 1000); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 9327 | } |
| 9328 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9329 | 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] | 9330 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9331 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9332 | |
| 9333 | return DIV_ROUND_CLOSEST(1000 * val, rps->gpll_ref_freq) + 0xb7; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 9334 | } |
| 9335 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9336 | 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] | 9337 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9338 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9339 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 9340 | /* |
| 9341 | * N = val / 2 |
| 9342 | * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2 |
| 9343 | */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9344 | return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * val, 2 * 2 * 1000); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9345 | } |
| 9346 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 9347 | 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] | 9348 | { |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9349 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
| 9350 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 9351 | /* CHV needs even values */ |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9352 | return DIV_ROUND_CLOSEST(2 * 1000 * val, rps->gpll_ref_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9353 | } |
| 9354 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9355 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 9356 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 9357 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9358 | return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, |
| 9359 | GEN9_FREQ_SCALER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9360 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9361 | return chv_gpu_freq(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9362 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9363 | return byt_gpu_freq(dev_priv, val); |
| 9364 | else |
| 9365 | return val * GT_FREQUENCY_MULTIPLIER; |
| 9366 | } |
| 9367 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9368 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 9369 | { |
Rodrigo Vivi | 35ceabf | 2017-07-06 13:41:13 -0700 | [diff] [blame] | 9370 | if (INTEL_GEN(dev_priv) >= 9) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9371 | return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, |
| 9372 | GT_FREQUENCY_MULTIPLIER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9373 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9374 | return chv_freq_opcode(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9375 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 9376 | return byt_freq_opcode(dev_priv, val); |
| 9377 | else |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 9378 | return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 9379 | } |
| 9380 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 9381 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9382 | { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9383 | mutex_init(&dev_priv->pcu_lock); |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9384 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 9385 | atomic_set(&dev_priv->gt_pm.rps.num_waiters, 0); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 9386 | |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 9387 | dev_priv->runtime_pm.suspended = false; |
| 9388 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9389 | } |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9390 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9391 | static u64 vlv_residency_raw(struct drm_i915_private *dev_priv, |
| 9392 | const i915_reg_t reg) |
| 9393 | { |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9394 | u32 lower, upper, tmp; |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9395 | int loop = 2; |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9396 | |
| 9397 | /* The register accessed do not need forcewake. We borrow |
| 9398 | * uncore lock to prevent concurrent access to range reg. |
| 9399 | */ |
| 9400 | spin_lock_irq(&dev_priv->uncore.lock); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9401 | |
| 9402 | /* vlv and chv residency counters are 40 bits in width. |
| 9403 | * With a control bit, we can choose between upper or lower |
| 9404 | * 32bit window into this counter. |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9405 | * |
| 9406 | * Although we always use the counter in high-range mode elsewhere, |
| 9407 | * userspace may attempt to read the value before rc6 is initialised, |
| 9408 | * before we have set the default VLV_COUNTER_CONTROL value. So always |
| 9409 | * set the high bit to be safe. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9410 | */ |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9411 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9412 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9413 | upper = I915_READ_FW(reg); |
| 9414 | do { |
| 9415 | tmp = upper; |
| 9416 | |
| 9417 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9418 | _MASKED_BIT_DISABLE(VLV_COUNT_RANGE_HIGH)); |
| 9419 | lower = I915_READ_FW(reg); |
| 9420 | |
| 9421 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9422 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
| 9423 | upper = I915_READ_FW(reg); |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9424 | } while (upper != tmp && --loop); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9425 | |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9426 | /* Everywhere else we always use VLV_COUNTER_CONTROL with the |
| 9427 | * VLV_COUNT_RANGE_HIGH bit set - so it is safe to leave it set |
| 9428 | * now. |
| 9429 | */ |
| 9430 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9431 | spin_unlock_irq(&dev_priv->uncore.lock); |
| 9432 | |
| 9433 | return lower | (u64)upper << 8; |
| 9434 | } |
| 9435 | |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9436 | u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv, |
| 9437 | const i915_reg_t reg) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9438 | { |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9439 | u64 time_hw, units, div; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9440 | |
Sagar Arun Kamble | 771decb | 2017-10-10 22:30:07 +0100 | [diff] [blame] | 9441 | if (!intel_rc6_enabled()) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9442 | return 0; |
| 9443 | |
| 9444 | intel_runtime_pm_get(dev_priv); |
| 9445 | |
| 9446 | /* On VLV and CHV, residency time is in CZ units rather than 1.28us */ |
| 9447 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9448 | units = 1000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9449 | div = dev_priv->czclk_freq; |
| 9450 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9451 | time_hw = vlv_residency_raw(dev_priv, reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9452 | } else if (IS_GEN9_LP(dev_priv)) { |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9453 | units = 1000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9454 | div = 1200; /* 833.33ns */ |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9455 | |
| 9456 | time_hw = I915_READ(reg); |
| 9457 | } else { |
| 9458 | units = 128000; /* 1.28us */ |
| 9459 | div = 100000; |
| 9460 | |
| 9461 | time_hw = I915_READ(reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9462 | } |
| 9463 | |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9464 | intel_runtime_pm_put(dev_priv); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9465 | return DIV_ROUND_UP_ULL(time_hw * units, div); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9466 | } |