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 | { |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 61 | /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl */ |
| 62 | I915_WRITE(CHICKEN_PAR1_1, |
| 63 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 64 | |
| 65 | I915_WRITE(GEN8_CONFIG0, |
| 66 | I915_READ(GEN8_CONFIG0) | GEN9_DEFAULT_FIXES); |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 67 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 68 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk */ |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 69 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 70 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 71 | |
| 72 | /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl */ |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 73 | /* WaFbcWakeMemOn:skl,bxt,kbl,glk */ |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 74 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 75 | DISP_FBC_WM_DIS | |
| 76 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | d1b4eef | 2016-06-07 17:19:19 +0300 | [diff] [blame] | 77 | |
| 78 | /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl */ |
| 79 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 80 | ILK_DPFC_DISABLE_DUMMY0); |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 81 | } |
| 82 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 83 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 84 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 85 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 86 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 87 | /* WaDisableSDEUnitClockGating:bxt */ |
| 88 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 89 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 90 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 91 | /* |
| 92 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 93 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 94 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 95 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 96 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 100 | * to stay fully on. |
| 101 | */ |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 102 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 103 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 106 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 107 | { |
| 108 | gen9_init_clock_gating(dev_priv); |
| 109 | |
| 110 | /* |
| 111 | * WaDisablePWMClockGating:glk |
| 112 | * Backlight PWM may stop in the asserted state, causing backlight |
| 113 | * to stay fully on. |
| 114 | */ |
| 115 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 116 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Ander Conselvan de Oliveira | f4f4b59 | 2017-02-22 08:34:29 +0200 | [diff] [blame] | 117 | |
| 118 | /* WaDDIIOTimeout:glk */ |
| 119 | if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1)) { |
| 120 | u32 val = I915_READ(CHICKEN_MISC_2); |
| 121 | val &= ~(GLK_CL0_PWR_DOWN | |
| 122 | GLK_CL1_PWR_DOWN | |
| 123 | GLK_CL2_PWR_DOWN); |
| 124 | I915_WRITE(CHICKEN_MISC_2, val); |
| 125 | } |
| 126 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 129 | 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] | 130 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 131 | u32 tmp; |
| 132 | |
| 133 | tmp = I915_READ(CLKCFG); |
| 134 | |
| 135 | switch (tmp & CLKCFG_FSB_MASK) { |
| 136 | case CLKCFG_FSB_533: |
| 137 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 138 | break; |
| 139 | case CLKCFG_FSB_800: |
| 140 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 141 | break; |
| 142 | case CLKCFG_FSB_667: |
| 143 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 144 | break; |
| 145 | case CLKCFG_FSB_400: |
| 146 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 147 | break; |
| 148 | } |
| 149 | |
| 150 | switch (tmp & CLKCFG_MEM_MASK) { |
| 151 | case CLKCFG_MEM_533: |
| 152 | dev_priv->mem_freq = 533; |
| 153 | break; |
| 154 | case CLKCFG_MEM_667: |
| 155 | dev_priv->mem_freq = 667; |
| 156 | break; |
| 157 | case CLKCFG_MEM_800: |
| 158 | dev_priv->mem_freq = 800; |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | /* detect pineview DDR3 setting */ |
| 163 | tmp = I915_READ(CSHRDDR3CTL); |
| 164 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 165 | } |
| 166 | |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 167 | 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] | 168 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 169 | u16 ddrpll, csipll; |
| 170 | |
| 171 | ddrpll = I915_READ16(DDRMPLL1); |
| 172 | csipll = I915_READ16(CSIPLL0); |
| 173 | |
| 174 | switch (ddrpll & 0xff) { |
| 175 | case 0xc: |
| 176 | dev_priv->mem_freq = 800; |
| 177 | break; |
| 178 | case 0x10: |
| 179 | dev_priv->mem_freq = 1066; |
| 180 | break; |
| 181 | case 0x14: |
| 182 | dev_priv->mem_freq = 1333; |
| 183 | break; |
| 184 | case 0x18: |
| 185 | dev_priv->mem_freq = 1600; |
| 186 | break; |
| 187 | default: |
| 188 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 189 | ddrpll & 0xff); |
| 190 | dev_priv->mem_freq = 0; |
| 191 | break; |
| 192 | } |
| 193 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 194 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 195 | |
| 196 | switch (csipll & 0x3ff) { |
| 197 | case 0x00c: |
| 198 | dev_priv->fsb_freq = 3200; |
| 199 | break; |
| 200 | case 0x00e: |
| 201 | dev_priv->fsb_freq = 3733; |
| 202 | break; |
| 203 | case 0x010: |
| 204 | dev_priv->fsb_freq = 4266; |
| 205 | break; |
| 206 | case 0x012: |
| 207 | dev_priv->fsb_freq = 4800; |
| 208 | break; |
| 209 | case 0x014: |
| 210 | dev_priv->fsb_freq = 5333; |
| 211 | break; |
| 212 | case 0x016: |
| 213 | dev_priv->fsb_freq = 5866; |
| 214 | break; |
| 215 | case 0x018: |
| 216 | dev_priv->fsb_freq = 6400; |
| 217 | break; |
| 218 | default: |
| 219 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 220 | csipll & 0x3ff); |
| 221 | dev_priv->fsb_freq = 0; |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 226 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 227 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 228 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 229 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 230 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 234 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 235 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 236 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 237 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 238 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 239 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 240 | |
| 241 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 242 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 243 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 244 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 245 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 246 | |
| 247 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 248 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 249 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 250 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 251 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 252 | |
| 253 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 254 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 255 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 256 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 257 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 258 | |
| 259 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 260 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 261 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 262 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 263 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 264 | |
| 265 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 266 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 267 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 268 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 269 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 270 | }; |
| 271 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 272 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 273 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 274 | int fsb, |
| 275 | int mem) |
| 276 | { |
| 277 | const struct cxsr_latency *latency; |
| 278 | int i; |
| 279 | |
| 280 | if (fsb == 0 || mem == 0) |
| 281 | return NULL; |
| 282 | |
| 283 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 284 | latency = &cxsr_latency_table[i]; |
| 285 | if (is_desktop == latency->is_desktop && |
| 286 | is_ddr3 == latency->is_ddr3 && |
| 287 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 288 | return latency; |
| 289 | } |
| 290 | |
| 291 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 292 | |
| 293 | return NULL; |
| 294 | } |
| 295 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 296 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 297 | { |
| 298 | u32 val; |
| 299 | |
| 300 | mutex_lock(&dev_priv->rps.hw_lock); |
| 301 | |
| 302 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 303 | if (enable) |
| 304 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 305 | else |
| 306 | val |= FORCE_DDR_HIGH_FREQ; |
| 307 | val &= ~FORCE_DDR_LOW_FREQ; |
| 308 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 309 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 310 | |
| 311 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 312 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 313 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 314 | |
| 315 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 316 | } |
| 317 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 318 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 319 | { |
| 320 | u32 val; |
| 321 | |
| 322 | mutex_lock(&dev_priv->rps.hw_lock); |
| 323 | |
| 324 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 325 | if (enable) |
| 326 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 327 | else |
| 328 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
| 329 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 330 | |
| 331 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 332 | } |
| 333 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 334 | #define FW_WM(value, plane) \ |
| 335 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 336 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 337 | 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] | 338 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 339 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 340 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 341 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 342 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 343 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 344 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 345 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 346 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 347 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 348 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 349 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 350 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 351 | val = I915_READ(DSPFW3); |
| 352 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 353 | if (enable) |
| 354 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 355 | else |
| 356 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 357 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 358 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 359 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 360 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 361 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 362 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 363 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 364 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 365 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 366 | /* |
| 367 | * FIXME can't find a bit like this for 915G, and |
| 368 | * and yet it does have the related watermark in |
| 369 | * FW_BLC_SELF. What's going on? |
| 370 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 371 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 372 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 373 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 374 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 375 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 376 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 377 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 378 | } |
| 379 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 380 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 381 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 382 | DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", |
| 383 | enableddisabled(enable), |
| 384 | enableddisabled(was_enabled)); |
| 385 | |
| 386 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 387 | } |
| 388 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 389 | /** |
| 390 | * intel_set_memory_cxsr - Configure CxSR state |
| 391 | * @dev_priv: i915 device |
| 392 | * @enable: Allow vs. disallow CxSR |
| 393 | * |
| 394 | * Allow or disallow the system to enter a special CxSR |
| 395 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 396 | * is that several display FIFOs may get combined into a single larger |
| 397 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 398 | * system to defer memory fetches longer, and the memory will enter |
| 399 | * self refresh. |
| 400 | * |
| 401 | * Note that enabling CxSR does not guarantee that the system enter |
| 402 | * this special mode, nor does it guarantee that the system stays |
| 403 | * in that mode once entered. So this just allows/disallows the system |
| 404 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 405 | * C-states will affect when/if the system actually enters/exits the |
| 406 | * CxSR mode. |
| 407 | * |
| 408 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 409 | * and the system is free to enter/exit memory self refresh at any time |
| 410 | * even when the use of CxSR has been disallowed. |
| 411 | * |
| 412 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 413 | * control registers will not get latched on vblank. Thus in order to |
| 414 | * guarantee the system will respond to changes in the plane registers |
| 415 | * we must always disallow CxSR prior to making changes to those registers. |
| 416 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 417 | * frame start which happens after vblank start (which is when the plane |
| 418 | * registers would get latched), so we can't proceed with the plane update |
| 419 | * during the same frame where we disallowed CxSR. |
| 420 | * |
| 421 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 422 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 423 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 424 | * Disallowing just CxSR is sufficient. |
| 425 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 426 | 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] | 427 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 428 | bool ret; |
| 429 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 430 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 431 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 432 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 433 | dev_priv->wm.vlv.cxsr = enable; |
| 434 | else if (IS_G4X(dev_priv)) |
| 435 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 436 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 437 | |
| 438 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 439 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 440 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 441 | /* |
| 442 | * Latency for FIFO fetches is dependent on several factors: |
| 443 | * - memory configuration (speed, channels) |
| 444 | * - chipset |
| 445 | * - current MCH state |
| 446 | * It can be fairly high in some situations, so here we assume a fairly |
| 447 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 448 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 449 | * and power consumption (set it too low to save power and we might see |
| 450 | * FIFO underruns and display "flicker"). |
| 451 | * |
| 452 | * A value of 5us seems to be a good balance; safe for very low end |
| 453 | * platforms but not overly aggressive on lower latency configs. |
| 454 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 455 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 456 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 457 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 458 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 459 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 460 | 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] | 461 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 462 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 463 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 464 | 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] | 465 | enum pipe pipe = crtc->pipe; |
| 466 | int sprite0_start, sprite1_start; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 467 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 468 | switch (pipe) { |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 469 | uint32_t dsparb, dsparb2, dsparb3; |
| 470 | case PIPE_A: |
| 471 | dsparb = I915_READ(DSPARB); |
| 472 | dsparb2 = I915_READ(DSPARB2); |
| 473 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 474 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 475 | break; |
| 476 | case PIPE_B: |
| 477 | dsparb = I915_READ(DSPARB); |
| 478 | dsparb2 = I915_READ(DSPARB2); |
| 479 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 480 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 481 | break; |
| 482 | case PIPE_C: |
| 483 | dsparb2 = I915_READ(DSPARB2); |
| 484 | dsparb3 = I915_READ(DSPARB3); |
| 485 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 486 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 487 | break; |
| 488 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 489 | MISSING_CASE(pipe); |
| 490 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 491 | } |
| 492 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 493 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 494 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 495 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 496 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 497 | } |
| 498 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 499 | 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] | 500 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 501 | uint32_t dsparb = I915_READ(DSPARB); |
| 502 | int size; |
| 503 | |
| 504 | size = dsparb & 0x7f; |
| 505 | if (plane) |
| 506 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 507 | |
| 508 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 509 | plane ? "B" : "A", size); |
| 510 | |
| 511 | return size; |
| 512 | } |
| 513 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 514 | 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] | 515 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 516 | uint32_t dsparb = I915_READ(DSPARB); |
| 517 | int size; |
| 518 | |
| 519 | size = dsparb & 0x1ff; |
| 520 | if (plane) |
| 521 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 522 | size >>= 1; /* Convert to cachelines */ |
| 523 | |
| 524 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 525 | plane ? "B" : "A", size); |
| 526 | |
| 527 | return size; |
| 528 | } |
| 529 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 530 | 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] | 531 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 532 | uint32_t dsparb = I915_READ(DSPARB); |
| 533 | int size; |
| 534 | |
| 535 | size = dsparb & 0x7f; |
| 536 | size >>= 2; /* Convert to cachelines */ |
| 537 | |
| 538 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 539 | plane ? "B" : "A", |
| 540 | size); |
| 541 | |
| 542 | return size; |
| 543 | } |
| 544 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 545 | /* Pineview has different values for various configs */ |
| 546 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 547 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 548 | .max_wm = PINEVIEW_MAX_WM, |
| 549 | .default_wm = PINEVIEW_DFT_WM, |
| 550 | .guard_size = PINEVIEW_GUARD_WM, |
| 551 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 552 | }; |
| 553 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 554 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 555 | .max_wm = PINEVIEW_MAX_WM, |
| 556 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 557 | .guard_size = PINEVIEW_GUARD_WM, |
| 558 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 559 | }; |
| 560 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 561 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 562 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 563 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 564 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 565 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 566 | }; |
| 567 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 568 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 569 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 570 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 571 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 572 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 573 | }; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 574 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 575 | .fifo_size = I965_CURSOR_FIFO, |
| 576 | .max_wm = I965_CURSOR_MAX_WM, |
| 577 | .default_wm = I965_CURSOR_DFT_WM, |
| 578 | .guard_size = 2, |
| 579 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 580 | }; |
| 581 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 582 | .fifo_size = I945_FIFO_SIZE, |
| 583 | .max_wm = I915_MAX_WM, |
| 584 | .default_wm = 1, |
| 585 | .guard_size = 2, |
| 586 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 587 | }; |
| 588 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 589 | .fifo_size = I915_FIFO_SIZE, |
| 590 | .max_wm = I915_MAX_WM, |
| 591 | .default_wm = 1, |
| 592 | .guard_size = 2, |
| 593 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 594 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 595 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 596 | .fifo_size = I855GM_FIFO_SIZE, |
| 597 | .max_wm = I915_MAX_WM, |
| 598 | .default_wm = 1, |
| 599 | .guard_size = 2, |
| 600 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 601 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 602 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 603 | .fifo_size = I855GM_FIFO_SIZE, |
| 604 | .max_wm = I915_MAX_WM/2, |
| 605 | .default_wm = 1, |
| 606 | .guard_size = 2, |
| 607 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 608 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 609 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 610 | .fifo_size = I830_FIFO_SIZE, |
| 611 | .max_wm = I915_MAX_WM, |
| 612 | .default_wm = 1, |
| 613 | .guard_size = 2, |
| 614 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 615 | }; |
| 616 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 617 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 618 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 619 | * @pixel_rate: Pipe pixel rate in kHz |
| 620 | * @cpp: Plane bytes per pixel |
| 621 | * @latency: Memory wakeup latency in 0.1us units |
| 622 | * |
| 623 | * Compute the watermark using the method 1 or "small buffer" |
| 624 | * formula. The caller may additonally add extra cachelines |
| 625 | * to account for TLB misses and clock crossings. |
| 626 | * |
| 627 | * This method is concerned with the short term drain rate |
| 628 | * of the FIFO, ie. it does not account for blanking periods |
| 629 | * which would effectively reduce the average drain rate across |
| 630 | * a longer period. The name "small" refers to the fact the |
| 631 | * FIFO is relatively small compared to the amount of data |
| 632 | * fetched. |
| 633 | * |
| 634 | * The FIFO level vs. time graph might look something like: |
| 635 | * |
| 636 | * |\ |\ |
| 637 | * | \ | \ |
| 638 | * __---__---__ (- plane active, _ blanking) |
| 639 | * -> time |
| 640 | * |
| 641 | * or perhaps like this: |
| 642 | * |
| 643 | * |\|\ |\|\ |
| 644 | * __----__----__ (- plane active, _ blanking) |
| 645 | * -> time |
| 646 | * |
| 647 | * Returns: |
| 648 | * The watermark in bytes |
| 649 | */ |
| 650 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 651 | unsigned int cpp, |
| 652 | unsigned int latency) |
| 653 | { |
| 654 | uint64_t ret; |
| 655 | |
| 656 | ret = (uint64_t) pixel_rate * cpp * latency; |
| 657 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 658 | |
| 659 | return ret; |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 664 | * @pixel_rate: Pipe pixel rate in kHz |
| 665 | * @htotal: Pipe horizontal total |
| 666 | * @width: Plane width in pixels |
| 667 | * @cpp: Plane bytes per pixel |
| 668 | * @latency: Memory wakeup latency in 0.1us units |
| 669 | * |
| 670 | * Compute the watermark using the method 2 or "large buffer" |
| 671 | * formula. The caller may additonally add extra cachelines |
| 672 | * to account for TLB misses and clock crossings. |
| 673 | * |
| 674 | * This method is concerned with the long term drain rate |
| 675 | * of the FIFO, ie. it does account for blanking periods |
| 676 | * which effectively reduce the average drain rate across |
| 677 | * a longer period. The name "large" refers to the fact the |
| 678 | * FIFO is relatively large compared to the amount of data |
| 679 | * fetched. |
| 680 | * |
| 681 | * The FIFO level vs. time graph might look something like: |
| 682 | * |
| 683 | * |\___ |\___ |
| 684 | * | \___ | \___ |
| 685 | * | \ | \ |
| 686 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 687 | * -> time |
| 688 | * |
| 689 | * Returns: |
| 690 | * The watermark in bytes |
| 691 | */ |
| 692 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 693 | unsigned int htotal, |
| 694 | unsigned int width, |
| 695 | unsigned int cpp, |
| 696 | unsigned int latency) |
| 697 | { |
| 698 | unsigned int ret; |
| 699 | |
| 700 | /* |
| 701 | * FIXME remove once all users are computing |
| 702 | * watermarks in the correct place. |
| 703 | */ |
| 704 | if (WARN_ON_ONCE(htotal == 0)) |
| 705 | htotal = 1; |
| 706 | |
| 707 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 708 | ret = (ret + 1) * width * cpp; |
| 709 | |
| 710 | return ret; |
| 711 | } |
| 712 | |
| 713 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 714 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 715 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 716 | * @wm: chip FIFO params |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 717 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 718 | * @latency_ns: memory latency for the platform |
| 719 | * |
| 720 | * Calculate the watermark level (the level at which the display plane will |
| 721 | * start fetching from memory again). Each chip has a different display |
| 722 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 723 | * in the correct intel_watermark_params structure. |
| 724 | * |
| 725 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 726 | * on the pixel size. When it reaches the watermark level, it'll start |
| 727 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 728 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 729 | * will occur, and a display engine hang could result. |
| 730 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 731 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 732 | const struct intel_watermark_params *wm, |
| 733 | int fifo_size, int cpp, |
| 734 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 735 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 736 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 737 | |
| 738 | /* |
| 739 | * Note: we need to make sure we don't overflow for various clock & |
| 740 | * latency values. |
| 741 | * clocks go from a few thousand to several hundred thousand. |
| 742 | * latency is usually a few thousand |
| 743 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 744 | entries = intel_wm_method1(pixel_rate, cpp, |
| 745 | latency_ns / 100); |
| 746 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 747 | wm->guard_size; |
| 748 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 749 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 750 | wm_size = fifo_size - entries; |
| 751 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 752 | |
| 753 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 754 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 755 | wm_size = wm->max_wm; |
| 756 | if (wm_size <= 0) |
| 757 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 758 | |
| 759 | /* |
| 760 | * Bspec seems to indicate that the value shouldn't be lower than |
| 761 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 762 | * Lets go for 8 which is the burst size since certain platforms |
| 763 | * already use a hardcoded 8 (which is what the spec says should be |
| 764 | * done). |
| 765 | */ |
| 766 | if (wm_size <= 8) |
| 767 | wm_size = 8; |
| 768 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 769 | return wm_size; |
| 770 | } |
| 771 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 772 | static bool is_disabling(int old, int new, int threshold) |
| 773 | { |
| 774 | return old >= threshold && new < threshold; |
| 775 | } |
| 776 | |
| 777 | static bool is_enabling(int old, int new, int threshold) |
| 778 | { |
| 779 | return old < threshold && new >= threshold; |
| 780 | } |
| 781 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 782 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 783 | { |
| 784 | return dev_priv->wm.max_level + 1; |
| 785 | } |
| 786 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 787 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 788 | const struct intel_plane_state *plane_state) |
| 789 | { |
| 790 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 791 | |
| 792 | /* FIXME check the 'enable' instead */ |
| 793 | if (!crtc_state->base.active) |
| 794 | return false; |
| 795 | |
| 796 | /* |
| 797 | * Treat cursor with fb as always visible since cursor updates |
| 798 | * can happen faster than the vrefresh rate, and the current |
| 799 | * watermark code doesn't handle that correctly. Cursor updates |
| 800 | * which set/clear the fb or change the cursor size are going |
| 801 | * to get throttled by intel_legacy_cursor_update() to work |
| 802 | * around this problem with the watermark code. |
| 803 | */ |
| 804 | if (plane->id == PLANE_CURSOR) |
| 805 | return plane_state->base.fb != NULL; |
| 806 | else |
| 807 | return plane_state->base.visible; |
| 808 | } |
| 809 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 810 | 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] | 811 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 812 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 813 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 814 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 815 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 816 | if (enabled) |
| 817 | return NULL; |
| 818 | enabled = crtc; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | return enabled; |
| 823 | } |
| 824 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 825 | static void pineview_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 826 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 827 | 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] | 828 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 829 | const struct cxsr_latency *latency; |
| 830 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 831 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 832 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 833 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
| 834 | dev_priv->is_ddr3, |
| 835 | dev_priv->fsb_freq, |
| 836 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 837 | if (!latency) { |
| 838 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 839 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 840 | return; |
| 841 | } |
| 842 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 843 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 844 | if (crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 845 | const struct drm_display_mode *adjusted_mode = |
| 846 | &crtc->config->base.adjusted_mode; |
| 847 | const struct drm_framebuffer *fb = |
| 848 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 849 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 850 | int clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 851 | |
| 852 | /* Display SR */ |
| 853 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 854 | pineview_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 855 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 856 | reg = I915_READ(DSPFW1); |
| 857 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 858 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 859 | I915_WRITE(DSPFW1, reg); |
| 860 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 861 | |
| 862 | /* cursor SR */ |
| 863 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 864 | pineview_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 865 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 866 | reg = I915_READ(DSPFW3); |
| 867 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 868 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 869 | I915_WRITE(DSPFW3, reg); |
| 870 | |
| 871 | /* Display HPLL off SR */ |
| 872 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 873 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 874 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 875 | reg = I915_READ(DSPFW3); |
| 876 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 877 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 878 | I915_WRITE(DSPFW3, reg); |
| 879 | |
| 880 | /* cursor HPLL off SR */ |
| 881 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 882 | pineview_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 883 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 884 | reg = I915_READ(DSPFW3); |
| 885 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 886 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 887 | I915_WRITE(DSPFW3, reg); |
| 888 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 889 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 890 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 891 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 892 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 896 | /* |
| 897 | * Documentation says: |
| 898 | * "If the line size is small, the TLB fetches can get in the way of the |
| 899 | * data fetches, causing some lag in the pixel data return which is not |
| 900 | * accounted for in the above formulas. The following adjustment only |
| 901 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 902 | * The WM is adjusted upwards by the difference between the FIFO size |
| 903 | * and the size of 8 whole lines. This adjustment is always performed |
| 904 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 905 | */ |
| 906 | static int g4x_tlb_miss_wa(int fifo_size, int width, int cpp) |
| 907 | { |
| 908 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 909 | |
| 910 | return max(0, tlb_miss); |
| 911 | } |
| 912 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 913 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 914 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 915 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 916 | I915_WRITE(DSPFW1, |
| 917 | FW_WM(wm->sr.plane, SR) | |
| 918 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 919 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 920 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 921 | I915_WRITE(DSPFW2, |
| 922 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 923 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 924 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 925 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 926 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 927 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 928 | I915_WRITE(DSPFW3, |
| 929 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 930 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 931 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 932 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 933 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 934 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 935 | } |
| 936 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 937 | #define FW_WM_VLV(value, plane) \ |
| 938 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 939 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 940 | 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] | 941 | const struct vlv_wm_values *wm) |
| 942 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 943 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 944 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 945 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 946 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 947 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 948 | I915_WRITE(VLV_DDL(pipe), |
| 949 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 950 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 951 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 952 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 953 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 954 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 955 | /* |
| 956 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 957 | * high order bits so that there are no out of bounds values |
| 958 | * present in the registers during the reprogramming. |
| 959 | */ |
| 960 | I915_WRITE(DSPHOWM, 0); |
| 961 | I915_WRITE(DSPHOWM1, 0); |
| 962 | I915_WRITE(DSPFW4, 0); |
| 963 | I915_WRITE(DSPFW5, 0); |
| 964 | I915_WRITE(DSPFW6, 0); |
| 965 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 966 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 967 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 968 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 969 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 970 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 971 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 972 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 973 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 974 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 975 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 976 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 977 | |
| 978 | if (IS_CHERRYVIEW(dev_priv)) { |
| 979 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 980 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 981 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 982 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 983 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 984 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 985 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 986 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 987 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 988 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 989 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 990 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 991 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 992 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 993 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 994 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 995 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 996 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 997 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 998 | 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] | 999 | } else { |
| 1000 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1001 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1002 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1003 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1004 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1005 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1006 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1007 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1008 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1009 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1010 | 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] | 1011 | } |
| 1012 | |
| 1013 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1016 | #undef FW_WM_VLV |
| 1017 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1018 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1019 | { |
| 1020 | /* all latencies in usec */ |
| 1021 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1022 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame^] | 1023 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1024 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame^] | 1025 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1029 | { |
| 1030 | /* |
| 1031 | * DSPCNTR[13] supposedly controls whether the |
| 1032 | * primary plane can use the FIFO space otherwise |
| 1033 | * reserved for the sprite plane. It's not 100% clear |
| 1034 | * what the actual FIFO size is, but it looks like we |
| 1035 | * can happily set both primary and sprite watermarks |
| 1036 | * up to 127 cachelines. So that would seem to mean |
| 1037 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1038 | * the total FIFO is >= 256 cachelines in size. Either |
| 1039 | * way, we don't seem to have to worry about this |
| 1040 | * repartitioning as the maximum watermark value the |
| 1041 | * register can hold for each plane is lower than the |
| 1042 | * minimum FIFO size. |
| 1043 | */ |
| 1044 | switch (plane_id) { |
| 1045 | case PLANE_CURSOR: |
| 1046 | return 63; |
| 1047 | case PLANE_PRIMARY: |
| 1048 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1049 | case PLANE_SPRITE0: |
| 1050 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1051 | default: |
| 1052 | MISSING_CASE(plane_id); |
| 1053 | return 0; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | static int g4x_fbc_fifo_size(int level) |
| 1058 | { |
| 1059 | switch (level) { |
| 1060 | case G4X_WM_LEVEL_SR: |
| 1061 | return 7; |
| 1062 | case G4X_WM_LEVEL_HPLL: |
| 1063 | return 15; |
| 1064 | default: |
| 1065 | MISSING_CASE(level); |
| 1066 | return 0; |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | static uint16_t g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1071 | const struct intel_plane_state *plane_state, |
| 1072 | int level) |
| 1073 | { |
| 1074 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1075 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 1076 | const struct drm_display_mode *adjusted_mode = |
| 1077 | &crtc_state->base.adjusted_mode; |
| 1078 | int clock, htotal, cpp, width, wm; |
| 1079 | int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1080 | |
| 1081 | if (latency == 0) |
| 1082 | return USHRT_MAX; |
| 1083 | |
| 1084 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1085 | return 0; |
| 1086 | |
| 1087 | /* |
| 1088 | * Not 100% sure which way ELK should go here as the |
| 1089 | * spec only says CL/CTG should assume 32bpp and BW |
| 1090 | * doesn't need to. But as these things followed the |
| 1091 | * mobile vs. desktop lines on gen3 as well, let's |
| 1092 | * assume ELK doesn't need this. |
| 1093 | * |
| 1094 | * The spec also fails to list such a restriction for |
| 1095 | * the HPLL watermark, which seems a little strange. |
| 1096 | * Let's use 32bpp for the HPLL watermark as well. |
| 1097 | */ |
| 1098 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1099 | level != G4X_WM_LEVEL_NORMAL) |
| 1100 | cpp = 4; |
| 1101 | else |
| 1102 | cpp = plane_state->base.fb->format->cpp[0]; |
| 1103 | |
| 1104 | clock = adjusted_mode->crtc_clock; |
| 1105 | htotal = adjusted_mode->crtc_htotal; |
| 1106 | |
| 1107 | if (plane->id == PLANE_CURSOR) |
| 1108 | width = plane_state->base.crtc_w; |
| 1109 | else |
| 1110 | width = drm_rect_width(&plane_state->base.dst); |
| 1111 | |
| 1112 | if (plane->id == PLANE_CURSOR) { |
| 1113 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1114 | } else if (plane->id == PLANE_PRIMARY && |
| 1115 | level == G4X_WM_LEVEL_NORMAL) { |
| 1116 | wm = intel_wm_method1(clock, cpp, latency); |
| 1117 | } else { |
| 1118 | int small, large; |
| 1119 | |
| 1120 | small = intel_wm_method1(clock, cpp, latency); |
| 1121 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1122 | |
| 1123 | wm = min(small, large); |
| 1124 | } |
| 1125 | |
| 1126 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1127 | width, cpp); |
| 1128 | |
| 1129 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1130 | |
| 1131 | return min_t(int, wm, USHRT_MAX); |
| 1132 | } |
| 1133 | |
| 1134 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1135 | int level, enum plane_id plane_id, u16 value) |
| 1136 | { |
| 1137 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1138 | bool dirty = false; |
| 1139 | |
| 1140 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1141 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1142 | |
| 1143 | dirty |= raw->plane[plane_id] != value; |
| 1144 | raw->plane[plane_id] = value; |
| 1145 | } |
| 1146 | |
| 1147 | return dirty; |
| 1148 | } |
| 1149 | |
| 1150 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1151 | int level, u16 value) |
| 1152 | { |
| 1153 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1154 | bool dirty = false; |
| 1155 | |
| 1156 | /* NORMAL level doesn't have an FBC watermark */ |
| 1157 | level = max(level, G4X_WM_LEVEL_SR); |
| 1158 | |
| 1159 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1160 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1161 | |
| 1162 | dirty |= raw->fbc != value; |
| 1163 | raw->fbc = value; |
| 1164 | } |
| 1165 | |
| 1166 | return dirty; |
| 1167 | } |
| 1168 | |
| 1169 | static uint32_t ilk_compute_fbc_wm(const struct intel_crtc_state *cstate, |
| 1170 | const struct intel_plane_state *pstate, |
| 1171 | uint32_t pri_val); |
| 1172 | |
| 1173 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1174 | const struct intel_plane_state *plane_state) |
| 1175 | { |
| 1176 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1177 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1178 | enum plane_id plane_id = plane->id; |
| 1179 | bool dirty = false; |
| 1180 | int level; |
| 1181 | |
| 1182 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1183 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1184 | if (plane_id == PLANE_PRIMARY) |
| 1185 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1186 | goto out; |
| 1187 | } |
| 1188 | |
| 1189 | for (level = 0; level < num_levels; level++) { |
| 1190 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1191 | int wm, max_wm; |
| 1192 | |
| 1193 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1194 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1195 | |
| 1196 | if (wm > max_wm) |
| 1197 | break; |
| 1198 | |
| 1199 | dirty |= raw->plane[plane_id] != wm; |
| 1200 | raw->plane[plane_id] = wm; |
| 1201 | |
| 1202 | if (plane_id != PLANE_PRIMARY || |
| 1203 | level == G4X_WM_LEVEL_NORMAL) |
| 1204 | continue; |
| 1205 | |
| 1206 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1207 | raw->plane[plane_id]); |
| 1208 | max_wm = g4x_fbc_fifo_size(level); |
| 1209 | |
| 1210 | /* |
| 1211 | * FBC wm is not mandatory as we |
| 1212 | * can always just disable its use. |
| 1213 | */ |
| 1214 | if (wm > max_wm) |
| 1215 | wm = USHRT_MAX; |
| 1216 | |
| 1217 | dirty |= raw->fbc != wm; |
| 1218 | raw->fbc = wm; |
| 1219 | } |
| 1220 | |
| 1221 | /* mark watermarks as invalid */ |
| 1222 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1223 | |
| 1224 | if (plane_id == PLANE_PRIMARY) |
| 1225 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1226 | |
| 1227 | out: |
| 1228 | if (dirty) { |
| 1229 | DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1230 | plane->base.name, |
| 1231 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1232 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1233 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
| 1234 | |
| 1235 | if (plane_id == PLANE_PRIMARY) |
| 1236 | DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", |
| 1237 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1238 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
| 1239 | } |
| 1240 | |
| 1241 | return dirty; |
| 1242 | } |
| 1243 | |
| 1244 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1245 | enum plane_id plane_id, int level) |
| 1246 | { |
| 1247 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1248 | |
| 1249 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1250 | } |
| 1251 | |
| 1252 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1253 | int level) |
| 1254 | { |
| 1255 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1256 | |
| 1257 | if (level > dev_priv->wm.max_level) |
| 1258 | return false; |
| 1259 | |
| 1260 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1261 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1262 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1263 | } |
| 1264 | |
| 1265 | /* mark all levels starting from 'level' as invalid */ |
| 1266 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1267 | struct g4x_wm_state *wm_state, int level) |
| 1268 | { |
| 1269 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1270 | enum plane_id plane_id; |
| 1271 | |
| 1272 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1273 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1274 | } |
| 1275 | |
| 1276 | if (level <= G4X_WM_LEVEL_SR) { |
| 1277 | wm_state->cxsr = false; |
| 1278 | wm_state->sr.cursor = USHRT_MAX; |
| 1279 | wm_state->sr.plane = USHRT_MAX; |
| 1280 | wm_state->sr.fbc = USHRT_MAX; |
| 1281 | } |
| 1282 | |
| 1283 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1284 | wm_state->hpll_en = false; |
| 1285 | wm_state->hpll.cursor = USHRT_MAX; |
| 1286 | wm_state->hpll.plane = USHRT_MAX; |
| 1287 | wm_state->hpll.fbc = USHRT_MAX; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1292 | { |
| 1293 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1294 | struct intel_atomic_state *state = |
| 1295 | to_intel_atomic_state(crtc_state->base.state); |
| 1296 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 1297 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1298 | ~BIT(PLANE_CURSOR)); |
| 1299 | const struct g4x_pipe_wm *raw; |
| 1300 | struct intel_plane_state *plane_state; |
| 1301 | struct intel_plane *plane; |
| 1302 | enum plane_id plane_id; |
| 1303 | int i, level; |
| 1304 | unsigned int dirty = 0; |
| 1305 | |
| 1306 | for_each_intel_plane_in_state(state, plane, plane_state, i) { |
| 1307 | const struct intel_plane_state *old_plane_state = |
| 1308 | to_intel_plane_state(plane->base.state); |
| 1309 | |
| 1310 | if (plane_state->base.crtc != &crtc->base && |
| 1311 | old_plane_state->base.crtc != &crtc->base) |
| 1312 | continue; |
| 1313 | |
| 1314 | if (g4x_raw_plane_wm_compute(crtc_state, plane_state)) |
| 1315 | dirty |= BIT(plane->id); |
| 1316 | } |
| 1317 | |
| 1318 | if (!dirty) |
| 1319 | return 0; |
| 1320 | |
| 1321 | level = G4X_WM_LEVEL_NORMAL; |
| 1322 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1323 | goto out; |
| 1324 | |
| 1325 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1326 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1327 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1328 | |
| 1329 | level = G4X_WM_LEVEL_SR; |
| 1330 | |
| 1331 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1332 | goto out; |
| 1333 | |
| 1334 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1335 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1336 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1337 | wm_state->sr.fbc = raw->fbc; |
| 1338 | |
| 1339 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1340 | |
| 1341 | level = G4X_WM_LEVEL_HPLL; |
| 1342 | |
| 1343 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1344 | goto out; |
| 1345 | |
| 1346 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1347 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1348 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1349 | wm_state->hpll.fbc = raw->fbc; |
| 1350 | |
| 1351 | wm_state->hpll_en = wm_state->cxsr; |
| 1352 | |
| 1353 | level++; |
| 1354 | |
| 1355 | out: |
| 1356 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1357 | return -EINVAL; |
| 1358 | |
| 1359 | /* invalidate the higher levels */ |
| 1360 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1361 | |
| 1362 | /* |
| 1363 | * Determine if the FBC watermark(s) can be used. IF |
| 1364 | * this isn't the case we prefer to disable the FBC |
| 1365 | ( watermark(s) rather than disable the SR/HPLL |
| 1366 | * level(s) entirely. |
| 1367 | */ |
| 1368 | wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL; |
| 1369 | |
| 1370 | if (level >= G4X_WM_LEVEL_SR && |
| 1371 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1372 | wm_state->fbc_en = false; |
| 1373 | else if (level >= G4X_WM_LEVEL_HPLL && |
| 1374 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1375 | wm_state->fbc_en = false; |
| 1376 | |
| 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | static int g4x_compute_intermediate_wm(struct drm_device *dev, |
| 1381 | struct intel_crtc *crtc, |
| 1382 | struct intel_crtc_state *crtc_state) |
| 1383 | { |
| 1384 | struct g4x_wm_state *intermediate = &crtc_state->wm.g4x.intermediate; |
| 1385 | const struct g4x_wm_state *optimal = &crtc_state->wm.g4x.optimal; |
| 1386 | const struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 1387 | enum plane_id plane_id; |
| 1388 | |
| 1389 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
| 1390 | !crtc_state->disable_cxsr; |
| 1391 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
| 1392 | !crtc_state->disable_cxsr; |
| 1393 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1394 | |
| 1395 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1396 | intermediate->wm.plane[plane_id] = |
| 1397 | max(optimal->wm.plane[plane_id], |
| 1398 | active->wm.plane[plane_id]); |
| 1399 | |
| 1400 | WARN_ON(intermediate->wm.plane[plane_id] > |
| 1401 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
| 1402 | } |
| 1403 | |
| 1404 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1405 | active->sr.plane); |
| 1406 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1407 | active->sr.cursor); |
| 1408 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1409 | active->sr.fbc); |
| 1410 | |
| 1411 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1412 | active->hpll.plane); |
| 1413 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1414 | active->hpll.cursor); |
| 1415 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1416 | active->hpll.fbc); |
| 1417 | |
| 1418 | WARN_ON((intermediate->sr.plane > |
| 1419 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1420 | intermediate->sr.cursor > |
| 1421 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1422 | intermediate->cxsr); |
| 1423 | WARN_ON((intermediate->sr.plane > |
| 1424 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1425 | intermediate->sr.cursor > |
| 1426 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1427 | intermediate->hpll_en); |
| 1428 | |
| 1429 | WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1430 | intermediate->fbc_en && intermediate->cxsr); |
| 1431 | WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1432 | intermediate->fbc_en && intermediate->hpll_en); |
| 1433 | |
| 1434 | /* |
| 1435 | * If our intermediate WM are identical to the final WM, then we can |
| 1436 | * omit the post-vblank programming; only update if it's different. |
| 1437 | */ |
| 1438 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
| 1439 | crtc_state->wm.need_postvbl_update = true; |
| 1440 | |
| 1441 | return 0; |
| 1442 | } |
| 1443 | |
| 1444 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1445 | struct g4x_wm_values *wm) |
| 1446 | { |
| 1447 | struct intel_crtc *crtc; |
| 1448 | int num_active_crtcs = 0; |
| 1449 | |
| 1450 | wm->cxsr = true; |
| 1451 | wm->hpll_en = true; |
| 1452 | wm->fbc_en = true; |
| 1453 | |
| 1454 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1455 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1456 | |
| 1457 | if (!crtc->active) |
| 1458 | continue; |
| 1459 | |
| 1460 | if (!wm_state->cxsr) |
| 1461 | wm->cxsr = false; |
| 1462 | if (!wm_state->hpll_en) |
| 1463 | wm->hpll_en = false; |
| 1464 | if (!wm_state->fbc_en) |
| 1465 | wm->fbc_en = false; |
| 1466 | |
| 1467 | num_active_crtcs++; |
| 1468 | } |
| 1469 | |
| 1470 | if (num_active_crtcs != 1) { |
| 1471 | wm->cxsr = false; |
| 1472 | wm->hpll_en = false; |
| 1473 | wm->fbc_en = false; |
| 1474 | } |
| 1475 | |
| 1476 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1477 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1478 | enum pipe pipe = crtc->pipe; |
| 1479 | |
| 1480 | wm->pipe[pipe] = wm_state->wm; |
| 1481 | if (crtc->active && wm->cxsr) |
| 1482 | wm->sr = wm_state->sr; |
| 1483 | if (crtc->active && wm->hpll_en) |
| 1484 | wm->hpll = wm_state->hpll; |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1489 | { |
| 1490 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1491 | struct g4x_wm_values new_wm = {}; |
| 1492 | |
| 1493 | g4x_merge_wm(dev_priv, &new_wm); |
| 1494 | |
| 1495 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1496 | return; |
| 1497 | |
| 1498 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1499 | _intel_set_memory_cxsr(dev_priv, false); |
| 1500 | |
| 1501 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1502 | |
| 1503 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1504 | _intel_set_memory_cxsr(dev_priv, true); |
| 1505 | |
| 1506 | *old_wm = new_wm; |
| 1507 | } |
| 1508 | |
| 1509 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
| 1510 | struct intel_crtc_state *crtc_state) |
| 1511 | { |
| 1512 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1513 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1514 | |
| 1515 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1516 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1517 | g4x_program_watermarks(dev_priv); |
| 1518 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1519 | } |
| 1520 | |
| 1521 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
| 1522 | struct intel_crtc_state *crtc_state) |
| 1523 | { |
| 1524 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1525 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1526 | |
| 1527 | if (!crtc_state->wm.need_postvbl_update) |
| 1528 | return; |
| 1529 | |
| 1530 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1531 | intel_crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 1532 | g4x_program_watermarks(dev_priv); |
| 1533 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1534 | } |
| 1535 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1536 | /* latency must be in 0.1us units. */ |
| 1537 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1538 | unsigned int htotal, |
| 1539 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1540 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1541 | unsigned int latency) |
| 1542 | { |
| 1543 | unsigned int ret; |
| 1544 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1545 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1546 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1547 | ret = DIV_ROUND_UP(ret, 64); |
| 1548 | |
| 1549 | return ret; |
| 1550 | } |
| 1551 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1552 | 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] | 1553 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1554 | /* all latencies in usec */ |
| 1555 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1556 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1557 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1558 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1559 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1560 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1561 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1562 | |
| 1563 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1564 | } |
| 1565 | } |
| 1566 | |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1567 | static uint16_t vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1568 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1569 | int level) |
| 1570 | { |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1571 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1572 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1573 | const struct drm_display_mode *adjusted_mode = |
| 1574 | &crtc_state->base.adjusted_mode; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1575 | int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1576 | |
| 1577 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1578 | return USHRT_MAX; |
| 1579 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1580 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1581 | return 0; |
| 1582 | |
Daniel Vetter | ef426c1 | 2017-01-04 11:41:10 +0100 | [diff] [blame] | 1583 | cpp = plane_state->base.fb->format->cpp[0]; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1584 | clock = adjusted_mode->crtc_clock; |
| 1585 | htotal = adjusted_mode->crtc_htotal; |
| 1586 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1587 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1588 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1589 | /* |
| 1590 | * FIXME the formula gives values that are |
| 1591 | * too big for the cursor FIFO, and hence we |
| 1592 | * would never be able to use cursors. For |
| 1593 | * now just hardcode the watermark. |
| 1594 | */ |
| 1595 | wm = 63; |
| 1596 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1597 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1598 | dev_priv->wm.pri_latency[level] * 10); |
| 1599 | } |
| 1600 | |
| 1601 | return min_t(int, wm, USHRT_MAX); |
| 1602 | } |
| 1603 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1604 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1605 | { |
| 1606 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1607 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1608 | } |
| 1609 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1610 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1611 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1612 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1613 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1614 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1615 | 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] | 1616 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1617 | int num_active_planes = hweight32(active_planes); |
| 1618 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1619 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1620 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1621 | unsigned int total_rate; |
| 1622 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1623 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1624 | /* |
| 1625 | * When enabling sprite0 after sprite1 has already been enabled |
| 1626 | * we tend to get an underrun unless sprite0 already has some |
| 1627 | * FIFO space allcoated. Hence we always allocate at least one |
| 1628 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1629 | * |
| 1630 | * All other plane enable sequences appear immune to this problem. |
| 1631 | */ |
| 1632 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1633 | sprite0_fifo_extra = 1; |
| 1634 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1635 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1636 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1637 | raw->plane[PLANE_SPRITE1] + |
| 1638 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1639 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1640 | if (total_rate > fifo_size) |
| 1641 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1642 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1643 | if (total_rate == 0) |
| 1644 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1645 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1646 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1647 | unsigned int rate; |
| 1648 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1649 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1650 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1651 | continue; |
| 1652 | } |
| 1653 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1654 | rate = raw->plane[plane_id]; |
| 1655 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1656 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1657 | } |
| 1658 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1659 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1660 | fifo_left -= sprite0_fifo_extra; |
| 1661 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1662 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1663 | |
| 1664 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1665 | |
| 1666 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1667 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1668 | int plane_extra; |
| 1669 | |
| 1670 | if (fifo_left == 0) |
| 1671 | break; |
| 1672 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1673 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1674 | continue; |
| 1675 | |
| 1676 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1677 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1678 | fifo_left -= plane_extra; |
| 1679 | } |
| 1680 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1681 | WARN_ON(active_planes != 0 && fifo_left != 0); |
| 1682 | |
| 1683 | /* give it all to the first plane if none are active */ |
| 1684 | if (active_planes == 0) { |
| 1685 | WARN_ON(fifo_left != fifo_size); |
| 1686 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1687 | } |
| 1688 | |
| 1689 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1690 | } |
| 1691 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1692 | /* mark all levels starting from 'level' as invalid */ |
| 1693 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1694 | struct vlv_wm_state *wm_state, int level) |
| 1695 | { |
| 1696 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1697 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1698 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1699 | enum plane_id plane_id; |
| 1700 | |
| 1701 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1702 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1703 | |
| 1704 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1705 | wm_state->sr[level].plane = USHRT_MAX; |
| 1706 | } |
| 1707 | } |
| 1708 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1709 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1710 | { |
| 1711 | if (wm > fifo_size) |
| 1712 | return USHRT_MAX; |
| 1713 | else |
| 1714 | return fifo_size - wm; |
| 1715 | } |
| 1716 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1717 | /* |
| 1718 | * Starting from 'level' set all higher |
| 1719 | * levels to 'value' in the "raw" watermarks. |
| 1720 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1721 | 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] | 1722 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1723 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1724 | 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] | 1725 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1726 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1727 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1728 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1729 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1730 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1731 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1732 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1733 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1734 | |
| 1735 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1736 | } |
| 1737 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1738 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1739 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1740 | { |
| 1741 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 1742 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1743 | 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] | 1744 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1745 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1746 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1747 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1748 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1749 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1753 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1754 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1755 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1756 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1757 | if (wm > max_wm) |
| 1758 | break; |
| 1759 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1760 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1761 | raw->plane[plane_id] = wm; |
| 1762 | } |
| 1763 | |
| 1764 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1765 | 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] | 1766 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1767 | out: |
| 1768 | if (dirty) |
Ville Syrjälä | 57a6528 | 2017-04-21 21:14:22 +0300 | [diff] [blame] | 1769 | 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] | 1770 | plane->base.name, |
| 1771 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1772 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1773 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
| 1774 | |
| 1775 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1776 | } |
| 1777 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1778 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1779 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1780 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1781 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1782 | &crtc_state->wm.vlv.raw[level]; |
| 1783 | const struct vlv_fifo_state *fifo_state = |
| 1784 | &crtc_state->wm.vlv.fifo_state; |
| 1785 | |
| 1786 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1787 | } |
| 1788 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1789 | 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] | 1790 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1791 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1792 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1793 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1794 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | 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] | 1798 | { |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1799 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1800 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1801 | struct intel_atomic_state *state = |
| 1802 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1803 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1804 | const struct vlv_fifo_state *fifo_state = |
| 1805 | &crtc_state->wm.vlv.fifo_state; |
| 1806 | int num_active_planes = hweight32(crtc_state->active_planes & |
| 1807 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1808 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->base); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1809 | struct intel_plane_state *plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1810 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1811 | enum plane_id plane_id; |
| 1812 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1813 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1814 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1815 | for_each_intel_plane_in_state(state, plane, plane_state, i) { |
| 1816 | const struct intel_plane_state *old_plane_state = |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1817 | to_intel_plane_state(plane->base.state); |
| 1818 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1819 | if (plane_state->base.crtc != &crtc->base && |
| 1820 | old_plane_state->base.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1821 | continue; |
| 1822 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1823 | if (vlv_raw_plane_wm_compute(crtc_state, plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1824 | dirty |= BIT(plane->id); |
| 1825 | } |
| 1826 | |
| 1827 | /* |
| 1828 | * DSPARB registers may have been reset due to the |
| 1829 | * power well being turned off. Make sure we restore |
| 1830 | * them to a consistent state even if no primary/sprite |
| 1831 | * planes are initially active. |
| 1832 | */ |
| 1833 | if (needs_modeset) |
| 1834 | crtc_state->fifo_changed = true; |
| 1835 | |
| 1836 | if (!dirty) |
| 1837 | return 0; |
| 1838 | |
| 1839 | /* cursor changes don't warrant a FIFO recompute */ |
| 1840 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1841 | const struct intel_crtc_state *old_crtc_state = |
| 1842 | to_intel_crtc_state(crtc->base.state); |
| 1843 | const struct vlv_fifo_state *old_fifo_state = |
| 1844 | &old_crtc_state->wm.vlv.fifo_state; |
| 1845 | |
| 1846 | ret = vlv_compute_fifo(crtc_state); |
| 1847 | if (ret) |
| 1848 | return ret; |
| 1849 | |
| 1850 | if (needs_modeset || |
| 1851 | memcmp(old_fifo_state, fifo_state, |
| 1852 | sizeof(*fifo_state)) != 0) |
| 1853 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1854 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1855 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1856 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1857 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1858 | /* |
| 1859 | * Note that enabling cxsr with no primary/sprite planes |
| 1860 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1861 | * with exactly one enabled primary/sprite plane. |
| 1862 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1863 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1864 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1865 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1866 | 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] | 1867 | 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] | 1868 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1869 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1870 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1871 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1872 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1873 | wm_state->wm[level].plane[plane_id] = |
| 1874 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1875 | fifo_state->plane[plane_id]); |
| 1876 | } |
| 1877 | |
| 1878 | wm_state->sr[level].plane = |
| 1879 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1880 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1881 | raw->plane[PLANE_SPRITE1]), |
| 1882 | sr_fifo_size); |
| 1883 | |
| 1884 | wm_state->sr[level].cursor = |
| 1885 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1886 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1887 | } |
| 1888 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1889 | if (level == 0) |
| 1890 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1891 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1892 | /* limit to only levels we can actually handle */ |
| 1893 | wm_state->num_levels = level; |
| 1894 | |
| 1895 | /* invalidate the higher levels */ |
| 1896 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1897 | |
| 1898 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1899 | } |
| 1900 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1901 | #define VLV_FIFO(plane, value) \ |
| 1902 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1903 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1904 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
| 1905 | struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1906 | { |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1907 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1908 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1909 | const struct vlv_fifo_state *fifo_state = |
| 1910 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1911 | int sprite0_start, sprite1_start, fifo_size; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1912 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1913 | if (!crtc_state->fifo_changed) |
| 1914 | return; |
| 1915 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1916 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 1917 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 1918 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1919 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1920 | WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63); |
| 1921 | WARN_ON(fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1922 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1923 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 1924 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1925 | /* |
| 1926 | * uncore.lock serves a double purpose here. It allows us to |
| 1927 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 1928 | * it protects the DSPARB registers from getting clobbered by |
| 1929 | * parallel updates from multiple pipes. |
| 1930 | * |
| 1931 | * intel_pipe_update_start() has already disabled interrupts |
| 1932 | * for us, so a plain spin_lock() is sufficient here. |
| 1933 | */ |
| 1934 | spin_lock(&dev_priv->uncore.lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1935 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1936 | switch (crtc->pipe) { |
| 1937 | uint32_t dsparb, dsparb2, dsparb3; |
| 1938 | case PIPE_A: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1939 | dsparb = I915_READ_FW(DSPARB); |
| 1940 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1941 | |
| 1942 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 1943 | VLV_FIFO(SPRITEB, 0xff)); |
| 1944 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 1945 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 1946 | |
| 1947 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 1948 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 1949 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 1950 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 1951 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1952 | I915_WRITE_FW(DSPARB, dsparb); |
| 1953 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1954 | break; |
| 1955 | case PIPE_B: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1956 | dsparb = I915_READ_FW(DSPARB); |
| 1957 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1958 | |
| 1959 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 1960 | VLV_FIFO(SPRITED, 0xff)); |
| 1961 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 1962 | VLV_FIFO(SPRITED, sprite1_start)); |
| 1963 | |
| 1964 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 1965 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 1966 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 1967 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 1968 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1969 | I915_WRITE_FW(DSPARB, dsparb); |
| 1970 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1971 | break; |
| 1972 | case PIPE_C: |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1973 | dsparb3 = I915_READ_FW(DSPARB3); |
| 1974 | dsparb2 = I915_READ_FW(DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1975 | |
| 1976 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 1977 | VLV_FIFO(SPRITEF, 0xff)); |
| 1978 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 1979 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 1980 | |
| 1981 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 1982 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 1983 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 1984 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 1985 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1986 | I915_WRITE_FW(DSPARB3, dsparb3); |
| 1987 | I915_WRITE_FW(DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1988 | break; |
| 1989 | default: |
| 1990 | break; |
| 1991 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1992 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1993 | POSTING_READ_FW(DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 1994 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 1995 | spin_unlock(&dev_priv->uncore.lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | #undef VLV_FIFO |
| 1999 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2000 | static int vlv_compute_intermediate_wm(struct drm_device *dev, |
| 2001 | struct intel_crtc *crtc, |
| 2002 | struct intel_crtc_state *crtc_state) |
| 2003 | { |
| 2004 | struct vlv_wm_state *intermediate = &crtc_state->wm.vlv.intermediate; |
| 2005 | const struct vlv_wm_state *optimal = &crtc_state->wm.vlv.optimal; |
| 2006 | const struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 2007 | int level; |
| 2008 | |
| 2009 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2010 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
| 2011 | !crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2012 | |
| 2013 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2014 | enum plane_id plane_id; |
| 2015 | |
| 2016 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2017 | intermediate->wm[level].plane[plane_id] = |
| 2018 | min(optimal->wm[level].plane[plane_id], |
| 2019 | active->wm[level].plane[plane_id]); |
| 2020 | } |
| 2021 | |
| 2022 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2023 | active->sr[level].plane); |
| 2024 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2025 | active->sr[level].cursor); |
| 2026 | } |
| 2027 | |
| 2028 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2029 | |
| 2030 | /* |
| 2031 | * If our intermediate WM are identical to the final WM, then we can |
| 2032 | * omit the post-vblank programming; only update if it's different. |
| 2033 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2034 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
| 2035 | crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2036 | |
| 2037 | return 0; |
| 2038 | } |
| 2039 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2040 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2041 | struct vlv_wm_values *wm) |
| 2042 | { |
| 2043 | struct intel_crtc *crtc; |
| 2044 | int num_active_crtcs = 0; |
| 2045 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2046 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2047 | wm->cxsr = true; |
| 2048 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2049 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2050 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2051 | |
| 2052 | if (!crtc->active) |
| 2053 | continue; |
| 2054 | |
| 2055 | if (!wm_state->cxsr) |
| 2056 | wm->cxsr = false; |
| 2057 | |
| 2058 | num_active_crtcs++; |
| 2059 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2060 | } |
| 2061 | |
| 2062 | if (num_active_crtcs != 1) |
| 2063 | wm->cxsr = false; |
| 2064 | |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2065 | if (num_active_crtcs > 1) |
| 2066 | wm->level = VLV_WM_LEVEL_PM2; |
| 2067 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2068 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2069 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2070 | enum pipe pipe = crtc->pipe; |
| 2071 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2072 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2073 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2074 | wm->sr = wm_state->sr[wm->level]; |
| 2075 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2076 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2077 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2078 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2079 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2080 | } |
| 2081 | } |
| 2082 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2083 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2084 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2085 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2086 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2087 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2088 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2089 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2090 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2091 | return; |
| 2092 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2093 | 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] | 2094 | chv_set_memory_dvfs(dev_priv, false); |
| 2095 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2096 | 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] | 2097 | chv_set_memory_pm5(dev_priv, false); |
| 2098 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2099 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2100 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2101 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2102 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2103 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2104 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2105 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2106 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2107 | 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] | 2108 | chv_set_memory_pm5(dev_priv, true); |
| 2109 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2110 | 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] | 2111 | chv_set_memory_dvfs(dev_priv, true); |
| 2112 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2113 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2114 | } |
| 2115 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2116 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
| 2117 | struct intel_crtc_state *crtc_state) |
| 2118 | { |
| 2119 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2120 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2121 | |
| 2122 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2123 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2124 | vlv_program_watermarks(dev_priv); |
| 2125 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2126 | } |
| 2127 | |
| 2128 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
| 2129 | struct intel_crtc_state *crtc_state) |
| 2130 | { |
| 2131 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2132 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2133 | |
| 2134 | if (!crtc_state->wm.need_postvbl_update) |
| 2135 | return; |
| 2136 | |
| 2137 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 2138 | intel_crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2139 | vlv_program_watermarks(dev_priv); |
| 2140 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2141 | } |
| 2142 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2143 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2144 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2145 | 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] | 2146 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2147 | int srwm = 1; |
| 2148 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2149 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2150 | |
| 2151 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2152 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2153 | if (crtc) { |
| 2154 | /* self-refresh has much higher latency */ |
| 2155 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2156 | const struct drm_display_mode *adjusted_mode = |
| 2157 | &crtc->config->base.adjusted_mode; |
| 2158 | const struct drm_framebuffer *fb = |
| 2159 | crtc->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2160 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2161 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2162 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2163 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2164 | int entries; |
| 2165 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2166 | entries = intel_wm_method2(clock, htotal, |
| 2167 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2168 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2169 | srwm = I965_FIFO_SIZE - entries; |
| 2170 | if (srwm < 0) |
| 2171 | srwm = 1; |
| 2172 | srwm &= 0x1ff; |
| 2173 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 2174 | entries, srwm); |
| 2175 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2176 | entries = intel_wm_method2(clock, htotal, |
| 2177 | crtc->base.cursor->state->crtc_w, 4, |
| 2178 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2179 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2180 | i965_cursor_wm_info.cacheline_size) + |
| 2181 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2182 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2183 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2184 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2185 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2186 | |
| 2187 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 2188 | "cursor %d\n", srwm, cursor_sr); |
| 2189 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2190 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2191 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2192 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2193 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2194 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2198 | srwm); |
| 2199 | |
| 2200 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2201 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2202 | FW_WM(8, CURSORB) | |
| 2203 | FW_WM(8, PLANEB) | |
| 2204 | FW_WM(8, PLANEA)); |
| 2205 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2206 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2207 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2208 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2209 | |
| 2210 | if (cxsr_enabled) |
| 2211 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2212 | } |
| 2213 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2214 | #undef FW_WM |
| 2215 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2216 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2217 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2218 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2219 | const struct intel_watermark_params *wm_info; |
| 2220 | uint32_t fwater_lo; |
| 2221 | uint32_t fwater_hi; |
| 2222 | int cwm, srwm = 1; |
| 2223 | int fifo_size; |
| 2224 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2225 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2226 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2227 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2228 | wm_info = &i945_wm_info; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2229 | else if (!IS_GEN2(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2230 | wm_info = &i915_wm_info; |
| 2231 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2232 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2233 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2234 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, 0); |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 2235 | crtc = intel_get_crtc_for_plane(dev_priv, 0); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2236 | if (intel_crtc_active(crtc)) { |
| 2237 | const struct drm_display_mode *adjusted_mode = |
| 2238 | &crtc->config->base.adjusted_mode; |
| 2239 | const struct drm_framebuffer *fb = |
| 2240 | crtc->base.primary->state->fb; |
| 2241 | int cpp; |
| 2242 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2243 | if (IS_GEN2(dev_priv)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2244 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2245 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2246 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2247 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2248 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2249 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2250 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2251 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2252 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2253 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2254 | if (planea_wm > (long)wm_info->max_wm) |
| 2255 | planea_wm = wm_info->max_wm; |
| 2256 | } |
| 2257 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2258 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2259 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2260 | |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2261 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, 1); |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 2262 | crtc = intel_get_crtc_for_plane(dev_priv, 1); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2263 | if (intel_crtc_active(crtc)) { |
| 2264 | const struct drm_display_mode *adjusted_mode = |
| 2265 | &crtc->config->base.adjusted_mode; |
| 2266 | const struct drm_framebuffer *fb = |
| 2267 | crtc->base.primary->state->fb; |
| 2268 | int cpp; |
| 2269 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2270 | if (IS_GEN2(dev_priv)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2271 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2272 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2273 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2274 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2275 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2276 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2277 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2278 | if (enabled == NULL) |
| 2279 | enabled = crtc; |
| 2280 | else |
| 2281 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2282 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2283 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2284 | if (planeb_wm > (long)wm_info->max_wm) |
| 2285 | planeb_wm = wm_info->max_wm; |
| 2286 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2287 | |
| 2288 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 2289 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2290 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2291 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2292 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2293 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2294 | |
| 2295 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2296 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2297 | enabled = NULL; |
| 2298 | } |
| 2299 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2300 | /* |
| 2301 | * Overlay gets an aggressive default since video jitter is bad. |
| 2302 | */ |
| 2303 | cwm = 2; |
| 2304 | |
| 2305 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2306 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2307 | |
| 2308 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2309 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2310 | /* self-refresh has much higher latency */ |
| 2311 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2312 | const struct drm_display_mode *adjusted_mode = |
| 2313 | &enabled->config->base.adjusted_mode; |
| 2314 | const struct drm_framebuffer *fb = |
| 2315 | enabled->base.primary->state->fb; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2316 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2317 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2318 | int hdisplay = enabled->config->pipe_src_w; |
| 2319 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2320 | int entries; |
| 2321 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2322 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2323 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2324 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2325 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2326 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2327 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2328 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2329 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 2330 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 2331 | srwm = wm_info->fifo_size - entries; |
| 2332 | if (srwm < 0) |
| 2333 | srwm = 1; |
| 2334 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2335 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2336 | I915_WRITE(FW_BLC_SELF, |
| 2337 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2338 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2339 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2340 | } |
| 2341 | |
| 2342 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2343 | planea_wm, planeb_wm, cwm, srwm); |
| 2344 | |
| 2345 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2346 | fwater_hi = (cwm & 0x1f); |
| 2347 | |
| 2348 | /* Set request length to 8 cachelines per fetch */ |
| 2349 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2350 | fwater_hi = fwater_hi | (1 << 8); |
| 2351 | |
| 2352 | I915_WRITE(FW_BLC, fwater_lo); |
| 2353 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2354 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2355 | if (enabled) |
| 2356 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2357 | } |
| 2358 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2359 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2360 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2361 | 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] | 2362 | struct intel_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2363 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2364 | uint32_t fwater_lo; |
| 2365 | int planea_wm; |
| 2366 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2367 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2368 | if (crtc == NULL) |
| 2369 | return; |
| 2370 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2371 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 2372 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2373 | &i845_wm_info, |
Ville Syrjälä | ef0f5e9 | 2016-10-31 22:37:17 +0200 | [diff] [blame] | 2374 | dev_priv->display.get_fifo_size(dev_priv, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2375 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2376 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2377 | fwater_lo |= (3<<8) | planea_wm; |
| 2378 | |
| 2379 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 2380 | |
| 2381 | I915_WRITE(FW_BLC, fwater_lo); |
| 2382 | } |
| 2383 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2384 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2385 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2386 | unsigned int cpp, |
| 2387 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2388 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2389 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2390 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2391 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2392 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2393 | |
| 2394 | return ret; |
| 2395 | } |
| 2396 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2397 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2398 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2399 | unsigned int htotal, |
| 2400 | unsigned int width, |
| 2401 | unsigned int cpp, |
| 2402 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2403 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2404 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2405 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2406 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2407 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2408 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2409 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2410 | return ret; |
| 2411 | } |
| 2412 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2413 | 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] | 2414 | uint8_t cpp) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2415 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2416 | /* |
| 2417 | * Neither of these should be possible since this function shouldn't be |
| 2418 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2419 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2420 | * elsewhere in the driver. |
| 2421 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2422 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2423 | return 0; |
| 2424 | if (WARN_ON(!horiz_pixels)) |
| 2425 | return 0; |
| 2426 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2427 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2428 | } |
| 2429 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2430 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2431 | uint16_t pri; |
| 2432 | uint16_t spr; |
| 2433 | uint16_t cur; |
| 2434 | uint16_t fbc; |
| 2435 | }; |
| 2436 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2437 | /* |
| 2438 | * For both WM_PIPE and WM_LP. |
| 2439 | * mem_value must be in 0.1us units. |
| 2440 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2441 | 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] | 2442 | const struct intel_plane_state *pstate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2443 | uint32_t mem_value, |
| 2444 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2445 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2446 | uint32_t method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2447 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2448 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2449 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2450 | return 0; |
| 2451 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2452 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2453 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2454 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2455 | |
| 2456 | if (!is_lp) |
| 2457 | return method1; |
| 2458 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2459 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2460 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2461 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2462 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2463 | |
| 2464 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2465 | } |
| 2466 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2467 | /* |
| 2468 | * For both WM_PIPE and WM_LP. |
| 2469 | * mem_value must be in 0.1us units. |
| 2470 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2471 | 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] | 2472 | const struct intel_plane_state *pstate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2473 | uint32_t mem_value) |
| 2474 | { |
| 2475 | uint32_t method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2476 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2477 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2478 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2479 | return 0; |
| 2480 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2481 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2482 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2483 | method1 = ilk_wm_method1(cstate->pixel_rate, cpp, mem_value); |
| 2484 | method2 = ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2485 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2486 | drm_rect_width(&pstate->base.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2487 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2488 | return min(method1, method2); |
| 2489 | } |
| 2490 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2491 | /* |
| 2492 | * For both WM_PIPE and WM_LP. |
| 2493 | * mem_value must be in 0.1us units. |
| 2494 | */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2495 | 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] | 2496 | const struct intel_plane_state *pstate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2497 | uint32_t mem_value) |
| 2498 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2499 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2500 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2501 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2502 | return 0; |
| 2503 | |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2504 | cpp = pstate->base.fb->format->cpp[0]; |
| 2505 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 2506 | return ilk_wm_method2(cstate->pixel_rate, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2507 | cstate->base.adjusted_mode.crtc_htotal, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2508 | pstate->base.crtc_w, cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2509 | } |
| 2510 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2511 | /* Only for WM_LP. */ |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2512 | 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] | 2513 | const struct intel_plane_state *pstate, |
Ville Syrjälä | 1fda988 | 2013-07-05 11:57:19 +0300 | [diff] [blame] | 2514 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2515 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2516 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2517 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 2518 | if (!intel_wm_plane_visible(cstate, pstate)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2519 | return 0; |
| 2520 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2521 | cpp = pstate->base.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2522 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2523 | 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] | 2524 | } |
| 2525 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2526 | static unsigned int |
| 2527 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2528 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2529 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2530 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2531 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2532 | return 768; |
| 2533 | else |
| 2534 | return 512; |
| 2535 | } |
| 2536 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2537 | static unsigned int |
| 2538 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2539 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2540 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2541 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2542 | /* BDW primary/sprite plane watermarks */ |
| 2543 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2544 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2545 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2546 | return level == 0 ? 127 : 1023; |
| 2547 | else if (!is_sprite) |
| 2548 | /* ILK/SNB primary plane watermarks */ |
| 2549 | return level == 0 ? 127 : 511; |
| 2550 | else |
| 2551 | /* ILK/SNB sprite plane watermarks */ |
| 2552 | return level == 0 ? 63 : 255; |
| 2553 | } |
| 2554 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2555 | static unsigned int |
| 2556 | 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] | 2557 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2558 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2559 | return level == 0 ? 63 : 255; |
| 2560 | else |
| 2561 | return level == 0 ? 31 : 63; |
| 2562 | } |
| 2563 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2564 | 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] | 2565 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2566 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2567 | return 31; |
| 2568 | else |
| 2569 | return 15; |
| 2570 | } |
| 2571 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2572 | /* Calculate the maximum primary/sprite plane watermark */ |
| 2573 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 2574 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2575 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2576 | enum intel_ddb_partitioning ddb_partitioning, |
| 2577 | bool is_sprite) |
| 2578 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2579 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 2580 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2581 | |
| 2582 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2583 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2584 | return 0; |
| 2585 | |
| 2586 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2587 | if (level == 0 || config->num_pipes_active > 1) { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2588 | fifo_size /= INTEL_INFO(dev_priv)->num_pipes; |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2589 | |
| 2590 | /* |
| 2591 | * For some reason the non self refresh |
| 2592 | * FIFO size is only half of the self |
| 2593 | * refresh FIFO size on ILK/SNB. |
| 2594 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2595 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2596 | fifo_size /= 2; |
| 2597 | } |
| 2598 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2599 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2600 | /* level 0 is always calculated with 1:1 split */ |
| 2601 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2602 | if (is_sprite) |
| 2603 | fifo_size *= 5; |
| 2604 | fifo_size /= 6; |
| 2605 | } else { |
| 2606 | fifo_size /= 2; |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2611 | 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] | 2612 | } |
| 2613 | |
| 2614 | /* Calculate the maximum cursor plane watermark */ |
| 2615 | 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] | 2616 | int level, |
| 2617 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2618 | { |
| 2619 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2620 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2621 | return 64; |
| 2622 | |
| 2623 | /* otherwise just report max that registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2624 | return ilk_cursor_wm_reg_max(to_i915(dev), level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2625 | } |
| 2626 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2627 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2628 | int level, |
| 2629 | const struct intel_wm_config *config, |
| 2630 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2631 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2632 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2633 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 2634 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 2635 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2636 | max->fbc = ilk_fbc_wm_reg_max(to_i915(dev)); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2637 | } |
| 2638 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2639 | 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] | 2640 | int level, |
| 2641 | struct ilk_wm_maximums *max) |
| 2642 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2643 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2644 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2645 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2646 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2647 | } |
| 2648 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2649 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2650 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2651 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2652 | { |
| 2653 | bool ret; |
| 2654 | |
| 2655 | /* already determined to be invalid? */ |
| 2656 | if (!result->enable) |
| 2657 | return false; |
| 2658 | |
| 2659 | result->enable = result->pri_val <= max->pri && |
| 2660 | result->spr_val <= max->spr && |
| 2661 | result->cur_val <= max->cur; |
| 2662 | |
| 2663 | ret = result->enable; |
| 2664 | |
| 2665 | /* |
| 2666 | * HACK until we can pre-compute everything, |
| 2667 | * and thus fail gracefully if LP0 watermarks |
| 2668 | * are exceeded... |
| 2669 | */ |
| 2670 | if (level == 0 && !result->enable) { |
| 2671 | if (result->pri_val > max->pri) |
| 2672 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2673 | level, result->pri_val, max->pri); |
| 2674 | if (result->spr_val > max->spr) |
| 2675 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2676 | level, result->spr_val, max->spr); |
| 2677 | if (result->cur_val > max->cur) |
| 2678 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2679 | level, result->cur_val, max->cur); |
| 2680 | |
| 2681 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2682 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2683 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2684 | result->enable = true; |
| 2685 | } |
| 2686 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2687 | return ret; |
| 2688 | } |
| 2689 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2690 | 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] | 2691 | const struct intel_crtc *intel_crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2692 | int level, |
Matt Roper | 7221fc3 | 2015-09-24 15:53:08 -0700 | [diff] [blame] | 2693 | struct intel_crtc_state *cstate, |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 2694 | struct intel_plane_state *pristate, |
| 2695 | struct intel_plane_state *sprstate, |
| 2696 | struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2697 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2698 | { |
| 2699 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2700 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2701 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2702 | |
| 2703 | /* WM1+ latency values stored in 0.5us units */ |
| 2704 | if (level > 0) { |
| 2705 | pri_latency *= 5; |
| 2706 | spr_latency *= 5; |
| 2707 | cur_latency *= 5; |
| 2708 | } |
| 2709 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2710 | if (pristate) { |
| 2711 | result->pri_val = ilk_compute_pri_wm(cstate, pristate, |
| 2712 | pri_latency, level); |
| 2713 | result->fbc_val = ilk_compute_fbc_wm(cstate, pristate, result->pri_val); |
| 2714 | } |
| 2715 | |
| 2716 | if (sprstate) |
| 2717 | result->spr_val = ilk_compute_spr_wm(cstate, sprstate, spr_latency); |
| 2718 | |
| 2719 | if (curstate) |
| 2720 | result->cur_val = ilk_compute_cur_wm(cstate, curstate, cur_latency); |
| 2721 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2722 | result->enable = true; |
| 2723 | } |
| 2724 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2725 | static uint32_t |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2726 | hsw_compute_linetime_wm(const struct intel_crtc_state *cstate) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2727 | { |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 2728 | const struct intel_atomic_state *intel_state = |
| 2729 | to_intel_atomic_state(cstate->base.state); |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2730 | const struct drm_display_mode *adjusted_mode = |
| 2731 | &cstate->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2732 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2733 | |
Matt Roper | ee91a15 | 2015-12-03 11:37:39 -0800 | [diff] [blame] | 2734 | if (!cstate->base.active) |
| 2735 | return 0; |
| 2736 | if (WARN_ON(adjusted_mode->crtc_clock == 0)) |
| 2737 | return 0; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2738 | if (WARN_ON(intel_state->cdclk.logical.cdclk == 0)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2739 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2740 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2741 | /* The WM are computed with base on how long it takes to fill a single |
| 2742 | * row at the given clock rate, multiplied by 8. |
| 2743 | * */ |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 2744 | linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
| 2745 | adjusted_mode->crtc_clock); |
| 2746 | ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8, |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 2747 | intel_state->cdclk.logical.cdclk); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2748 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2749 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2750 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2751 | } |
| 2752 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2753 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
| 2754 | uint16_t wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2755 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2756 | if (IS_GEN9(dev_priv)) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2757 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2758 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2759 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2760 | |
| 2761 | /* read the first set of memory latencies[0:3] */ |
| 2762 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 2763 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2764 | ret = sandybridge_pcode_read(dev_priv, |
| 2765 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2766 | &val); |
| 2767 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2768 | |
| 2769 | if (ret) { |
| 2770 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2771 | return; |
| 2772 | } |
| 2773 | |
| 2774 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2775 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2776 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2777 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2778 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2779 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2780 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2781 | |
| 2782 | /* read the second set of memory latencies[4:7] */ |
| 2783 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 2784 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2785 | ret = sandybridge_pcode_read(dev_priv, |
| 2786 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2787 | &val); |
| 2788 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2789 | if (ret) { |
| 2790 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2791 | return; |
| 2792 | } |
| 2793 | |
| 2794 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2795 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2796 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2797 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2798 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2799 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2800 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2801 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2802 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2803 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2804 | * need to be disabled. We make sure to sanitize the values out |
| 2805 | * of the punit to satisfy this requirement. |
| 2806 | */ |
| 2807 | for (level = 1; level <= max_level; level++) { |
| 2808 | if (wm[level] == 0) { |
| 2809 | for (i = level + 1; i <= max_level; i++) |
| 2810 | wm[i] = 0; |
| 2811 | break; |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | /* |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 2816 | * WaWmMemoryReadLatency:skl,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2817 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2818 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2819 | * to add 2us to the various latency levels we retrieve from the |
| 2820 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2821 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2822 | if (wm[0] == 0) { |
| 2823 | wm[0] += 2; |
| 2824 | for (level = 1; level <= max_level; level++) { |
| 2825 | if (wm[level] == 0) |
| 2826 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2827 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2828 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2829 | } |
| 2830 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2831 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2832 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2833 | |
| 2834 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2835 | if (wm[0] == 0) |
| 2836 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2837 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2838 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2839 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2840 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2841 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2842 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2843 | |
| 2844 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2845 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2846 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2847 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2848 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2849 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2850 | |
| 2851 | /* ILK primary LP0 latency is 700 ns */ |
| 2852 | wm[0] = 7; |
| 2853 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2854 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2855 | } |
| 2856 | } |
| 2857 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2858 | static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv, |
| 2859 | uint16_t wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2860 | { |
| 2861 | /* ILK sprite LP0 latency is 1300 ns */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2862 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2863 | wm[0] = 13; |
| 2864 | } |
| 2865 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2866 | static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv, |
| 2867 | uint16_t wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2868 | { |
| 2869 | /* ILK cursor LP0 latency is 1300 ns */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2870 | if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2871 | wm[0] = 13; |
| 2872 | |
| 2873 | /* WaDoubleCursorLP3Latency:ivb */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2874 | if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2875 | wm[3] *= 2; |
| 2876 | } |
| 2877 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2878 | 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] | 2879 | { |
| 2880 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2881 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2882 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2883 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2884 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2885 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2886 | return 3; |
| 2887 | else |
| 2888 | return 2; |
| 2889 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2890 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2891 | 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] | 2892 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2893 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2894 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2895 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2896 | |
| 2897 | for (level = 0; level <= max_level; level++) { |
| 2898 | unsigned int latency = wm[level]; |
| 2899 | |
| 2900 | if (latency == 0) { |
| 2901 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2902 | name, level); |
| 2903 | continue; |
| 2904 | } |
| 2905 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2906 | /* |
| 2907 | * - latencies are in us on gen9. |
| 2908 | * - before then, WM1+ latency values are in 0.5us units |
| 2909 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2910 | if (IS_GEN9(dev_priv)) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2911 | latency *= 10; |
| 2912 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2913 | latency *= 5; |
| 2914 | |
| 2915 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2916 | name, level, wm[level], |
| 2917 | latency / 10, latency % 10); |
| 2918 | } |
| 2919 | } |
| 2920 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2921 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2922 | uint16_t wm[5], uint16_t min) |
| 2923 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2924 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2925 | |
| 2926 | if (wm[0] >= min) |
| 2927 | return false; |
| 2928 | |
| 2929 | wm[0] = max(wm[0], min); |
| 2930 | for (level = 1; level <= max_level; level++) |
| 2931 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2932 | |
| 2933 | return true; |
| 2934 | } |
| 2935 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2936 | 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] | 2937 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2938 | bool changed; |
| 2939 | |
| 2940 | /* |
| 2941 | * The BIOS provided WM memory latency values are often |
| 2942 | * inadequate for high resolution displays. Adjust them. |
| 2943 | */ |
| 2944 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2945 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2946 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2947 | |
| 2948 | if (!changed) |
| 2949 | return; |
| 2950 | |
| 2951 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2952 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 2953 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 2954 | 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] | 2955 | } |
| 2956 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2957 | 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] | 2958 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2959 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2960 | |
| 2961 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2962 | sizeof(dev_priv->wm.pri_latency)); |
| 2963 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2964 | sizeof(dev_priv->wm.pri_latency)); |
| 2965 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2966 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2967 | 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] | 2968 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2969 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 2970 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 2971 | 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] | 2972 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2973 | if (IS_GEN6(dev_priv)) |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2974 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2975 | } |
| 2976 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2977 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2978 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2979 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2980 | 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] | 2981 | } |
| 2982 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 2983 | static bool ilk_validate_pipe_wm(struct drm_device *dev, |
| 2984 | struct intel_pipe_wm *pipe_wm) |
| 2985 | { |
| 2986 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2987 | const struct intel_wm_config config = { |
| 2988 | .num_pipes_active = 1, |
| 2989 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 2990 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 2991 | }; |
| 2992 | struct ilk_wm_maximums max; |
| 2993 | |
| 2994 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2995 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2996 | |
| 2997 | /* At least LP0 must be valid */ |
| 2998 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
| 2999 | DRM_DEBUG_KMS("LP0 watermark invalid\n"); |
| 3000 | return false; |
| 3001 | } |
| 3002 | |
| 3003 | return true; |
| 3004 | } |
| 3005 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3006 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3007 | static int ilk_compute_pipe_wm(struct intel_crtc_state *cstate) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3008 | { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3009 | struct drm_atomic_state *state = cstate->base.state; |
| 3010 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3011 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3012 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3013 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3014 | struct intel_plane *intel_plane; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3015 | struct intel_plane_state *pristate = NULL; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3016 | struct intel_plane_state *sprstate = NULL; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3017 | struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3018 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3019 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3020 | |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3021 | pipe_wm = &cstate->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3022 | |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3023 | for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3024 | struct intel_plane_state *ps; |
| 3025 | |
| 3026 | ps = intel_atomic_get_existing_plane_state(state, |
| 3027 | intel_plane); |
| 3028 | if (!ps) |
| 3029 | continue; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3030 | |
| 3031 | if (intel_plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3032 | pristate = ps; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3033 | else if (intel_plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3034 | sprstate = ps; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3035 | else if (intel_plane->base.type == DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3036 | curstate = ps; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3039 | pipe_wm->pipe_enabled = cstate->base.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3040 | if (sprstate) { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3041 | pipe_wm->sprites_enabled = sprstate->base.visible; |
| 3042 | pipe_wm->sprites_scaled = sprstate->base.visible && |
| 3043 | (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 || |
| 3044 | 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] | 3045 | } |
| 3046 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3047 | usable_level = max_level; |
| 3048 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3049 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3050 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3051 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3052 | |
| 3053 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3054 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3055 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3056 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3057 | ilk_compute_wm_level(dev_priv, intel_crtc, 0, cstate, |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3058 | pristate, sprstate, curstate, &pipe_wm->raw_wm[0]); |
| 3059 | |
| 3060 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
| 3061 | pipe_wm->wm[0] = pipe_wm->raw_wm[0]; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3062 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3063 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 532f7a7 | 2016-04-29 17:31:17 +0300 | [diff] [blame] | 3064 | pipe_wm->linetime = hsw_compute_linetime_wm(cstate); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3065 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3066 | if (!ilk_validate_pipe_wm(dev, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3067 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3068 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3069 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3070 | |
| 3071 | for (level = 1; level <= max_level; level++) { |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3072 | struct intel_wm_level *wm = &pipe_wm->raw_wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3073 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3074 | ilk_compute_wm_level(dev_priv, intel_crtc, level, cstate, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3075 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3076 | |
| 3077 | /* |
| 3078 | * Disable any watermark level that exceeds the |
| 3079 | * register maximums since such watermarks are |
| 3080 | * always invalid. |
| 3081 | */ |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3082 | if (level > usable_level) |
| 3083 | continue; |
| 3084 | |
| 3085 | if (ilk_validate_wm_level(level, &max, wm)) |
| 3086 | pipe_wm->wm[level] = *wm; |
| 3087 | else |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3088 | usable_level = level; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3089 | } |
| 3090 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3091 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3095 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3096 | * state and the new state. These can be programmed to the hardware |
| 3097 | * immediately. |
| 3098 | */ |
| 3099 | static int ilk_compute_intermediate_wm(struct drm_device *dev, |
| 3100 | struct intel_crtc *intel_crtc, |
| 3101 | struct intel_crtc_state *newstate) |
| 3102 | { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3103 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3104 | struct intel_pipe_wm *b = &intel_crtc->wm.active.ilk; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3105 | int level, max_level = ilk_wm_max_level(to_i915(dev)); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3106 | |
| 3107 | /* |
| 3108 | * Start with the final, target watermarks, then combine with the |
| 3109 | * currently active watermarks to get values that are safe both before |
| 3110 | * and after the vblank. |
| 3111 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3112 | *a = newstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3113 | a->pipe_enabled |= b->pipe_enabled; |
| 3114 | a->sprites_enabled |= b->sprites_enabled; |
| 3115 | a->sprites_scaled |= b->sprites_scaled; |
| 3116 | |
| 3117 | for (level = 0; level <= max_level; level++) { |
| 3118 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3119 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3120 | |
| 3121 | a_wm->enable &= b_wm->enable; |
| 3122 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3123 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3124 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3125 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3126 | } |
| 3127 | |
| 3128 | /* |
| 3129 | * We need to make sure that these merged watermark values are |
| 3130 | * actually a valid configuration themselves. If they're not, |
| 3131 | * there's no safe way to transition from the old state to |
| 3132 | * the new state, so we need to fail the atomic transaction. |
| 3133 | */ |
| 3134 | if (!ilk_validate_pipe_wm(dev, a)) |
| 3135 | return -EINVAL; |
| 3136 | |
| 3137 | /* |
| 3138 | * If our intermediate WM are identical to the final WM, then we can |
| 3139 | * omit the post-vblank programming; only update if it's different. |
| 3140 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3141 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3142 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3143 | |
| 3144 | return 0; |
| 3145 | } |
| 3146 | |
| 3147 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3148 | * Merge the watermarks from all active pipes for a specific level. |
| 3149 | */ |
| 3150 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 3151 | int level, |
| 3152 | struct intel_wm_level *ret_wm) |
| 3153 | { |
| 3154 | const struct intel_crtc *intel_crtc; |
| 3155 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3156 | ret_wm->enable = true; |
| 3157 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3158 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3159 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3160 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3161 | |
| 3162 | if (!active->pipe_enabled) |
| 3163 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3164 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3165 | /* |
| 3166 | * The watermark values may have been used in the past, |
| 3167 | * so we must maintain them in the registers for some |
| 3168 | * time even if the level is now disabled. |
| 3169 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3170 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3171 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3172 | |
| 3173 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3174 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3175 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3176 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3177 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | /* |
| 3181 | * Merge all low power watermarks for all active pipes. |
| 3182 | */ |
| 3183 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3184 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3185 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3186 | struct intel_pipe_wm *merged) |
| 3187 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3188 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3189 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3190 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3191 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3192 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3193 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3194 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3195 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3196 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3197 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3198 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3199 | |
| 3200 | /* merge each WM1+ level */ |
| 3201 | for (level = 1; level <= max_level; level++) { |
| 3202 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3203 | |
| 3204 | ilk_merge_wm_level(dev, level, wm); |
| 3205 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3206 | if (level > last_enabled_level) |
| 3207 | wm->enable = false; |
| 3208 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3209 | /* make sure all following levels get disabled */ |
| 3210 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3211 | |
| 3212 | /* |
| 3213 | * The spec says it is preferred to disable |
| 3214 | * FBC WMs instead of disabling a WM level. |
| 3215 | */ |
| 3216 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3217 | if (wm->enable) |
| 3218 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3219 | wm->fbc_val = 0; |
| 3220 | } |
| 3221 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3222 | |
| 3223 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3224 | /* |
| 3225 | * FIXME this is racy. FBC might get enabled later. |
| 3226 | * What we should check here is whether FBC can be |
| 3227 | * enabled sometime later. |
| 3228 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3229 | if (IS_GEN5(dev_priv) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3230 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3231 | for (level = 2; level <= max_level; level++) { |
| 3232 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3233 | |
| 3234 | wm->enable = false; |
| 3235 | } |
| 3236 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3237 | } |
| 3238 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3239 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3240 | { |
| 3241 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3242 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3243 | } |
| 3244 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3245 | /* The value we need to program into the WM_LPx latency field */ |
| 3246 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 3247 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3248 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3249 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3250 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3251 | return 2 * level; |
| 3252 | else |
| 3253 | return dev_priv->wm.pri_latency[level]; |
| 3254 | } |
| 3255 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3256 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3257 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3258 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3259 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3260 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3261 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3262 | struct intel_crtc *intel_crtc; |
| 3263 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3264 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3265 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3266 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3267 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3268 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3269 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3270 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3271 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3272 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3273 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3274 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3275 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3276 | /* |
| 3277 | * Maintain the watermark values even if the level is |
| 3278 | * disabled. Doing otherwise could cause underruns. |
| 3279 | */ |
| 3280 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3281 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3282 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3283 | r->cur_val; |
| 3284 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3285 | if (r->enable) |
| 3286 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3287 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3288 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3289 | results->wm_lp[wm_lp - 1] |= |
| 3290 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3291 | else |
| 3292 | results->wm_lp[wm_lp - 1] |= |
| 3293 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3294 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3295 | /* |
| 3296 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3297 | * level is disabled. Doing otherwise could cause underruns. |
| 3298 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3299 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3300 | WARN_ON(wm_lp != 1); |
| 3301 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3302 | } else |
| 3303 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3304 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3305 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3306 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3307 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3308 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3309 | const struct intel_wm_level *r = |
| 3310 | &intel_crtc->wm.active.ilk.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3311 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3312 | if (WARN_ON(!r->enable)) |
| 3313 | continue; |
| 3314 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3315 | results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3316 | |
| 3317 | results->wm_pipe[pipe] = |
| 3318 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3319 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3320 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3324 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3325 | * 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] | 3326 | 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] | 3327 | struct intel_pipe_wm *r1, |
| 3328 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3329 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3330 | int level, max_level = ilk_wm_max_level(to_i915(dev)); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3331 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3332 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3333 | for (level = 1; level <= max_level; level++) { |
| 3334 | if (r1->wm[level].enable) |
| 3335 | level1 = level; |
| 3336 | if (r2->wm[level].enable) |
| 3337 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3338 | } |
| 3339 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3340 | if (level1 == level2) { |
| 3341 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3342 | return r2; |
| 3343 | else |
| 3344 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3345 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3346 | return r1; |
| 3347 | } else { |
| 3348 | return r2; |
| 3349 | } |
| 3350 | } |
| 3351 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3352 | /* dirty bits used to track which watermarks need changes */ |
| 3353 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 3354 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 3355 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3356 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3357 | #define WM_DIRTY_FBC (1 << 24) |
| 3358 | #define WM_DIRTY_DDB (1 << 25) |
| 3359 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3360 | 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] | 3361 | const struct ilk_wm_values *old, |
| 3362 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3363 | { |
| 3364 | unsigned int dirty = 0; |
| 3365 | enum pipe pipe; |
| 3366 | int wm_lp; |
| 3367 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3368 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3369 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 3370 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 3371 | /* Must disable LP1+ watermarks too */ |
| 3372 | dirty |= WM_DIRTY_LP_ALL; |
| 3373 | } |
| 3374 | |
| 3375 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3376 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3377 | /* Must disable LP1+ watermarks too */ |
| 3378 | dirty |= WM_DIRTY_LP_ALL; |
| 3379 | } |
| 3380 | } |
| 3381 | |
| 3382 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3383 | dirty |= WM_DIRTY_FBC; |
| 3384 | /* Must disable LP1+ watermarks too */ |
| 3385 | dirty |= WM_DIRTY_LP_ALL; |
| 3386 | } |
| 3387 | |
| 3388 | if (old->partitioning != new->partitioning) { |
| 3389 | dirty |= WM_DIRTY_DDB; |
| 3390 | /* Must disable LP1+ watermarks too */ |
| 3391 | dirty |= WM_DIRTY_LP_ALL; |
| 3392 | } |
| 3393 | |
| 3394 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3395 | if (dirty & WM_DIRTY_LP_ALL) |
| 3396 | return dirty; |
| 3397 | |
| 3398 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3399 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3400 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3401 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3402 | break; |
| 3403 | } |
| 3404 | |
| 3405 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3406 | for (; wm_lp <= 3; wm_lp++) |
| 3407 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3408 | |
| 3409 | return dirty; |
| 3410 | } |
| 3411 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3412 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3413 | unsigned int dirty) |
| 3414 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3415 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3416 | bool changed = false; |
| 3417 | |
| 3418 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3419 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3420 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3421 | changed = true; |
| 3422 | } |
| 3423 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3424 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3425 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3426 | changed = true; |
| 3427 | } |
| 3428 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3429 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3430 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3431 | changed = true; |
| 3432 | } |
| 3433 | |
| 3434 | /* |
| 3435 | * Don't touch WM1S_LP_EN here. |
| 3436 | * Doing so could cause underruns. |
| 3437 | */ |
| 3438 | |
| 3439 | return changed; |
| 3440 | } |
| 3441 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3442 | /* |
| 3443 | * The spec says we shouldn't write when we don't need, because every write |
| 3444 | * causes WMs to be re-evaluated, expending some power. |
| 3445 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3446 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3447 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3448 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3449 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3450 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3451 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3452 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3453 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3454 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3455 | return; |
| 3456 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3457 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3458 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3459 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3460 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3461 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3462 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3463 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3464 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 3465 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3466 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3467 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3468 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3469 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3470 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3471 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 3472 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3473 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3474 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3475 | val = I915_READ(WM_MISC); |
| 3476 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3477 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3478 | else |
| 3479 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3480 | I915_WRITE(WM_MISC, val); |
| 3481 | } else { |
| 3482 | val = I915_READ(DISP_ARB_CTL2); |
| 3483 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3484 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3485 | else |
| 3486 | val |= DISP_DATA_PARTITION_5_6; |
| 3487 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3488 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3489 | } |
| 3490 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3491 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3492 | val = I915_READ(DISP_ARB_CTL); |
| 3493 | if (results->enable_fbc_wm) |
| 3494 | val &= ~DISP_FBC_WM_DIS; |
| 3495 | else |
| 3496 | val |= DISP_FBC_WM_DIS; |
| 3497 | I915_WRITE(DISP_ARB_CTL, val); |
| 3498 | } |
| 3499 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3500 | if (dirty & WM_DIRTY_LP(1) && |
| 3501 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3502 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3503 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3504 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3505 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3506 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3507 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3508 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3509 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3510 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3511 | 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] | 3512 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3513 | 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] | 3514 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3515 | 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] | 3516 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3517 | |
| 3518 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3519 | } |
| 3520 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3521 | bool ilk_disable_lp_wm(struct drm_device *dev) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3522 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3523 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3524 | |
| 3525 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3526 | } |
| 3527 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3528 | #define SKL_SAGV_BLOCK_TIME 30 /* µs */ |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3529 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3530 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3531 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3532 | * so assume we'll always need it in order to avoid underruns. |
| 3533 | */ |
| 3534 | static bool skl_needs_memory_bw_wa(struct intel_atomic_state *state) |
| 3535 | { |
| 3536 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 3537 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 3538 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3539 | return true; |
| 3540 | |
| 3541 | return false; |
| 3542 | } |
| 3543 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3544 | static bool |
| 3545 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3546 | { |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3547 | if (IS_KABYLAKE(dev_priv)) |
| 3548 | return true; |
| 3549 | |
| 3550 | if (IS_SKYLAKE(dev_priv) && |
| 3551 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED) |
| 3552 | return true; |
| 3553 | |
| 3554 | return false; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3555 | } |
| 3556 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3557 | /* |
| 3558 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3559 | * depending on power and performance requirements. The display engine access |
| 3560 | * to system memory is blocked during the adjustment time. Because of the |
| 3561 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3562 | * underruns if we don't meet all of the following requirements: |
| 3563 | * |
| 3564 | * - <= 1 pipe enabled |
| 3565 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3566 | * - We're not using an interlaced display configuration |
| 3567 | */ |
| 3568 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3569 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3570 | { |
| 3571 | int ret; |
| 3572 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3573 | if (!intel_has_sagv(dev_priv)) |
| 3574 | return 0; |
| 3575 | |
| 3576 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3577 | return 0; |
| 3578 | |
| 3579 | DRM_DEBUG_KMS("Enabling the SAGV\n"); |
| 3580 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3581 | |
| 3582 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3583 | GEN9_SAGV_ENABLE); |
| 3584 | |
| 3585 | /* We don't need to wait for the SAGV when enabling */ |
| 3586 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3587 | |
| 3588 | /* |
| 3589 | * Some skl systems, pre-release machines in particular, |
| 3590 | * don't actually have an SAGV. |
| 3591 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3592 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3593 | DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3594 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3595 | return 0; |
| 3596 | } else if (ret < 0) { |
| 3597 | DRM_ERROR("Failed to enable the SAGV\n"); |
| 3598 | return ret; |
| 3599 | } |
| 3600 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3601 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3602 | return 0; |
| 3603 | } |
| 3604 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3605 | int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3606 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3607 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3608 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3609 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3610 | if (!intel_has_sagv(dev_priv)) |
| 3611 | return 0; |
| 3612 | |
| 3613 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3614 | return 0; |
| 3615 | |
| 3616 | DRM_DEBUG_KMS("Disabling the SAGV\n"); |
| 3617 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3618 | |
| 3619 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3620 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3621 | GEN9_SAGV_DISABLE, |
| 3622 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3623 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3624 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3625 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3626 | /* |
| 3627 | * Some skl systems, pre-release machines in particular, |
| 3628 | * don't actually have an SAGV. |
| 3629 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [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; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3634 | } else if (ret < 0) { |
| 3635 | DRM_ERROR("Failed to disable the SAGV (%d)\n", ret); |
| 3636 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3637 | } |
| 3638 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3639 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3640 | return 0; |
| 3641 | } |
| 3642 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3643 | bool intel_can_enable_sagv(struct drm_atomic_state *state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3644 | { |
| 3645 | struct drm_device *dev = state->dev; |
| 3646 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3647 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3648 | struct intel_crtc *crtc; |
| 3649 | struct intel_plane *plane; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3650 | struct intel_crtc_state *cstate; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3651 | enum pipe pipe; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3652 | int level, latency; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3653 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3654 | if (!intel_has_sagv(dev_priv)) |
| 3655 | return false; |
| 3656 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3657 | /* |
| 3658 | * SKL workaround: bspec recommends we disable the SAGV when we have |
| 3659 | * more then one pipe enabled |
| 3660 | * |
| 3661 | * If there are no active CRTCs, no additional checks need be performed |
| 3662 | */ |
| 3663 | if (hweight32(intel_state->active_crtcs) == 0) |
| 3664 | return true; |
| 3665 | else if (hweight32(intel_state->active_crtcs) > 1) |
| 3666 | return false; |
| 3667 | |
| 3668 | /* Since we're now guaranteed to only have one active CRTC... */ |
| 3669 | pipe = ffs(intel_state->active_crtcs) - 1; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 3670 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3671 | cstate = to_intel_crtc_state(crtc->base.state); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3672 | |
Paulo Zanoni | c89cadd | 2016-10-10 17:30:59 -0300 | [diff] [blame] | 3673 | if (crtc->base.state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3674 | return false; |
| 3675 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3676 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3677 | struct skl_plane_wm *wm = |
| 3678 | &cstate->wm.skl.optimal.planes[plane->id]; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3679 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3680 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3681 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3682 | continue; |
| 3683 | |
| 3684 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3685 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3686 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3687 | { } |
| 3688 | |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3689 | latency = dev_priv->wm.skl_latency[level]; |
| 3690 | |
| 3691 | if (skl_needs_memory_bw_wa(intel_state) && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3692 | plane->base.state->fb->modifier == |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3693 | I915_FORMAT_MOD_X_TILED) |
| 3694 | latency += 15; |
| 3695 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3696 | /* |
| 3697 | * If any of the planes on this pipe don't enable wm levels |
| 3698 | * that incur memory latencies higher then 30µs we can't enable |
| 3699 | * the SAGV |
| 3700 | */ |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3701 | if (latency < SKL_SAGV_BLOCK_TIME) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3702 | return false; |
| 3703 | } |
| 3704 | |
| 3705 | return true; |
| 3706 | } |
| 3707 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3708 | static void |
| 3709 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3710 | const struct intel_crtc_state *cstate, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3711 | struct skl_ddb_entry *alloc, /* out */ |
| 3712 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3713 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3714 | struct drm_atomic_state *state = cstate->base.state; |
| 3715 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 3716 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3717 | struct drm_crtc *for_crtc = cstate->base.crtc; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3718 | unsigned int pipe_size, ddb_size; |
| 3719 | int nth_active_pipe; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3720 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3721 | if (WARN_ON(!state) || !cstate->base.active) { |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3722 | alloc->start = 0; |
| 3723 | alloc->end = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3724 | *num_active = hweight32(dev_priv->active_crtcs); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3725 | return; |
| 3726 | } |
| 3727 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3728 | if (intel_state->active_pipe_changes) |
| 3729 | *num_active = hweight32(intel_state->active_crtcs); |
| 3730 | else |
| 3731 | *num_active = hweight32(dev_priv->active_crtcs); |
| 3732 | |
Deepak M | 6f3fff6 | 2016-09-15 15:01:10 +0530 | [diff] [blame] | 3733 | ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
| 3734 | WARN_ON(ddb_size == 0); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3735 | |
| 3736 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 3737 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3738 | /* |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3739 | * If the state doesn't change the active CRTC's, then there's |
| 3740 | * no need to recalculate; the existing pipe allocation limits |
| 3741 | * should remain unchanged. Note that we're safe from racing |
| 3742 | * commits since any racing commit that changes the active CRTC |
| 3743 | * list would need to grab _all_ crtc locks, including the one |
| 3744 | * we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3745 | */ |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3746 | if (!intel_state->active_pipe_changes) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 3747 | /* |
| 3748 | * alloc may be cleared by clear_intel_crtc_state, |
| 3749 | * copy from old state to be sure |
| 3750 | */ |
| 3751 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3752 | return; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3753 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3754 | |
| 3755 | nth_active_pipe = hweight32(intel_state->active_crtcs & |
| 3756 | (drm_crtc_mask(for_crtc) - 1)); |
| 3757 | pipe_size = ddb_size / hweight32(intel_state->active_crtcs); |
| 3758 | alloc->start = nth_active_pipe * ddb_size / *num_active; |
| 3759 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3760 | } |
| 3761 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3762 | static unsigned int skl_cursor_allocation(int num_active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3763 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 3764 | if (num_active == 1) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3765 | return 32; |
| 3766 | |
| 3767 | return 8; |
| 3768 | } |
| 3769 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3770 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 3771 | { |
| 3772 | entry->start = reg & 0x3ff; |
| 3773 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3774 | if (entry->end) |
| 3775 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3776 | } |
| 3777 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 3778 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 3779 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3780 | { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3781 | struct intel_crtc *crtc; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3782 | |
Maarten Lankhorst | b10f1b2 | 2015-10-22 13:56:34 +0200 | [diff] [blame] | 3783 | memset(ddb, 0, sizeof(*ddb)); |
| 3784 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3785 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3786 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3787 | enum plane_id plane_id; |
| 3788 | enum pipe pipe = crtc->pipe; |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3789 | |
| 3790 | power_domain = POWER_DOMAIN_PIPE(pipe); |
| 3791 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Maarten Lankhorst | b10f1b2 | 2015-10-22 13:56:34 +0200 | [diff] [blame] | 3792 | continue; |
| 3793 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3794 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 3795 | u32 val; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3796 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3797 | if (plane_id != PLANE_CURSOR) |
| 3798 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 3799 | else |
| 3800 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 3801 | |
| 3802 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane_id], val); |
| 3803 | } |
Imre Deak | 4d80003 | 2016-02-17 16:31:29 +0200 | [diff] [blame] | 3804 | |
| 3805 | intel_display_power_put(dev_priv, power_domain); |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3806 | } |
| 3807 | } |
| 3808 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3809 | /* |
| 3810 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 3811 | * The bspec defines downscale amount as: |
| 3812 | * |
| 3813 | * """ |
| 3814 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 3815 | * Horizontal destination size] |
| 3816 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 3817 | * Vertical destination size] |
| 3818 | * Total down scale amount = Horizontal down scale amount * |
| 3819 | * Vertical down scale amount |
| 3820 | * """ |
| 3821 | * |
| 3822 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 3823 | * Caller should take care of dividing & rounding off the value. |
| 3824 | */ |
| 3825 | static uint32_t |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3826 | skl_plane_downscale_amount(const struct intel_crtc_state *cstate, |
| 3827 | const struct intel_plane_state *pstate) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3828 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3829 | struct intel_plane *plane = to_intel_plane(pstate->base.plane); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3830 | uint32_t downscale_h, downscale_w; |
| 3831 | uint32_t src_w, src_h, dst_w, dst_h; |
| 3832 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3833 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3834 | return DRM_PLANE_HELPER_NO_SCALING; |
| 3835 | |
| 3836 | /* 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] | 3837 | if (plane->id == PLANE_CURSOR) { |
| 3838 | src_w = pstate->base.src_w; |
| 3839 | src_h = pstate->base.src_h; |
| 3840 | dst_w = pstate->base.crtc_w; |
| 3841 | dst_h = pstate->base.crtc_h; |
| 3842 | } else { |
| 3843 | src_w = drm_rect_width(&pstate->base.src); |
| 3844 | src_h = drm_rect_height(&pstate->base.src); |
| 3845 | dst_w = drm_rect_width(&pstate->base.dst); |
| 3846 | dst_h = drm_rect_height(&pstate->base.dst); |
| 3847 | } |
| 3848 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3849 | if (drm_rotation_90_or_270(pstate->base.rotation)) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 3850 | swap(dst_w, dst_h); |
| 3851 | |
| 3852 | downscale_h = max(src_h / dst_h, (uint32_t)DRM_PLANE_HELPER_NO_SCALING); |
| 3853 | downscale_w = max(src_w / dst_w, (uint32_t)DRM_PLANE_HELPER_NO_SCALING); |
| 3854 | |
| 3855 | /* Provide result in 16.16 fixed point */ |
| 3856 | return (uint64_t)downscale_w * downscale_h >> 16; |
| 3857 | } |
| 3858 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3859 | static unsigned int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3860 | skl_plane_relative_data_rate(const struct intel_crtc_state *cstate, |
| 3861 | const struct drm_plane_state *pstate, |
| 3862 | int y) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3863 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3864 | struct intel_plane *plane = to_intel_plane(pstate->plane); |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3865 | struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3866 | uint32_t down_scale_amount, data_rate; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3867 | uint32_t width = 0, height = 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 3868 | struct drm_framebuffer *fb; |
| 3869 | u32 format; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3870 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3871 | if (!intel_pstate->base.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3872 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 3873 | |
| 3874 | fb = pstate->fb; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3875 | format = fb->format->format; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 3876 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3877 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3878 | return 0; |
| 3879 | if (y && format != DRM_FORMAT_NV12) |
| 3880 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3881 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3882 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 3883 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3884 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3885 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 3886 | swap(width, height); |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3887 | |
| 3888 | /* for planar format */ |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3889 | if (format == DRM_FORMAT_NV12) { |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3890 | if (y) /* y-plane data rate */ |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3891 | data_rate = width * height * |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3892 | fb->format->cpp[0]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3893 | else /* uv-plane data rate */ |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3894 | data_rate = (width / 2) * (height / 2) * |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3895 | fb->format->cpp[1]; |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3896 | } else { |
| 3897 | /* for packed formats */ |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3898 | data_rate = width * height * fb->format->cpp[0]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 3901 | down_scale_amount = skl_plane_downscale_amount(cstate, intel_pstate); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 3902 | |
| 3903 | return (uint64_t)data_rate * down_scale_amount >> 16; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3904 | } |
| 3905 | |
| 3906 | /* |
| 3907 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 3908 | * a 8192x4096@32bpp framebuffer: |
| 3909 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 3910 | */ |
| 3911 | static unsigned int |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3912 | skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate, |
| 3913 | unsigned *plane_data_rate, |
| 3914 | unsigned *plane_y_data_rate) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3915 | { |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 3916 | struct drm_crtc_state *cstate = &intel_cstate->base; |
| 3917 | struct drm_atomic_state *state = cstate->state; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 3918 | struct drm_plane *plane; |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 3919 | const struct drm_plane_state *pstate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3920 | unsigned int total_data_rate = 0; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3921 | |
| 3922 | if (WARN_ON(!state)) |
| 3923 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3924 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3925 | /* Calculate and cache data rate for each plane */ |
Maarten Lankhorst | c8fe32c | 2016-10-26 15:41:29 +0200 | [diff] [blame] | 3926 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, cstate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3927 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 3928 | unsigned int rate; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3929 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3930 | /* packed/uv */ |
| 3931 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 3932 | pstate, 0); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3933 | plane_data_rate[plane_id] = rate; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3934 | |
| 3935 | total_data_rate += rate; |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 3936 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 3937 | /* y-plane */ |
| 3938 | rate = skl_plane_relative_data_rate(intel_cstate, |
| 3939 | pstate, 1); |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 3940 | plane_y_data_rate[plane_id] = rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 3941 | |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 3942 | total_data_rate += rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | return total_data_rate; |
| 3946 | } |
| 3947 | |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3948 | static uint16_t |
| 3949 | skl_ddb_min_alloc(const struct drm_plane_state *pstate, |
| 3950 | const int y) |
| 3951 | { |
| 3952 | struct drm_framebuffer *fb = pstate->fb; |
| 3953 | struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate); |
| 3954 | uint32_t src_w, src_h; |
| 3955 | uint32_t min_scanlines = 8; |
| 3956 | uint8_t plane_bpp; |
| 3957 | |
| 3958 | if (WARN_ON(!fb)) |
| 3959 | return 0; |
| 3960 | |
| 3961 | /* For packed formats, no y-plane, return 0 */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3962 | if (y && fb->format->format != DRM_FORMAT_NV12) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3963 | return 0; |
| 3964 | |
| 3965 | /* For Non Y-tile return 8-blocks */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3966 | if (fb->modifier != I915_FORMAT_MOD_Y_TILED && |
| 3967 | fb->modifier != I915_FORMAT_MOD_Yf_TILED) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3968 | return 8; |
| 3969 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3970 | src_w = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 3971 | src_h = drm_rect_height(&intel_pstate->base.src) >> 16; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3972 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3973 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3974 | swap(src_w, src_h); |
| 3975 | |
| 3976 | /* Halve UV plane width and height for NV12 */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3977 | if (fb->format->format == DRM_FORMAT_NV12 && !y) { |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3978 | src_w /= 2; |
| 3979 | src_h /= 2; |
| 3980 | } |
| 3981 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3982 | if (fb->format->format == DRM_FORMAT_NV12 && !y) |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3983 | plane_bpp = fb->format->cpp[1]; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3984 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3985 | plane_bpp = fb->format->cpp[0]; |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3986 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3987 | if (drm_rotation_90_or_270(pstate->rotation)) { |
Kumar, Mahesh | cbcfd14 | 2016-05-31 09:58:59 -0700 | [diff] [blame] | 3988 | switch (plane_bpp) { |
| 3989 | case 1: |
| 3990 | min_scanlines = 32; |
| 3991 | break; |
| 3992 | case 2: |
| 3993 | min_scanlines = 16; |
| 3994 | break; |
| 3995 | case 4: |
| 3996 | min_scanlines = 8; |
| 3997 | break; |
| 3998 | case 8: |
| 3999 | min_scanlines = 4; |
| 4000 | break; |
| 4001 | default: |
| 4002 | WARN(1, "Unsupported pixel depth %u for rotation", |
| 4003 | plane_bpp); |
| 4004 | min_scanlines = 32; |
| 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | return DIV_ROUND_UP((4 * src_w * plane_bpp), 512) * min_scanlines/4 + 3; |
| 4009 | } |
| 4010 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4011 | static void |
| 4012 | skl_ddb_calc_min(const struct intel_crtc_state *cstate, int num_active, |
| 4013 | uint16_t *minimum, uint16_t *y_minimum) |
| 4014 | { |
| 4015 | const struct drm_plane_state *pstate; |
| 4016 | struct drm_plane *plane; |
| 4017 | |
| 4018 | 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] | 4019 | enum plane_id plane_id = to_intel_plane(plane)->id; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4020 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4021 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4022 | continue; |
| 4023 | |
| 4024 | if (!pstate->visible) |
| 4025 | continue; |
| 4026 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4027 | minimum[plane_id] = skl_ddb_min_alloc(pstate, 0); |
| 4028 | y_minimum[plane_id] = skl_ddb_min_alloc(pstate, 1); |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | minimum[PLANE_CURSOR] = skl_cursor_allocation(num_active); |
| 4032 | } |
| 4033 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4034 | static int |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4035 | skl_allocate_pipe_ddb(struct intel_crtc_state *cstate, |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4036 | struct skl_ddb_allocation *ddb /* out */) |
| 4037 | { |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4038 | struct drm_atomic_state *state = cstate->base.state; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4039 | struct drm_crtc *crtc = cstate->base.crtc; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4040 | struct drm_device *dev = crtc->dev; |
| 4041 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4042 | enum pipe pipe = intel_crtc->pipe; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4043 | struct skl_ddb_entry *alloc = &cstate->wm.skl.ddb; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4044 | uint16_t alloc_size, start; |
Maarten Lankhorst | fefdd81 | 2016-10-26 15:41:33 +0200 | [diff] [blame] | 4045 | uint16_t minimum[I915_MAX_PLANES] = {}; |
| 4046 | uint16_t y_minimum[I915_MAX_PLANES] = {}; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4047 | unsigned int total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4048 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4049 | int num_active; |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4050 | unsigned plane_data_rate[I915_MAX_PLANES] = {}; |
| 4051 | unsigned plane_y_data_rate[I915_MAX_PLANES] = {}; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4052 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4053 | /* Clear the partitioning for disabled planes. */ |
| 4054 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 4055 | memset(ddb->y_plane[pipe], 0, sizeof(ddb->y_plane[pipe])); |
| 4056 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4057 | if (WARN_ON(!state)) |
| 4058 | return 0; |
| 4059 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4060 | if (!cstate->base.active) { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4061 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4062 | return 0; |
| 4063 | } |
| 4064 | |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4065 | skl_ddb_get_pipe_allocation_limits(dev, cstate, alloc, &num_active); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4066 | alloc_size = skl_ddb_entry_size(alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4067 | if (alloc_size == 0) { |
| 4068 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4069 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4070 | } |
| 4071 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4072 | skl_ddb_calc_min(cstate, num_active, minimum, y_minimum); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4073 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4074 | /* |
| 4075 | * 1. Allocate the mininum required blocks for each active plane |
| 4076 | * and allocate the cursor, it doesn't require extra allocation |
| 4077 | * proportional to the data rate. |
| 4078 | */ |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4079 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4080 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 4081 | alloc_size -= minimum[plane_id]; |
| 4082 | alloc_size -= y_minimum[plane_id]; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 4083 | } |
| 4084 | |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4085 | ddb->plane[pipe][PLANE_CURSOR].start = alloc->end - minimum[PLANE_CURSOR]; |
| 4086 | ddb->plane[pipe][PLANE_CURSOR].end = alloc->end; |
| 4087 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4088 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 4089 | * 2. Distribute the remaining space in proportion to the amount of |
| 4090 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4091 | * |
| 4092 | * FIXME: we may not allocate every single block here. |
| 4093 | */ |
Maarten Lankhorst | 1e6ee54 | 2016-10-26 15:41:32 +0200 | [diff] [blame] | 4094 | total_data_rate = skl_get_total_relative_data_rate(cstate, |
| 4095 | plane_data_rate, |
| 4096 | plane_y_data_rate); |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4097 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4098 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4099 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4100 | start = alloc->start; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4101 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4102 | unsigned int data_rate, y_data_rate; |
| 4103 | uint16_t plane_blocks, y_plane_blocks = 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4104 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4105 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4106 | continue; |
| 4107 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4108 | data_rate = plane_data_rate[plane_id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4109 | |
| 4110 | /* |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4111 | * allocation for (packed formats) or (uv-plane part of planar format): |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4112 | * promote the expression to 64 bits to avoid overflowing, the |
| 4113 | * result is < available as data_rate / total_data_rate < 1 |
| 4114 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4115 | plane_blocks = minimum[plane_id]; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 4116 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 4117 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4118 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4119 | /* Leave disabled planes at (0,0) */ |
| 4120 | if (data_rate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4121 | ddb->plane[pipe][plane_id].start = start; |
| 4122 | ddb->plane[pipe][plane_id].end = start + plane_blocks; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4123 | } |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4124 | |
| 4125 | start += plane_blocks; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4126 | |
| 4127 | /* |
| 4128 | * allocation for y_plane part of planar format: |
| 4129 | */ |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4130 | y_data_rate = plane_y_data_rate[plane_id]; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4131 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4132 | y_plane_blocks = y_minimum[plane_id]; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4133 | y_plane_blocks += div_u64((uint64_t)alloc_size * y_data_rate, |
| 4134 | total_data_rate); |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4135 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4136 | if (y_data_rate) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4137 | ddb->y_plane[pipe][plane_id].start = start; |
| 4138 | ddb->y_plane[pipe][plane_id].end = start + y_plane_blocks; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4139 | } |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4140 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4141 | start += y_plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4142 | } |
| 4143 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4144 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4145 | } |
| 4146 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4147 | /* |
| 4148 | * 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] | 4149 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4150 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 4151 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 4152 | */ |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4153 | static uint_fixed_16_16_t skl_wm_method1(uint32_t pixel_rate, uint8_t cpp, |
| 4154 | uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4155 | { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4156 | uint32_t wm_intermediate_val; |
| 4157 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4158 | |
| 4159 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4160 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4161 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4162 | wm_intermediate_val = latency * pixel_rate * cpp; |
| 4163 | ret = fixed_16_16_div_round_up_u64(wm_intermediate_val, 1000 * 512); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4164 | return ret; |
| 4165 | } |
| 4166 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4167 | static uint_fixed_16_16_t skl_wm_method2(uint32_t pixel_rate, |
| 4168 | uint32_t pipe_htotal, |
| 4169 | uint32_t latency, |
| 4170 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4171 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4172 | uint32_t wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4173 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4174 | |
| 4175 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4176 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4177 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4178 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4179 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 4180 | pipe_htotal * 1000); |
| 4181 | ret = mul_u32_fixed_16_16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4182 | return ret; |
| 4183 | } |
| 4184 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4185 | static uint32_t skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *cstate, |
| 4186 | struct intel_plane_state *pstate) |
| 4187 | { |
| 4188 | uint64_t adjusted_pixel_rate; |
| 4189 | uint64_t downscale_amount; |
| 4190 | uint64_t pixel_rate; |
| 4191 | |
| 4192 | /* Shouldn't reach here on disabled planes... */ |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4193 | if (WARN_ON(!intel_wm_plane_visible(cstate, pstate))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4194 | return 0; |
| 4195 | |
| 4196 | /* |
| 4197 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 4198 | * with additional adjustments for plane-specific scaling. |
| 4199 | */ |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 4200 | adjusted_pixel_rate = cstate->pixel_rate; |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4201 | downscale_amount = skl_plane_downscale_amount(cstate, pstate); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4202 | |
| 4203 | pixel_rate = adjusted_pixel_rate * downscale_amount >> 16; |
| 4204 | WARN_ON(pixel_rate != clamp_t(uint32_t, pixel_rate, 0, ~0)); |
| 4205 | |
| 4206 | return pixel_rate; |
| 4207 | } |
| 4208 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4209 | static int skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 4210 | struct intel_crtc_state *cstate, |
| 4211 | struct intel_plane_state *intel_pstate, |
| 4212 | uint16_t ddb_allocation, |
| 4213 | int level, |
| 4214 | uint16_t *out_blocks, /* out */ |
| 4215 | uint8_t *out_lines, /* out */ |
| 4216 | bool *enabled /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4217 | { |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4218 | struct intel_plane *plane = to_intel_plane(intel_pstate->base.plane); |
Matt Roper | 33815fa | 2016-05-12 07:06:05 -0700 | [diff] [blame] | 4219 | struct drm_plane_state *pstate = &intel_pstate->base; |
| 4220 | struct drm_framebuffer *fb = pstate->fb; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4221 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4222 | uint_fixed_16_16_t method1, method2; |
| 4223 | uint_fixed_16_16_t plane_blocks_per_line; |
| 4224 | uint_fixed_16_16_t selected_result; |
| 4225 | uint32_t interm_pbpl; |
| 4226 | uint32_t plane_bytes_per_line; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4227 | uint32_t res_blocks, res_lines; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 4228 | uint8_t cpp; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4229 | uint32_t width = 0, height = 0; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4230 | uint32_t plane_pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4231 | uint_fixed_16_16_t y_tile_minimum; |
| 4232 | uint32_t y_min_scanlines; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4233 | struct intel_atomic_state *state = |
| 4234 | to_intel_atomic_state(cstate->base.state); |
| 4235 | bool apply_memory_bw_wa = skl_needs_memory_bw_wa(state); |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4236 | bool y_tiled, x_tiled; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4237 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4238 | if (latency == 0 || |
| 4239 | !intel_wm_plane_visible(cstate, intel_pstate)) { |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4240 | *enabled = false; |
| 4241 | return 0; |
| 4242 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4243 | |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4244 | y_tiled = fb->modifier == I915_FORMAT_MOD_Y_TILED || |
| 4245 | fb->modifier == I915_FORMAT_MOD_Yf_TILED; |
| 4246 | x_tiled = fb->modifier == I915_FORMAT_MOD_X_TILED; |
| 4247 | |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 4248 | /* Display WA #1141: kbl. */ |
| 4249 | if (IS_KABYLAKE(dev_priv) && dev_priv->ipc_enabled) |
| 4250 | latency += 4; |
| 4251 | |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4252 | if (apply_memory_bw_wa && x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 4253 | latency += 15; |
| 4254 | |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4255 | if (plane->id == PLANE_CURSOR) { |
| 4256 | width = intel_pstate->base.crtc_w; |
| 4257 | height = intel_pstate->base.crtc_h; |
| 4258 | } else { |
| 4259 | width = drm_rect_width(&intel_pstate->base.src) >> 16; |
| 4260 | height = drm_rect_height(&intel_pstate->base.src) >> 16; |
| 4261 | } |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4262 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 4263 | if (drm_rotation_90_or_270(pstate->rotation)) |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4264 | swap(width, height); |
| 4265 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4266 | cpp = fb->format->cpp[0]; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4267 | plane_pixel_rate = skl_adjusted_plane_pixel_rate(cstate, intel_pstate); |
| 4268 | |
Dave Airlie | 61d0a04 | 2016-10-25 16:35:20 +1000 | [diff] [blame] | 4269 | if (drm_rotation_90_or_270(pstate->rotation)) { |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4270 | int cpp = (fb->format->format == DRM_FORMAT_NV12) ? |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 4271 | fb->format->cpp[1] : |
| 4272 | fb->format->cpp[0]; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4273 | |
| 4274 | switch (cpp) { |
| 4275 | case 1: |
| 4276 | y_min_scanlines = 16; |
| 4277 | break; |
| 4278 | case 2: |
| 4279 | y_min_scanlines = 8; |
| 4280 | break; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4281 | case 4: |
| 4282 | y_min_scanlines = 4; |
| 4283 | break; |
Paulo Zanoni | 86a462b | 2016-09-22 18:00:35 -0300 | [diff] [blame] | 4284 | default: |
| 4285 | MISSING_CASE(cpp); |
| 4286 | return -EINVAL; |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4287 | } |
| 4288 | } else { |
| 4289 | y_min_scanlines = 4; |
| 4290 | } |
| 4291 | |
Paulo Zanoni | 2ef32de | 2016-11-08 18:22:11 -0200 | [diff] [blame] | 4292 | if (apply_memory_bw_wa) |
| 4293 | y_min_scanlines *= 2; |
| 4294 | |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 4295 | plane_bytes_per_line = width * cpp; |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4296 | if (y_tiled) { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4297 | interm_pbpl = DIV_ROUND_UP(plane_bytes_per_line * |
| 4298 | y_min_scanlines, 512); |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 4299 | plane_blocks_per_line = |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4300 | fixed_16_16_div_round_up(interm_pbpl, y_min_scanlines); |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4301 | } else if (x_tiled) { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4302 | interm_pbpl = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 4303 | plane_blocks_per_line = u32_to_fixed_16_16(interm_pbpl); |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4304 | } else { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4305 | interm_pbpl = DIV_ROUND_UP(plane_bytes_per_line, 512) + 1; |
| 4306 | plane_blocks_per_line = u32_to_fixed_16_16(interm_pbpl); |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 4307 | } |
| 4308 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4309 | method1 = skl_wm_method1(plane_pixel_rate, cpp, latency); |
| 4310 | method2 = skl_wm_method2(plane_pixel_rate, |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4311 | cstate->base.adjusted_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4312 | latency, |
Paulo Zanoni | 7a1a8ae | 2016-09-22 18:00:32 -0300 | [diff] [blame] | 4313 | plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4314 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4315 | y_tile_minimum = mul_u32_fixed_16_16(y_min_scanlines, |
| 4316 | plane_blocks_per_line); |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4317 | |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4318 | if (y_tiled) { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4319 | selected_result = max_fixed_16_16(method2, y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4320 | } else { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 4321 | if ((cpp * cstate->base.adjusted_mode.crtc_htotal / 512 < 1) && |
| 4322 | (plane_bytes_per_line / 512 < 1)) |
| 4323 | selected_result = method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4324 | else if ((ddb_allocation / |
| 4325 | fixed_16_16_to_u32_round_up(plane_blocks_per_line)) >= 1) |
| 4326 | selected_result = min_fixed_16_16(method1, method2); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4327 | else |
| 4328 | selected_result = method1; |
| 4329 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4330 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4331 | res_blocks = fixed_16_16_to_u32_round_up(selected_result) + 1; |
| 4332 | res_lines = DIV_ROUND_UP(selected_result.val, |
| 4333 | plane_blocks_per_line.val); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4334 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4335 | if (level >= 1 && level <= 7) { |
Mahesh Kumar | ef8a4fb | 2016-12-01 21:19:33 +0530 | [diff] [blame] | 4336 | if (y_tiled) { |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 4337 | res_blocks += fixed_16_16_to_u32_round_up(y_tile_minimum); |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 4338 | res_lines += y_min_scanlines; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4339 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4340 | res_blocks++; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 4341 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 4342 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 4343 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4344 | if (res_blocks >= ddb_allocation || res_lines > 31) { |
| 4345 | *enabled = false; |
Matt Roper | 6b6bada | 2016-05-12 07:06:10 -0700 | [diff] [blame] | 4346 | |
| 4347 | /* |
| 4348 | * If there are no valid level 0 watermarks, then we can't |
| 4349 | * support this display configuration. |
| 4350 | */ |
| 4351 | if (level) { |
| 4352 | return 0; |
| 4353 | } else { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4354 | struct drm_plane *plane = pstate->plane; |
Matt Roper | 6b6bada | 2016-05-12 07:06:10 -0700 | [diff] [blame] | 4355 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4356 | DRM_DEBUG_KMS("Requested display configuration exceeds system watermark limitations\n"); |
| 4357 | DRM_DEBUG_KMS("[PLANE:%d:%s] blocks required = %u/%u, lines required = %u/31\n", |
| 4358 | plane->base.id, plane->name, |
| 4359 | res_blocks, ddb_allocation, res_lines); |
Matt Roper | 6b6bada | 2016-05-12 07:06:10 -0700 | [diff] [blame] | 4360 | return -EINVAL; |
| 4361 | } |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4362 | } |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 4363 | |
| 4364 | *out_blocks = res_blocks; |
| 4365 | *out_lines = res_lines; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4366 | *enabled = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4367 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4368 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4371 | static int |
| 4372 | skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 4373 | struct skl_ddb_allocation *ddb, |
| 4374 | struct intel_crtc_state *cstate, |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4375 | struct intel_plane *intel_plane, |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4376 | int level, |
| 4377 | struct skl_wm_level *result) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4378 | { |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4379 | struct drm_atomic_state *state = cstate->base.state; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4380 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4381 | struct drm_plane *plane = &intel_plane->base; |
| 4382 | struct intel_plane_state *intel_pstate = NULL; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4383 | uint16_t ddb_blocks; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4384 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4385 | int ret; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4386 | |
| 4387 | if (state) |
| 4388 | intel_pstate = |
| 4389 | intel_atomic_get_existing_plane_state(state, |
| 4390 | intel_plane); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4391 | |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4392 | /* |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4393 | * Note: If we start supporting multiple pending atomic commits against |
| 4394 | * the same planes/CRTC's in the future, plane->state will no longer be |
| 4395 | * the correct pre-state to use for the calculations here and we'll |
| 4396 | * need to change where we get the 'unchanged' plane data from. |
| 4397 | * |
| 4398 | * For now this is fine because we only allow one queued commit against |
| 4399 | * a CRTC. Even if the plane isn't modified by this transaction and we |
| 4400 | * don't have a plane lock, we still have the CRTC's lock, so we know |
| 4401 | * that no other transactions are racing with us to update it. |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4402 | */ |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4403 | if (!intel_pstate) |
| 4404 | intel_pstate = to_intel_plane_state(plane->state); |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4405 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4406 | WARN_ON(!intel_pstate->base.fb); |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4407 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4408 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][intel_plane->id]); |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4409 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4410 | ret = skl_compute_plane_wm(dev_priv, |
| 4411 | cstate, |
| 4412 | intel_pstate, |
| 4413 | ddb_blocks, |
| 4414 | level, |
| 4415 | &result->plane_res_b, |
| 4416 | &result->plane_res_l, |
| 4417 | &result->plane_en); |
| 4418 | if (ret) |
| 4419 | return ret; |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4420 | |
| 4421 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4422 | } |
| 4423 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4424 | static uint32_t |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4425 | skl_compute_linetime_wm(struct intel_crtc_state *cstate) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4426 | { |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4427 | struct drm_atomic_state *state = cstate->base.state; |
| 4428 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4429 | uint32_t pixel_rate; |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4430 | uint32_t linetime_wm; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4431 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4432 | if (!cstate->base.active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4433 | return 0; |
| 4434 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 4435 | pixel_rate = cstate->pixel_rate; |
Paulo Zanoni | 30d1b5f | 2016-10-07 17:28:58 -0300 | [diff] [blame] | 4436 | |
| 4437 | if (WARN_ON(pixel_rate == 0)) |
Mika Kuoppala | 661abfc | 2015-07-16 19:36:51 +0300 | [diff] [blame] | 4438 | return 0; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4439 | |
Mahesh Kumar | a3a8986 | 2016-12-01 21:19:34 +0530 | [diff] [blame] | 4440 | linetime_wm = DIV_ROUND_UP(8 * cstate->base.adjusted_mode.crtc_htotal * |
| 4441 | 1000, pixel_rate); |
| 4442 | |
| 4443 | /* Display WA #1135: bxt. */ |
| 4444 | if (IS_BROXTON(dev_priv) && dev_priv->ipc_enabled) |
| 4445 | linetime_wm = DIV_ROUND_UP(linetime_wm, 2); |
| 4446 | |
| 4447 | return linetime_wm; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4448 | } |
| 4449 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4450 | static void skl_compute_transition_wm(struct intel_crtc_state *cstate, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4451 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4452 | { |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4453 | if (!cstate->base.active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4454 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 4455 | |
| 4456 | /* Until we know more, just disable transition WMs */ |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4457 | trans_wm->plane_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 4458 | } |
| 4459 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4460 | static int skl_build_pipe_wm(struct intel_crtc_state *cstate, |
| 4461 | struct skl_ddb_allocation *ddb, |
| 4462 | struct skl_pipe_wm *pipe_wm) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4463 | { |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4464 | struct drm_device *dev = cstate->base.crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4465 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4466 | struct intel_plane *intel_plane; |
| 4467 | struct skl_plane_wm *wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4468 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4469 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4470 | |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4471 | /* |
| 4472 | * We'll only calculate watermarks for planes that are actually |
| 4473 | * enabled, so make sure all other planes are set as disabled. |
| 4474 | */ |
| 4475 | memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes)); |
| 4476 | |
| 4477 | for_each_intel_plane_mask(&dev_priv->drm, |
| 4478 | intel_plane, |
| 4479 | cstate->base.plane_mask) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4480 | wm = &pipe_wm->planes[intel_plane->id]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 4481 | |
| 4482 | for (level = 0; level <= max_level; level++) { |
| 4483 | ret = skl_compute_wm_level(dev_priv, ddb, cstate, |
| 4484 | intel_plane, level, |
| 4485 | &wm->wm[level]); |
| 4486 | if (ret) |
| 4487 | return ret; |
| 4488 | } |
| 4489 | skl_compute_transition_wm(cstate, &wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4490 | } |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4491 | pipe_wm->linetime = skl_compute_linetime_wm(cstate); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4492 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4493 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4494 | } |
| 4495 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4496 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 4497 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 4498 | const struct skl_ddb_entry *entry) |
| 4499 | { |
| 4500 | if (entry->end) |
| 4501 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 4502 | else |
| 4503 | I915_WRITE(reg, 0); |
| 4504 | } |
| 4505 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4506 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 4507 | i915_reg_t reg, |
| 4508 | const struct skl_wm_level *level) |
| 4509 | { |
| 4510 | uint32_t val = 0; |
| 4511 | |
| 4512 | if (level->plane_en) { |
| 4513 | val |= PLANE_WM_EN; |
| 4514 | val |= level->plane_res_b; |
| 4515 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
| 4516 | } |
| 4517 | |
| 4518 | I915_WRITE(reg, val); |
| 4519 | } |
| 4520 | |
Ville Syrjälä | d9348de | 2016-11-22 22:21:53 +0200 | [diff] [blame] | 4521 | static void skl_write_plane_wm(struct intel_crtc *intel_crtc, |
| 4522 | const struct skl_plane_wm *wm, |
| 4523 | const struct skl_ddb_allocation *ddb, |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4524 | enum plane_id plane_id) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4525 | { |
| 4526 | struct drm_crtc *crtc = &intel_crtc->base; |
| 4527 | struct drm_device *dev = crtc->dev; |
| 4528 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4529 | int level, max_level = ilk_wm_max_level(dev_priv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4530 | enum pipe pipe = intel_crtc->pipe; |
| 4531 | |
| 4532 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4533 | 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] | 4534 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4535 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4536 | 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] | 4537 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4538 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4539 | skl_ddb_entry_write(dev_priv, PLANE_BUF_CFG(pipe, plane_id), |
| 4540 | &ddb->plane[pipe][plane_id]); |
| 4541 | skl_ddb_entry_write(dev_priv, PLANE_NV12_BUF_CFG(pipe, plane_id), |
| 4542 | &ddb->y_plane[pipe][plane_id]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4543 | } |
| 4544 | |
Ville Syrjälä | d9348de | 2016-11-22 22:21:53 +0200 | [diff] [blame] | 4545 | static void skl_write_cursor_wm(struct intel_crtc *intel_crtc, |
| 4546 | const struct skl_plane_wm *wm, |
| 4547 | const struct skl_ddb_allocation *ddb) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4548 | { |
| 4549 | struct drm_crtc *crtc = &intel_crtc->base; |
| 4550 | struct drm_device *dev = crtc->dev; |
| 4551 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4552 | int level, max_level = ilk_wm_max_level(dev_priv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4553 | enum pipe pipe = intel_crtc->pipe; |
| 4554 | |
| 4555 | for (level = 0; level <= max_level; level++) { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4556 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
| 4557 | &wm->wm[level]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4558 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4559 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4560 | |
| 4561 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4562 | &ddb->plane[pipe][PLANE_CURSOR]); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 4563 | } |
| 4564 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 4565 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 4566 | const struct skl_wm_level *l2) |
| 4567 | { |
| 4568 | if (l1->plane_en != l2->plane_en) |
| 4569 | return false; |
| 4570 | |
| 4571 | /* If both planes aren't enabled, the rest shouldn't matter */ |
| 4572 | if (!l1->plane_en) |
| 4573 | return true; |
| 4574 | |
| 4575 | return (l1->plane_res_l == l2->plane_res_l && |
| 4576 | l1->plane_res_b == l2->plane_res_b); |
| 4577 | } |
| 4578 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4579 | static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 4580 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4581 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4582 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4583 | } |
| 4584 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 4585 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry **entries, |
| 4586 | const struct skl_ddb_entry *ddb, |
| 4587 | int ignore) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4588 | { |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4589 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4590 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 4591 | for (i = 0; i < I915_MAX_PIPES; i++) |
| 4592 | if (i != ignore && entries[i] && |
| 4593 | skl_ddb_entries_overlap(ddb, entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4594 | return true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4595 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4596 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 4597 | } |
| 4598 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4599 | static int skl_update_pipe_wm(struct drm_crtc_state *cstate, |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4600 | const struct skl_pipe_wm *old_pipe_wm, |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4601 | struct skl_pipe_wm *pipe_wm, /* out */ |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4602 | struct skl_ddb_allocation *ddb, /* out */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4603 | bool *changed /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4604 | { |
Matt Roper | f4a9675 | 2016-05-12 07:06:06 -0700 | [diff] [blame] | 4605 | struct intel_crtc_state *intel_cstate = to_intel_crtc_state(cstate); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4606 | int ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4607 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4608 | ret = skl_build_pipe_wm(intel_cstate, ddb, pipe_wm); |
| 4609 | if (ret) |
| 4610 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4611 | |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4612 | if (!memcmp(old_pipe_wm, pipe_wm, sizeof(*pipe_wm))) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4613 | *changed = false; |
| 4614 | else |
| 4615 | *changed = true; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4616 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 4617 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4620 | static uint32_t |
| 4621 | pipes_modified(struct drm_atomic_state *state) |
| 4622 | { |
| 4623 | struct drm_crtc *crtc; |
| 4624 | struct drm_crtc_state *cstate; |
| 4625 | uint32_t i, ret = 0; |
| 4626 | |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 4627 | for_each_new_crtc_in_state(state, crtc, cstate, i) |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4628 | ret |= drm_crtc_mask(crtc); |
| 4629 | |
| 4630 | return ret; |
| 4631 | } |
| 4632 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 4633 | static int |
Paulo Zanoni | 7f60e20 | 2016-09-29 16:36:48 -0300 | [diff] [blame] | 4634 | skl_ddb_add_affected_planes(struct intel_crtc_state *cstate) |
| 4635 | { |
| 4636 | struct drm_atomic_state *state = cstate->base.state; |
| 4637 | struct drm_device *dev = state->dev; |
| 4638 | struct drm_crtc *crtc = cstate->base.crtc; |
| 4639 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4640 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 4641 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4642 | struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb; |
| 4643 | struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 4644 | struct drm_plane_state *plane_state; |
| 4645 | struct drm_plane *plane; |
| 4646 | enum pipe pipe = intel_crtc->pipe; |
Paulo Zanoni | 7f60e20 | 2016-09-29 16:36:48 -0300 | [diff] [blame] | 4647 | |
| 4648 | WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc)); |
| 4649 | |
Maarten Lankhorst | 220b096 | 2016-10-26 15:41:30 +0200 | [diff] [blame] | 4650 | drm_for_each_plane_mask(plane, dev, cstate->base.plane_mask) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4651 | enum plane_id plane_id = to_intel_plane(plane)->id; |
Paulo Zanoni | 7f60e20 | 2016-09-29 16:36:48 -0300 | [diff] [blame] | 4652 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4653 | if (skl_ddb_entry_equal(&cur_ddb->plane[pipe][plane_id], |
| 4654 | &new_ddb->plane[pipe][plane_id]) && |
| 4655 | skl_ddb_entry_equal(&cur_ddb->y_plane[pipe][plane_id], |
| 4656 | &new_ddb->y_plane[pipe][plane_id])) |
Paulo Zanoni | 7f60e20 | 2016-09-29 16:36:48 -0300 | [diff] [blame] | 4657 | continue; |
| 4658 | |
| 4659 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 4660 | if (IS_ERR(plane_state)) |
| 4661 | return PTR_ERR(plane_state); |
| 4662 | } |
| 4663 | |
| 4664 | return 0; |
| 4665 | } |
| 4666 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4667 | static int |
| 4668 | skl_compute_ddb(struct drm_atomic_state *state) |
| 4669 | { |
| 4670 | struct drm_device *dev = state->dev; |
| 4671 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 4672 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4673 | struct intel_crtc *intel_crtc; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4674 | struct skl_ddb_allocation *ddb = &intel_state->wm_results.ddb; |
Matt Roper | 9b61302 | 2016-06-27 16:42:44 -0700 | [diff] [blame] | 4675 | uint32_t realloc_pipes = pipes_modified(state); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4676 | int ret; |
| 4677 | |
| 4678 | /* |
| 4679 | * If this is our first atomic update following hardware readout, |
| 4680 | * we can't trust the DDB that the BIOS programmed for us. Let's |
| 4681 | * pretend that all pipes switched active status so that we'll |
| 4682 | * ensure a full DDB recompute. |
| 4683 | */ |
Matt Roper | 1b54a88 | 2016-06-17 13:42:18 -0700 | [diff] [blame] | 4684 | if (dev_priv->wm.distrust_bios_wm) { |
| 4685 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
| 4686 | state->acquire_ctx); |
| 4687 | if (ret) |
| 4688 | return ret; |
| 4689 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4690 | intel_state->active_pipe_changes = ~0; |
| 4691 | |
Matt Roper | 1b54a88 | 2016-06-17 13:42:18 -0700 | [diff] [blame] | 4692 | /* |
| 4693 | * We usually only initialize intel_state->active_crtcs if we |
| 4694 | * we're doing a modeset; make sure this field is always |
| 4695 | * initialized during the sanitization process that happens |
| 4696 | * on the first commit too. |
| 4697 | */ |
| 4698 | if (!intel_state->modeset) |
| 4699 | intel_state->active_crtcs = dev_priv->active_crtcs; |
| 4700 | } |
| 4701 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4702 | /* |
| 4703 | * If the modeset changes which CRTC's are active, we need to |
| 4704 | * recompute the DDB allocation for *all* active pipes, even |
| 4705 | * those that weren't otherwise being modified in any way by this |
| 4706 | * atomic commit. Due to the shrinking of the per-pipe allocations |
| 4707 | * when new active CRTC's are added, it's possible for a pipe that |
| 4708 | * we were already using and aren't changing at all here to suddenly |
| 4709 | * become invalid if its DDB needs exceeds its new allocation. |
| 4710 | * |
| 4711 | * Note that if we wind up doing a full DDB recompute, we can't let |
| 4712 | * any other display updates race with this transaction, so we need |
| 4713 | * to grab the lock on *all* CRTC's. |
| 4714 | */ |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4715 | if (intel_state->active_pipe_changes) { |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4716 | realloc_pipes = ~0; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4717 | intel_state->wm_results.dirty_pipes = ~0; |
| 4718 | } |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4719 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4720 | /* |
| 4721 | * We're not recomputing for the pipes not included in the commit, so |
| 4722 | * make sure we start with the current state. |
| 4723 | */ |
| 4724 | memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb)); |
| 4725 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4726 | for_each_intel_crtc_mask(dev, intel_crtc, realloc_pipes) { |
| 4727 | struct intel_crtc_state *cstate; |
| 4728 | |
| 4729 | cstate = intel_atomic_get_crtc_state(state, intel_crtc); |
| 4730 | if (IS_ERR(cstate)) |
| 4731 | return PTR_ERR(cstate); |
| 4732 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4733 | ret = skl_allocate_pipe_ddb(cstate, ddb); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4734 | if (ret) |
| 4735 | return ret; |
Lyude | 05a76d3 | 2016-08-17 15:55:57 -0400 | [diff] [blame] | 4736 | |
Paulo Zanoni | 7f60e20 | 2016-09-29 16:36:48 -0300 | [diff] [blame] | 4737 | ret = skl_ddb_add_affected_planes(cstate); |
Lyude | 05a76d3 | 2016-08-17 15:55:57 -0400 | [diff] [blame] | 4738 | if (ret) |
| 4739 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | return 0; |
| 4743 | } |
| 4744 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4745 | static void |
| 4746 | skl_copy_wm_for_pipe(struct skl_wm_values *dst, |
| 4747 | struct skl_wm_values *src, |
| 4748 | enum pipe pipe) |
| 4749 | { |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4750 | memcpy(dst->ddb.y_plane[pipe], src->ddb.y_plane[pipe], |
| 4751 | sizeof(dst->ddb.y_plane[pipe])); |
| 4752 | memcpy(dst->ddb.plane[pipe], src->ddb.plane[pipe], |
| 4753 | sizeof(dst->ddb.plane[pipe])); |
| 4754 | } |
| 4755 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4756 | static void |
| 4757 | skl_print_wm_changes(const struct drm_atomic_state *state) |
| 4758 | { |
| 4759 | const struct drm_device *dev = state->dev; |
| 4760 | const struct drm_i915_private *dev_priv = to_i915(dev); |
| 4761 | const struct intel_atomic_state *intel_state = |
| 4762 | to_intel_atomic_state(state); |
| 4763 | const struct drm_crtc *crtc; |
| 4764 | const struct drm_crtc_state *cstate; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4765 | const struct intel_plane *intel_plane; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4766 | const struct skl_ddb_allocation *old_ddb = &dev_priv->wm.skl_hw.ddb; |
| 4767 | const struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4768 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4769 | |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 4770 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4771 | const struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4772 | enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4773 | |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4774 | for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4775 | enum plane_id plane_id = intel_plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4776 | const struct skl_ddb_entry *old, *new; |
| 4777 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4778 | old = &old_ddb->plane[pipe][plane_id]; |
| 4779 | new = &new_ddb->plane[pipe][plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4780 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4781 | if (skl_ddb_entry_equal(old, new)) |
| 4782 | continue; |
| 4783 | |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 4784 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] ddb (%d - %d) -> (%d - %d)\n", |
| 4785 | intel_plane->base.base.id, |
| 4786 | intel_plane->base.name, |
| 4787 | old->start, old->end, |
| 4788 | new->start, new->end); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4789 | } |
| 4790 | } |
| 4791 | } |
| 4792 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4793 | static int |
| 4794 | skl_compute_wm(struct drm_atomic_state *state) |
| 4795 | { |
| 4796 | struct drm_crtc *crtc; |
| 4797 | struct drm_crtc_state *cstate; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4798 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 4799 | struct skl_wm_values *results = &intel_state->wm_results; |
| 4800 | struct skl_pipe_wm *pipe_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4801 | bool changed = false; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4802 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4803 | |
| 4804 | /* |
| 4805 | * If this transaction isn't actually touching any CRTC's, don't |
| 4806 | * bother with watermark calculation. Note that if we pass this |
| 4807 | * test, we're guaranteed to hold at least one CRTC state mutex, |
| 4808 | * which means we can safely use values like dev_priv->active_crtcs |
| 4809 | * since any racing commits that want to update them would need to |
| 4810 | * hold _all_ CRTC state mutexes. |
| 4811 | */ |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 4812 | for_each_new_crtc_in_state(state, crtc, cstate, i) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4813 | changed = true; |
| 4814 | if (!changed) |
| 4815 | return 0; |
| 4816 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4817 | /* Clear all dirty flags */ |
| 4818 | results->dirty_pipes = 0; |
| 4819 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4820 | ret = skl_compute_ddb(state); |
| 4821 | if (ret) |
| 4822 | return ret; |
| 4823 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4824 | /* |
| 4825 | * Calculate WM's for all pipes that are part of this transaction. |
| 4826 | * Note that the DDB allocation above may have added more CRTC's that |
| 4827 | * weren't otherwise being modified (and set bits in dirty_pipes) if |
| 4828 | * pipe allocations had to change. |
| 4829 | * |
| 4830 | * FIXME: Now that we're doing this in the atomic check phase, we |
| 4831 | * should allow skl_update_pipe_wm() to return failure in cases where |
| 4832 | * no suitable watermark values can be found. |
| 4833 | */ |
Maarten Lankhorst | 6ebdb5a | 2017-03-09 15:52:03 +0100 | [diff] [blame] | 4834 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4835 | struct intel_crtc_state *intel_cstate = |
| 4836 | to_intel_crtc_state(cstate); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4837 | const struct skl_pipe_wm *old_pipe_wm = |
| 4838 | &to_intel_crtc_state(crtc->state)->wm.skl.optimal; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4839 | |
| 4840 | pipe_wm = &intel_cstate->wm.skl.optimal; |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 4841 | ret = skl_update_pipe_wm(cstate, old_pipe_wm, pipe_wm, |
| 4842 | &results->ddb, &changed); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4843 | if (ret) |
| 4844 | return ret; |
| 4845 | |
| 4846 | if (changed) |
| 4847 | results->dirty_pipes |= drm_crtc_mask(crtc); |
| 4848 | |
| 4849 | if ((results->dirty_pipes & drm_crtc_mask(crtc)) == 0) |
| 4850 | /* This pipe's WM's did not change */ |
| 4851 | continue; |
| 4852 | |
| 4853 | intel_cstate->update_wm_pre = true; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 4856 | skl_print_wm_changes(state); |
| 4857 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 4858 | return 0; |
| 4859 | } |
| 4860 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 4861 | static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state, |
| 4862 | struct intel_crtc_state *cstate) |
| 4863 | { |
| 4864 | struct intel_crtc *crtc = to_intel_crtc(cstate->base.crtc); |
| 4865 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 4866 | struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 4867 | const struct skl_ddb_allocation *ddb = &state->wm_results.ddb; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 4868 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4869 | enum plane_id plane_id; |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 4870 | |
| 4871 | if (!(state->wm_results.dirty_pipes & drm_crtc_mask(&crtc->base))) |
| 4872 | return; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 4873 | |
| 4874 | I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 4875 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4876 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 4877 | if (plane_id != PLANE_CURSOR) |
| 4878 | skl_write_plane_wm(crtc, &pipe_wm->planes[plane_id], |
| 4879 | ddb, plane_id); |
| 4880 | else |
| 4881 | skl_write_cursor_wm(crtc, &pipe_wm->planes[plane_id], |
| 4882 | ddb); |
| 4883 | } |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 4884 | } |
| 4885 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 4886 | static void skl_initial_wm(struct intel_atomic_state *state, |
| 4887 | struct intel_crtc_state *cstate) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4888 | { |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 4889 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4890 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4891 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 4892 | struct skl_wm_values *results = &state->wm_results; |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 4893 | struct skl_wm_values *hw_vals = &dev_priv->wm.skl_hw; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4894 | enum pipe pipe = intel_crtc->pipe; |
Bob Paauwe | adda50b | 2015-07-21 10:42:53 -0700 | [diff] [blame] | 4895 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 4896 | if ((results->dirty_pipes & drm_crtc_mask(&intel_crtc->base)) == 0) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4897 | return; |
| 4898 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4899 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 4900 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 4901 | if (cstate->base.active_changed) |
| 4902 | skl_atomic_update_crtc_wm(state, cstate); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 4903 | |
| 4904 | skl_copy_wm_for_pipe(hw_vals, results, pipe); |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 4905 | |
| 4906 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 4907 | } |
| 4908 | |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 4909 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 4910 | struct intel_wm_config *config) |
| 4911 | { |
| 4912 | struct intel_crtc *crtc; |
| 4913 | |
| 4914 | /* Compute the currently _active_ config */ |
| 4915 | for_each_intel_crtc(dev, crtc) { |
| 4916 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 4917 | |
| 4918 | if (!wm->pipe_enabled) |
| 4919 | continue; |
| 4920 | |
| 4921 | config->sprites_enabled |= wm->sprites_enabled; |
| 4922 | config->sprites_scaled |= wm->sprites_scaled; |
| 4923 | config->num_pipes_active++; |
| 4924 | } |
| 4925 | } |
| 4926 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4927 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 4928 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 4929 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4930 | 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] | 4931 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 4932 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4933 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 4934 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 4935 | |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 4936 | ilk_compute_wm_config(dev, &config); |
| 4937 | |
| 4938 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 4939 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 4940 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 4941 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 4942 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 4943 | config.num_pipes_active == 1 && config.sprites_enabled) { |
| 4944 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 4945 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 4946 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4947 | 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] | 4948 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 4949 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 4950 | } |
| 4951 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 4952 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 4953 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 4954 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4955 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 4956 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 4957 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 4958 | } |
| 4959 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 4960 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
| 4961 | struct intel_crtc_state *cstate) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4962 | { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4963 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 4964 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4965 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4966 | mutex_lock(&dev_priv->wm.wm_mutex); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 4967 | intel_crtc->wm.active.ilk = cstate->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4968 | ilk_program_watermarks(dev_priv); |
| 4969 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 4970 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4971 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 4972 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
| 4973 | struct intel_crtc_state *cstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4974 | { |
| 4975 | struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev); |
| 4976 | struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc); |
| 4977 | |
| 4978 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 4979 | if (cstate->wm.need_postvbl_update) { |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 4980 | intel_crtc->wm.active.ilk = cstate->wm.ilk.optimal; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4981 | ilk_program_watermarks(dev_priv); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4982 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4983 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 4984 | } |
| 4985 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4986 | static inline void skl_wm_level_from_reg_val(uint32_t val, |
| 4987 | struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4988 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 4989 | level->plane_en = val & PLANE_WM_EN; |
| 4990 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 4991 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 4992 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4993 | } |
| 4994 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 4995 | void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc, |
| 4996 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4997 | { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4998 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 4999 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5000 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5001 | int level, max_level; |
| 5002 | enum plane_id plane_id; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5003 | uint32_t val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5004 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5005 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5006 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5007 | for_each_plane_id_on_crtc(intel_crtc, plane_id) { |
| 5008 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5009 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5010 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5011 | if (plane_id != PLANE_CURSOR) |
| 5012 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5013 | else |
| 5014 | val = I915_READ(CUR_WM(pipe, level)); |
| 5015 | |
| 5016 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 5017 | } |
| 5018 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5019 | if (plane_id != PLANE_CURSOR) |
| 5020 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5021 | else |
| 5022 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 5023 | |
| 5024 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 5025 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5026 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 5027 | if (!intel_crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5028 | return; |
| 5029 | |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5030 | out->linetime = I915_READ(PIPE_WM_LINETIME(pipe)); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 5034 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5035 | struct drm_i915_private *dev_priv = to_i915(dev); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5036 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5037 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5038 | struct drm_crtc *crtc; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5039 | struct intel_crtc *intel_crtc; |
| 5040 | struct intel_crtc_state *cstate; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5041 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 5042 | skl_ddb_get_hw_state(dev_priv, ddb); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5043 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 5044 | intel_crtc = to_intel_crtc(crtc); |
| 5045 | cstate = to_intel_crtc_state(crtc->state); |
| 5046 | |
| 5047 | skl_pipe_wm_get_hw_state(crtc, &cstate->wm.skl.optimal); |
| 5048 | |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 5049 | if (intel_crtc->active) |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5050 | hw->dirty_pipes |= drm_crtc_mask(crtc); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 5051 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5052 | |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 5053 | if (dev_priv->active_crtcs) { |
| 5054 | /* Fully recompute DDB on first atomic commit */ |
| 5055 | dev_priv->wm.distrust_bios_wm = true; |
| 5056 | } else { |
| 5057 | /* Easy/common case; just sanitize DDB now if everything off */ |
| 5058 | memset(ddb, 0, sizeof(*ddb)); |
| 5059 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 5060 | } |
| 5061 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5062 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 5063 | { |
| 5064 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5065 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5066 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5067 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5068 | struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 5069 | struct intel_pipe_wm *active = &cstate->wm.ilk.optimal; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5070 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5071 | static const i915_reg_t wm0_pipe_reg[] = { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5072 | [PIPE_A] = WM0_PIPEA_ILK, |
| 5073 | [PIPE_B] = WM0_PIPEB_ILK, |
| 5074 | [PIPE_C] = WM0_PIPEC_IVB, |
| 5075 | }; |
| 5076 | |
| 5077 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5078 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 5079 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5080 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 5081 | memset(active, 0, sizeof(*active)); |
| 5082 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 5083 | active->pipe_enabled = intel_crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 5084 | |
| 5085 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5086 | u32 tmp = hw->wm_pipe[pipe]; |
| 5087 | |
| 5088 | /* |
| 5089 | * For active pipes LP0 watermark is marked as |
| 5090 | * enabled, and LP1+ watermaks as disabled since |
| 5091 | * we can't really reverse compute them in case |
| 5092 | * multiple pipes are active. |
| 5093 | */ |
| 5094 | active->wm[0].enable = true; |
| 5095 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 5096 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 5097 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 5098 | active->linetime = hw->wm_linetime[pipe]; |
| 5099 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5100 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5101 | |
| 5102 | /* |
| 5103 | * For inactive pipes, all watermark levels |
| 5104 | * should be marked as enabled but zeroed, |
| 5105 | * which is what we'd compute them to. |
| 5106 | */ |
| 5107 | for (level = 0; level <= max_level; level++) |
| 5108 | active->wm[level].enable = true; |
| 5109 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 5110 | |
| 5111 | intel_crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5112 | } |
| 5113 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5114 | #define _FW_WM(value, plane) \ |
| 5115 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 5116 | #define _FW_WM_VLV(value, plane) \ |
| 5117 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 5118 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5119 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 5120 | struct g4x_wm_values *wm) |
| 5121 | { |
| 5122 | uint32_t tmp; |
| 5123 | |
| 5124 | tmp = I915_READ(DSPFW1); |
| 5125 | wm->sr.plane = _FW_WM(tmp, SR); |
| 5126 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5127 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 5128 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 5129 | |
| 5130 | tmp = I915_READ(DSPFW2); |
| 5131 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 5132 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 5133 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 5134 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 5135 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5136 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 5137 | |
| 5138 | tmp = I915_READ(DSPFW3); |
| 5139 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 5140 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5141 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 5142 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 5143 | } |
| 5144 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5145 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 5146 | struct vlv_wm_values *wm) |
| 5147 | { |
| 5148 | enum pipe pipe; |
| 5149 | uint32_t tmp; |
| 5150 | |
| 5151 | for_each_pipe(dev_priv, pipe) { |
| 5152 | tmp = I915_READ(VLV_DDL(pipe)); |
| 5153 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5154 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5155 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5156 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5157 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5158 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5159 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5160 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5161 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 5162 | } |
| 5163 | |
| 5164 | tmp = I915_READ(DSPFW1); |
| 5165 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5166 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 5167 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 5168 | 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] | 5169 | |
| 5170 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5171 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 5172 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 5173 | 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] | 5174 | |
| 5175 | tmp = I915_READ(DSPFW3); |
| 5176 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 5177 | |
| 5178 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5179 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5180 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5181 | 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] | 5182 | |
| 5183 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5184 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 5185 | 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] | 5186 | |
| 5187 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5188 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 5189 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5190 | |
| 5191 | tmp = I915_READ(DSPHOWM); |
| 5192 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5193 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 5194 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 5195 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 5196 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5197 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5198 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5199 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5200 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5201 | 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] | 5202 | } else { |
| 5203 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5204 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 5205 | 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] | 5206 | |
| 5207 | tmp = I915_READ(DSPHOWM); |
| 5208 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 5209 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 5210 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 5211 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 5212 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 5213 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 5214 | 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] | 5215 | } |
| 5216 | } |
| 5217 | |
| 5218 | #undef _FW_WM |
| 5219 | #undef _FW_WM_VLV |
| 5220 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5221 | void g4x_wm_get_hw_state(struct drm_device *dev) |
| 5222 | { |
| 5223 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5224 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 5225 | struct intel_crtc *crtc; |
| 5226 | |
| 5227 | g4x_read_wm_values(dev_priv, wm); |
| 5228 | |
| 5229 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 5230 | |
| 5231 | for_each_intel_crtc(dev, crtc) { |
| 5232 | struct intel_crtc_state *crtc_state = |
| 5233 | to_intel_crtc_state(crtc->base.state); |
| 5234 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 5235 | struct g4x_pipe_wm *raw; |
| 5236 | enum pipe pipe = crtc->pipe; |
| 5237 | enum plane_id plane_id; |
| 5238 | int level, max_level; |
| 5239 | |
| 5240 | active->cxsr = wm->cxsr; |
| 5241 | active->hpll_en = wm->hpll_en; |
| 5242 | active->fbc_en = wm->fbc_en; |
| 5243 | |
| 5244 | active->sr = wm->sr; |
| 5245 | active->hpll = wm->hpll; |
| 5246 | |
| 5247 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5248 | active->wm.plane[plane_id] = |
| 5249 | wm->pipe[pipe].plane[plane_id]; |
| 5250 | } |
| 5251 | |
| 5252 | if (wm->cxsr && wm->hpll_en) |
| 5253 | max_level = G4X_WM_LEVEL_HPLL; |
| 5254 | else if (wm->cxsr) |
| 5255 | max_level = G4X_WM_LEVEL_SR; |
| 5256 | else |
| 5257 | max_level = G4X_WM_LEVEL_NORMAL; |
| 5258 | |
| 5259 | level = G4X_WM_LEVEL_NORMAL; |
| 5260 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5261 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5262 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 5263 | |
| 5264 | if (++level > max_level) |
| 5265 | goto out; |
| 5266 | |
| 5267 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5268 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 5269 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 5270 | raw->plane[PLANE_SPRITE0] = 0; |
| 5271 | raw->fbc = active->sr.fbc; |
| 5272 | |
| 5273 | if (++level > max_level) |
| 5274 | goto out; |
| 5275 | |
| 5276 | raw = &crtc_state->wm.g4x.raw[level]; |
| 5277 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 5278 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 5279 | raw->plane[PLANE_SPRITE0] = 0; |
| 5280 | raw->fbc = active->hpll.fbc; |
| 5281 | |
| 5282 | out: |
| 5283 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5284 | g4x_raw_plane_wm_set(crtc_state, level, |
| 5285 | plane_id, USHRT_MAX); |
| 5286 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 5287 | |
| 5288 | crtc_state->wm.g4x.optimal = *active; |
| 5289 | crtc_state->wm.g4x.intermediate = *active; |
| 5290 | |
| 5291 | DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 5292 | pipe_name(pipe), |
| 5293 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 5294 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 5295 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
| 5296 | } |
| 5297 | |
| 5298 | DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 5299 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 5300 | DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 5301 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 5302 | DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", |
| 5303 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
| 5304 | } |
| 5305 | |
| 5306 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 5307 | { |
| 5308 | struct intel_plane *plane; |
| 5309 | struct intel_crtc *crtc; |
| 5310 | |
| 5311 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5312 | |
| 5313 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 5314 | struct intel_crtc *crtc = |
| 5315 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 5316 | struct intel_crtc_state *crtc_state = |
| 5317 | to_intel_crtc_state(crtc->base.state); |
| 5318 | struct intel_plane_state *plane_state = |
| 5319 | to_intel_plane_state(plane->base.state); |
| 5320 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 5321 | enum plane_id plane_id = plane->id; |
| 5322 | int level; |
| 5323 | |
| 5324 | if (plane_state->base.visible) |
| 5325 | continue; |
| 5326 | |
| 5327 | for (level = 0; level < 3; level++) { |
| 5328 | struct g4x_pipe_wm *raw = |
| 5329 | &crtc_state->wm.g4x.raw[level]; |
| 5330 | |
| 5331 | raw->plane[plane_id] = 0; |
| 5332 | wm_state->wm.plane[plane_id] = 0; |
| 5333 | } |
| 5334 | |
| 5335 | if (plane_id == PLANE_PRIMARY) { |
| 5336 | for (level = 0; level < 3; level++) { |
| 5337 | struct g4x_pipe_wm *raw = |
| 5338 | &crtc_state->wm.g4x.raw[level]; |
| 5339 | raw->fbc = 0; |
| 5340 | } |
| 5341 | |
| 5342 | wm_state->sr.fbc = 0; |
| 5343 | wm_state->hpll.fbc = 0; |
| 5344 | wm_state->fbc_en = false; |
| 5345 | } |
| 5346 | } |
| 5347 | |
| 5348 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5349 | struct intel_crtc_state *crtc_state = |
| 5350 | to_intel_crtc_state(crtc->base.state); |
| 5351 | |
| 5352 | crtc_state->wm.g4x.intermediate = |
| 5353 | crtc_state->wm.g4x.optimal; |
| 5354 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 5355 | } |
| 5356 | |
| 5357 | g4x_program_watermarks(dev_priv); |
| 5358 | |
| 5359 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5360 | } |
| 5361 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5362 | void vlv_wm_get_hw_state(struct drm_device *dev) |
| 5363 | { |
| 5364 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5365 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 5366 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5367 | u32 val; |
| 5368 | |
| 5369 | vlv_read_wm_values(dev_priv, wm); |
| 5370 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5371 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 5372 | wm->level = VLV_WM_LEVEL_PM2; |
| 5373 | |
| 5374 | if (IS_CHERRYVIEW(dev_priv)) { |
| 5375 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5376 | |
| 5377 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5378 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 5379 | wm->level = VLV_WM_LEVEL_PM5; |
| 5380 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 5381 | /* |
| 5382 | * If DDR DVFS is disabled in the BIOS, Punit |
| 5383 | * will never ack the request. So if that happens |
| 5384 | * assume we don't have to enable/disable DDR DVFS |
| 5385 | * dynamically. To test that just set the REQ_ACK |
| 5386 | * bit to poke the Punit, but don't change the |
| 5387 | * HIGH/LOW bits so that we don't actually change |
| 5388 | * the current state. |
| 5389 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5390 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 5391 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 5392 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 5393 | |
| 5394 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 5395 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
| 5396 | DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " |
| 5397 | "assuming DDR DVFS is disabled\n"); |
| 5398 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 5399 | } else { |
| 5400 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 5401 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 5402 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 5403 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5404 | |
| 5405 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5406 | } |
| 5407 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5408 | for_each_intel_crtc(dev, crtc) { |
| 5409 | struct intel_crtc_state *crtc_state = |
| 5410 | to_intel_crtc_state(crtc->base.state); |
| 5411 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 5412 | const struct vlv_fifo_state *fifo_state = |
| 5413 | &crtc_state->wm.vlv.fifo_state; |
| 5414 | enum pipe pipe = crtc->pipe; |
| 5415 | enum plane_id plane_id; |
| 5416 | int level; |
| 5417 | |
| 5418 | vlv_get_fifo_size(crtc_state); |
| 5419 | |
| 5420 | active->num_levels = wm->level + 1; |
| 5421 | active->cxsr = wm->cxsr; |
| 5422 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5423 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 5424 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5425 | &crtc_state->wm.vlv.raw[level]; |
| 5426 | |
| 5427 | active->sr[level].plane = wm->sr.plane; |
| 5428 | active->sr[level].cursor = wm->sr.cursor; |
| 5429 | |
| 5430 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 5431 | active->wm[level].plane[plane_id] = |
| 5432 | wm->pipe[pipe].plane[plane_id]; |
| 5433 | |
| 5434 | raw->plane[plane_id] = |
| 5435 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 5436 | fifo_state->plane[plane_id]); |
| 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5441 | vlv_raw_plane_wm_set(crtc_state, level, |
| 5442 | plane_id, USHRT_MAX); |
| 5443 | vlv_invalidate_wms(crtc, active, level); |
| 5444 | |
| 5445 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 5446 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5447 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5448 | 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] | 5449 | pipe_name(pipe), |
| 5450 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 5451 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 5452 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 5453 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5454 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 5455 | |
| 5456 | DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 5457 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
| 5458 | } |
| 5459 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 5460 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 5461 | { |
| 5462 | struct intel_plane *plane; |
| 5463 | struct intel_crtc *crtc; |
| 5464 | |
| 5465 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 5466 | |
| 5467 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 5468 | struct intel_crtc *crtc = |
| 5469 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 5470 | struct intel_crtc_state *crtc_state = |
| 5471 | to_intel_crtc_state(crtc->base.state); |
| 5472 | struct intel_plane_state *plane_state = |
| 5473 | to_intel_plane_state(plane->base.state); |
| 5474 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 5475 | const struct vlv_fifo_state *fifo_state = |
| 5476 | &crtc_state->wm.vlv.fifo_state; |
| 5477 | enum plane_id plane_id = plane->id; |
| 5478 | int level; |
| 5479 | |
| 5480 | if (plane_state->base.visible) |
| 5481 | continue; |
| 5482 | |
| 5483 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 5484 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 5485 | &crtc_state->wm.vlv.raw[level]; |
| 5486 | |
| 5487 | raw->plane[plane_id] = 0; |
| 5488 | |
| 5489 | wm_state->wm[level].plane[plane_id] = |
| 5490 | vlv_invert_wm_value(raw->plane[plane_id], |
| 5491 | fifo_state->plane[plane_id]); |
| 5492 | } |
| 5493 | } |
| 5494 | |
| 5495 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5496 | struct intel_crtc_state *crtc_state = |
| 5497 | to_intel_crtc_state(crtc->base.state); |
| 5498 | |
| 5499 | crtc_state->wm.vlv.intermediate = |
| 5500 | crtc_state->wm.vlv.optimal; |
| 5501 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 5502 | } |
| 5503 | |
| 5504 | vlv_program_watermarks(dev_priv); |
| 5505 | |
| 5506 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 5507 | } |
| 5508 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5509 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 5510 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5511 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 5512 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5513 | struct drm_crtc *crtc; |
| 5514 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 5515 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5516 | ilk_pipe_wm_get_hw_state(crtc); |
| 5517 | |
| 5518 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 5519 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 5520 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 5521 | |
| 5522 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 5523 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 5524 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 5525 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 5526 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5527 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5528 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 5529 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 5530 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5531 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 5532 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 5533 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 5534 | |
| 5535 | hw->enable_fbc_wm = |
| 5536 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 5537 | } |
| 5538 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5539 | /** |
| 5540 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 5541 | * |
| 5542 | * Calculate watermark values for the various WM regs based on current mode |
| 5543 | * and plane configuration. |
| 5544 | * |
| 5545 | * There are several cases to deal with here: |
| 5546 | * - normal (i.e. non-self-refresh) |
| 5547 | * - self-refresh (SR) mode |
| 5548 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 5549 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 5550 | * lines), so need to account for TLB latency |
| 5551 | * |
| 5552 | * The normal calculation is: |
| 5553 | * watermark = dotclock * bytes per pixel * latency |
| 5554 | * where latency is platform & configuration dependent (we assume pessimal |
| 5555 | * values here). |
| 5556 | * |
| 5557 | * The SR calculation is: |
| 5558 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 5559 | * bytes per pixel |
| 5560 | * where |
| 5561 | * line time = htotal / dotclock |
| 5562 | * surface width = hdisplay for normal plane and 64 for cursor |
| 5563 | * and latency is assumed to be high, as above. |
| 5564 | * |
| 5565 | * The final value programmed to the register should always be rounded up, |
| 5566 | * and include an extra 2 entries to account for clock crossings. |
| 5567 | * |
| 5568 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 5569 | * to set the non-SR watermarks to 8. |
| 5570 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5571 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5572 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5573 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5574 | |
| 5575 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 5576 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 5577 | } |
| 5578 | |
Jani Nikula | e282891 | 2016-01-18 09:19:47 +0200 | [diff] [blame] | 5579 | /* |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5580 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5581 | */ |
| 5582 | DEFINE_SPINLOCK(mchdev_lock); |
| 5583 | |
| 5584 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 5585 | * mchdev_lock. */ |
| 5586 | static struct drm_i915_private *i915_mch_dev; |
| 5587 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5588 | bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5589 | { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5590 | u16 rgvswctl; |
| 5591 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 5592 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5593 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5594 | rgvswctl = I915_READ16(MEMSWCTL); |
| 5595 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 5596 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 5597 | return false; /* still busy with another command */ |
| 5598 | } |
| 5599 | |
| 5600 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 5601 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 5602 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 5603 | POSTING_READ16(MEMSWCTL); |
| 5604 | |
| 5605 | rgvswctl |= MEMCTL_CMD_STS; |
| 5606 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 5607 | |
| 5608 | return true; |
| 5609 | } |
| 5610 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5611 | static void ironlake_enable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5612 | { |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 5613 | u32 rgvmodectl; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5614 | u8 fmax, fmin, fstart, vstart; |
| 5615 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5616 | spin_lock_irq(&mchdev_lock); |
| 5617 | |
Tvrtko Ursulin | 84f1b20 | 2016-02-11 10:27:32 +0000 | [diff] [blame] | 5618 | rgvmodectl = I915_READ(MEMMODECTL); |
| 5619 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5620 | /* Enable temp reporting */ |
| 5621 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 5622 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 5623 | |
| 5624 | /* 100ms RC evaluation intervals */ |
| 5625 | I915_WRITE(RCUPEI, 100000); |
| 5626 | I915_WRITE(RCDNEI, 100000); |
| 5627 | |
| 5628 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 5629 | I915_WRITE(RCBMAXAVG, 90000); |
| 5630 | I915_WRITE(RCBMINAVG, 80000); |
| 5631 | |
| 5632 | I915_WRITE(MEMIHYST, 1); |
| 5633 | |
| 5634 | /* Set up min, max, and cur for interrupt handling */ |
| 5635 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 5636 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 5637 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 5638 | MEMMODE_FSTART_SHIFT; |
| 5639 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 5640 | vstart = (I915_READ(PXVFREQ(fstart)) & PXVFREQ_PX_MASK) >> |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5641 | PXVFREQ_PX_SHIFT; |
| 5642 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5643 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 5644 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5645 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5646 | dev_priv->ips.max_delay = fstart; |
| 5647 | dev_priv->ips.min_delay = fmin; |
| 5648 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5649 | |
| 5650 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 5651 | fmax, fmin, fstart); |
| 5652 | |
| 5653 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 5654 | |
| 5655 | /* |
| 5656 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 5657 | */ |
| 5658 | |
| 5659 | I915_WRITE(VIDSTART, vstart); |
| 5660 | POSTING_READ(VIDSTART); |
| 5661 | |
| 5662 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 5663 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 5664 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5665 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5666 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 5667 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5668 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5669 | ironlake_set_drps(dev_priv, fstart); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5670 | |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 5671 | dev_priv->ips.last_count1 = I915_READ(DMIEC) + |
| 5672 | I915_READ(DDREC) + I915_READ(CSIEC); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5673 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
Ville Syrjälä | 7d81c3e | 2015-09-18 20:03:20 +0300 | [diff] [blame] | 5674 | dev_priv->ips.last_count2 = I915_READ(GFXEC); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5675 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5676 | |
| 5677 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5678 | } |
| 5679 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5680 | static void ironlake_disable_drps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5681 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5682 | u16 rgvswctl; |
| 5683 | |
| 5684 | spin_lock_irq(&mchdev_lock); |
| 5685 | |
| 5686 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5687 | |
| 5688 | /* Ack interrupts, disable EFC interrupt */ |
| 5689 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 5690 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 5691 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 5692 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 5693 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 5694 | |
| 5695 | /* Go back to the starting frequency */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 5696 | ironlake_set_drps(dev_priv, dev_priv->ips.fstart); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 5697 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5698 | rgvswctl |= MEMCTL_CMD_STS; |
| 5699 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | dd92d8d | 2015-07-20 10:58:21 +0200 | [diff] [blame] | 5700 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5701 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5702 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5703 | } |
| 5704 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 5705 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 5706 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 5707 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 5708 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 5709 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 5710 | 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] | 5711 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 5712 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5713 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 5714 | /* Only set the down limit when we've reached the lowest level to avoid |
| 5715 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 5716 | * race in the hw when coming out of rc6: There's a tiny window where |
| 5717 | * the hw runs at the minimal clock before selecting the desired |
| 5718 | * frequency, if the down threshold expires in that window we will not |
| 5719 | * receive a down interrupt. */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 5720 | if (IS_GEN9(dev_priv)) { |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 5721 | limits = (dev_priv->rps.max_freq_softlimit) << 23; |
| 5722 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 5723 | limits |= (dev_priv->rps.min_freq_softlimit) << 14; |
| 5724 | } else { |
| 5725 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 5726 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 5727 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
| 5728 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 5729 | |
| 5730 | return limits; |
| 5731 | } |
| 5732 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5733 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 5734 | { |
| 5735 | int new_power; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5736 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 5737 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5738 | |
| 5739 | new_power = dev_priv->rps.power; |
| 5740 | switch (dev_priv->rps.power) { |
| 5741 | case LOW_POWER: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5742 | if (val > dev_priv->rps.efficient_freq + 1 && |
| 5743 | val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5744 | new_power = BETWEEN; |
| 5745 | break; |
| 5746 | |
| 5747 | case BETWEEN: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5748 | if (val <= dev_priv->rps.efficient_freq && |
| 5749 | val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5750 | new_power = LOW_POWER; |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5751 | else if (val >= dev_priv->rps.rp0_freq && |
| 5752 | val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5753 | new_power = HIGH_POWER; |
| 5754 | break; |
| 5755 | |
| 5756 | case HIGH_POWER: |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5757 | if (val < (dev_priv->rps.rp1_freq + dev_priv->rps.rp0_freq) >> 1 && |
| 5758 | val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5759 | new_power = BETWEEN; |
| 5760 | break; |
| 5761 | } |
| 5762 | /* Max/min bins are special */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5763 | if (val <= dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5764 | new_power = LOW_POWER; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5765 | if (val >= dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5766 | new_power = HIGH_POWER; |
| 5767 | if (new_power == dev_priv->rps.power) |
| 5768 | return; |
| 5769 | |
| 5770 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 5771 | switch (new_power) { |
| 5772 | case LOW_POWER: |
| 5773 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5774 | ei_up = 16000; |
| 5775 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5776 | |
| 5777 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5778 | ei_down = 32000; |
| 5779 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5780 | break; |
| 5781 | |
| 5782 | case BETWEEN: |
| 5783 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5784 | ei_up = 13000; |
| 5785 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5786 | |
| 5787 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5788 | ei_down = 32000; |
| 5789 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5790 | break; |
| 5791 | |
| 5792 | case HIGH_POWER: |
| 5793 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5794 | ei_up = 10000; |
| 5795 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5796 | |
| 5797 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5798 | ei_down = 32000; |
| 5799 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5800 | break; |
| 5801 | } |
| 5802 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 5803 | /* When byt can survive without system hang with dynamic |
| 5804 | * sw freq adjustments, this restriction can be lifted. |
| 5805 | */ |
| 5806 | if (IS_VALLEYVIEW(dev_priv)) |
| 5807 | goto skip_hw_write; |
| 5808 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5809 | I915_WRITE(GEN6_RP_UP_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5810 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5811 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5812 | GT_INTERVAL_FROM_US(dev_priv, |
| 5813 | ei_up * threshold_up / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5814 | |
| 5815 | I915_WRITE(GEN6_RP_DOWN_EI, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5816 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5817 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5818 | GT_INTERVAL_FROM_US(dev_priv, |
| 5819 | ei_down * threshold_down / 100)); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5820 | |
Chris Wilson | a72b562 | 2016-07-02 15:35:59 +0100 | [diff] [blame] | 5821 | I915_WRITE(GEN6_RP_CONTROL, |
| 5822 | GEN6_RP_MEDIA_TURBO | |
| 5823 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 5824 | GEN6_RP_MEDIA_IS_GFX | |
| 5825 | GEN6_RP_ENABLE | |
| 5826 | GEN6_RP_UP_BUSY_AVG | |
| 5827 | GEN6_RP_DOWN_IDLE_AVG); |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 5828 | |
Mika Kuoppala | 6067a27 | 2017-02-15 15:52:59 +0200 | [diff] [blame] | 5829 | skip_hw_write: |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5830 | dev_priv->rps.power = new_power; |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 5831 | dev_priv->rps.up_threshold = threshold_up; |
| 5832 | dev_priv->rps.down_threshold = threshold_down; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 5833 | dev_priv->rps.last_adj = 0; |
| 5834 | } |
| 5835 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 5836 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 5837 | { |
| 5838 | u32 mask = 0; |
| 5839 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 5840 | /* We use UP_EI_EXPIRED interupts for both up/down in manual mode */ |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 5841 | if (val > dev_priv->rps.min_freq_softlimit) |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 5842 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 5843 | if (val < dev_priv->rps.max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 5844 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 5845 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 5846 | mask &= dev_priv->pm_rps_events; |
| 5847 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 5848 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 5851 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 5852 | * called when the range (min_delay and max_delay) is modified so that we can |
| 5853 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5854 | 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] | 5855 | { |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 5856 | /* min/max delay may still have been modified so be sure to |
| 5857 | * write the limits value. |
| 5858 | */ |
| 5859 | if (val != dev_priv->rps.cur_freq) { |
| 5860 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 5861 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5862 | if (IS_GEN9(dev_priv)) |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 5863 | I915_WRITE(GEN6_RPNSWREQ, |
| 5864 | GEN9_FREQUENCY(val)); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5865 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 5866 | I915_WRITE(GEN6_RPNSWREQ, |
| 5867 | HSW_FREQUENCY(val)); |
| 5868 | else |
| 5869 | I915_WRITE(GEN6_RPNSWREQ, |
| 5870 | GEN6_FREQUENCY(val) | |
| 5871 | GEN6_OFFSET(0) | |
| 5872 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 5873 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 5874 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 5875 | /* Make sure we continue to get interrupts |
| 5876 | * until we hit the minimum or maximum frequencies. |
| 5877 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 5878 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 5879 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 5880 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5881 | dev_priv->rps.cur_freq = val; |
Mika Kuoppala | 0f94592 | 2015-11-17 18:14:26 +0200 | [diff] [blame] | 5882 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5883 | |
| 5884 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5885 | } |
| 5886 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5887 | 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] | 5888 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5889 | int err; |
| 5890 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5891 | if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1), |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5892 | "Odd GPU freq value\n")) |
| 5893 | val &= ~1; |
| 5894 | |
Deepak S | cd25dd5 | 2015-07-10 18:31:40 +0530 | [diff] [blame] | 5895 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 5896 | |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 5897 | if (val != dev_priv->rps.cur_freq) { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5898 | err = vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 5899 | if (err) |
| 5900 | return err; |
| 5901 | |
Chris Wilson | db4c5e0 | 2017-02-10 15:03:46 +0000 | [diff] [blame] | 5902 | gen6_set_rps_thresholds(dev_priv, val); |
Chris Wilson | 8fb5519 | 2015-04-07 16:20:28 +0100 | [diff] [blame] | 5903 | } |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5904 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5905 | dev_priv->rps.cur_freq = val; |
| 5906 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5907 | |
| 5908 | return 0; |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 5909 | } |
| 5910 | |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 5911 | /* 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] | 5912 | * |
| 5913 | * * If Gfx is Idle, then |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 5914 | * 1. Forcewake Media well. |
| 5915 | * 2. Request idle freq. |
| 5916 | * 3. Release Forcewake of Media well. |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5917 | */ |
| 5918 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 5919 | { |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5920 | u32 val = dev_priv->rps.idle_freq; |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5921 | int err; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 5922 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5923 | if (dev_priv->rps.cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5924 | return; |
| 5925 | |
Chris Wilson | c9efef7 | 2017-01-02 15:28:45 +0000 | [diff] [blame] | 5926 | /* The punit delays the write of the frequency and voltage until it |
| 5927 | * determines the GPU is awake. During normal usage we don't want to |
| 5928 | * waste power changing the frequency if the GPU is sleeping (rc6). |
| 5929 | * However, the GPU and driver is now idle and we do not want to delay |
| 5930 | * switching to minimum voltage (reducing power whilst idle) as we do |
| 5931 | * not expect to be woken in the near future and so must flush the |
| 5932 | * change by waking the device. |
| 5933 | * |
| 5934 | * We choose to take the media powerwell (either would do to trick the |
| 5935 | * punit into committing the voltage change) as that takes a lot less |
| 5936 | * power than the render powerwell. |
| 5937 | */ |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 5938 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5939 | err = valleyview_set_rps(dev_priv, val); |
Deepak S | a7f6e23 | 2015-05-09 18:04:44 +0530 | [diff] [blame] | 5940 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_MEDIA); |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5941 | |
| 5942 | if (err) |
| 5943 | DRM_ERROR("Failed to set RPS for idle\n"); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5944 | } |
| 5945 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 5946 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 5947 | { |
| 5948 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5949 | if (dev_priv->rps.enabled) { |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 5950 | u8 freq; |
| 5951 | |
Chris Wilson | e0e8c7c | 2017-03-09 21:12:30 +0000 | [diff] [blame] | 5952 | if (dev_priv->pm_rps_events & GEN6_PM_RP_UP_EI_EXPIRED) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 5953 | gen6_rps_reset_ei(dev_priv); |
| 5954 | I915_WRITE(GEN6_PMINTRMSK, |
| 5955 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Michał Winiarski | 2b83c4c | 2016-06-20 11:58:27 +0200 | [diff] [blame] | 5956 | |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 5957 | gen6_enable_rps_interrupts(dev_priv); |
| 5958 | |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 5959 | /* Use the user's desired frequency as a guide, but for better |
| 5960 | * performance, jump directly to RPe as our starting frequency. |
| 5961 | */ |
| 5962 | freq = max(dev_priv->rps.cur_freq, |
| 5963 | dev_priv->rps.efficient_freq); |
| 5964 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5965 | if (intel_set_rps(dev_priv, |
Chris Wilson | bd64818 | 2017-02-10 15:03:48 +0000 | [diff] [blame] | 5966 | clamp(freq, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 5967 | dev_priv->rps.min_freq_softlimit, |
| 5968 | dev_priv->rps.max_freq_softlimit))) |
| 5969 | DRM_DEBUG_DRIVER("Failed to set idle frequency\n"); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 5970 | } |
| 5971 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5972 | } |
| 5973 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 5974 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 5975 | { |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 5976 | /* Flush our bottom-half so that it does not race with us |
| 5977 | * setting the idle frequency and so that it is bounded by |
| 5978 | * our rpm wakeref. And then disable the interrupts to stop any |
| 5979 | * futher RPS reclocking whilst we are asleep. |
| 5980 | */ |
| 5981 | gen6_disable_rps_interrupts(dev_priv); |
| 5982 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 5983 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5984 | if (dev_priv->rps.enabled) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5985 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5986 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 5987 | else |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 5988 | gen6_set_rps(dev_priv, dev_priv->rps.idle_freq); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5989 | dev_priv->rps.last_adj = 0; |
Ville Syrjälä | 12c100b | 2016-05-23 17:42:48 +0300 | [diff] [blame] | 5990 | I915_WRITE(GEN6_PMINTRMSK, |
| 5991 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5992 | } |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5993 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 5994 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5995 | spin_lock(&dev_priv->rps.client_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 5996 | while (!list_empty(&dev_priv->rps.clients)) |
| 5997 | list_del_init(dev_priv->rps.clients.next); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 5998 | spin_unlock(&dev_priv->rps.client_lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 5999 | } |
| 6000 | |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6001 | void gen6_rps_boost(struct drm_i915_private *dev_priv, |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 6002 | struct intel_rps_client *rps, |
| 6003 | unsigned long submitted) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6004 | { |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6005 | /* This is intentionally racy! We peek at the state here, then |
| 6006 | * validate inside the RPS worker. |
| 6007 | */ |
Chris Wilson | 67d97da | 2016-07-04 08:08:31 +0100 | [diff] [blame] | 6008 | if (!(dev_priv->gt.awake && |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6009 | dev_priv->rps.enabled && |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 6010 | dev_priv->rps.cur_freq < dev_priv->rps.boost_freq)) |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6011 | return; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 6012 | |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 6013 | /* Force a RPS boost (and don't count it against the client) if |
| 6014 | * the GPU is severely congested. |
| 6015 | */ |
Chris Wilson | d0bc54f | 2015-05-21 21:01:48 +0100 | [diff] [blame] | 6016 | if (rps && time_after(jiffies, submitted + DRM_I915_THROTTLE_JIFFIES)) |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 6017 | rps = NULL; |
| 6018 | |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6019 | spin_lock(&dev_priv->rps.client_lock); |
| 6020 | if (rps == NULL || list_empty(&rps->link)) { |
| 6021 | spin_lock_irq(&dev_priv->irq_lock); |
| 6022 | if (dev_priv->rps.interrupts_enabled) { |
| 6023 | dev_priv->rps.client_boost = true; |
Chris Wilson | c33d247 | 2016-07-04 08:08:36 +0100 | [diff] [blame] | 6024 | schedule_work(&dev_priv->rps.work); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6025 | } |
| 6026 | spin_unlock_irq(&dev_priv->irq_lock); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6027 | |
Chris Wilson | 2e1b873 | 2015-04-27 13:41:22 +0100 | [diff] [blame] | 6028 | if (rps != NULL) { |
| 6029 | list_add(&rps->link, &dev_priv->rps.clients); |
| 6030 | rps->boosts++; |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 6031 | } else |
| 6032 | dev_priv->rps.boosts++; |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6033 | } |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 6034 | spin_unlock(&dev_priv->rps.client_lock); |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 6035 | } |
| 6036 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6037 | int intel_set_rps(struct drm_i915_private *dev_priv, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6038 | { |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6039 | int err; |
| 6040 | |
Chris Wilson | cfd1c48 | 2017-02-20 09:47:07 +0000 | [diff] [blame] | 6041 | lockdep_assert_held(&dev_priv->rps.hw_lock); |
| 6042 | GEM_BUG_ON(val > dev_priv->rps.max_freq); |
| 6043 | GEM_BUG_ON(val < dev_priv->rps.min_freq); |
| 6044 | |
Chris Wilson | 76e4e4b | 2017-02-20 09:47:08 +0000 | [diff] [blame] | 6045 | if (!dev_priv->rps.enabled) { |
| 6046 | dev_priv->rps.cur_freq = val; |
| 6047 | return 0; |
| 6048 | } |
| 6049 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6050 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6051 | err = valleyview_set_rps(dev_priv, val); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 6052 | else |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6053 | err = gen6_set_rps(dev_priv, val); |
| 6054 | |
| 6055 | return err; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6056 | } |
| 6057 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6058 | static void gen9_disable_rc6(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6059 | { |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6060 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6061 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6062 | } |
| 6063 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6064 | static void gen9_disable_rps(struct drm_i915_private *dev_priv) |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6065 | { |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6066 | I915_WRITE(GEN6_RP_CONTROL, 0); |
| 6067 | } |
| 6068 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6069 | static void gen6_disable_rps(struct drm_i915_private *dev_priv) |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6070 | { |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6071 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6072 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Akash Goel | 2030d68 | 2016-04-23 00:05:45 +0530 | [diff] [blame] | 6073 | I915_WRITE(GEN6_RP_CONTROL, 0); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 6074 | } |
| 6075 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6076 | static void cherryview_disable_rps(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6077 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6078 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6079 | } |
| 6080 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6081 | static void valleyview_disable_rps(struct drm_i915_private *dev_priv) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6082 | { |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6083 | /* we're doing forcewake before Disabling RC6, |
| 6084 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6085 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 6086 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6087 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6088 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6089 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6090 | } |
| 6091 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6092 | 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] | 6093 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6094 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 6095 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 6096 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 6097 | else |
| 6098 | mode = 0; |
| 6099 | } |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6100 | if (HAS_RC6p(dev_priv)) |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6101 | DRM_DEBUG_DRIVER("Enabling RC6 states: " |
| 6102 | "RC6 %s RC6p %s RC6pp %s\n", |
| 6103 | onoff(mode & GEN6_RC_CTL_RC6_ENABLE), |
| 6104 | onoff(mode & GEN6_RC_CTL_RC6p_ENABLE), |
| 6105 | onoff(mode & GEN6_RC_CTL_RC6pp_ENABLE)); |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 6106 | |
| 6107 | else |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6108 | DRM_DEBUG_DRIVER("Enabling RC6 states: RC6 %s\n", |
| 6109 | onoff(mode & GEN6_RC_CTL_RC6_ENABLE)); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 6110 | } |
| 6111 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6112 | 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] | 6113 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 6114 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6115 | bool enable_rc6 = true; |
| 6116 | unsigned long rc6_ctx_base; |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6117 | u32 rc_ctl; |
| 6118 | int rc_sw_target; |
| 6119 | |
| 6120 | rc_ctl = I915_READ(GEN6_RC_CONTROL); |
| 6121 | rc_sw_target = (I915_READ(GEN6_RC_STATE) & RC_SW_TARGET_STATE_MASK) >> |
| 6122 | RC_SW_TARGET_STATE_SHIFT; |
| 6123 | DRM_DEBUG_DRIVER("BIOS enabled RC states: " |
| 6124 | "HW_CTRL %s HW_RC6 %s SW_TARGET_STATE %x\n", |
| 6125 | onoff(rc_ctl & GEN6_RC_CTL_HW_ENABLE), |
| 6126 | onoff(rc_ctl & GEN6_RC_CTL_RC6_ENABLE), |
| 6127 | rc_sw_target); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6128 | |
| 6129 | if (!(I915_READ(RC6_LOCATION) & RC6_CTX_IN_DRAM)) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6130 | DRM_DEBUG_DRIVER("RC6 Base location not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6131 | enable_rc6 = false; |
| 6132 | } |
| 6133 | |
| 6134 | /* |
| 6135 | * The exact context size is not known for BXT, so assume a page size |
| 6136 | * for this check. |
| 6137 | */ |
| 6138 | rc6_ctx_base = I915_READ(RC6_CTX_BASE) & RC6_CTX_BASE_MASK; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 6139 | if (!((rc6_ctx_base >= ggtt->stolen_reserved_base) && |
| 6140 | (rc6_ctx_base + PAGE_SIZE <= ggtt->stolen_reserved_base + |
| 6141 | ggtt->stolen_reserved_size))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6142 | DRM_DEBUG_DRIVER("RC6 Base address not as expected.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6143 | enable_rc6 = false; |
| 6144 | } |
| 6145 | |
| 6146 | if (!(((I915_READ(PWRCTX_MAXCNT_RCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6147 | ((I915_READ(PWRCTX_MAXCNT_VCSUNIT0) & IDLE_TIME_MASK) > 1) && |
| 6148 | ((I915_READ(PWRCTX_MAXCNT_BCSUNIT) & IDLE_TIME_MASK) > 1) && |
| 6149 | ((I915_READ(PWRCTX_MAXCNT_VECSUNIT) & IDLE_TIME_MASK) > 1))) { |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6150 | DRM_DEBUG_DRIVER("Engine Idle wait time not set properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6151 | enable_rc6 = false; |
| 6152 | } |
| 6153 | |
Imre Deak | fc61984 | 2016-06-29 19:13:55 +0300 | [diff] [blame] | 6154 | if (!I915_READ(GEN8_PUSHBUS_CONTROL) || |
| 6155 | !I915_READ(GEN8_PUSHBUS_ENABLE) || |
| 6156 | !I915_READ(GEN8_PUSHBUS_SHIFT)) { |
| 6157 | DRM_DEBUG_DRIVER("Pushbus not setup properly.\n"); |
| 6158 | enable_rc6 = false; |
| 6159 | } |
| 6160 | |
| 6161 | if (!I915_READ(GEN6_GFXPAUSE)) { |
| 6162 | DRM_DEBUG_DRIVER("GFX pause not setup properly.\n"); |
| 6163 | enable_rc6 = false; |
| 6164 | } |
| 6165 | |
| 6166 | if (!I915_READ(GEN8_MISC_CTRL0)) { |
| 6167 | DRM_DEBUG_DRIVER("GPM control not setup properly.\n"); |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6168 | enable_rc6 = false; |
| 6169 | } |
| 6170 | |
| 6171 | return enable_rc6; |
| 6172 | } |
| 6173 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6174 | 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] | 6175 | { |
Daniel Vetter | e7d66d8 | 2015-06-15 23:23:54 +0200 | [diff] [blame] | 6176 | /* No RC6 before Ironlake and code is gone for ilk. */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6177 | if (INTEL_INFO(dev_priv)->gen < 6) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6178 | return 0; |
| 6179 | |
Sagar Arun Kamble | 274008e | 2016-02-06 00:13:29 +0530 | [diff] [blame] | 6180 | if (!enable_rc6) |
| 6181 | return 0; |
| 6182 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 6183 | 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] | 6184 | DRM_INFO("RC6 disabled by BIOS\n"); |
| 6185 | return 0; |
| 6186 | } |
| 6187 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 6188 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6189 | if (enable_rc6 >= 0) { |
| 6190 | int mask; |
| 6191 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6192 | if (HAS_RC6p(dev_priv)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6193 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 6194 | INTEL_RC6pp_ENABLE; |
| 6195 | else |
| 6196 | mask = INTEL_RC6_ENABLE; |
| 6197 | |
| 6198 | if ((enable_rc6 & mask) != enable_rc6) |
Imre Deak | b99d49c | 2016-06-29 19:13:54 +0300 | [diff] [blame] | 6199 | DRM_DEBUG_DRIVER("Adjusting RC6 mask to %d " |
| 6200 | "(requested %d, valid %d)\n", |
| 6201 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6202 | |
| 6203 | return enable_rc6 & mask; |
| 6204 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6205 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6206 | if (IS_IVYBRIDGE(dev_priv)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 6207 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 6208 | |
| 6209 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6210 | } |
| 6211 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6212 | static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6213 | { |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6214 | /* All of these values are in units of 50MHz */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6215 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6216 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 6217 | if (IS_GEN9_LP(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6218 | u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP); |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 6219 | dev_priv->rps.rp0_freq = (rp_state_cap >> 16) & 0xff; |
| 6220 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 6221 | dev_priv->rps.min_freq = (rp_state_cap >> 0) & 0xff; |
| 6222 | } else { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6223 | u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Bob Paauwe | 3504056 | 2015-06-25 14:54:07 -0700 | [diff] [blame] | 6224 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 6225 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 6226 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 6227 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6228 | /* hw_max = RP0 until we check for overclocking */ |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6229 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6230 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6231 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6232 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) || |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 6233 | IS_GEN9_BC(dev_priv)) { |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6234 | u32 ddcc_status = 0; |
| 6235 | |
| 6236 | if (sandybridge_pcode_read(dev_priv, |
| 6237 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 6238 | &ddcc_status) == 0) |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6239 | dev_priv->rps.efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 6240 | clamp_t(u8, |
| 6241 | ((ddcc_status >> 8) & 0xff), |
| 6242 | dev_priv->rps.min_freq, |
| 6243 | dev_priv->rps.max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6244 | } |
| 6245 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 6246 | if (IS_GEN9_BC(dev_priv)) { |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 6247 | /* Store the frequency values in 16.66 MHZ units, which is |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 6248 | * the natural hardware unit for SKL |
| 6249 | */ |
Akash Goel | c5e0688 | 2015-06-29 14:50:19 +0530 | [diff] [blame] | 6250 | dev_priv->rps.rp0_freq *= GEN9_FREQ_SCALER; |
| 6251 | dev_priv->rps.rp1_freq *= GEN9_FREQ_SCALER; |
| 6252 | dev_priv->rps.min_freq *= GEN9_FREQ_SCALER; |
| 6253 | dev_priv->rps.max_freq *= GEN9_FREQ_SCALER; |
| 6254 | dev_priv->rps.efficient_freq *= GEN9_FREQ_SCALER; |
| 6255 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 6256 | } |
| 6257 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6258 | static void reset_rps(struct drm_i915_private *dev_priv, |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6259 | int (*set)(struct drm_i915_private *, u8)) |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6260 | { |
| 6261 | u8 freq = dev_priv->rps.cur_freq; |
| 6262 | |
| 6263 | /* force a reset */ |
| 6264 | dev_priv->rps.power = -1; |
| 6265 | dev_priv->rps.cur_freq = -1; |
| 6266 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 6267 | if (set(dev_priv, freq)) |
| 6268 | DRM_ERROR("Failed to reset RPS to initial values\n"); |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6269 | } |
| 6270 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6271 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6272 | static void gen9_enable_rps(struct drm_i915_private *dev_priv) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6273 | { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6274 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 6275 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6276 | /* Program defaults and thresholds for RPS*/ |
| 6277 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 6278 | GEN9_FREQUENCY(dev_priv->rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6279 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6280 | /* 1 second timeout*/ |
| 6281 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 6282 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 6283 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6284 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6285 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 6286 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 6287 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 6288 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6289 | reset_rps(dev_priv, gen6_set_rps); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6290 | |
| 6291 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 6292 | } |
| 6293 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6294 | static void gen9_enable_rc6(struct drm_i915_private *dev_priv) |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 6295 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6296 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6297 | enum intel_engine_id id; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6298 | uint32_t rc6_mask = 0; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6299 | |
| 6300 | /* 1a: Software RC state - RC0 */ |
| 6301 | I915_WRITE(GEN6_RC_STATE, 0); |
| 6302 | |
| 6303 | /* 1b: Get forcewake during program sequence. Although the driver |
| 6304 | * 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] | 6305 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6306 | |
| 6307 | /* 2a: Disable RC states. */ |
| 6308 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6309 | |
| 6310 | /* 2b: Program RC6 thresholds.*/ |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 6311 | |
| 6312 | /* WaRsDoubleRc6WrlWithCoarsePowerGating: Doubling WRL only when CPG is enabled */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6313 | if (IS_SKYLAKE(dev_priv)) |
Sagar Arun Kamble | 63a4dec | 2015-09-12 10:17:53 +0530 | [diff] [blame] | 6314 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 108 << 16); |
| 6315 | else |
| 6316 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6317 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 6318 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6319 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6320 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 6321 | |
Dave Gordon | 1a3d189 | 2016-05-13 15:36:30 +0100 | [diff] [blame] | 6322 | if (HAS_GUC(dev_priv)) |
Sagar Arun Kamble | 97c322e | 2015-09-12 10:17:54 +0530 | [diff] [blame] | 6323 | I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA); |
| 6324 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6325 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6326 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6327 | /* 2c: Program Coarse Power Gating Policies. */ |
| 6328 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 6329 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 6330 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6331 | /* 3a: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6332 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6333 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 6334 | 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] | 6335 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
| 6336 | I915_WRITE(GEN6_RC_CONTROL, |
| 6337 | GEN6_RC_CTL_HW_ENABLE | GEN6_RC_CTL_EI_MODE(1) | rc6_mask); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6338 | |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 6339 | /* |
| 6340 | * 3b: Enable Coarse Power Gating only when RC6 is enabled. |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 6341 | * WaRsDisableCoarsePowerGating:skl,bxt - Render/Media PG need to be disabled with RC6. |
Sagar Kamble | cb07bae | 2015-04-12 11:28:14 +0530 | [diff] [blame] | 6342 | */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6343 | if (NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) |
Sagar Arun Kamble | f2d2fe9 | 2015-09-12 10:17:51 +0530 | [diff] [blame] | 6344 | I915_WRITE(GEN9_PG_ENABLE, 0); |
| 6345 | else |
| 6346 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 6347 | (GEN9_RENDER_PG_ENABLE | GEN9_MEDIA_PG_ENABLE) : 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 6348 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6349 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6352 | static void gen8_enable_rps(struct drm_i915_private *dev_priv) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6353 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6354 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6355 | enum intel_engine_id id; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 6356 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6357 | |
| 6358 | /* 1a: Software RC state - RC0 */ |
| 6359 | I915_WRITE(GEN6_RC_STATE, 0); |
| 6360 | |
| 6361 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 6362 | * 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] | 6363 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6364 | |
| 6365 | /* 2a: Disable RC states. */ |
| 6366 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6367 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6368 | /* 2b: Program RC6 thresholds.*/ |
| 6369 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 6370 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 6371 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6372 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6373 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6374 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6375 | if (IS_BROADWELL(dev_priv)) |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 6376 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 6377 | else |
| 6378 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6379 | |
| 6380 | /* 3: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6381 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6382 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6383 | intel_print_rc6_info(dev_priv, rc6_mask); |
| 6384 | if (IS_BROADWELL(dev_priv)) |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 6385 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 6386 | GEN7_RC_CTL_TO_MODE | |
| 6387 | rc6_mask); |
| 6388 | else |
| 6389 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 6390 | GEN6_RC_CTL_EI_MODE(1) | |
| 6391 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6392 | |
| 6393 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 6394 | I915_WRITE(GEN6_RPNSWREQ, |
| 6395 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 6396 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 6397 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6398 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 6399 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6400 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6401 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 6402 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 6403 | dev_priv->rps.max_freq_softlimit << 24 | |
| 6404 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6405 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6406 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 6407 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 6408 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 6409 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6410 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6411 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6412 | |
| 6413 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6414 | I915_WRITE(GEN6_RP_CONTROL, |
| 6415 | GEN6_RP_MEDIA_TURBO | |
| 6416 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 6417 | GEN6_RP_MEDIA_IS_GFX | |
| 6418 | GEN6_RP_ENABLE | |
| 6419 | GEN6_RP_UP_BUSY_AVG | |
| 6420 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6421 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6422 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6423 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6424 | reset_rps(dev_priv, gen6_set_rps); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 6425 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6426 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6427 | } |
| 6428 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6429 | static void gen6_enable_rps(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6430 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6431 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6432 | enum intel_engine_id id; |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 6433 | u32 rc6vids, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6434 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6435 | int rc6_mode; |
Dave Gordon | b4ac5af | 2016-03-24 11:20:38 +0000 | [diff] [blame] | 6436 | int ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6437 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6438 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 6439 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6440 | /* Here begins a magic sequence of register writes to enable |
| 6441 | * auto-downclocking. |
| 6442 | * |
| 6443 | * Perhaps there might be some value in exposing these to |
| 6444 | * userspace... |
| 6445 | */ |
| 6446 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6447 | |
| 6448 | /* Clear the DBG now so we don't confuse earlier errors */ |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 6449 | gtfifodbg = I915_READ(GTFIFODBG); |
| 6450 | if (gtfifodbg) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6451 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 6452 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 6453 | } |
| 6454 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6455 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6456 | |
| 6457 | /* disable the counters and set deterministic thresholds */ |
| 6458 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6459 | |
| 6460 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 6461 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 6462 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 6463 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 6464 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 6465 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6466 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6467 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6468 | |
| 6469 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 6470 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6471 | if (IS_IVYBRIDGE(dev_priv)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 6472 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 6473 | else |
| 6474 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 6475 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6476 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 6477 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6478 | /* Check if we are enabling RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6479 | rc6_mode = intel_enable_rc6(); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6480 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 6481 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 6482 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6483 | /* We don't use those on Haswell */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6484 | if (!IS_HASWELL(dev_priv)) { |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6485 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 6486 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6487 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 6488 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 6489 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 6490 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6491 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6492 | intel_print_rc6_info(dev_priv, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6493 | |
| 6494 | I915_WRITE(GEN6_RC_CONTROL, |
| 6495 | rc6_mask | |
| 6496 | GEN6_RC_CTL_EI_MODE(1) | |
| 6497 | GEN6_RC_CTL_HW_ENABLE); |
| 6498 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 6499 | /* Power down if completely idle for over 50ms */ |
| 6500 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6501 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6502 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 6503 | reset_rps(dev_priv, gen6_set_rps); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6504 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 6505 | rc6vids = 0; |
| 6506 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6507 | if (IS_GEN6(dev_priv) && ret) { |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 6508 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6509 | } 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] | 6510 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 6511 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 6512 | rc6vids &= 0xffff00; |
| 6513 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 6514 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 6515 | if (ret) |
| 6516 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 6517 | } |
| 6518 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 6519 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6520 | } |
| 6521 | |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 6522 | static void gen6_update_ring_freq(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6523 | { |
| 6524 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6525 | unsigned int gpu_freq; |
| 6526 | unsigned int max_ia_freq, min_ring_freq; |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6527 | unsigned int max_gpu_freq, min_gpu_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6528 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6529 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6530 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6531 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 6532 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6533 | policy = cpufreq_cpu_get(0); |
| 6534 | if (policy) { |
| 6535 | max_ia_freq = policy->cpuinfo.max_freq; |
| 6536 | cpufreq_cpu_put(policy); |
| 6537 | } else { |
| 6538 | /* |
| 6539 | * Default to measured freq if none found, PCU will ensure we |
| 6540 | * don't go over |
| 6541 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6542 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 6543 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6544 | |
| 6545 | /* Convert from kHz to MHz */ |
| 6546 | max_ia_freq /= 1000; |
| 6547 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 6548 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 6549 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 6550 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6551 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 6552 | if (IS_GEN9_BC(dev_priv)) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6553 | /* Convert GT frequency to 50 HZ units */ |
| 6554 | min_gpu_freq = dev_priv->rps.min_freq / GEN9_FREQ_SCALER; |
| 6555 | max_gpu_freq = dev_priv->rps.max_freq / GEN9_FREQ_SCALER; |
| 6556 | } else { |
| 6557 | min_gpu_freq = dev_priv->rps.min_freq; |
| 6558 | max_gpu_freq = dev_priv->rps.max_freq; |
| 6559 | } |
| 6560 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6561 | /* |
| 6562 | * For each potential GPU frequency, load a ring frequency we'd like |
| 6563 | * to use for memory access. We do this by specifying the IA frequency |
| 6564 | * the PCU should use as a reference to determine the ring frequency. |
| 6565 | */ |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6566 | for (gpu_freq = max_gpu_freq; gpu_freq >= min_gpu_freq; gpu_freq--) { |
| 6567 | int diff = max_gpu_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6568 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6569 | |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 6570 | if (IS_GEN9_BC(dev_priv)) { |
Akash Goel | 4c8c774 | 2015-06-29 14:50:20 +0530 | [diff] [blame] | 6571 | /* |
| 6572 | * ring_freq = 2 * GT. ring_freq is in 100MHz units |
| 6573 | * No floor required for ring frequency on SKL. |
| 6574 | */ |
| 6575 | ring_freq = gpu_freq; |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6576 | } else if (INTEL_INFO(dev_priv)->gen >= 8) { |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 6577 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 6578 | ring_freq = max(min_ring_freq, gpu_freq); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6579 | } else if (IS_HASWELL(dev_priv)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 6580 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6581 | ring_freq = max(min_ring_freq, ring_freq); |
| 6582 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 6583 | } else { |
| 6584 | /* On older processors, there is no separate ring |
| 6585 | * clock domain, so in order to boost the bandwidth |
| 6586 | * of the ring, we need to upclock the CPU (ia_freq). |
| 6587 | * |
| 6588 | * For GPU frequencies less than 750MHz, |
| 6589 | * just use the lowest ring freq. |
| 6590 | */ |
| 6591 | if (gpu_freq < min_freq) |
| 6592 | ia_freq = 800; |
| 6593 | else |
| 6594 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 6595 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 6596 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6597 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6598 | sandybridge_pcode_write(dev_priv, |
| 6599 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 6600 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 6601 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 6602 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6603 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 6604 | } |
| 6605 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 6606 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6607 | { |
| 6608 | u32 val, rp0; |
| 6609 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6610 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6611 | |
Imre Deak | 43b6799 | 2016-08-31 19:13:02 +0300 | [diff] [blame] | 6612 | switch (INTEL_INFO(dev_priv)->sseu.eu_total) { |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6613 | case 8: |
| 6614 | /* (2 * 4) config */ |
| 6615 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 6616 | break; |
| 6617 | case 12: |
| 6618 | /* (2 * 6) config */ |
| 6619 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 6620 | break; |
| 6621 | case 16: |
| 6622 | /* (2 * 8) config */ |
| 6623 | default: |
| 6624 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 6625 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 6626 | break; |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 6627 | } |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6628 | |
| 6629 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 6630 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6631 | return rp0; |
| 6632 | } |
| 6633 | |
| 6634 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 6635 | { |
| 6636 | u32 val, rpe; |
| 6637 | |
| 6638 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 6639 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 6640 | |
| 6641 | return rpe; |
| 6642 | } |
| 6643 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 6644 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 6645 | { |
| 6646 | u32 val, rp1; |
| 6647 | |
Jani Nikula | 5b5929c | 2015-10-07 11:17:46 +0300 | [diff] [blame] | 6648 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 6649 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 6650 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 6651 | return rp1; |
| 6652 | } |
| 6653 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 6654 | static u32 cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 6655 | { |
| 6656 | u32 val, rpn; |
| 6657 | |
| 6658 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 6659 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 6660 | FB_GFX_FREQ_FUSE_MASK); |
| 6661 | |
| 6662 | return rpn; |
| 6663 | } |
| 6664 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 6665 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 6666 | { |
| 6667 | u32 val, rp1; |
| 6668 | |
| 6669 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 6670 | |
| 6671 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 6672 | |
| 6673 | return rp1; |
| 6674 | } |
| 6675 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 6676 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6677 | { |
| 6678 | u32 val, rp0; |
| 6679 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 6680 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6681 | |
| 6682 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 6683 | /* Clamp to max */ |
| 6684 | rp0 = min_t(u32, rp0, 0xea); |
| 6685 | |
| 6686 | return rp0; |
| 6687 | } |
| 6688 | |
| 6689 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 6690 | { |
| 6691 | u32 val, rpe; |
| 6692 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 6693 | 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] | 6694 | 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] | 6695 | 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] | 6696 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 6697 | |
| 6698 | return rpe; |
| 6699 | } |
| 6700 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 6701 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6702 | { |
Imre Deak | 3614603 | 2014-12-04 18:39:35 +0200 | [diff] [blame] | 6703 | u32 val; |
| 6704 | |
| 6705 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
| 6706 | /* |
| 6707 | * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value |
| 6708 | * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on |
| 6709 | * a BYT-M B0 the above register contains 0xbf. Moreover when setting |
| 6710 | * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0 |
| 6711 | * to make sure it matches what Punit accepts. |
| 6712 | */ |
| 6713 | return max_t(u32, val, 0xc0); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6714 | } |
| 6715 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6716 | /* Check that the pctx buffer wasn't move under us. */ |
| 6717 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 6718 | { |
| 6719 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 6720 | |
| 6721 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 6722 | dev_priv->vlv_pctx->stolen->start); |
| 6723 | } |
| 6724 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6725 | |
| 6726 | /* Check that the pcbr address is not empty. */ |
| 6727 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 6728 | { |
| 6729 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 6730 | |
| 6731 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 6732 | } |
| 6733 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6734 | static void cherryview_setup_pctx(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6735 | { |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 6736 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 6737 | unsigned long pctx_paddr, paddr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6738 | u32 pcbr; |
| 6739 | int pctx_size = 32*1024; |
| 6740 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6741 | pcbr = I915_READ(VLV_PCBR); |
| 6742 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 6743 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6744 | paddr = (dev_priv->mm.stolen_base + |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 6745 | (ggtt->stolen_size - pctx_size)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6746 | |
| 6747 | pctx_paddr = (paddr & (~4095)); |
| 6748 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 6749 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 6750 | |
| 6751 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6752 | } |
| 6753 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6754 | static void valleyview_setup_pctx(struct drm_i915_private *dev_priv) |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6755 | { |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6756 | struct drm_i915_gem_object *pctx; |
| 6757 | unsigned long pctx_paddr; |
| 6758 | u32 pcbr; |
| 6759 | int pctx_size = 24*1024; |
| 6760 | |
| 6761 | pcbr = I915_READ(VLV_PCBR); |
| 6762 | if (pcbr) { |
| 6763 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 6764 | int pcbr_offset; |
| 6765 | |
| 6766 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 6767 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6768 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 6769 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6770 | pctx_size); |
| 6771 | goto out; |
| 6772 | } |
| 6773 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 6774 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 6775 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6776 | /* |
| 6777 | * From the Gunit register HAS: |
| 6778 | * The Gfx driver is expected to program this register and ensure |
| 6779 | * proper allocation within Gfx stolen memory. For example, this |
| 6780 | * register should be programmed such than the PCBR range does not |
| 6781 | * overlap with other ranges, such as the frame buffer, protected |
| 6782 | * memory, or any other relevant ranges. |
| 6783 | */ |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 6784 | pctx = i915_gem_object_create_stolen(dev_priv, pctx_size); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6785 | if (!pctx) { |
| 6786 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
Tvrtko Ursulin | ee50489 | 2016-02-11 10:27:30 +0000 | [diff] [blame] | 6787 | goto out; |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 6791 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 6792 | |
| 6793 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 6794 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 6795 | dev_priv->vlv_pctx = pctx; |
| 6796 | } |
| 6797 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6798 | static void valleyview_cleanup_pctx(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6799 | { |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6800 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 6801 | return; |
| 6802 | |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 6803 | i915_gem_object_put(dev_priv->vlv_pctx); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6804 | dev_priv->vlv_pctx = NULL; |
| 6805 | } |
| 6806 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 6807 | static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv) |
| 6808 | { |
| 6809 | dev_priv->rps.gpll_ref_freq = |
| 6810 | vlv_get_cck_clock(dev_priv, "GPLL ref", |
| 6811 | CCK_GPLL_CLOCK_CONTROL, |
| 6812 | dev_priv->czclk_freq); |
| 6813 | |
| 6814 | DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n", |
| 6815 | dev_priv->rps.gpll_ref_freq); |
| 6816 | } |
| 6817 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6818 | static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6819 | { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 6820 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6821 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6822 | valleyview_setup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6823 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 6824 | vlv_init_gpll_ref_freq(dev_priv); |
| 6825 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 6826 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 6827 | switch ((val >> 6) & 3) { |
| 6828 | case 0: |
| 6829 | case 1: |
| 6830 | dev_priv->mem_freq = 800; |
| 6831 | break; |
| 6832 | case 2: |
| 6833 | dev_priv->mem_freq = 1066; |
| 6834 | break; |
| 6835 | case 3: |
| 6836 | dev_priv->mem_freq = 1333; |
| 6837 | break; |
| 6838 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 6839 | 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] | 6840 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6841 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 6842 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 6843 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 6844 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6845 | dev_priv->rps.max_freq); |
| 6846 | |
| 6847 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 6848 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 6849 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6850 | dev_priv->rps.efficient_freq); |
| 6851 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 6852 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 6853 | DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 6854 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 6855 | dev_priv->rps.rp1_freq); |
| 6856 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6857 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 6858 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 6859 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6860 | dev_priv->rps.min_freq); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6861 | } |
| 6862 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6863 | static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6864 | { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 6865 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6866 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6867 | cherryview_setup_pctx(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6868 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 6869 | vlv_init_gpll_ref_freq(dev_priv); |
| 6870 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6871 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 6872 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6873 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 6874 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 6875 | switch ((val >> 2) & 0x7) { |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 6876 | case 3: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 6877 | dev_priv->mem_freq = 2000; |
| 6878 | break; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 6879 | default: |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 6880 | dev_priv->mem_freq = 1600; |
| 6881 | break; |
| 6882 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 6883 | 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] | 6884 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6885 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 6886 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 6887 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 6888 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6889 | dev_priv->rps.max_freq); |
| 6890 | |
| 6891 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 6892 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 6893 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6894 | dev_priv->rps.efficient_freq); |
| 6895 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 6896 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 6897 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 6898 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 6899 | dev_priv->rps.rp1_freq); |
| 6900 | |
Deepak S | 96676fe | 2016-08-12 18:46:41 +0530 | [diff] [blame] | 6901 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6902 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 6903 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6904 | dev_priv->rps.min_freq); |
| 6905 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 6906 | WARN_ONCE((dev_priv->rps.max_freq | |
| 6907 | dev_priv->rps.efficient_freq | |
| 6908 | dev_priv->rps.rp1_freq | |
| 6909 | dev_priv->rps.min_freq) & 1, |
| 6910 | "Odd GPU freq values\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6911 | } |
| 6912 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6913 | static void valleyview_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6914 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6915 | valleyview_cleanup_pctx(dev_priv); |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6916 | } |
| 6917 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6918 | static void cherryview_enable_rps(struct drm_i915_private *dev_priv) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6919 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6920 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6921 | enum intel_engine_id id; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6922 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6923 | |
| 6924 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 6925 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 6926 | gtfifodbg = I915_READ(GTFIFODBG) & ~(GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV | |
| 6927 | GT_FIFO_FREE_ENTRIES_CHV); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6928 | if (gtfifodbg) { |
| 6929 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 6930 | gtfifodbg); |
| 6931 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 6932 | } |
| 6933 | |
| 6934 | cherryview_check_pctx(dev_priv); |
| 6935 | |
| 6936 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 6937 | * 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] | 6938 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6939 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 6940 | /* Disable RC states. */ |
| 6941 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 6942 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6943 | /* 2a: Program RC6 thresholds.*/ |
| 6944 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 6945 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 6946 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 6947 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 6948 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 6949 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6950 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 6951 | |
Deepak S | f4f71c7 | 2015-03-28 15:23:35 +0530 | [diff] [blame] | 6952 | /* TO threshold set to 500 us ( 0x186 * 1.28 us) */ |
| 6953 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x186); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6954 | |
| 6955 | /* allows RC6 residency counter to work */ |
| 6956 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 6957 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 6958 | VLV_MEDIA_RC6_COUNT_EN | |
| 6959 | VLV_RENDER_RC6_COUNT_EN)); |
| 6960 | |
| 6961 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 6962 | pcbr = I915_READ(VLV_PCBR); |
| 6963 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6964 | /* 3: Enable RC6 */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 6965 | if ((intel_enable_rc6() & INTEL_RC6_ENABLE) && |
| 6966 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 6967 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6968 | |
| 6969 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 6970 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6971 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 6972 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6973 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 6974 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 6975 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 6976 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 6977 | |
| 6978 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 6979 | |
| 6980 | /* 5: Enable RPS */ |
| 6981 | I915_WRITE(GEN6_RP_CONTROL, |
| 6982 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 6983 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6984 | GEN6_RP_ENABLE | |
| 6985 | GEN6_RP_UP_BUSY_AVG | |
| 6986 | GEN6_RP_DOWN_IDLE_AVG); |
| 6987 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 6988 | /* Setting Fixed Bias */ |
| 6989 | val = VLV_OVERRIDE_EN | |
| 6990 | VLV_SOC_TDP_EN | |
| 6991 | CHV_BIAS_CPU_50_SOC_50; |
| 6992 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 6993 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 6994 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 6995 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 6996 | /* RPS code assumes GPLL is used */ |
| 6997 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 6998 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 6999 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7000 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7001 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7002 | reset_rps(dev_priv, valleyview_set_rps); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 7003 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7004 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 7005 | } |
| 7006 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7007 | static void valleyview_enable_rps(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7008 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7009 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7010 | enum intel_engine_id id; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 7011 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7012 | |
| 7013 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 7014 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7015 | valleyview_check_pctx(dev_priv); |
| 7016 | |
Ville Syrjälä | 297b32e | 2016-04-13 21:09:30 +0300 | [diff] [blame] | 7017 | gtfifodbg = I915_READ(GTFIFODBG); |
| 7018 | if (gtfifodbg) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 7019 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 7020 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7021 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 7022 | } |
| 7023 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 7024 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7025 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7026 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 7027 | /* Disable RC states. */ |
| 7028 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 7029 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 7030 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7031 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 7032 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 7033 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 7034 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 7035 | |
| 7036 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 7037 | |
| 7038 | I915_WRITE(GEN6_RP_CONTROL, |
| 7039 | GEN6_RP_MEDIA_TURBO | |
| 7040 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 7041 | GEN6_RP_MEDIA_IS_GFX | |
| 7042 | GEN6_RP_ENABLE | |
| 7043 | GEN6_RP_UP_BUSY_AVG | |
| 7044 | GEN6_RP_DOWN_IDLE_CONT); |
| 7045 | |
| 7046 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 7047 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 7048 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 7049 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7050 | for_each_engine(engine, dev_priv, id) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 7051 | I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7052 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 7053 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7054 | |
| 7055 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 7056 | I915_WRITE(VLV_COUNTER_CONTROL, |
Mika Kuoppala | 6b7f6aa | 2017-03-15 18:12:59 +0200 | [diff] [blame] | 7057 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 7058 | VLV_MEDIA_RC0_COUNT_EN | |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 7059 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 7060 | VLV_MEDIA_RC6_COUNT_EN | |
| 7061 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 7062 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7063 | if (intel_enable_rc6() & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 7064 | rc6_mode = GEN7_RC_CTL_TO_MODE | VLV_RC_CTL_CTX_RST_PARALLEL; |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 7065 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7066 | intel_print_rc6_info(dev_priv, rc6_mode); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 7067 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 7068 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7069 | |
Deepak S | 3ef6234 | 2015-04-29 08:36:24 +0530 | [diff] [blame] | 7070 | /* Setting Fixed Bias */ |
| 7071 | val = VLV_OVERRIDE_EN | |
| 7072 | VLV_SOC_TDP_EN | |
| 7073 | VLV_BIAS_CPU_125_SOC_875; |
| 7074 | vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val); |
| 7075 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 7076 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7077 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 7078 | /* RPS code assumes GPLL is used */ |
| 7079 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 7080 | |
Jani Nikula | 742f491 | 2015-09-03 11:16:09 +0300 | [diff] [blame] | 7081 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7082 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 7083 | |
Chris Wilson | 3a45b05 | 2016-07-13 09:10:32 +0100 | [diff] [blame] | 7084 | reset_rps(dev_priv, valleyview_set_rps); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7085 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 7086 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7087 | } |
| 7088 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7089 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 7090 | { |
| 7091 | unsigned long freq; |
| 7092 | int div = (vidfreq & 0x3f0000) >> 16; |
| 7093 | int post = (vidfreq & 0x3000) >> 12; |
| 7094 | int pre = (vidfreq & 0x7); |
| 7095 | |
| 7096 | if (!pre) |
| 7097 | return 0; |
| 7098 | |
| 7099 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 7100 | |
| 7101 | return freq; |
| 7102 | } |
| 7103 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7104 | static const struct cparams { |
| 7105 | u16 i; |
| 7106 | u16 t; |
| 7107 | u16 m; |
| 7108 | u16 c; |
| 7109 | } cparams[] = { |
| 7110 | { 1, 1333, 301, 28664 }, |
| 7111 | { 1, 1066, 294, 24460 }, |
| 7112 | { 1, 800, 294, 25192 }, |
| 7113 | { 0, 1333, 276, 27605 }, |
| 7114 | { 0, 1066, 276, 27605 }, |
| 7115 | { 0, 800, 231, 23784 }, |
| 7116 | }; |
| 7117 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7118 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7119 | { |
| 7120 | u64 total_count, diff, ret; |
| 7121 | u32 count1, count2, count3, m = 0, c = 0; |
| 7122 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 7123 | int i; |
| 7124 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7125 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7126 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7127 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7128 | |
| 7129 | /* Prevent division-by-zero if we are asking too fast. |
| 7130 | * Also, we don't get interesting results if we are polling |
| 7131 | * faster than once in 10ms, so just return the saved value |
| 7132 | * in such cases. |
| 7133 | */ |
| 7134 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7135 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7136 | |
| 7137 | count1 = I915_READ(DMIEC); |
| 7138 | count2 = I915_READ(DDREC); |
| 7139 | count3 = I915_READ(CSIEC); |
| 7140 | |
| 7141 | total_count = count1 + count2 + count3; |
| 7142 | |
| 7143 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7144 | if (total_count < dev_priv->ips.last_count1) { |
| 7145 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7146 | diff += total_count; |
| 7147 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7148 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7149 | } |
| 7150 | |
| 7151 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7152 | if (cparams[i].i == dev_priv->ips.c_m && |
| 7153 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7154 | m = cparams[i].m; |
| 7155 | c = cparams[i].c; |
| 7156 | break; |
| 7157 | } |
| 7158 | } |
| 7159 | |
| 7160 | diff = div_u64(diff, diff1); |
| 7161 | ret = ((m * diff) + c); |
| 7162 | ret = div_u64(ret, 10); |
| 7163 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7164 | dev_priv->ips.last_count1 = total_count; |
| 7165 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7166 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7167 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7168 | |
| 7169 | return ret; |
| 7170 | } |
| 7171 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7172 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 7173 | { |
| 7174 | unsigned long val; |
| 7175 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7176 | if (INTEL_INFO(dev_priv)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7177 | return 0; |
| 7178 | |
| 7179 | spin_lock_irq(&mchdev_lock); |
| 7180 | |
| 7181 | val = __i915_chipset_val(dev_priv); |
| 7182 | |
| 7183 | spin_unlock_irq(&mchdev_lock); |
| 7184 | |
| 7185 | return val; |
| 7186 | } |
| 7187 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7188 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 7189 | { |
| 7190 | unsigned long m, x, b; |
| 7191 | u32 tsfs; |
| 7192 | |
| 7193 | tsfs = I915_READ(TSFS); |
| 7194 | |
| 7195 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 7196 | x = I915_READ8(TR1); |
| 7197 | |
| 7198 | b = tsfs & TSFS_INTR_MASK; |
| 7199 | |
| 7200 | return ((m * x) / 127) - b; |
| 7201 | } |
| 7202 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7203 | static int _pxvid_to_vd(u8 pxvid) |
| 7204 | { |
| 7205 | if (pxvid == 0) |
| 7206 | return 0; |
| 7207 | |
| 7208 | if (pxvid >= 8 && pxvid < 31) |
| 7209 | pxvid = 31; |
| 7210 | |
| 7211 | return (pxvid + 2) * 125; |
| 7212 | } |
| 7213 | |
| 7214 | 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] | 7215 | { |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7216 | const int vd = _pxvid_to_vd(pxvid); |
| 7217 | const int vm = vd - 1125; |
| 7218 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7219 | if (INTEL_INFO(dev_priv)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 7220 | return vm > 0 ? vm : 0; |
| 7221 | |
| 7222 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7223 | } |
| 7224 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7225 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7226 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 7227 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7228 | u32 count; |
| 7229 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7230 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7231 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 7232 | now = ktime_get_raw_ns(); |
| 7233 | diffms = now - dev_priv->ips.last_time2; |
| 7234 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7235 | |
| 7236 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7237 | if (!diffms) |
| 7238 | return; |
| 7239 | |
| 7240 | count = I915_READ(GFXEC); |
| 7241 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7242 | if (count < dev_priv->ips.last_count2) { |
| 7243 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7244 | diff += count; |
| 7245 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7246 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7247 | } |
| 7248 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7249 | dev_priv->ips.last_count2 = count; |
| 7250 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7251 | |
| 7252 | /* More magic constants... */ |
| 7253 | diff = diff * 1181; |
| 7254 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7255 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7256 | } |
| 7257 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7258 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 7259 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7260 | if (INTEL_INFO(dev_priv)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7261 | return; |
| 7262 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7263 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7264 | |
| 7265 | __i915_update_gfx_val(dev_priv); |
| 7266 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7267 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7268 | } |
| 7269 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7270 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7271 | { |
| 7272 | unsigned long t, corr, state1, corr2, state2; |
| 7273 | u32 pxvid, ext_v; |
| 7274 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 7275 | lockdep_assert_held(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7276 | |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7277 | pxvid = I915_READ(PXVFREQ(dev_priv->rps.cur_freq)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7278 | pxvid = (pxvid >> 24) & 0x7f; |
| 7279 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 7280 | |
| 7281 | state1 = ext_v; |
| 7282 | |
| 7283 | t = i915_mch_val(dev_priv); |
| 7284 | |
| 7285 | /* Revel in the empirically derived constants */ |
| 7286 | |
| 7287 | /* Correction factor in 1/100000 units */ |
| 7288 | if (t > 80) |
| 7289 | corr = ((t * 2349) + 135940); |
| 7290 | else if (t >= 50) |
| 7291 | corr = ((t * 964) + 29317); |
| 7292 | else /* < 50 */ |
| 7293 | corr = ((t * 301) + 1004); |
| 7294 | |
| 7295 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 7296 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7297 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7298 | |
| 7299 | state2 = (corr2 * state1) / 10000; |
| 7300 | state2 /= 100; /* convert to mW */ |
| 7301 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7302 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7303 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7304 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7305 | } |
| 7306 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7307 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 7308 | { |
| 7309 | unsigned long val; |
| 7310 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7311 | if (INTEL_INFO(dev_priv)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7312 | return 0; |
| 7313 | |
| 7314 | spin_lock_irq(&mchdev_lock); |
| 7315 | |
| 7316 | val = __i915_gfx_val(dev_priv); |
| 7317 | |
| 7318 | spin_unlock_irq(&mchdev_lock); |
| 7319 | |
| 7320 | return val; |
| 7321 | } |
| 7322 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7323 | /** |
| 7324 | * i915_read_mch_val - return value for IPS use |
| 7325 | * |
| 7326 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 7327 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 7328 | */ |
| 7329 | unsigned long i915_read_mch_val(void) |
| 7330 | { |
| 7331 | struct drm_i915_private *dev_priv; |
| 7332 | unsigned long chipset_val, graphics_val, ret = 0; |
| 7333 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7334 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7335 | if (!i915_mch_dev) |
| 7336 | goto out_unlock; |
| 7337 | dev_priv = i915_mch_dev; |
| 7338 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 7339 | chipset_val = __i915_chipset_val(dev_priv); |
| 7340 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7341 | |
| 7342 | ret = chipset_val + graphics_val; |
| 7343 | |
| 7344 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7345 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7346 | |
| 7347 | return ret; |
| 7348 | } |
| 7349 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 7350 | |
| 7351 | /** |
| 7352 | * i915_gpu_raise - raise GPU frequency limit |
| 7353 | * |
| 7354 | * Raise the limit; IPS indicates we have thermal headroom. |
| 7355 | */ |
| 7356 | bool i915_gpu_raise(void) |
| 7357 | { |
| 7358 | struct drm_i915_private *dev_priv; |
| 7359 | bool ret = true; |
| 7360 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7361 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7362 | if (!i915_mch_dev) { |
| 7363 | ret = false; |
| 7364 | goto out_unlock; |
| 7365 | } |
| 7366 | dev_priv = i915_mch_dev; |
| 7367 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7368 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 7369 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7370 | |
| 7371 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7372 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7373 | |
| 7374 | return ret; |
| 7375 | } |
| 7376 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 7377 | |
| 7378 | /** |
| 7379 | * i915_gpu_lower - lower GPU frequency limit |
| 7380 | * |
| 7381 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 7382 | * frequency maximum. |
| 7383 | */ |
| 7384 | bool i915_gpu_lower(void) |
| 7385 | { |
| 7386 | struct drm_i915_private *dev_priv; |
| 7387 | bool ret = true; |
| 7388 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7389 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7390 | if (!i915_mch_dev) { |
| 7391 | ret = false; |
| 7392 | goto out_unlock; |
| 7393 | } |
| 7394 | dev_priv = i915_mch_dev; |
| 7395 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7396 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 7397 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7398 | |
| 7399 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7400 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7401 | |
| 7402 | return ret; |
| 7403 | } |
| 7404 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 7405 | |
| 7406 | /** |
| 7407 | * i915_gpu_busy - indicate GPU business to IPS |
| 7408 | * |
| 7409 | * Tell the IPS driver whether or not the GPU is busy. |
| 7410 | */ |
| 7411 | bool i915_gpu_busy(void) |
| 7412 | { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7413 | bool ret = false; |
| 7414 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7415 | spin_lock_irq(&mchdev_lock); |
Chris Wilson | dcff85c | 2016-08-05 10:14:11 +0100 | [diff] [blame] | 7416 | if (i915_mch_dev) |
| 7417 | ret = i915_mch_dev->gt.awake; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7418 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7419 | |
| 7420 | return ret; |
| 7421 | } |
| 7422 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 7423 | |
| 7424 | /** |
| 7425 | * i915_gpu_turbo_disable - disable graphics turbo |
| 7426 | * |
| 7427 | * Disable graphics turbo by resetting the max frequency and setting the |
| 7428 | * current frequency to the default. |
| 7429 | */ |
| 7430 | bool i915_gpu_turbo_disable(void) |
| 7431 | { |
| 7432 | struct drm_i915_private *dev_priv; |
| 7433 | bool ret = true; |
| 7434 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7435 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7436 | if (!i915_mch_dev) { |
| 7437 | ret = false; |
| 7438 | goto out_unlock; |
| 7439 | } |
| 7440 | dev_priv = i915_mch_dev; |
| 7441 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7442 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7443 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 7444 | if (!ironlake_set_drps(dev_priv, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7445 | ret = false; |
| 7446 | |
| 7447 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7448 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7449 | |
| 7450 | return ret; |
| 7451 | } |
| 7452 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 7453 | |
| 7454 | /** |
| 7455 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 7456 | * IPS got loaded first. |
| 7457 | * |
| 7458 | * This awkward dance is so that neither module has to depend on the |
| 7459 | * other in order for IPS to do the appropriate communication of |
| 7460 | * GPU turbo limits to i915. |
| 7461 | */ |
| 7462 | static void |
| 7463 | ips_ping_for_i915_load(void) |
| 7464 | { |
| 7465 | void (*link)(void); |
| 7466 | |
| 7467 | link = symbol_get(ips_link_to_i915_driver); |
| 7468 | if (link) { |
| 7469 | link(); |
| 7470 | symbol_put(ips_link_to_i915_driver); |
| 7471 | } |
| 7472 | } |
| 7473 | |
| 7474 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 7475 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 7476 | /* We only register the i915 ips part with intel-ips once everything is |
| 7477 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7478 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7479 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7480 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7481 | |
| 7482 | ips_ping_for_i915_load(); |
| 7483 | } |
| 7484 | |
| 7485 | void intel_gpu_ips_teardown(void) |
| 7486 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7487 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7488 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 7489 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 7490 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 7491 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7492 | static void intel_init_emon(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7493 | { |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7494 | u32 lcfuse; |
| 7495 | u8 pxw[16]; |
| 7496 | int i; |
| 7497 | |
| 7498 | /* Disable to program */ |
| 7499 | I915_WRITE(ECR, 0); |
| 7500 | POSTING_READ(ECR); |
| 7501 | |
| 7502 | /* Program energy weights for various events */ |
| 7503 | I915_WRITE(SDEW, 0x15040d00); |
| 7504 | I915_WRITE(CSIEW0, 0x007f0000); |
| 7505 | I915_WRITE(CSIEW1, 0x1e220004); |
| 7506 | I915_WRITE(CSIEW2, 0x04000004); |
| 7507 | |
| 7508 | for (i = 0; i < 5; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7509 | I915_WRITE(PEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7510 | for (i = 0; i < 3; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7511 | I915_WRITE(DEW(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7512 | |
| 7513 | /* Program P-state weights to account for frequency power adjustment */ |
| 7514 | for (i = 0; i < 16; i++) { |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7515 | u32 pxvidfreq = I915_READ(PXVFREQ(i)); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7516 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 7517 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 7518 | PXVFREQ_PX_SHIFT; |
| 7519 | unsigned long val; |
| 7520 | |
| 7521 | val = vid * vid; |
| 7522 | val *= (freq / 1000); |
| 7523 | val *= 255; |
| 7524 | val /= (127*127*900); |
| 7525 | if (val > 0xff) |
| 7526 | DRM_ERROR("bad pxval: %ld\n", val); |
| 7527 | pxw[i] = val; |
| 7528 | } |
| 7529 | /* Render standby states get 0 weight */ |
| 7530 | pxw[14] = 0; |
| 7531 | pxw[15] = 0; |
| 7532 | |
| 7533 | for (i = 0; i < 4; i++) { |
| 7534 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 7535 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7536 | I915_WRITE(PXW(i), val); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7537 | } |
| 7538 | |
| 7539 | /* Adjust magic regs to magic values (more experimental results) */ |
| 7540 | I915_WRITE(OGW0, 0); |
| 7541 | I915_WRITE(OGW1, 0); |
| 7542 | I915_WRITE(EG0, 0x00007f00); |
| 7543 | I915_WRITE(EG1, 0x0000000e); |
| 7544 | I915_WRITE(EG2, 0x000e0000); |
| 7545 | I915_WRITE(EG3, 0x68000300); |
| 7546 | I915_WRITE(EG4, 0x42000000); |
| 7547 | I915_WRITE(EG5, 0x00140031); |
| 7548 | I915_WRITE(EG6, 0); |
| 7549 | I915_WRITE(EG7, 0); |
| 7550 | |
| 7551 | for (i = 0; i < 8; i++) |
Ville Syrjälä | 616847e | 2015-09-18 20:03:19 +0300 | [diff] [blame] | 7552 | I915_WRITE(PXWL(i), 0); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7553 | |
| 7554 | /* Enable PMON + select events */ |
| 7555 | I915_WRITE(ECR, 0x80000019); |
| 7556 | |
| 7557 | lcfuse = I915_READ(LCFUSE02); |
| 7558 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 7559 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 7560 | } |
| 7561 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7562 | void intel_init_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7563 | { |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 7564 | /* |
| 7565 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 7566 | * requirement. |
| 7567 | */ |
| 7568 | if (!i915.enable_rc6) { |
| 7569 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 7570 | intel_runtime_pm_get(dev_priv); |
| 7571 | } |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 7572 | |
Chris Wilson | b5163db | 2016-08-10 13:58:24 +0100 | [diff] [blame] | 7573 | mutex_lock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7574 | mutex_lock(&dev_priv->rps.hw_lock); |
| 7575 | |
| 7576 | /* Initialize RPS limits (for userspace) */ |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7577 | if (IS_CHERRYVIEW(dev_priv)) |
| 7578 | cherryview_init_gt_powersave(dev_priv); |
| 7579 | else if (IS_VALLEYVIEW(dev_priv)) |
| 7580 | valleyview_init_gt_powersave(dev_priv); |
Chris Wilson | 2a13ae7 | 2016-08-02 11:15:27 +0100 | [diff] [blame] | 7581 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7582 | gen6_init_rps_frequencies(dev_priv); |
| 7583 | |
| 7584 | /* Derive initial user preferences/limits from the hardware limits */ |
| 7585 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 7586 | dev_priv->rps.cur_freq = dev_priv->rps.idle_freq; |
| 7587 | |
| 7588 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 7589 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 7590 | |
| 7591 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 7592 | dev_priv->rps.min_freq_softlimit = |
| 7593 | max_t(int, |
| 7594 | dev_priv->rps.efficient_freq, |
| 7595 | intel_freq_opcode(dev_priv, 450)); |
| 7596 | |
Chris Wilson | 99ac961 | 2016-07-13 09:10:34 +0100 | [diff] [blame] | 7597 | /* After setting max-softlimit, find the overclock max freq */ |
| 7598 | if (IS_GEN6(dev_priv) || |
| 7599 | IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
| 7600 | u32 params = 0; |
| 7601 | |
| 7602 | sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, ¶ms); |
| 7603 | if (params & BIT(31)) { /* OC supported */ |
| 7604 | DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n", |
| 7605 | (dev_priv->rps.max_freq & 0xff) * 50, |
| 7606 | (params & 0xff) * 50); |
| 7607 | dev_priv->rps.max_freq = params & 0xff; |
| 7608 | } |
| 7609 | } |
| 7610 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 7611 | /* Finally allow us to boost to max by default */ |
| 7612 | dev_priv->rps.boost_freq = dev_priv->rps.max_freq; |
| 7613 | |
Chris Wilson | 773ea9a | 2016-07-13 09:10:33 +0100 | [diff] [blame] | 7614 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | b5163db | 2016-08-10 13:58:24 +0100 | [diff] [blame] | 7615 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7616 | |
| 7617 | intel_autoenable_gt_powersave(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7618 | } |
| 7619 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7620 | void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv) |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7621 | { |
Ville Syrjälä | 8dac1e1 | 2016-08-02 14:07:33 +0300 | [diff] [blame] | 7622 | if (IS_VALLEYVIEW(dev_priv)) |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7623 | valleyview_cleanup_gt_powersave(dev_priv); |
Imre Deak | b268c69 | 2015-12-15 20:10:31 +0200 | [diff] [blame] | 7624 | |
| 7625 | if (!i915.enable_rc6) |
| 7626 | intel_runtime_pm_put(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 7627 | } |
| 7628 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7629 | /** |
| 7630 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 7631 | * @dev_priv: i915 device |
| 7632 | * |
| 7633 | * We don't want to disable RC6 or other features here, we just want |
| 7634 | * to make sure any work we've queued has finished and won't bother |
| 7635 | * us while we're suspended. |
| 7636 | */ |
| 7637 | void intel_suspend_gt_powersave(struct drm_i915_private *dev_priv) |
| 7638 | { |
| 7639 | if (INTEL_GEN(dev_priv) < 6) |
| 7640 | return; |
| 7641 | |
| 7642 | if (cancel_delayed_work_sync(&dev_priv->rps.autoenable_work)) |
| 7643 | intel_runtime_pm_put(dev_priv); |
| 7644 | |
| 7645 | /* gen6_rps_idle() will be called later to disable interrupts */ |
| 7646 | } |
| 7647 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7648 | void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv) |
| 7649 | { |
| 7650 | dev_priv->rps.enabled = true; /* force disabling */ |
| 7651 | intel_disable_gt_powersave(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7652 | |
| 7653 | gen6_reset_rps_interrupts(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 7654 | } |
| 7655 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7656 | void intel_disable_gt_powersave(struct drm_i915_private *dev_priv) |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 7657 | { |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7658 | if (!READ_ONCE(dev_priv->rps.enabled)) |
| 7659 | return; |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 7660 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7661 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7662 | |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7663 | if (INTEL_GEN(dev_priv) >= 9) { |
| 7664 | gen9_disable_rc6(dev_priv); |
| 7665 | gen9_disable_rps(dev_priv); |
| 7666 | } else if (IS_CHERRYVIEW(dev_priv)) { |
| 7667 | cherryview_disable_rps(dev_priv); |
| 7668 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 7669 | valleyview_disable_rps(dev_priv); |
| 7670 | } else if (INTEL_GEN(dev_priv) >= 6) { |
| 7671 | gen6_disable_rps(dev_priv); |
| 7672 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 7673 | ironlake_disable_drps(dev_priv); |
| 7674 | } |
| 7675 | |
| 7676 | dev_priv->rps.enabled = false; |
| 7677 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 7678 | } |
| 7679 | |
| 7680 | void intel_enable_gt_powersave(struct drm_i915_private *dev_priv) |
| 7681 | { |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7682 | /* We shouldn't be disabling as we submit, so this should be less |
| 7683 | * racy than it appears! |
| 7684 | */ |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7685 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 7686 | return; |
| 7687 | |
| 7688 | /* Powersaving is controlled by the host when inside a VM */ |
| 7689 | if (intel_vgpu_active(dev_priv)) |
| 7690 | return; |
| 7691 | |
| 7692 | mutex_lock(&dev_priv->rps.hw_lock); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 7693 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7694 | if (IS_CHERRYVIEW(dev_priv)) { |
| 7695 | cherryview_enable_rps(dev_priv); |
| 7696 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 7697 | valleyview_enable_rps(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7698 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7699 | gen9_enable_rc6(dev_priv); |
| 7700 | gen9_enable_rps(dev_priv); |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 7701 | if (IS_GEN9_BC(dev_priv)) |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7702 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7703 | } else if (IS_BROADWELL(dev_priv)) { |
| 7704 | gen8_enable_rps(dev_priv); |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7705 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7706 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 7707 | gen6_enable_rps(dev_priv); |
Chris Wilson | fb7404e | 2016-07-13 09:10:38 +0100 | [diff] [blame] | 7708 | gen6_update_ring_freq(dev_priv); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7709 | } else if (IS_IRONLAKE_M(dev_priv)) { |
| 7710 | ironlake_enable_drps(dev_priv); |
| 7711 | intel_init_emon(dev_priv); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 7712 | } |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 7713 | |
| 7714 | WARN_ON(dev_priv->rps.max_freq < dev_priv->rps.min_freq); |
| 7715 | WARN_ON(dev_priv->rps.idle_freq > dev_priv->rps.max_freq); |
| 7716 | |
| 7717 | WARN_ON(dev_priv->rps.efficient_freq < dev_priv->rps.min_freq); |
| 7718 | WARN_ON(dev_priv->rps.efficient_freq > dev_priv->rps.max_freq); |
| 7719 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7720 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7721 | mutex_unlock(&dev_priv->rps.hw_lock); |
Chris Wilson | b7137e0 | 2016-07-13 09:10:37 +0100 | [diff] [blame] | 7722 | } |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 7723 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7724 | static void __intel_autoenable_gt_powersave(struct work_struct *work) |
| 7725 | { |
| 7726 | struct drm_i915_private *dev_priv = |
| 7727 | container_of(work, typeof(*dev_priv), rps.autoenable_work.work); |
| 7728 | struct intel_engine_cs *rcs; |
| 7729 | struct drm_i915_gem_request *req; |
| 7730 | |
| 7731 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 7732 | goto out; |
| 7733 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 7734 | rcs = dev_priv->engine[RCS]; |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 7735 | if (rcs->last_retired_context) |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7736 | goto out; |
| 7737 | |
| 7738 | if (!rcs->init_context) |
| 7739 | goto out; |
| 7740 | |
| 7741 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 7742 | |
| 7743 | req = i915_gem_request_alloc(rcs, dev_priv->kernel_context); |
| 7744 | if (IS_ERR(req)) |
| 7745 | goto unlock; |
| 7746 | |
| 7747 | if (!i915.enable_execlists && i915_switch_context(req) == 0) |
| 7748 | rcs->init_context(req); |
| 7749 | |
| 7750 | /* Mark the device busy, calling intel_enable_gt_powersave() */ |
Chris Wilson | e642c85 | 2017-03-17 11:47:09 +0000 | [diff] [blame] | 7751 | i915_add_request(req); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7752 | |
| 7753 | unlock: |
| 7754 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 7755 | out: |
| 7756 | intel_runtime_pm_put(dev_priv); |
| 7757 | } |
| 7758 | |
| 7759 | void intel_autoenable_gt_powersave(struct drm_i915_private *dev_priv) |
| 7760 | { |
| 7761 | if (READ_ONCE(dev_priv->rps.enabled)) |
| 7762 | return; |
| 7763 | |
| 7764 | if (IS_IRONLAKE_M(dev_priv)) { |
| 7765 | ironlake_enable_drps(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7766 | intel_init_emon(dev_priv); |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 7767 | } else if (INTEL_INFO(dev_priv)->gen >= 6) { |
| 7768 | /* |
| 7769 | * PCU communication is slow and this doesn't need to be |
| 7770 | * done at any specific time, so do this out of our fast path |
| 7771 | * to make resume and init faster. |
| 7772 | * |
| 7773 | * We depend on the HW RC6 power context save/restore |
| 7774 | * mechanism when entering D3 through runtime PM suspend. So |
| 7775 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 7776 | * get here via the driver load/system resume/runtime resume |
| 7777 | * paths, so the _noresume version is enough (and in case of |
| 7778 | * runtime resume it's necessary). |
| 7779 | */ |
| 7780 | if (queue_delayed_work(dev_priv->wq, |
| 7781 | &dev_priv->rps.autoenable_work, |
| 7782 | round_jiffies_up_relative(HZ))) |
| 7783 | intel_runtime_pm_get_noresume(dev_priv); |
| 7784 | } |
| 7785 | } |
| 7786 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7787 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7788 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7789 | /* |
| 7790 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7791 | * gating for the panel power sequencer or it will fail to |
| 7792 | * start up when no ports are active. |
| 7793 | */ |
| 7794 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 7795 | } |
| 7796 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7797 | 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] | 7798 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7799 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7800 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7801 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7802 | I915_WRITE(DSPCNTR(pipe), |
| 7803 | I915_READ(DSPCNTR(pipe)) | |
| 7804 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7805 | |
| 7806 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 7807 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7808 | } |
| 7809 | } |
| 7810 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7811 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7812 | { |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7813 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 7814 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 7815 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 7816 | |
| 7817 | /* |
| 7818 | * Don't touch WM1S_LP_EN here. |
| 7819 | * Doing so could cause underruns. |
| 7820 | */ |
| 7821 | } |
| 7822 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7823 | static void ironlake_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7824 | { |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7825 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7826 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 7827 | /* |
| 7828 | * Required for FBC |
| 7829 | * WaFbcDisableDpfcClockGating:ilk |
| 7830 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7831 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 7832 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 7833 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7834 | |
| 7835 | I915_WRITE(PCH_3DCGDIS0, |
| 7836 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 7837 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 7838 | I915_WRITE(PCH_3DCGDIS1, |
| 7839 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 7840 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7841 | /* |
| 7842 | * According to the spec the following bits should be set in |
| 7843 | * order to enable memory self-refresh |
| 7844 | * The bit 22/21 of 0x42004 |
| 7845 | * The bit 5 of 0x42020 |
| 7846 | * The bit 15 of 0x45000 |
| 7847 | */ |
| 7848 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 7849 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 7850 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7851 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7852 | I915_WRITE(DISP_ARB_CTL, |
| 7853 | (I915_READ(DISP_ARB_CTL) | |
| 7854 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7855 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7856 | ilk_init_lp_watermarks(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7857 | |
| 7858 | /* |
| 7859 | * Based on the document from hardware guys the following bits |
| 7860 | * should be set unconditionally in order to enable FBC. |
| 7861 | * The bit 22 of 0x42000 |
| 7862 | * The bit 22 of 0x42004 |
| 7863 | * The bit 7,8,9 of 0x42020. |
| 7864 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7865 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7866 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7867 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 7868 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 7869 | ILK_FBCQ_DIS); |
| 7870 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 7871 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 7872 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7873 | } |
| 7874 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7875 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 7876 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7877 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 7878 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 7879 | ILK_ELPIN_409_SELECT); |
| 7880 | I915_WRITE(_3D_CHICKEN2, |
| 7881 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 7882 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 7883 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7884 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 7885 | I915_WRITE(CACHE_MODE_0, |
| 7886 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7887 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7888 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 7889 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 7890 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7891 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 7892 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7893 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7894 | } |
| 7895 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7896 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7897 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7898 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7899 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7900 | |
| 7901 | /* |
| 7902 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7903 | * gating for the panel power sequencer or it will fail to |
| 7904 | * start up when no ports are active. |
| 7905 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 7906 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 7907 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 7908 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7909 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 7910 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 7911 | /* The below fixes the weird display corruption, a few pixels shifted |
| 7912 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 7913 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7914 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7915 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 7916 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 7917 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7918 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7919 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7920 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 7921 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 7922 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7923 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 7924 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7925 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7926 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7927 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 7928 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 7929 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7930 | } |
| 7931 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7932 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7933 | { |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7934 | uint32_t tmp; |
| 7935 | |
| 7936 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 7937 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 7938 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 7939 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7940 | } |
| 7941 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7942 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7943 | { |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7944 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7945 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7946 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7947 | |
| 7948 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 7949 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 7950 | ILK_ELPIN_409_SELECT); |
| 7951 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7952 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 7953 | I915_WRITE(_3D_CHICKEN, |
| 7954 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 7955 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7956 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 7957 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 7958 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 7959 | /* |
| 7960 | * BSpec recoomends 8x4 when MSAA is used, |
| 7961 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 7962 | * |
| 7963 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 7964 | * disable bit, which we don't touch here, but it's good |
| 7965 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 7966 | */ |
| 7967 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 7968 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 7969 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7970 | ilk_init_lp_watermarks(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7971 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7972 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 7973 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7974 | |
| 7975 | I915_WRITE(GEN6_UCGCTL1, |
| 7976 | I915_READ(GEN6_UCGCTL1) | |
| 7977 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 7978 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 7979 | |
| 7980 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 7981 | * gating disable must be set. Failure to set it results in |
| 7982 | * flickering pixels due to Z write ordering failures after |
| 7983 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 7984 | * Sanctuary and Tropics, and apparently anything else with |
| 7985 | * alpha test or pixel discard. |
| 7986 | * |
| 7987 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 7988 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7989 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 7990 | * WaDisableRCCUnitClockGating:snb |
| 7991 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7992 | */ |
| 7993 | I915_WRITE(GEN6_UCGCTL2, |
| 7994 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 7995 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 7996 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 7997 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 7998 | I915_WRITE(_3D_CHICKEN3, |
| 7999 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8000 | |
| 8001 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 8002 | * Bspec says: |
| 8003 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 8004 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 8005 | */ |
| 8006 | I915_WRITE(_3D_CHICKEN3, |
| 8007 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 8008 | |
| 8009 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8010 | * According to the spec the following bits should be |
| 8011 | * set in order to enable memory self-refresh and fbc: |
| 8012 | * The bit21 and bit22 of 0x42000 |
| 8013 | * The bit21 and bit22 of 0x42004 |
| 8014 | * The bit5 and bit7 of 0x42020 |
| 8015 | * The bit14 of 0x70180 |
| 8016 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 8017 | * |
| 8018 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8019 | */ |
| 8020 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 8021 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 8022 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 8023 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 8024 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 8025 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8026 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 8027 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 8028 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 8029 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8030 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8031 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 8032 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8033 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8034 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8035 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8036 | } |
| 8037 | |
| 8038 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 8039 | { |
| 8040 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 8041 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8042 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8043 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 8044 | * |
| 8045 | * This actually overrides the dispatch |
| 8046 | * mode for all thread types. |
| 8047 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8048 | reg &= ~GEN7_FF_SCHED_MASK; |
| 8049 | reg |= GEN7_FF_TS_SCHED_HW; |
| 8050 | reg |= GEN7_FF_VS_SCHED_HW; |
| 8051 | reg |= GEN7_FF_DS_SCHED_HW; |
| 8052 | |
| 8053 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 8054 | } |
| 8055 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8056 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8057 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8058 | /* |
| 8059 | * TODO: this bit should only be enabled when really needed, then |
| 8060 | * disabled when not needed anymore in order to save power. |
| 8061 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8062 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8063 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 8064 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 8065 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8066 | |
| 8067 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 8068 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 8069 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 8070 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 8071 | } |
| 8072 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8073 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8074 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8075 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8076 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8077 | |
| 8078 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8079 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8080 | } |
| 8081 | } |
| 8082 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8083 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 8084 | int general_prio_credits, |
| 8085 | int high_prio_credits) |
| 8086 | { |
| 8087 | u32 misccpctl; |
| 8088 | |
| 8089 | /* WaTempDisableDOPClkGating:bdw */ |
| 8090 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 8091 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 8092 | |
| 8093 | I915_WRITE(GEN8_L3SQCREG1, |
| 8094 | L3_GENERAL_PRIO_CREDITS(general_prio_credits) | |
| 8095 | L3_HIGH_PRIO_CREDITS(high_prio_credits)); |
| 8096 | |
| 8097 | /* |
| 8098 | * Wait at least 100 clocks before re-enabling clock gating. |
| 8099 | * See the definition of L3SQCREG1 in BSpec. |
| 8100 | */ |
| 8101 | POSTING_READ(GEN8_L3SQCREG1); |
| 8102 | udelay(1); |
| 8103 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 8104 | } |
| 8105 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8106 | static void kabylake_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8107 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8108 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8109 | |
| 8110 | /* WaDisableSDEUnitClockGating:kbl */ |
| 8111 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 8112 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8113 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 8114 | |
| 8115 | /* WaDisableGamClockGating:kbl */ |
| 8116 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
| 8117 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 8118 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8119 | |
| 8120 | /* WaFbcNukeOnHostModify:kbl */ |
| 8121 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8122 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8123 | } |
| 8124 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8125 | static void skylake_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8126 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8127 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 8128 | |
| 8129 | /* WAC6entrylatency:skl */ |
| 8130 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 8131 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 8132 | |
| 8133 | /* WaFbcNukeOnHostModify:skl */ |
| 8134 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 8135 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8136 | } |
| 8137 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8138 | static void broadwell_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8139 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 8140 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8141 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8142 | ilk_init_lp_watermarks(dev_priv); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 8143 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8144 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 8145 | 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] | 8146 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8147 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 8148 | I915_WRITE(CHICKEN_PAR1_1, |
| 8149 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 8150 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8151 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 8152 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 8153 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 8154 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 8155 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 8156 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 8157 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 8158 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 8159 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 8160 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8161 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 8162 | ~(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] | 8163 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 8164 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 8165 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 8166 | |
| 8167 | /* WaDisableSDEUnitClockGating:bdw */ |
| 8168 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8169 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 8170 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8171 | /* WaProgramL3SqcReg1Default:bdw */ |
| 8172 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 8173 | |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8174 | /* |
| 8175 | * WaGttCachingOffByDefault:bdw |
| 8176 | * GTT cache may not work with big pages, so if those |
| 8177 | * are ever enabled GTT cache may need to be disabled. |
| 8178 | */ |
| 8179 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
| 8180 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 8181 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 8182 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 8183 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 8184 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8185 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 8186 | |
| 8187 | /* WaDisableDopClockGating:bdw |
| 8188 | * |
| 8189 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 8190 | * clock gating. |
| 8191 | */ |
| 8192 | I915_WRITE(GEN6_UCGCTL1, |
| 8193 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 8194 | } |
| 8195 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8196 | static void haswell_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8197 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8198 | ilk_init_lp_watermarks(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8199 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 8200 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 8201 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 8202 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 8203 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 8204 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8205 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8206 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8207 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8208 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8209 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 8210 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 8211 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8212 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8213 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8214 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 8215 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8216 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 8217 | /* enable HiZ Raw Stall Optimization */ |
| 8218 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 8219 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 8220 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8221 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8222 | I915_WRITE(CACHE_MODE_1, |
| 8223 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 8224 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8225 | /* |
| 8226 | * BSpec recommends 8x4 when MSAA is used, |
| 8227 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8228 | * |
| 8229 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8230 | * disable bit, which we don't touch here, but it's good |
| 8231 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8232 | */ |
| 8233 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8234 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 8235 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 8236 | /* WaSampleCChickenBitEnable:hsw */ |
| 8237 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 8238 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 8239 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8240 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 8241 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 8242 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 8243 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 8244 | I915_WRITE(CHICKEN_PAR1_1, |
| 8245 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 8246 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8247 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 8248 | } |
| 8249 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8250 | static void ivybridge_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8251 | { |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8252 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8253 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8254 | ilk_init_lp_watermarks(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8255 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 8256 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8257 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8258 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 8259 | I915_WRITE(_3D_CHICKEN3, |
| 8260 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 8261 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8262 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8263 | I915_WRITE(IVB_CHICKEN3, |
| 8264 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 8265 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 8266 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8267 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8268 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8269 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 8270 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8271 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8272 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 8273 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8274 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8275 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8276 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 8277 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 8278 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8279 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8280 | I915_WRITE(GEN7_L3CNTLREG1, |
| 8281 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 8282 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8283 | GEN7_WA_L3_CHICKEN_MODE); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8284 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8285 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8286 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 8287 | else { |
| 8288 | /* must write both registers */ |
| 8289 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8290 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8291 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 8292 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 8293 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8294 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8295 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 8296 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 8297 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 8298 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 8299 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8300 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8301 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8302 | */ |
| 8303 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 8304 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8305 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8306 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8307 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8308 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8309 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8310 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8311 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8312 | |
| 8313 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 8314 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 8315 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 8316 | /* enable HiZ Raw Stall Optimization */ |
| 8317 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 8318 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 8319 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 8320 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8321 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 8322 | I915_WRITE(CACHE_MODE_1, |
| 8323 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8324 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8325 | /* |
| 8326 | * BSpec recommends 8x4 when MSAA is used, |
| 8327 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 8328 | * |
| 8329 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8330 | * disable bit, which we don't touch here, but it's good |
| 8331 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8332 | */ |
| 8333 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 8334 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 8335 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 8336 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 8337 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 8338 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 8339 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 8340 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8341 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8342 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 8343 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8344 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8345 | } |
| 8346 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8347 | static void valleyview_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8348 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8349 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 8350 | I915_WRITE(_3D_CHICKEN3, |
| 8351 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 8352 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8353 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8354 | I915_WRITE(IVB_CHICKEN3, |
| 8355 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 8356 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 8357 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 8358 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8359 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8360 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 8361 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 8362 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 8363 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8364 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 8365 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8366 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8367 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 8368 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 8369 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 8370 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8371 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 8372 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 8373 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 8374 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8375 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8376 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 8377 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 8378 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 8379 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 8380 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 8381 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 8382 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8383 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8384 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8385 | */ |
| 8386 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 8387 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 8388 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 8389 | /* WaDisableL3Bank2xClockGate:vlv |
| 8390 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 8391 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 8392 | I915_WRITE(GEN7_UCGCTL4, |
| 8393 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 8394 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 8395 | /* |
| 8396 | * BSpec says this must be set, even though |
| 8397 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 8398 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 8399 | I915_WRITE(CACHE_MODE_1, |
| 8400 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 8401 | |
| 8402 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 8403 | * BSpec recommends 8x4 when MSAA is used, |
| 8404 | * however in practice 16x4 seems fastest. |
| 8405 | * |
| 8406 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 8407 | * disable bit, which we don't touch here, but it's good |
| 8408 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 8409 | */ |
| 8410 | I915_WRITE(GEN7_GT_MODE, |
| 8411 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 8412 | |
| 8413 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 8414 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 8415 | * This is the hardware default actually. |
| 8416 | */ |
| 8417 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 8418 | |
| 8419 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 8420 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 8421 | * Disable clock gating on th GCFG unit to prevent a delay |
| 8422 | * in the reporting of vblank events. |
| 8423 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 8424 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8425 | } |
| 8426 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8427 | static void cherryview_init_clock_gating(struct drm_i915_private *dev_priv) |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 8428 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 8429 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 8430 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 8431 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 8432 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 8433 | ~(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] | 8434 | |
| 8435 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 8436 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 8437 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 8438 | |
| 8439 | /* WaDisableCSUnitClockGating:chv */ |
| 8440 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 8441 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 8442 | |
| 8443 | /* WaDisableSDEUnitClockGating:chv */ |
| 8444 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 8445 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8446 | |
| 8447 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 8448 | * WaProgramL3SqcReg1Default:chv |
| 8449 | * See gfxspecs/Related Documents/Performance Guide/ |
| 8450 | * LSQC Setting Recommendations. |
| 8451 | */ |
| 8452 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
| 8453 | |
| 8454 | /* |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 8455 | * GTT cache may not work with big pages, so if those |
| 8456 | * are ever enabled GTT cache may need to be disabled. |
| 8457 | */ |
| 8458 | I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 8459 | } |
| 8460 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8461 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8462 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8463 | uint32_t dspclk_gate; |
| 8464 | |
| 8465 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 8466 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 8467 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 8468 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 8469 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 8470 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 8471 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 8472 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8473 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8474 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 8475 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 8476 | |
| 8477 | /* WaDisableRenderCachePipelinedFlush */ |
| 8478 | I915_WRITE(CACHE_MODE_0, |
| 8479 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 8480 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8481 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 8482 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 8483 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8484 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8485 | } |
| 8486 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8487 | static void crestline_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8488 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8489 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 8490 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 8491 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 8492 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 8493 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 8494 | I915_WRITE(MI_ARB_STATE, |
| 8495 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8496 | |
| 8497 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 8498 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8499 | } |
| 8500 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8501 | static void broadwater_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8502 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8503 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 8504 | I965_RCC_CLOCK_GATE_DISABLE | |
| 8505 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 8506 | I965_ISC_CLOCK_GATE_DISABLE | |
| 8507 | I965_FBC_CLOCK_GATE_DISABLE); |
| 8508 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 8509 | I915_WRITE(MI_ARB_STATE, |
| 8510 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 8511 | |
| 8512 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 8513 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8514 | } |
| 8515 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8516 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8517 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8518 | u32 dstate = I915_READ(D_STATE); |
| 8519 | |
| 8520 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 8521 | DSTATE_DOT_CLOCK_GATING; |
| 8522 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 8523 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8524 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 8525 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 8526 | |
| 8527 | /* IIR "flip pending" means done if this bit is set */ |
| 8528 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 8529 | |
| 8530 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 8531 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 8532 | |
| 8533 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 8534 | 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] | 8535 | |
| 8536 | I915_WRITE(MI_ARB_STATE, |
| 8537 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8538 | } |
| 8539 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8540 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8541 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8542 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 8543 | |
| 8544 | /* interrupts should cause a wake up from C3 */ |
| 8545 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 8546 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 8547 | |
| 8548 | I915_WRITE(MEM_MODE, |
| 8549 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8550 | } |
| 8551 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8552 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8553 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 8554 | I915_WRITE(MEM_MODE, |
| 8555 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 8556 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8557 | } |
| 8558 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8559 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8560 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8561 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 8562 | } |
| 8563 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8564 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8565 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 8566 | if (HAS_PCH_LPT(dev_priv)) |
| 8567 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 8568 | } |
| 8569 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 8570 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8571 | { |
| 8572 | DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); |
| 8573 | } |
| 8574 | |
| 8575 | /** |
| 8576 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 8577 | * @dev_priv: device private |
| 8578 | * |
| 8579 | * Setup the hooks that configure which clocks of a given platform can be |
| 8580 | * gated and also apply various GT and display specific workarounds for these |
| 8581 | * platforms. Note that some GT specific workarounds are applied separately |
| 8582 | * when GPU contexts or batchbuffers start their execution. |
| 8583 | */ |
| 8584 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 8585 | { |
| 8586 | if (IS_SKYLAKE(dev_priv)) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 8587 | dev_priv->display.init_clock_gating = skylake_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8588 | else if (IS_KABYLAKE(dev_priv)) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 8589 | dev_priv->display.init_clock_gating = kabylake_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 8590 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8591 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 8592 | else if (IS_GEMINILAKE(dev_priv)) |
| 8593 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8594 | else if (IS_BROADWELL(dev_priv)) |
| 8595 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
| 8596 | else if (IS_CHERRYVIEW(dev_priv)) |
| 8597 | dev_priv->display.init_clock_gating = cherryview_init_clock_gating; |
| 8598 | else if (IS_HASWELL(dev_priv)) |
| 8599 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
| 8600 | else if (IS_IVYBRIDGE(dev_priv)) |
| 8601 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
| 8602 | else if (IS_VALLEYVIEW(dev_priv)) |
| 8603 | dev_priv->display.init_clock_gating = valleyview_init_clock_gating; |
| 8604 | else if (IS_GEN6(dev_priv)) |
| 8605 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
| 8606 | else if (IS_GEN5(dev_priv)) |
| 8607 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
| 8608 | else if (IS_G4X(dev_priv)) |
| 8609 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 8610 | else if (IS_I965GM(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8611 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 8612 | else if (IS_I965G(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8613 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 8614 | else if (IS_GEN3(dev_priv)) |
| 8615 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 8616 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 8617 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 8618 | else if (IS_GEN2(dev_priv)) |
| 8619 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 8620 | else { |
| 8621 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 8622 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 8623 | } |
| 8624 | } |
| 8625 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8626 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8627 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8628 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 8629 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8630 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8631 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8632 | if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 8633 | i915_pineview_get_mem_freq(dev_priv); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8634 | else if (IS_GEN5(dev_priv)) |
Ville Syrjälä | 148ac1f | 2016-10-31 22:37:16 +0200 | [diff] [blame] | 8635 | i915_ironlake_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8636 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8637 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8638 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8639 | skl_setup_wm_latency(dev_priv); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 8640 | dev_priv->display.initial_watermarks = skl_initial_wm; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 8641 | dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 8642 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8643 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8644 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 8645 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8646 | if ((IS_GEN5(dev_priv) && dev_priv->wm.pri_latency[1] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8647 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8648 | (!IS_GEN5(dev_priv) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8649 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 8650 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 8651 | dev_priv->display.compute_intermediate_wm = |
| 8652 | ilk_compute_intermediate_wm; |
| 8653 | dev_priv->display.initial_watermarks = |
| 8654 | ilk_initial_watermarks; |
| 8655 | dev_priv->display.optimize_watermarks = |
| 8656 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8657 | } else { |
| 8658 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 8659 | "Disable CxSR\n"); |
| 8660 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 8661 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8662 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8663 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 8664 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8665 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 8666 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8667 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 8668 | } else if (IS_G4X(dev_priv)) { |
| 8669 | g4x_setup_wm_latency(dev_priv); |
| 8670 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 8671 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 8672 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 8673 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8674 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8675 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8676 | dev_priv->is_ddr3, |
| 8677 | dev_priv->fsb_freq, |
| 8678 | dev_priv->mem_freq)) { |
| 8679 | DRM_INFO("failed to find known CxSR latency " |
| 8680 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 8681 | "disabling CxSR\n", |
| 8682 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 8683 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 8684 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 8685 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8686 | dev_priv->display.update_wm = NULL; |
| 8687 | } else |
| 8688 | dev_priv->display.update_wm = pineview_update_wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8689 | } else if (IS_GEN4(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8690 | dev_priv->display.update_wm = i965_update_wm; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8691 | } else if (IS_GEN3(dev_priv)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8692 | dev_priv->display.update_wm = i9xx_update_wm; |
| 8693 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8694 | } else if (IS_GEN2(dev_priv)) { |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8695 | if (INTEL_INFO(dev_priv)->num_pipes == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8696 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8697 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8698 | } else { |
| 8699 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8700 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8701 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8702 | } else { |
| 8703 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8704 | } |
| 8705 | } |
| 8706 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8707 | static inline int gen6_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 8708 | { |
| 8709 | uint32_t flags = |
| 8710 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 8711 | |
| 8712 | switch (flags) { |
| 8713 | case GEN6_PCODE_SUCCESS: |
| 8714 | return 0; |
| 8715 | case GEN6_PCODE_UNIMPLEMENTED_CMD: |
| 8716 | case GEN6_PCODE_ILLEGAL_CMD: |
| 8717 | return -ENXIO; |
| 8718 | case GEN6_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Chris Wilson | 7850d1c | 2016-08-26 11:59:26 +0100 | [diff] [blame] | 8719 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8720 | return -EOVERFLOW; |
| 8721 | case GEN6_PCODE_TIMEOUT: |
| 8722 | return -ETIMEDOUT; |
| 8723 | default: |
Michal Wajdeczko | f0d6615 | 2017-03-28 08:45:12 +0000 | [diff] [blame] | 8724 | MISSING_CASE(flags); |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8725 | return 0; |
| 8726 | } |
| 8727 | } |
| 8728 | |
| 8729 | static inline int gen7_check_mailbox_status(struct drm_i915_private *dev_priv) |
| 8730 | { |
| 8731 | uint32_t flags = |
| 8732 | I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK; |
| 8733 | |
| 8734 | switch (flags) { |
| 8735 | case GEN6_PCODE_SUCCESS: |
| 8736 | return 0; |
| 8737 | case GEN6_PCODE_ILLEGAL_CMD: |
| 8738 | return -ENXIO; |
| 8739 | case GEN7_PCODE_TIMEOUT: |
| 8740 | return -ETIMEDOUT; |
| 8741 | case GEN7_PCODE_ILLEGAL_DATA: |
| 8742 | return -EINVAL; |
| 8743 | case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE: |
| 8744 | return -EOVERFLOW; |
| 8745 | default: |
| 8746 | MISSING_CASE(flags); |
| 8747 | return 0; |
| 8748 | } |
| 8749 | } |
| 8750 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 8751 | 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] | 8752 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8753 | int status; |
| 8754 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 8755 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8756 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8757 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 8758 | * use te fw I915_READ variants to reduce the amount of work |
| 8759 | * required when reading/writing. |
| 8760 | */ |
| 8761 | |
| 8762 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8763 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 8764 | return -EAGAIN; |
| 8765 | } |
| 8766 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8767 | I915_WRITE_FW(GEN6_PCODE_DATA, *val); |
| 8768 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
| 8769 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8770 | |
Chris Wilson | e09a303 | 2017-04-11 11:13:39 +0100 | [diff] [blame] | 8771 | if (__intel_wait_for_register_fw(dev_priv, |
| 8772 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 8773 | 500, 0, NULL)) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8774 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 8775 | return -ETIMEDOUT; |
| 8776 | } |
| 8777 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8778 | *val = I915_READ_FW(GEN6_PCODE_DATA); |
| 8779 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8780 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8781 | if (INTEL_GEN(dev_priv) > 6) |
| 8782 | status = gen7_check_mailbox_status(dev_priv); |
| 8783 | else |
| 8784 | status = gen6_check_mailbox_status(dev_priv); |
| 8785 | |
| 8786 | if (status) { |
| 8787 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed: %d\n", |
| 8788 | status); |
| 8789 | return status; |
| 8790 | } |
| 8791 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8792 | return 0; |
| 8793 | } |
| 8794 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8795 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8796 | u32 mbox, u32 val) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8797 | { |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8798 | int status; |
| 8799 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 8800 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8801 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8802 | /* GEN6_PCODE_* are outside of the forcewake domain, we can |
| 8803 | * use te fw I915_READ variants to reduce the amount of work |
| 8804 | * required when reading/writing. |
| 8805 | */ |
| 8806 | |
| 8807 | if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8808 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 8809 | return -EAGAIN; |
| 8810 | } |
| 8811 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8812 | I915_WRITE_FW(GEN6_PCODE_DATA, val); |
Imre Deak | 8bf41b7 | 2016-11-28 17:29:27 +0200 | [diff] [blame] | 8813 | I915_WRITE_FW(GEN6_PCODE_DATA1, 0); |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8814 | I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8815 | |
Chris Wilson | e09a303 | 2017-04-11 11:13:39 +0100 | [diff] [blame] | 8816 | if (__intel_wait_for_register_fw(dev_priv, |
| 8817 | GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0, |
| 8818 | 500, 0, NULL)) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8819 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 8820 | return -ETIMEDOUT; |
| 8821 | } |
| 8822 | |
Chris Wilson | 3f5582d | 2016-06-30 15:32:45 +0100 | [diff] [blame] | 8823 | I915_WRITE_FW(GEN6_PCODE_DATA, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8824 | |
Lyude | 8766050 | 2016-08-17 15:55:53 -0400 | [diff] [blame] | 8825 | if (INTEL_GEN(dev_priv) > 6) |
| 8826 | status = gen7_check_mailbox_status(dev_priv); |
| 8827 | else |
| 8828 | status = gen6_check_mailbox_status(dev_priv); |
| 8829 | |
| 8830 | if (status) { |
| 8831 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed: %d\n", |
| 8832 | status); |
| 8833 | return status; |
| 8834 | } |
| 8835 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 8836 | return 0; |
| 8837 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 8838 | |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 8839 | static bool skl_pcode_try_request(struct drm_i915_private *dev_priv, u32 mbox, |
| 8840 | u32 request, u32 reply_mask, u32 reply, |
| 8841 | u32 *status) |
| 8842 | { |
| 8843 | u32 val = request; |
| 8844 | |
| 8845 | *status = sandybridge_pcode_read(dev_priv, mbox, &val); |
| 8846 | |
| 8847 | return *status || ((val & reply_mask) == reply); |
| 8848 | } |
| 8849 | |
| 8850 | /** |
| 8851 | * skl_pcode_request - send PCODE request until acknowledgment |
| 8852 | * @dev_priv: device private |
| 8853 | * @mbox: PCODE mailbox ID the request is targeted for |
| 8854 | * @request: request ID |
| 8855 | * @reply_mask: mask used to check for request acknowledgment |
| 8856 | * @reply: value used to check for request acknowledgment |
| 8857 | * @timeout_base_ms: timeout for polling with preemption enabled |
| 8858 | * |
| 8859 | * Keep resending the @request to @mbox until PCODE acknowledges it, PCODE |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 8860 | * 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] | 8861 | * The request is acknowledged once the PCODE reply dword equals @reply after |
| 8862 | * applying @reply_mask. Polling is first attempted with preemption enabled |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 8863 | * 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] | 8864 | * preemption disabled. |
| 8865 | * |
| 8866 | * Returns 0 on success, %-ETIMEDOUT in case of a timeout, <0 in case of some |
| 8867 | * other error as reported by PCODE. |
| 8868 | */ |
| 8869 | int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request, |
| 8870 | u32 reply_mask, u32 reply, int timeout_base_ms) |
| 8871 | { |
| 8872 | u32 status; |
| 8873 | int ret; |
| 8874 | |
| 8875 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 8876 | |
| 8877 | #define COND skl_pcode_try_request(dev_priv, mbox, request, reply_mask, reply, \ |
| 8878 | &status) |
| 8879 | |
| 8880 | /* |
| 8881 | * Prime the PCODE by doing a request first. Normally it guarantees |
| 8882 | * that a subsequent request, at most @timeout_base_ms later, succeeds. |
| 8883 | * _wait_for() doesn't guarantee when its passed condition is evaluated |
| 8884 | * first, so send the first request explicitly. |
| 8885 | */ |
| 8886 | if (COND) { |
| 8887 | ret = 0; |
| 8888 | goto out; |
| 8889 | } |
| 8890 | ret = _wait_for(COND, timeout_base_ms * 1000, 10); |
| 8891 | if (!ret) |
| 8892 | goto out; |
| 8893 | |
| 8894 | /* |
| 8895 | * The above can time out if the number of requests was low (2 in the |
| 8896 | * worst case) _and_ PCODE was busy for some reason even after a |
| 8897 | * (queued) request and @timeout_base_ms delay. As a workaround retry |
| 8898 | * the poll with preemption disabled to maximize the number of |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 8899 | * requests. Increase the timeout from @timeout_base_ms to 50ms to |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 8900 | * account for interrupts that could reduce the number of these |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 8901 | * requests, and for any quirks of the PCODE firmware that delays |
| 8902 | * the request completion. |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 8903 | */ |
| 8904 | DRM_DEBUG_KMS("PCODE timeout, retrying with preemption disabled\n"); |
| 8905 | WARN_ON_ONCE(timeout_base_ms > 3); |
| 8906 | preempt_disable(); |
Imre Deak | 0129936 | 2017-02-24 16:32:10 +0200 | [diff] [blame] | 8907 | ret = wait_for_atomic(COND, 50); |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 8908 | preempt_enable(); |
| 8909 | |
| 8910 | out: |
| 8911 | return ret ? ret : status; |
| 8912 | #undef COND |
| 8913 | } |
| 8914 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 8915 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 8916 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 8917 | /* |
| 8918 | * N = val - 0xb7 |
| 8919 | * Slow = Fast = GPLL ref * N |
| 8920 | */ |
| 8921 | return DIV_ROUND_CLOSEST(dev_priv->rps.gpll_ref_freq * (val - 0xb7), 1000); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 8922 | } |
| 8923 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 8924 | 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] | 8925 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 8926 | return DIV_ROUND_CLOSEST(1000 * val, dev_priv->rps.gpll_ref_freq) + 0xb7; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 8927 | } |
| 8928 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 8929 | 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] | 8930 | { |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 8931 | /* |
| 8932 | * N = val / 2 |
| 8933 | * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2 |
| 8934 | */ |
| 8935 | return DIV_ROUND_CLOSEST(dev_priv->rps.gpll_ref_freq * val, 2 * 2 * 1000); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 8936 | } |
| 8937 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 8938 | 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] | 8939 | { |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 8940 | /* CHV needs even values */ |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 8941 | return DIV_ROUND_CLOSEST(2 * 1000 * val, dev_priv->rps.gpll_ref_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 8942 | } |
| 8943 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8944 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 8945 | { |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8946 | if (IS_GEN9(dev_priv)) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 8947 | return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, |
| 8948 | GEN9_FREQ_SCALER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8949 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8950 | return chv_gpu_freq(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8951 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8952 | return byt_gpu_freq(dev_priv, val); |
| 8953 | else |
| 8954 | return val * GT_FREQUENCY_MULTIPLIER; |
| 8955 | } |
| 8956 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8957 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 8958 | { |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8959 | if (IS_GEN9(dev_priv)) |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 8960 | return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, |
| 8961 | GT_FREQUENCY_MULTIPLIER); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8962 | else if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8963 | return chv_freq_opcode(dev_priv, val); |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8964 | else if (IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 8965 | return byt_freq_opcode(dev_priv, val); |
| 8966 | else |
Mika Kuoppala | 500a3d2 | 2015-11-13 19:29:41 +0200 | [diff] [blame] | 8967 | return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 8968 | } |
| 8969 | |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8970 | struct request_boost { |
| 8971 | struct work_struct work; |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 8972 | struct drm_i915_gem_request *req; |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8973 | }; |
| 8974 | |
| 8975 | static void __intel_rps_boost_work(struct work_struct *work) |
| 8976 | { |
| 8977 | struct request_boost *boost = container_of(work, struct request_boost, work); |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 8978 | struct drm_i915_gem_request *req = boost->req; |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8979 | |
Chris Wilson | f69a02c | 2016-07-01 17:23:16 +0100 | [diff] [blame] | 8980 | if (!i915_gem_request_completed(req)) |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 8981 | gen6_rps_boost(req->i915, NULL, req->emitted_jiffies); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8982 | |
Chris Wilson | e8a261e | 2016-07-20 13:31:49 +0100 | [diff] [blame] | 8983 | i915_gem_request_put(req); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8984 | kfree(boost); |
| 8985 | } |
| 8986 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 8987 | void intel_queue_rps_boost_for_request(struct drm_i915_gem_request *req) |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8988 | { |
| 8989 | struct request_boost *boost; |
| 8990 | |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 8991 | if (req == NULL || INTEL_GEN(req->i915) < 6) |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8992 | return; |
| 8993 | |
Chris Wilson | f69a02c | 2016-07-01 17:23:16 +0100 | [diff] [blame] | 8994 | if (i915_gem_request_completed(req)) |
Chris Wilson | e61b995 | 2015-04-27 13:41:24 +0100 | [diff] [blame] | 8995 | return; |
| 8996 | |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 8997 | boost = kmalloc(sizeof(*boost), GFP_ATOMIC); |
| 8998 | if (boost == NULL) |
| 8999 | return; |
| 9000 | |
Chris Wilson | e8a261e | 2016-07-20 13:31:49 +0100 | [diff] [blame] | 9001 | boost->req = i915_gem_request_get(req); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9002 | |
| 9003 | INIT_WORK(&boost->work, __intel_rps_boost_work); |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 9004 | queue_work(req->i915->wq, &boost->work); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 9005 | } |
| 9006 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 9007 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9008 | { |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9009 | mutex_init(&dev_priv->rps.hw_lock); |
Chris Wilson | 8d3afd7 | 2015-05-21 21:01:47 +0100 | [diff] [blame] | 9010 | spin_lock_init(&dev_priv->rps.client_lock); |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 9011 | |
Chris Wilson | 54b4f68 | 2016-07-21 21:16:19 +0100 | [diff] [blame] | 9012 | INIT_DELAYED_WORK(&dev_priv->rps.autoenable_work, |
| 9013 | __intel_autoenable_gt_powersave); |
Chris Wilson | 1854d5c | 2015-04-07 16:20:32 +0100 | [diff] [blame] | 9014 | INIT_LIST_HEAD(&dev_priv->rps.clients); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 9015 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 9016 | dev_priv->pm.suspended = false; |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 9017 | atomic_set(&dev_priv->pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 9018 | } |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9019 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9020 | static u64 vlv_residency_raw(struct drm_i915_private *dev_priv, |
| 9021 | const i915_reg_t reg) |
| 9022 | { |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9023 | u32 lower, upper, tmp; |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9024 | int loop = 2; |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9025 | |
| 9026 | /* The register accessed do not need forcewake. We borrow |
| 9027 | * uncore lock to prevent concurrent access to range reg. |
| 9028 | */ |
| 9029 | spin_lock_irq(&dev_priv->uncore.lock); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9030 | |
| 9031 | /* vlv and chv residency counters are 40 bits in width. |
| 9032 | * With a control bit, we can choose between upper or lower |
| 9033 | * 32bit window into this counter. |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9034 | * |
| 9035 | * Although we always use the counter in high-range mode elsewhere, |
| 9036 | * userspace may attempt to read the value before rc6 is initialised, |
| 9037 | * before we have set the default VLV_COUNTER_CONTROL value. So always |
| 9038 | * set the high bit to be safe. |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9039 | */ |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9040 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9041 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9042 | upper = I915_READ_FW(reg); |
| 9043 | do { |
| 9044 | tmp = upper; |
| 9045 | |
| 9046 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9047 | _MASKED_BIT_DISABLE(VLV_COUNT_RANGE_HIGH)); |
| 9048 | lower = I915_READ_FW(reg); |
| 9049 | |
| 9050 | I915_WRITE_FW(VLV_COUNTER_CONTROL, |
| 9051 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH)); |
| 9052 | upper = I915_READ_FW(reg); |
Chris Wilson | 71cc2b1 | 2017-03-24 16:54:18 +0000 | [diff] [blame] | 9053 | } while (upper != tmp && --loop); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9054 | |
Chris Wilson | facbeca | 2017-03-17 12:59:18 +0000 | [diff] [blame] | 9055 | /* Everywhere else we always use VLV_COUNTER_CONTROL with the |
| 9056 | * VLV_COUNT_RANGE_HIGH bit set - so it is safe to leave it set |
| 9057 | * now. |
| 9058 | */ |
| 9059 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9060 | spin_unlock_irq(&dev_priv->uncore.lock); |
| 9061 | |
| 9062 | return lower | (u64)upper << 8; |
| 9063 | } |
| 9064 | |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9065 | u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv, |
| 9066 | const i915_reg_t reg) |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9067 | { |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9068 | u64 time_hw, units, div; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9069 | |
| 9070 | if (!intel_enable_rc6()) |
| 9071 | return 0; |
| 9072 | |
| 9073 | intel_runtime_pm_get(dev_priv); |
| 9074 | |
| 9075 | /* On VLV and CHV, residency time is in CZ units rather than 1.28us */ |
| 9076 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9077 | units = 1000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9078 | div = dev_priv->czclk_freq; |
| 9079 | |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9080 | time_hw = vlv_residency_raw(dev_priv, reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9081 | } else if (IS_GEN9_LP(dev_priv)) { |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 9082 | units = 1000; |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9083 | div = 1200; /* 833.33ns */ |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9084 | |
| 9085 | time_hw = I915_READ(reg); |
| 9086 | } else { |
| 9087 | units = 128000; /* 1.28us */ |
| 9088 | div = 100000; |
| 9089 | |
| 9090 | time_hw = I915_READ(reg); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9091 | } |
| 9092 | |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9093 | intel_runtime_pm_put(dev_priv); |
Mika Kuoppala | 47c21d9 | 2017-03-15 18:07:13 +0200 | [diff] [blame] | 9094 | return DIV_ROUND_UP_ULL(time_hw * units, div); |
Mika Kuoppala | 135bafa | 2017-03-15 17:42:59 +0200 | [diff] [blame] | 9095 | } |