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 | |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 28 | #include <linux/module.h> |
Chris Wilson | 08ea70a | 2018-08-12 23:36:31 +0100 | [diff] [blame] | 29 | #include <linux/pm_runtime.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 30 | |
| 31 | #include <drm/drm_atomic_helper.h> |
| 32 | #include <drm/drm_fourcc.h> |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 33 | #include <drm/drm_plane_helper.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 34 | |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 35 | #include "display/intel_atomic.h" |
Stanislav Lisovskiy | cac91e6 | 2020-05-22 16:18:43 +0300 | [diff] [blame] | 36 | #include "display/intel_bw.h" |
Jani Nikula | 1d455f8 | 2019-08-06 14:39:33 +0300 | [diff] [blame] | 37 | #include "display/intel_display_types.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 38 | #include "display/intel_fbc.h" |
| 39 | #include "display/intel_sprite.h" |
| 40 | |
Andi Shyti | 0dc3c56 | 2019-10-20 19:41:39 +0100 | [diff] [blame] | 41 | #include "gt/intel_llc.h" |
| 42 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 43 | #include "i915_drv.h" |
Jani Nikula | a10510a | 2020-02-27 19:00:47 +0200 | [diff] [blame] | 44 | #include "i915_fixed.h" |
Jani Nikula | 440e2b3 | 2019-04-29 15:29:27 +0300 | [diff] [blame] | 45 | #include "i915_irq.h" |
Jani Nikula | a09d9a8 | 2019-08-06 13:07:28 +0300 | [diff] [blame] | 46 | #include "i915_trace.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 47 | #include "intel_pm.h" |
Chris Wilson | 56c5098 | 2019-04-26 09:17:22 +0100 | [diff] [blame] | 48 | #include "intel_sideband.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 49 | #include "../../../platform/x86/intel_ips.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 50 | |
Jani Nikula | a10510a | 2020-02-27 19:00:47 +0200 | [diff] [blame] | 51 | /* Stores plane specific WM parameters */ |
| 52 | struct skl_wm_params { |
| 53 | bool x_tiled, y_tiled; |
| 54 | bool rc_surface; |
| 55 | bool is_planar; |
| 56 | u32 width; |
| 57 | u8 cpp; |
| 58 | u32 plane_pixel_rate; |
| 59 | u32 y_min_scanlines; |
| 60 | u32 plane_bytes_per_line; |
| 61 | uint_fixed_16_16_t plane_blocks_per_line; |
| 62 | uint_fixed_16_16_t y_tile_minimum; |
| 63 | u32 linetime_us; |
| 64 | u32 dbuf_block_size; |
| 65 | }; |
| 66 | |
| 67 | /* used in computing the new watermarks state */ |
| 68 | struct intel_wm_config { |
| 69 | unsigned int num_pipes_active; |
| 70 | bool sprites_enabled; |
| 71 | bool sprites_scaled; |
| 72 | }; |
| 73 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 74 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 75 | { |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 76 | if (HAS_LLC(dev_priv)) { |
| 77 | /* |
| 78 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
Lucas De Marchi | e0403cb | 2017-12-05 11:01:17 -0800 | [diff] [blame] | 79 | * Display WA #0390: skl,kbl |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 80 | * |
| 81 | * Must match Sampler, Pixel Back End, and Media. See |
| 82 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 83 | */ |
| 84 | I915_WRITE(CHICKEN_PAR1_1, |
| 85 | I915_READ(CHICKEN_PAR1_1) | |
| 86 | SKL_DE_COMPRESSED_HASH_MODE); |
| 87 | } |
| 88 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 89 | /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl,cfl */ |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 90 | I915_WRITE(CHICKEN_PAR1_1, |
| 91 | I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
| 92 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 93 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
Mika Kuoppala | 590e8ff | 2016-06-07 17:19:13 +0300 | [diff] [blame] | 94 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 95 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 96 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 97 | /* |
| 98 | * WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl |
| 99 | * Display WA #0859: skl,bxt,kbl,glk,cfl |
| 100 | */ |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 101 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 102 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 103 | } |
| 104 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 105 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 106 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 107 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 108 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 109 | /* WaDisableSDEUnitClockGating:bxt */ |
| 110 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 111 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 112 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 113 | /* |
| 114 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 115 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 116 | */ |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 117 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 118 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 122 | * to stay fully on. |
| 123 | */ |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 124 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 125 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Uma Shankar | 1d85a29 | 2018-08-07 21:15:35 +0530 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * Lower the display internal timeout. |
| 129 | * This is needed to avoid any hard hangs when DSI port PLL |
| 130 | * is off and a MMIO access is attempted by any privilege |
| 131 | * application, using batch buffers or any other means. |
| 132 | */ |
| 133 | I915_WRITE(RM_TIMEOUT, MMIO_TIMEOUT_US(950)); |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 134 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 135 | /* |
| 136 | * WaFbcTurnOffFbcWatermark:bxt |
| 137 | * Display WA #0562: bxt |
| 138 | */ |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 139 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 140 | DISP_FBC_WM_DIS); |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 141 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 142 | /* |
| 143 | * WaFbcHighMemBwCorruptionAvoidance:bxt |
| 144 | * Display WA #0883: bxt |
| 145 | */ |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 146 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 147 | ILK_DPFC_DISABLE_DUMMY0); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 148 | } |
| 149 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 150 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 151 | { |
| 152 | gen9_init_clock_gating(dev_priv); |
| 153 | |
| 154 | /* |
| 155 | * WaDisablePWMClockGating:glk |
| 156 | * Backlight PWM may stop in the asserted state, causing backlight |
| 157 | * to stay fully on. |
| 158 | */ |
| 159 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 160 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
| 161 | } |
| 162 | |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 163 | static void pnv_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 164 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 165 | u32 tmp; |
| 166 | |
| 167 | tmp = I915_READ(CLKCFG); |
| 168 | |
| 169 | switch (tmp & CLKCFG_FSB_MASK) { |
| 170 | case CLKCFG_FSB_533: |
| 171 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 172 | break; |
| 173 | case CLKCFG_FSB_800: |
| 174 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 175 | break; |
| 176 | case CLKCFG_FSB_667: |
| 177 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 178 | break; |
| 179 | case CLKCFG_FSB_400: |
| 180 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | switch (tmp & CLKCFG_MEM_MASK) { |
| 185 | case CLKCFG_MEM_533: |
| 186 | dev_priv->mem_freq = 533; |
| 187 | break; |
| 188 | case CLKCFG_MEM_667: |
| 189 | dev_priv->mem_freq = 667; |
| 190 | break; |
| 191 | case CLKCFG_MEM_800: |
| 192 | dev_priv->mem_freq = 800; |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | /* detect pineview DDR3 setting */ |
| 197 | tmp = I915_READ(CSHRDDR3CTL); |
| 198 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 199 | } |
| 200 | |
Lucas De Marchi | 9eae5e2 | 2019-12-24 00:40:09 -0800 | [diff] [blame] | 201 | static void ilk_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 202 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 203 | u16 ddrpll, csipll; |
| 204 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 205 | ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1); |
| 206 | csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 207 | |
| 208 | switch (ddrpll & 0xff) { |
| 209 | case 0xc: |
| 210 | dev_priv->mem_freq = 800; |
| 211 | break; |
| 212 | case 0x10: |
| 213 | dev_priv->mem_freq = 1066; |
| 214 | break; |
| 215 | case 0x14: |
| 216 | dev_priv->mem_freq = 1333; |
| 217 | break; |
| 218 | case 0x18: |
| 219 | dev_priv->mem_freq = 1600; |
| 220 | break; |
| 221 | default: |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 222 | drm_dbg(&dev_priv->drm, "unknown memory frequency 0x%02x\n", |
| 223 | ddrpll & 0xff); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 224 | dev_priv->mem_freq = 0; |
| 225 | break; |
| 226 | } |
| 227 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 228 | switch (csipll & 0x3ff) { |
| 229 | case 0x00c: |
| 230 | dev_priv->fsb_freq = 3200; |
| 231 | break; |
| 232 | case 0x00e: |
| 233 | dev_priv->fsb_freq = 3733; |
| 234 | break; |
| 235 | case 0x010: |
| 236 | dev_priv->fsb_freq = 4266; |
| 237 | break; |
| 238 | case 0x012: |
| 239 | dev_priv->fsb_freq = 4800; |
| 240 | break; |
| 241 | case 0x014: |
| 242 | dev_priv->fsb_freq = 5333; |
| 243 | break; |
| 244 | case 0x016: |
| 245 | dev_priv->fsb_freq = 5866; |
| 246 | break; |
| 247 | case 0x018: |
| 248 | dev_priv->fsb_freq = 6400; |
| 249 | break; |
| 250 | default: |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 251 | drm_dbg(&dev_priv->drm, "unknown fsb frequency 0x%04x\n", |
| 252 | csipll & 0x3ff); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 253 | dev_priv->fsb_freq = 0; |
| 254 | break; |
| 255 | } |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 258 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 259 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 260 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 261 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 262 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 263 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 264 | |
| 265 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 266 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 267 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 268 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 269 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 270 | |
| 271 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 272 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 273 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 274 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 275 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 276 | |
| 277 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 278 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 279 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 280 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 281 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 282 | |
| 283 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 284 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 285 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 286 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 287 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 288 | |
| 289 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 290 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 291 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 292 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 293 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 294 | }; |
| 295 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 296 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 297 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 298 | int fsb, |
| 299 | int mem) |
| 300 | { |
| 301 | const struct cxsr_latency *latency; |
| 302 | int i; |
| 303 | |
| 304 | if (fsb == 0 || mem == 0) |
| 305 | return NULL; |
| 306 | |
| 307 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 308 | latency = &cxsr_latency_table[i]; |
| 309 | if (is_desktop == latency->is_desktop && |
| 310 | is_ddr3 == latency->is_ddr3 && |
| 311 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 312 | return latency; |
| 313 | } |
| 314 | |
| 315 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 316 | |
| 317 | return NULL; |
| 318 | } |
| 319 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 320 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 321 | { |
| 322 | u32 val; |
| 323 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 324 | vlv_punit_get(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 325 | |
| 326 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 327 | if (enable) |
| 328 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 329 | else |
| 330 | val |= FORCE_DDR_HIGH_FREQ; |
| 331 | val &= ~FORCE_DDR_LOW_FREQ; |
| 332 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 333 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 334 | |
| 335 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 336 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 337 | drm_err(&dev_priv->drm, |
| 338 | "timed out waiting for Punit DDR DVFS request\n"); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 339 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 340 | vlv_punit_put(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 341 | } |
| 342 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 343 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 344 | { |
| 345 | u32 val; |
| 346 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 347 | vlv_punit_get(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 348 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 349 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 350 | if (enable) |
| 351 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 352 | else |
| 353 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 354 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 355 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 356 | vlv_punit_put(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 359 | #define FW_WM(value, plane) \ |
| 360 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 361 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 362 | 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] | 363 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 364 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 365 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 366 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 367 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 368 | was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 369 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 370 | POSTING_READ(FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 371 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 372 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 373 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 374 | POSTING_READ(FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 375 | } else if (IS_PINEVIEW(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 376 | val = I915_READ(DSPFW3); |
| 377 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 378 | if (enable) |
| 379 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 380 | else |
| 381 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 382 | I915_WRITE(DSPFW3, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 383 | POSTING_READ(DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 384 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 385 | was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 386 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 387 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 388 | I915_WRITE(FW_BLC_SELF, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 389 | POSTING_READ(FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 390 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 391 | /* |
| 392 | * FIXME can't find a bit like this for 915G, and |
| 393 | * and yet it does have the related watermark in |
| 394 | * FW_BLC_SELF. What's going on? |
| 395 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 396 | was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 397 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 398 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 399 | I915_WRITE(INSTPM, val); |
Ville Syrjälä | a7a6c49 | 2015-06-24 22:00:01 +0300 | [diff] [blame] | 400 | POSTING_READ(INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 401 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 402 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 403 | } |
| 404 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 405 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 406 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 407 | drm_dbg_kms(&dev_priv->drm, "memory self-refresh is %s (was %s)\n", |
| 408 | enableddisabled(enable), |
| 409 | enableddisabled(was_enabled)); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 410 | |
| 411 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 412 | } |
| 413 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 414 | /** |
| 415 | * intel_set_memory_cxsr - Configure CxSR state |
| 416 | * @dev_priv: i915 device |
| 417 | * @enable: Allow vs. disallow CxSR |
| 418 | * |
| 419 | * Allow or disallow the system to enter a special CxSR |
| 420 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 421 | * is that several display FIFOs may get combined into a single larger |
| 422 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 423 | * system to defer memory fetches longer, and the memory will enter |
| 424 | * self refresh. |
| 425 | * |
| 426 | * Note that enabling CxSR does not guarantee that the system enter |
| 427 | * this special mode, nor does it guarantee that the system stays |
| 428 | * in that mode once entered. So this just allows/disallows the system |
| 429 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 430 | * C-states will affect when/if the system actually enters/exits the |
| 431 | * CxSR mode. |
| 432 | * |
| 433 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 434 | * and the system is free to enter/exit memory self refresh at any time |
| 435 | * even when the use of CxSR has been disallowed. |
| 436 | * |
| 437 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 438 | * control registers will not get latched on vblank. Thus in order to |
| 439 | * guarantee the system will respond to changes in the plane registers |
| 440 | * we must always disallow CxSR prior to making changes to those registers. |
| 441 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 442 | * frame start which happens after vblank start (which is when the plane |
| 443 | * registers would get latched), so we can't proceed with the plane update |
| 444 | * during the same frame where we disallowed CxSR. |
| 445 | * |
| 446 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 447 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 448 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 449 | * Disallowing just CxSR is sufficient. |
| 450 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 451 | 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] | 452 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 453 | bool ret; |
| 454 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 455 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 456 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 457 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 458 | dev_priv->wm.vlv.cxsr = enable; |
| 459 | else if (IS_G4X(dev_priv)) |
| 460 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 461 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 462 | |
| 463 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 464 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 465 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 466 | /* |
| 467 | * Latency for FIFO fetches is dependent on several factors: |
| 468 | * - memory configuration (speed, channels) |
| 469 | * - chipset |
| 470 | * - current MCH state |
| 471 | * It can be fairly high in some situations, so here we assume a fairly |
| 472 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 473 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 474 | * and power consumption (set it too low to save power and we might see |
| 475 | * FIFO underruns and display "flicker"). |
| 476 | * |
| 477 | * A value of 5us seems to be a good balance; safe for very low end |
| 478 | * platforms but not overly aggressive on lower latency configs. |
| 479 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 480 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 481 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 482 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 483 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 484 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 485 | 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] | 486 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 487 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 488 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 489 | 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] | 490 | enum pipe pipe = crtc->pipe; |
| 491 | int sprite0_start, sprite1_start; |
Kees Cook | 2713eb4 | 2020-02-20 16:05:17 -0800 | [diff] [blame] | 492 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 493 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 494 | switch (pipe) { |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 495 | case PIPE_A: |
| 496 | dsparb = I915_READ(DSPARB); |
| 497 | dsparb2 = I915_READ(DSPARB2); |
| 498 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 499 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 500 | break; |
| 501 | case PIPE_B: |
| 502 | dsparb = I915_READ(DSPARB); |
| 503 | dsparb2 = I915_READ(DSPARB2); |
| 504 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 505 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 506 | break; |
| 507 | case PIPE_C: |
| 508 | dsparb2 = I915_READ(DSPARB2); |
| 509 | dsparb3 = I915_READ(DSPARB3); |
| 510 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 511 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 512 | break; |
| 513 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 514 | MISSING_CASE(pipe); |
| 515 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 518 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 519 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 520 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 521 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 524 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 525 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 526 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 527 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 528 | int size; |
| 529 | |
| 530 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 531 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 532 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 533 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 534 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 535 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 536 | |
| 537 | return size; |
| 538 | } |
| 539 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 540 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 541 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 542 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 543 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 544 | int size; |
| 545 | |
| 546 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 547 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 548 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 549 | size >>= 1; /* Convert to cachelines */ |
| 550 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 551 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 552 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 553 | |
| 554 | return size; |
| 555 | } |
| 556 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 557 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 558 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 559 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 560 | u32 dsparb = I915_READ(DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 561 | int size; |
| 562 | |
| 563 | size = dsparb & 0x7f; |
| 564 | size >>= 2; /* Convert to cachelines */ |
| 565 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 566 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 567 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 568 | |
| 569 | return size; |
| 570 | } |
| 571 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 572 | /* Pineview has different values for various configs */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 573 | static const struct intel_watermark_params pnv_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 574 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 575 | .max_wm = PINEVIEW_MAX_WM, |
| 576 | .default_wm = PINEVIEW_DFT_WM, |
| 577 | .guard_size = PINEVIEW_GUARD_WM, |
| 578 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 579 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 580 | |
| 581 | static const struct intel_watermark_params pnv_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 582 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 583 | .max_wm = PINEVIEW_MAX_WM, |
| 584 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 585 | .guard_size = PINEVIEW_GUARD_WM, |
| 586 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 587 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 588 | |
| 589 | static const struct intel_watermark_params pnv_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 590 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 591 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 592 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 593 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 594 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 595 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 596 | |
| 597 | static const struct intel_watermark_params pnv_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 598 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 599 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 600 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 601 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 602 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 603 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 604 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 605 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 606 | .fifo_size = I965_CURSOR_FIFO, |
| 607 | .max_wm = I965_CURSOR_MAX_WM, |
| 608 | .default_wm = I965_CURSOR_DFT_WM, |
| 609 | .guard_size = 2, |
| 610 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 611 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 612 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 613 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 614 | .fifo_size = I945_FIFO_SIZE, |
| 615 | .max_wm = I915_MAX_WM, |
| 616 | .default_wm = 1, |
| 617 | .guard_size = 2, |
| 618 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 619 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 620 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 621 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 622 | .fifo_size = I915_FIFO_SIZE, |
| 623 | .max_wm = I915_MAX_WM, |
| 624 | .default_wm = 1, |
| 625 | .guard_size = 2, |
| 626 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 627 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 628 | |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 629 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 630 | .fifo_size = I855GM_FIFO_SIZE, |
| 631 | .max_wm = I915_MAX_WM, |
| 632 | .default_wm = 1, |
| 633 | .guard_size = 2, |
| 634 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 635 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 636 | |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 637 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 638 | .fifo_size = I855GM_FIFO_SIZE, |
| 639 | .max_wm = I915_MAX_WM/2, |
| 640 | .default_wm = 1, |
| 641 | .guard_size = 2, |
| 642 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 643 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 644 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 645 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 646 | .fifo_size = I830_FIFO_SIZE, |
| 647 | .max_wm = I915_MAX_WM, |
| 648 | .default_wm = 1, |
| 649 | .guard_size = 2, |
| 650 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 651 | }; |
| 652 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 653 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 654 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 655 | * @pixel_rate: Pipe pixel rate in kHz |
| 656 | * @cpp: Plane bytes per pixel |
| 657 | * @latency: Memory wakeup latency in 0.1us units |
| 658 | * |
| 659 | * Compute the watermark using the method 1 or "small buffer" |
| 660 | * formula. The caller may additonally add extra cachelines |
| 661 | * to account for TLB misses and clock crossings. |
| 662 | * |
| 663 | * This method is concerned with the short term drain rate |
| 664 | * of the FIFO, ie. it does not account for blanking periods |
| 665 | * which would effectively reduce the average drain rate across |
| 666 | * a longer period. The name "small" refers to the fact the |
| 667 | * FIFO is relatively small compared to the amount of data |
| 668 | * fetched. |
| 669 | * |
| 670 | * The FIFO level vs. time graph might look something like: |
| 671 | * |
| 672 | * |\ |\ |
| 673 | * | \ | \ |
| 674 | * __---__---__ (- plane active, _ blanking) |
| 675 | * -> time |
| 676 | * |
| 677 | * or perhaps like this: |
| 678 | * |
| 679 | * |\|\ |\|\ |
| 680 | * __----__----__ (- plane active, _ blanking) |
| 681 | * -> time |
| 682 | * |
| 683 | * Returns: |
| 684 | * The watermark in bytes |
| 685 | */ |
| 686 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 687 | unsigned int cpp, |
| 688 | unsigned int latency) |
| 689 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 690 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 691 | |
Ville Syrjälä | d492a29 | 2019-04-08 18:27:01 +0300 | [diff] [blame] | 692 | ret = mul_u32_u32(pixel_rate, cpp * latency); |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 693 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 694 | |
| 695 | return ret; |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 700 | * @pixel_rate: Pipe pixel rate in kHz |
| 701 | * @htotal: Pipe horizontal total |
| 702 | * @width: Plane width in pixels |
| 703 | * @cpp: Plane bytes per pixel |
| 704 | * @latency: Memory wakeup latency in 0.1us units |
| 705 | * |
| 706 | * Compute the watermark using the method 2 or "large buffer" |
| 707 | * formula. The caller may additonally add extra cachelines |
| 708 | * to account for TLB misses and clock crossings. |
| 709 | * |
| 710 | * This method is concerned with the long term drain rate |
| 711 | * of the FIFO, ie. it does account for blanking periods |
| 712 | * which effectively reduce the average drain rate across |
| 713 | * a longer period. The name "large" refers to the fact the |
| 714 | * FIFO is relatively large compared to the amount of data |
| 715 | * fetched. |
| 716 | * |
| 717 | * The FIFO level vs. time graph might look something like: |
| 718 | * |
| 719 | * |\___ |\___ |
| 720 | * | \___ | \___ |
| 721 | * | \ | \ |
| 722 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 723 | * -> time |
| 724 | * |
| 725 | * Returns: |
| 726 | * The watermark in bytes |
| 727 | */ |
| 728 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 729 | unsigned int htotal, |
| 730 | unsigned int width, |
| 731 | unsigned int cpp, |
| 732 | unsigned int latency) |
| 733 | { |
| 734 | unsigned int ret; |
| 735 | |
| 736 | /* |
| 737 | * FIXME remove once all users are computing |
| 738 | * watermarks in the correct place. |
| 739 | */ |
| 740 | if (WARN_ON_ONCE(htotal == 0)) |
| 741 | htotal = 1; |
| 742 | |
| 743 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 744 | ret = (ret + 1) * width * cpp; |
| 745 | |
| 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 750 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 751 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 752 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 753 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 754 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 755 | * @latency_ns: memory latency for the platform |
| 756 | * |
| 757 | * Calculate the watermark level (the level at which the display plane will |
| 758 | * start fetching from memory again). Each chip has a different display |
| 759 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 760 | * in the correct intel_watermark_params structure. |
| 761 | * |
| 762 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 763 | * on the pixel size. When it reaches the watermark level, it'll start |
| 764 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 765 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 766 | * will occur, and a display engine hang could result. |
| 767 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 768 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 769 | const struct intel_watermark_params *wm, |
| 770 | int fifo_size, int cpp, |
| 771 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 772 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 773 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 774 | |
| 775 | /* |
| 776 | * Note: we need to make sure we don't overflow for various clock & |
| 777 | * latency values. |
| 778 | * clocks go from a few thousand to several hundred thousand. |
| 779 | * latency is usually a few thousand |
| 780 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 781 | entries = intel_wm_method1(pixel_rate, cpp, |
| 782 | latency_ns / 100); |
| 783 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 784 | wm->guard_size; |
| 785 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 786 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 787 | wm_size = fifo_size - entries; |
| 788 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 789 | |
| 790 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 791 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 792 | wm_size = wm->max_wm; |
| 793 | if (wm_size <= 0) |
| 794 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 795 | |
| 796 | /* |
| 797 | * Bspec seems to indicate that the value shouldn't be lower than |
| 798 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 799 | * Lets go for 8 which is the burst size since certain platforms |
| 800 | * already use a hardcoded 8 (which is what the spec says should be |
| 801 | * done). |
| 802 | */ |
| 803 | if (wm_size <= 8) |
| 804 | wm_size = 8; |
| 805 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 806 | return wm_size; |
| 807 | } |
| 808 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 809 | static bool is_disabling(int old, int new, int threshold) |
| 810 | { |
| 811 | return old >= threshold && new < threshold; |
| 812 | } |
| 813 | |
| 814 | static bool is_enabling(int old, int new, int threshold) |
| 815 | { |
| 816 | return old < threshold && new >= threshold; |
| 817 | } |
| 818 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 819 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 820 | { |
| 821 | return dev_priv->wm.max_level + 1; |
| 822 | } |
| 823 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 824 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 825 | const struct intel_plane_state *plane_state) |
| 826 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 827 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 828 | |
| 829 | /* FIXME check the 'enable' instead */ |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 830 | if (!crtc_state->hw.active) |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 831 | return false; |
| 832 | |
| 833 | /* |
| 834 | * Treat cursor with fb as always visible since cursor updates |
| 835 | * can happen faster than the vrefresh rate, and the current |
| 836 | * watermark code doesn't handle that correctly. Cursor updates |
| 837 | * which set/clear the fb or change the cursor size are going |
| 838 | * to get throttled by intel_legacy_cursor_update() to work |
| 839 | * around this problem with the watermark code. |
| 840 | */ |
| 841 | if (plane->id == PLANE_CURSOR) |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 842 | return plane_state->hw.fb != NULL; |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 843 | else |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 844 | return plane_state->uapi.visible; |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 845 | } |
| 846 | |
Ville Syrjälä | 04da7b9 | 2019-11-27 22:12:11 +0200 | [diff] [blame] | 847 | static bool intel_crtc_active(struct intel_crtc *crtc) |
| 848 | { |
| 849 | /* Be paranoid as we can arrive here with only partial |
| 850 | * state retrieved from the hardware during setup. |
| 851 | * |
| 852 | * We can ditch the adjusted_mode.crtc_clock check as soon |
| 853 | * as Haswell has gained clock readout/fastboot support. |
| 854 | * |
| 855 | * We can ditch the crtc->primary->state->fb check as soon as we can |
| 856 | * properly reconstruct framebuffers. |
| 857 | * |
| 858 | * FIXME: The intel_crtc->active here should be switched to |
| 859 | * crtc->state->active once we have proper CRTC states wired up |
| 860 | * for atomic. |
| 861 | */ |
| 862 | return crtc->active && crtc->base.primary->state->fb && |
| 863 | crtc->config->hw.adjusted_mode.crtc_clock; |
| 864 | } |
| 865 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 866 | 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] | 867 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 868 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 869 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 870 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 871 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 872 | if (enabled) |
| 873 | return NULL; |
| 874 | enabled = crtc; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | return enabled; |
| 879 | } |
| 880 | |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 881 | static void pnv_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 882 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 883 | 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] | 884 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 885 | const struct cxsr_latency *latency; |
| 886 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 887 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 888 | |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 889 | latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 890 | dev_priv->is_ddr3, |
| 891 | dev_priv->fsb_freq, |
| 892 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 893 | if (!latency) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 894 | drm_dbg_kms(&dev_priv->drm, |
| 895 | "Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 896 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 897 | return; |
| 898 | } |
| 899 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 900 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 901 | if (crtc) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 902 | const struct drm_display_mode *pipe_mode = |
| 903 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 904 | const struct drm_framebuffer *fb = |
| 905 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 906 | int cpp = fb->format->cpp[0]; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 907 | int clock = pipe_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 908 | |
| 909 | /* Display SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 910 | wm = intel_calculate_wm(clock, &pnv_display_wm, |
| 911 | pnv_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 912 | cpp, latency->display_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 913 | reg = I915_READ(DSPFW1); |
| 914 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 915 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 916 | I915_WRITE(DSPFW1, reg); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 917 | drm_dbg_kms(&dev_priv->drm, "DSPFW1 register is %x\n", reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 918 | |
| 919 | /* cursor SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 920 | wm = intel_calculate_wm(clock, &pnv_cursor_wm, |
| 921 | pnv_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 922 | 4, latency->cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 923 | reg = I915_READ(DSPFW3); |
| 924 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 925 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 926 | I915_WRITE(DSPFW3, reg); |
| 927 | |
| 928 | /* Display HPLL off SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 929 | wm = intel_calculate_wm(clock, &pnv_display_hplloff_wm, |
| 930 | pnv_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 931 | cpp, latency->display_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 932 | reg = I915_READ(DSPFW3); |
| 933 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 934 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 935 | I915_WRITE(DSPFW3, reg); |
| 936 | |
| 937 | /* cursor HPLL off SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 938 | wm = intel_calculate_wm(clock, &pnv_cursor_hplloff_wm, |
| 939 | pnv_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 940 | 4, latency->cursor_hpll_disable); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 941 | reg = I915_READ(DSPFW3); |
| 942 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 943 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 944 | I915_WRITE(DSPFW3, reg); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 945 | drm_dbg_kms(&dev_priv->drm, "DSPFW3 register is %x\n", reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 946 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 947 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 948 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 949 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 953 | /* |
| 954 | * Documentation says: |
| 955 | * "If the line size is small, the TLB fetches can get in the way of the |
| 956 | * data fetches, causing some lag in the pixel data return which is not |
| 957 | * accounted for in the above formulas. The following adjustment only |
| 958 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 959 | * The WM is adjusted upwards by the difference between the FIFO size |
| 960 | * and the size of 8 whole lines. This adjustment is always performed |
| 961 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 962 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 963 | static unsigned int g4x_tlb_miss_wa(int fifo_size, int width, int cpp) |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 964 | { |
| 965 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 966 | |
| 967 | return max(0, tlb_miss); |
| 968 | } |
| 969 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 970 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 971 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 972 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 973 | enum pipe pipe; |
| 974 | |
| 975 | for_each_pipe(dev_priv, pipe) |
| 976 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 977 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 978 | I915_WRITE(DSPFW1, |
| 979 | FW_WM(wm->sr.plane, SR) | |
| 980 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 981 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 982 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
| 983 | I915_WRITE(DSPFW2, |
| 984 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 985 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 986 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 987 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 988 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 989 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
| 990 | I915_WRITE(DSPFW3, |
| 991 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 992 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 993 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 994 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 995 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 996 | POSTING_READ(DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 997 | } |
| 998 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 999 | #define FW_WM_VLV(value, plane) \ |
| 1000 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 1001 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1002 | 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] | 1003 | const struct vlv_wm_values *wm) |
| 1004 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1005 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1006 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1007 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1008 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 1009 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1010 | I915_WRITE(VLV_DDL(pipe), |
| 1011 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 1012 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 1013 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 1014 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 1015 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1016 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 1017 | /* |
| 1018 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 1019 | * high order bits so that there are no out of bounds values |
| 1020 | * present in the registers during the reprogramming. |
| 1021 | */ |
| 1022 | I915_WRITE(DSPHOWM, 0); |
| 1023 | I915_WRITE(DSPHOWM1, 0); |
| 1024 | I915_WRITE(DSPFW4, 0); |
| 1025 | I915_WRITE(DSPFW5, 0); |
| 1026 | I915_WRITE(DSPFW6, 0); |
| 1027 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1028 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1029 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1030 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 1031 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 1032 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1033 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1034 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 1035 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1036 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1037 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1038 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1039 | |
| 1040 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1041 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1042 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1043 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1044 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1045 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 1046 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1047 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1048 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1049 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1050 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1051 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1052 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1053 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1054 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 1055 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1056 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1057 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1058 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1059 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1060 | 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] | 1061 | } else { |
| 1062 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1063 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1064 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1065 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1066 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1067 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1068 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1069 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1070 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1071 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1072 | 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] | 1073 | } |
| 1074 | |
| 1075 | POSTING_READ(DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1076 | } |
| 1077 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1078 | #undef FW_WM_VLV |
| 1079 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1080 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1081 | { |
| 1082 | /* all latencies in usec */ |
| 1083 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1084 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1085 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1086 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1087 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1091 | { |
| 1092 | /* |
| 1093 | * DSPCNTR[13] supposedly controls whether the |
| 1094 | * primary plane can use the FIFO space otherwise |
| 1095 | * reserved for the sprite plane. It's not 100% clear |
| 1096 | * what the actual FIFO size is, but it looks like we |
| 1097 | * can happily set both primary and sprite watermarks |
| 1098 | * up to 127 cachelines. So that would seem to mean |
| 1099 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1100 | * the total FIFO is >= 256 cachelines in size. Either |
| 1101 | * way, we don't seem to have to worry about this |
| 1102 | * repartitioning as the maximum watermark value the |
| 1103 | * register can hold for each plane is lower than the |
| 1104 | * minimum FIFO size. |
| 1105 | */ |
| 1106 | switch (plane_id) { |
| 1107 | case PLANE_CURSOR: |
| 1108 | return 63; |
| 1109 | case PLANE_PRIMARY: |
| 1110 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1111 | case PLANE_SPRITE0: |
| 1112 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1113 | default: |
| 1114 | MISSING_CASE(plane_id); |
| 1115 | return 0; |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | static int g4x_fbc_fifo_size(int level) |
| 1120 | { |
| 1121 | switch (level) { |
| 1122 | case G4X_WM_LEVEL_SR: |
| 1123 | return 7; |
| 1124 | case G4X_WM_LEVEL_HPLL: |
| 1125 | return 15; |
| 1126 | default: |
| 1127 | MISSING_CASE(level); |
| 1128 | return 0; |
| 1129 | } |
| 1130 | } |
| 1131 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1132 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1133 | const struct intel_plane_state *plane_state, |
| 1134 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1135 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1136 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1137 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1138 | const struct drm_display_mode *pipe_mode = |
| 1139 | &crtc_state->hw.pipe_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1140 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1141 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1142 | |
| 1143 | if (latency == 0) |
| 1144 | return USHRT_MAX; |
| 1145 | |
| 1146 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1147 | return 0; |
| 1148 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1149 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1150 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1151 | /* |
| 1152 | * Not 100% sure which way ELK should go here as the |
| 1153 | * spec only says CL/CTG should assume 32bpp and BW |
| 1154 | * doesn't need to. But as these things followed the |
| 1155 | * mobile vs. desktop lines on gen3 as well, let's |
| 1156 | * assume ELK doesn't need this. |
| 1157 | * |
| 1158 | * The spec also fails to list such a restriction for |
| 1159 | * the HPLL watermark, which seems a little strange. |
| 1160 | * Let's use 32bpp for the HPLL watermark as well. |
| 1161 | */ |
| 1162 | if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY && |
| 1163 | level != G4X_WM_LEVEL_NORMAL) |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1164 | cpp = max(cpp, 4u); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1165 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1166 | clock = pipe_mode->crtc_clock; |
| 1167 | htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1168 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1169 | width = drm_rect_width(&plane_state->uapi.dst); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1170 | |
| 1171 | if (plane->id == PLANE_CURSOR) { |
| 1172 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1173 | } else if (plane->id == PLANE_PRIMARY && |
| 1174 | level == G4X_WM_LEVEL_NORMAL) { |
| 1175 | wm = intel_wm_method1(clock, cpp, latency); |
| 1176 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1177 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1178 | |
| 1179 | small = intel_wm_method1(clock, cpp, latency); |
| 1180 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1181 | |
| 1182 | wm = min(small, large); |
| 1183 | } |
| 1184 | |
| 1185 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1186 | width, cpp); |
| 1187 | |
| 1188 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1189 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1190 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1194 | int level, enum plane_id plane_id, u16 value) |
| 1195 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1196 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1197 | bool dirty = false; |
| 1198 | |
| 1199 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1200 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1201 | |
| 1202 | dirty |= raw->plane[plane_id] != value; |
| 1203 | raw->plane[plane_id] = value; |
| 1204 | } |
| 1205 | |
| 1206 | return dirty; |
| 1207 | } |
| 1208 | |
| 1209 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1210 | int level, u16 value) |
| 1211 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1212 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1213 | bool dirty = false; |
| 1214 | |
| 1215 | /* NORMAL level doesn't have an FBC watermark */ |
| 1216 | level = max(level, G4X_WM_LEVEL_SR); |
| 1217 | |
| 1218 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1219 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1220 | |
| 1221 | dirty |= raw->fbc != value; |
| 1222 | raw->fbc = value; |
| 1223 | } |
| 1224 | |
| 1225 | return dirty; |
| 1226 | } |
| 1227 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 1228 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 1229 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1230 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1231 | |
| 1232 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1233 | const struct intel_plane_state *plane_state) |
| 1234 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1235 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1236 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1237 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1238 | enum plane_id plane_id = plane->id; |
| 1239 | bool dirty = false; |
| 1240 | int level; |
| 1241 | |
| 1242 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1243 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1244 | if (plane_id == PLANE_PRIMARY) |
| 1245 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1246 | goto out; |
| 1247 | } |
| 1248 | |
| 1249 | for (level = 0; level < num_levels; level++) { |
| 1250 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1251 | int wm, max_wm; |
| 1252 | |
| 1253 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1254 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1255 | |
| 1256 | if (wm > max_wm) |
| 1257 | break; |
| 1258 | |
| 1259 | dirty |= raw->plane[plane_id] != wm; |
| 1260 | raw->plane[plane_id] = wm; |
| 1261 | |
| 1262 | if (plane_id != PLANE_PRIMARY || |
| 1263 | level == G4X_WM_LEVEL_NORMAL) |
| 1264 | continue; |
| 1265 | |
| 1266 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1267 | raw->plane[plane_id]); |
| 1268 | max_wm = g4x_fbc_fifo_size(level); |
| 1269 | |
| 1270 | /* |
| 1271 | * FBC wm is not mandatory as we |
| 1272 | * can always just disable its use. |
| 1273 | */ |
| 1274 | if (wm > max_wm) |
| 1275 | wm = USHRT_MAX; |
| 1276 | |
| 1277 | dirty |= raw->fbc != wm; |
| 1278 | raw->fbc = wm; |
| 1279 | } |
| 1280 | |
| 1281 | /* mark watermarks as invalid */ |
| 1282 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1283 | |
| 1284 | if (plane_id == PLANE_PRIMARY) |
| 1285 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1286 | |
| 1287 | out: |
| 1288 | if (dirty) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1289 | drm_dbg_kms(&dev_priv->drm, |
| 1290 | "%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1291 | plane->base.name, |
| 1292 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1293 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1294 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1295 | |
| 1296 | if (plane_id == PLANE_PRIMARY) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1297 | drm_dbg_kms(&dev_priv->drm, |
| 1298 | "FBC watermarks: SR=%d, HPLL=%d\n", |
| 1299 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1300 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | return dirty; |
| 1304 | } |
| 1305 | |
| 1306 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1307 | enum plane_id plane_id, int level) |
| 1308 | { |
| 1309 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1310 | |
| 1311 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1312 | } |
| 1313 | |
| 1314 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1315 | int level) |
| 1316 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1317 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1318 | |
| 1319 | if (level > dev_priv->wm.max_level) |
| 1320 | return false; |
| 1321 | |
| 1322 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1323 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1324 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1325 | } |
| 1326 | |
| 1327 | /* mark all levels starting from 'level' as invalid */ |
| 1328 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1329 | struct g4x_wm_state *wm_state, int level) |
| 1330 | { |
| 1331 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1332 | enum plane_id plane_id; |
| 1333 | |
| 1334 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1335 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1336 | } |
| 1337 | |
| 1338 | if (level <= G4X_WM_LEVEL_SR) { |
| 1339 | wm_state->cxsr = false; |
| 1340 | wm_state->sr.cursor = USHRT_MAX; |
| 1341 | wm_state->sr.plane = USHRT_MAX; |
| 1342 | wm_state->sr.fbc = USHRT_MAX; |
| 1343 | } |
| 1344 | |
| 1345 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1346 | wm_state->hpll_en = false; |
| 1347 | wm_state->hpll.cursor = USHRT_MAX; |
| 1348 | wm_state->hpll.plane = USHRT_MAX; |
| 1349 | wm_state->hpll.fbc = USHRT_MAX; |
| 1350 | } |
| 1351 | } |
| 1352 | |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1353 | static bool g4x_compute_fbc_en(const struct g4x_wm_state *wm_state, |
| 1354 | int level) |
| 1355 | { |
| 1356 | if (level < G4X_WM_LEVEL_SR) |
| 1357 | return false; |
| 1358 | |
| 1359 | if (level >= G4X_WM_LEVEL_SR && |
| 1360 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1361 | return false; |
| 1362 | |
| 1363 | if (level >= G4X_WM_LEVEL_HPLL && |
| 1364 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1365 | return false; |
| 1366 | |
| 1367 | return true; |
| 1368 | } |
| 1369 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1370 | static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
| 1371 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1372 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1373 | struct intel_atomic_state *state = |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1374 | to_intel_atomic_state(crtc_state->uapi.state); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1375 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1376 | int num_active_planes = hweight8(crtc_state->active_planes & |
| 1377 | ~BIT(PLANE_CURSOR)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1378 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1379 | const struct intel_plane_state *old_plane_state; |
| 1380 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1381 | struct intel_plane *plane; |
| 1382 | enum plane_id plane_id; |
| 1383 | int i, level; |
| 1384 | unsigned int dirty = 0; |
| 1385 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1386 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1387 | old_plane_state, |
| 1388 | new_plane_state, i) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1389 | if (new_plane_state->hw.crtc != &crtc->base && |
| 1390 | old_plane_state->hw.crtc != &crtc->base) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1391 | continue; |
| 1392 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1393 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1394 | dirty |= BIT(plane->id); |
| 1395 | } |
| 1396 | |
| 1397 | if (!dirty) |
| 1398 | return 0; |
| 1399 | |
| 1400 | level = G4X_WM_LEVEL_NORMAL; |
| 1401 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1402 | goto out; |
| 1403 | |
| 1404 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1405 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1406 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1407 | |
| 1408 | level = G4X_WM_LEVEL_SR; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1409 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1410 | goto out; |
| 1411 | |
| 1412 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1413 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1414 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1415 | wm_state->sr.fbc = raw->fbc; |
| 1416 | |
| 1417 | wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY); |
| 1418 | |
| 1419 | level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1420 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1421 | goto out; |
| 1422 | |
| 1423 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1424 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1425 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1426 | wm_state->hpll.fbc = raw->fbc; |
| 1427 | |
| 1428 | wm_state->hpll_en = wm_state->cxsr; |
| 1429 | |
| 1430 | level++; |
| 1431 | |
| 1432 | out: |
| 1433 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1434 | return -EINVAL; |
| 1435 | |
| 1436 | /* invalidate the higher levels */ |
| 1437 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1438 | |
| 1439 | /* |
| 1440 | * Determine if the FBC watermark(s) can be used. IF |
| 1441 | * this isn't the case we prefer to disable the FBC |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1442 | * watermark(s) rather than disable the SR/HPLL |
| 1443 | * level(s) entirely. 'level-1' is the highest valid |
| 1444 | * level here. |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1445 | */ |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1446 | wm_state->fbc_en = g4x_compute_fbc_en(wm_state, level - 1); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1447 | |
| 1448 | return 0; |
| 1449 | } |
| 1450 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 1451 | static int g4x_compute_intermediate_wm(struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1452 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1453 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1454 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1455 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1456 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
| 1457 | struct intel_atomic_state *intel_state = |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1458 | to_intel_atomic_state(new_crtc_state->uapi.state); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1459 | const struct intel_crtc_state *old_crtc_state = |
| 1460 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 1461 | const struct g4x_wm_state *active = &old_crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1462 | enum plane_id plane_id; |
| 1463 | |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1464 | if (!new_crtc_state->hw.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) { |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1465 | *intermediate = *optimal; |
| 1466 | |
| 1467 | intermediate->cxsr = false; |
| 1468 | intermediate->hpll_en = false; |
| 1469 | goto out; |
| 1470 | } |
| 1471 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1472 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1473 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1474 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1475 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1476 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1477 | |
| 1478 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1479 | intermediate->wm.plane[plane_id] = |
| 1480 | max(optimal->wm.plane[plane_id], |
| 1481 | active->wm.plane[plane_id]); |
| 1482 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1483 | drm_WARN_ON(&dev_priv->drm, intermediate->wm.plane[plane_id] > |
| 1484 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1488 | active->sr.plane); |
| 1489 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1490 | active->sr.cursor); |
| 1491 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1492 | active->sr.fbc); |
| 1493 | |
| 1494 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1495 | active->hpll.plane); |
| 1496 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1497 | active->hpll.cursor); |
| 1498 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1499 | active->hpll.fbc); |
| 1500 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1501 | drm_WARN_ON(&dev_priv->drm, |
| 1502 | (intermediate->sr.plane > |
| 1503 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1504 | intermediate->sr.cursor > |
| 1505 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1506 | intermediate->cxsr); |
| 1507 | drm_WARN_ON(&dev_priv->drm, |
| 1508 | (intermediate->sr.plane > |
| 1509 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1510 | intermediate->sr.cursor > |
| 1511 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1512 | intermediate->hpll_en); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1513 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1514 | drm_WARN_ON(&dev_priv->drm, |
| 1515 | intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1516 | intermediate->fbc_en && intermediate->cxsr); |
| 1517 | drm_WARN_ON(&dev_priv->drm, |
| 1518 | intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1519 | intermediate->fbc_en && intermediate->hpll_en); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1520 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1521 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1522 | /* |
| 1523 | * If our intermediate WM are identical to the final WM, then we can |
| 1524 | * omit the post-vblank programming; only update if it's different. |
| 1525 | */ |
| 1526 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1527 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1528 | |
| 1529 | return 0; |
| 1530 | } |
| 1531 | |
| 1532 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1533 | struct g4x_wm_values *wm) |
| 1534 | { |
| 1535 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1536 | int num_active_pipes = 0; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1537 | |
| 1538 | wm->cxsr = true; |
| 1539 | wm->hpll_en = true; |
| 1540 | wm->fbc_en = true; |
| 1541 | |
| 1542 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1543 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1544 | |
| 1545 | if (!crtc->active) |
| 1546 | continue; |
| 1547 | |
| 1548 | if (!wm_state->cxsr) |
| 1549 | wm->cxsr = false; |
| 1550 | if (!wm_state->hpll_en) |
| 1551 | wm->hpll_en = false; |
| 1552 | if (!wm_state->fbc_en) |
| 1553 | wm->fbc_en = false; |
| 1554 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1555 | num_active_pipes++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1556 | } |
| 1557 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1558 | if (num_active_pipes != 1) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1559 | wm->cxsr = false; |
| 1560 | wm->hpll_en = false; |
| 1561 | wm->fbc_en = false; |
| 1562 | } |
| 1563 | |
| 1564 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1565 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1566 | enum pipe pipe = crtc->pipe; |
| 1567 | |
| 1568 | wm->pipe[pipe] = wm_state->wm; |
| 1569 | if (crtc->active && wm->cxsr) |
| 1570 | wm->sr = wm_state->sr; |
| 1571 | if (crtc->active && wm->hpll_en) |
| 1572 | wm->hpll = wm_state->hpll; |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1577 | { |
| 1578 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1579 | struct g4x_wm_values new_wm = {}; |
| 1580 | |
| 1581 | g4x_merge_wm(dev_priv, &new_wm); |
| 1582 | |
| 1583 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1584 | return; |
| 1585 | |
| 1586 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1587 | _intel_set_memory_cxsr(dev_priv, false); |
| 1588 | |
| 1589 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1590 | |
| 1591 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1592 | _intel_set_memory_cxsr(dev_priv, true); |
| 1593 | |
| 1594 | *old_wm = new_wm; |
| 1595 | } |
| 1596 | |
| 1597 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1598 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1599 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1600 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1601 | const struct intel_crtc_state *crtc_state = |
| 1602 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1603 | |
| 1604 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1605 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1606 | g4x_program_watermarks(dev_priv); |
| 1607 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1608 | } |
| 1609 | |
| 1610 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1611 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1612 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1613 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1614 | const struct intel_crtc_state *crtc_state = |
| 1615 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1616 | |
| 1617 | if (!crtc_state->wm.need_postvbl_update) |
| 1618 | return; |
| 1619 | |
| 1620 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 1621 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1622 | g4x_program_watermarks(dev_priv); |
| 1623 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1624 | } |
| 1625 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1626 | /* latency must be in 0.1us units. */ |
| 1627 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1628 | unsigned int htotal, |
| 1629 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1630 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1631 | unsigned int latency) |
| 1632 | { |
| 1633 | unsigned int ret; |
| 1634 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1635 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1636 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1637 | ret = DIV_ROUND_UP(ret, 64); |
| 1638 | |
| 1639 | return ret; |
| 1640 | } |
| 1641 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1642 | 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] | 1643 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1644 | /* all latencies in usec */ |
| 1645 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1646 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1647 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1648 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1649 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1650 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1651 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1652 | |
| 1653 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1654 | } |
| 1655 | } |
| 1656 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1657 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1658 | const struct intel_plane_state *plane_state, |
| 1659 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1660 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1661 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1662 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1663 | const struct drm_display_mode *pipe_mode = |
| 1664 | &crtc_state->hw.pipe_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1665 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1666 | |
| 1667 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1668 | return USHRT_MAX; |
| 1669 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1670 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1671 | return 0; |
| 1672 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1673 | cpp = plane_state->hw.fb->format->cpp[0]; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1674 | clock = pipe_mode->crtc_clock; |
| 1675 | htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1676 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1677 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1678 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1679 | /* |
| 1680 | * FIXME the formula gives values that are |
| 1681 | * too big for the cursor FIFO, and hence we |
| 1682 | * would never be able to use cursors. For |
| 1683 | * now just hardcode the watermark. |
| 1684 | */ |
| 1685 | wm = 63; |
| 1686 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1687 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1688 | dev_priv->wm.pri_latency[level] * 10); |
| 1689 | } |
| 1690 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1691 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1692 | } |
| 1693 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1694 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1695 | { |
| 1696 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1697 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1698 | } |
| 1699 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1700 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1701 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1702 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1703 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1704 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1705 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1706 | 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] | 1707 | unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1708 | int num_active_planes = hweight8(active_planes); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1709 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1710 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1711 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1712 | unsigned int total_rate; |
| 1713 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1714 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1715 | /* |
| 1716 | * When enabling sprite0 after sprite1 has already been enabled |
| 1717 | * we tend to get an underrun unless sprite0 already has some |
| 1718 | * FIFO space allcoated. Hence we always allocate at least one |
| 1719 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1720 | * |
| 1721 | * All other plane enable sequences appear immune to this problem. |
| 1722 | */ |
| 1723 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1724 | sprite0_fifo_extra = 1; |
| 1725 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1726 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1727 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1728 | raw->plane[PLANE_SPRITE1] + |
| 1729 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1730 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1731 | if (total_rate > fifo_size) |
| 1732 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1733 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1734 | if (total_rate == 0) |
| 1735 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1736 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1737 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1738 | unsigned int rate; |
| 1739 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1740 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1741 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1742 | continue; |
| 1743 | } |
| 1744 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1745 | rate = raw->plane[plane_id]; |
| 1746 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1747 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1748 | } |
| 1749 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1750 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1751 | fifo_left -= sprite0_fifo_extra; |
| 1752 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1753 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1754 | |
| 1755 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1756 | |
| 1757 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1758 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1759 | int plane_extra; |
| 1760 | |
| 1761 | if (fifo_left == 0) |
| 1762 | break; |
| 1763 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1764 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1765 | continue; |
| 1766 | |
| 1767 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1768 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1769 | fifo_left -= plane_extra; |
| 1770 | } |
| 1771 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1772 | drm_WARN_ON(&dev_priv->drm, active_planes != 0 && fifo_left != 0); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1773 | |
| 1774 | /* give it all to the first plane if none are active */ |
| 1775 | if (active_planes == 0) { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1776 | drm_WARN_ON(&dev_priv->drm, fifo_left != fifo_size); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1777 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1778 | } |
| 1779 | |
| 1780 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1781 | } |
| 1782 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1783 | /* mark all levels starting from 'level' as invalid */ |
| 1784 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1785 | struct vlv_wm_state *wm_state, int level) |
| 1786 | { |
| 1787 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1788 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1789 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1790 | enum plane_id plane_id; |
| 1791 | |
| 1792 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1793 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1794 | |
| 1795 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1796 | wm_state->sr[level].plane = USHRT_MAX; |
| 1797 | } |
| 1798 | } |
| 1799 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1800 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1801 | { |
| 1802 | if (wm > fifo_size) |
| 1803 | return USHRT_MAX; |
| 1804 | else |
| 1805 | return fifo_size - wm; |
| 1806 | } |
| 1807 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1808 | /* |
| 1809 | * Starting from 'level' set all higher |
| 1810 | * levels to 'value' in the "raw" watermarks. |
| 1811 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1812 | 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] | 1813 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1814 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1815 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1816 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1817 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1818 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1819 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1820 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1821 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1822 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1823 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1824 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1825 | |
| 1826 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1827 | } |
| 1828 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1829 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1830 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1831 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1832 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1833 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1834 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1835 | 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] | 1836 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1837 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1838 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1839 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1840 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1841 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1845 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1846 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1847 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1848 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1849 | if (wm > max_wm) |
| 1850 | break; |
| 1851 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1852 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1853 | raw->plane[plane_id] = wm; |
| 1854 | } |
| 1855 | |
| 1856 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1857 | 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] | 1858 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1859 | out: |
| 1860 | if (dirty) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1861 | drm_dbg_kms(&dev_priv->drm, |
| 1862 | "%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n", |
| 1863 | plane->base.name, |
| 1864 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1865 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1866 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1867 | |
| 1868 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1871 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1872 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1873 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1874 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1875 | &crtc_state->wm.vlv.raw[level]; |
| 1876 | const struct vlv_fifo_state *fifo_state = |
| 1877 | &crtc_state->wm.vlv.fifo_state; |
| 1878 | |
| 1879 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1880 | } |
| 1881 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1882 | 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] | 1883 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1884 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1885 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1886 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1887 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | 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] | 1891 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1892 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1893 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1894 | struct intel_atomic_state *state = |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1895 | to_intel_atomic_state(crtc_state->uapi.state); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1896 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1897 | const struct vlv_fifo_state *fifo_state = |
| 1898 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1899 | int num_active_planes = hweight8(crtc_state->active_planes & |
| 1900 | ~BIT(PLANE_CURSOR)); |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1901 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->uapi); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1902 | const struct intel_plane_state *old_plane_state; |
| 1903 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1904 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1905 | enum plane_id plane_id; |
| 1906 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1907 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1908 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1909 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1910 | old_plane_state, |
| 1911 | new_plane_state, i) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1912 | if (new_plane_state->hw.crtc != &crtc->base && |
| 1913 | old_plane_state->hw.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1914 | continue; |
| 1915 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1916 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1917 | dirty |= BIT(plane->id); |
| 1918 | } |
| 1919 | |
| 1920 | /* |
| 1921 | * DSPARB registers may have been reset due to the |
| 1922 | * power well being turned off. Make sure we restore |
| 1923 | * them to a consistent state even if no primary/sprite |
| 1924 | * planes are initially active. |
| 1925 | */ |
| 1926 | if (needs_modeset) |
| 1927 | crtc_state->fifo_changed = true; |
| 1928 | |
| 1929 | if (!dirty) |
| 1930 | return 0; |
| 1931 | |
| 1932 | /* cursor changes don't warrant a FIFO recompute */ |
| 1933 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1934 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1935 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1936 | const struct vlv_fifo_state *old_fifo_state = |
| 1937 | &old_crtc_state->wm.vlv.fifo_state; |
| 1938 | |
| 1939 | ret = vlv_compute_fifo(crtc_state); |
| 1940 | if (ret) |
| 1941 | return ret; |
| 1942 | |
| 1943 | if (needs_modeset || |
| 1944 | memcmp(old_fifo_state, fifo_state, |
| 1945 | sizeof(*fifo_state)) != 0) |
| 1946 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1947 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1948 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1949 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1950 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1951 | /* |
| 1952 | * Note that enabling cxsr with no primary/sprite planes |
| 1953 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1954 | * with exactly one enabled primary/sprite plane. |
| 1955 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1956 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1957 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1958 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1959 | const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 1960 | const int sr_fifo_size = INTEL_NUM_PIPES(dev_priv) * 512 - 1; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1961 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1962 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1963 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1964 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1965 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1966 | wm_state->wm[level].plane[plane_id] = |
| 1967 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1968 | fifo_state->plane[plane_id]); |
| 1969 | } |
| 1970 | |
| 1971 | wm_state->sr[level].plane = |
| 1972 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1973 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1974 | raw->plane[PLANE_SPRITE1]), |
| 1975 | sr_fifo_size); |
| 1976 | |
| 1977 | wm_state->sr[level].cursor = |
| 1978 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1979 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1980 | } |
| 1981 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1982 | if (level == 0) |
| 1983 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1984 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1985 | /* limit to only levels we can actually handle */ |
| 1986 | wm_state->num_levels = level; |
| 1987 | |
| 1988 | /* invalidate the higher levels */ |
| 1989 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1990 | |
| 1991 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1992 | } |
| 1993 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1994 | #define VLV_FIFO(plane, value) \ |
| 1995 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1996 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1997 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1998 | struct intel_crtc *crtc) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1999 | { |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2000 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2001 | struct intel_uncore *uncore = &dev_priv->uncore; |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2002 | const struct intel_crtc_state *crtc_state = |
| 2003 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 2004 | const struct vlv_fifo_state *fifo_state = |
| 2005 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2006 | int sprite0_start, sprite1_start, fifo_size; |
Kees Cook | 2713eb4 | 2020-02-20 16:05:17 -0800 | [diff] [blame] | 2007 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2008 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 2009 | if (!crtc_state->fifo_changed) |
| 2010 | return; |
| 2011 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2012 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 2013 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 2014 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2015 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 2016 | drm_WARN_ON(&dev_priv->drm, fifo_state->plane[PLANE_CURSOR] != 63); |
| 2017 | drm_WARN_ON(&dev_priv->drm, fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2018 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 2019 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 2020 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2021 | /* |
| 2022 | * uncore.lock serves a double purpose here. It allows us to |
| 2023 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 2024 | * it protects the DSPARB registers from getting clobbered by |
| 2025 | * parallel updates from multiple pipes. |
| 2026 | * |
| 2027 | * intel_pipe_update_start() has already disabled interrupts |
| 2028 | * for us, so a plain spin_lock() is sufficient here. |
| 2029 | */ |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2030 | spin_lock(&uncore->lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2031 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2032 | switch (crtc->pipe) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2033 | case PIPE_A: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2034 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2035 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2036 | |
| 2037 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 2038 | VLV_FIFO(SPRITEB, 0xff)); |
| 2039 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 2040 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 2041 | |
| 2042 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 2043 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 2044 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 2045 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 2046 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2047 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2048 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2049 | break; |
| 2050 | case PIPE_B: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2051 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2052 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2053 | |
| 2054 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 2055 | VLV_FIFO(SPRITED, 0xff)); |
| 2056 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 2057 | VLV_FIFO(SPRITED, sprite1_start)); |
| 2058 | |
| 2059 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 2060 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 2061 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 2062 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 2063 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2064 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2065 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2066 | break; |
| 2067 | case PIPE_C: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2068 | dsparb3 = intel_uncore_read_fw(uncore, DSPARB3); |
| 2069 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2070 | |
| 2071 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2072 | VLV_FIFO(SPRITEF, 0xff)); |
| 2073 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2074 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2075 | |
| 2076 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2077 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2078 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2079 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2080 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2081 | intel_uncore_write_fw(uncore, DSPARB3, dsparb3); |
| 2082 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2083 | break; |
| 2084 | default: |
| 2085 | break; |
| 2086 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2087 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2088 | intel_uncore_posting_read_fw(uncore, DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2089 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2090 | spin_unlock(&uncore->lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | #undef VLV_FIFO |
| 2094 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2095 | static int vlv_compute_intermediate_wm(struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2096 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 2097 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2098 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2099 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
| 2100 | struct intel_atomic_state *intel_state = |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 2101 | to_intel_atomic_state(new_crtc_state->uapi.state); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2102 | const struct intel_crtc_state *old_crtc_state = |
| 2103 | intel_atomic_get_old_crtc_state(intel_state, crtc); |
| 2104 | const struct vlv_wm_state *active = &old_crtc_state->wm.vlv.optimal; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2105 | int level; |
| 2106 | |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 2107 | if (!new_crtc_state->hw.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) { |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2108 | *intermediate = *optimal; |
| 2109 | |
| 2110 | intermediate->cxsr = false; |
| 2111 | goto out; |
| 2112 | } |
| 2113 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2114 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2115 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2116 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2117 | |
| 2118 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2119 | enum plane_id plane_id; |
| 2120 | |
| 2121 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2122 | intermediate->wm[level].plane[plane_id] = |
| 2123 | min(optimal->wm[level].plane[plane_id], |
| 2124 | active->wm[level].plane[plane_id]); |
| 2125 | } |
| 2126 | |
| 2127 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2128 | active->sr[level].plane); |
| 2129 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2130 | active->sr[level].cursor); |
| 2131 | } |
| 2132 | |
| 2133 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2134 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2135 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2136 | /* |
| 2137 | * If our intermediate WM are identical to the final WM, then we can |
| 2138 | * omit the post-vblank programming; only update if it's different. |
| 2139 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2140 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2141 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2142 | |
| 2143 | return 0; |
| 2144 | } |
| 2145 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2146 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2147 | struct vlv_wm_values *wm) |
| 2148 | { |
| 2149 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2150 | int num_active_pipes = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2151 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2152 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2153 | wm->cxsr = true; |
| 2154 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2155 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2156 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2157 | |
| 2158 | if (!crtc->active) |
| 2159 | continue; |
| 2160 | |
| 2161 | if (!wm_state->cxsr) |
| 2162 | wm->cxsr = false; |
| 2163 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2164 | num_active_pipes++; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2165 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2166 | } |
| 2167 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2168 | if (num_active_pipes != 1) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2169 | wm->cxsr = false; |
| 2170 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2171 | if (num_active_pipes > 1) |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2172 | wm->level = VLV_WM_LEVEL_PM2; |
| 2173 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2174 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2175 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2176 | enum pipe pipe = crtc->pipe; |
| 2177 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2178 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2179 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2180 | wm->sr = wm_state->sr[wm->level]; |
| 2181 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2182 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2183 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2184 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2185 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2189 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2190 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2191 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2192 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2193 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2194 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2195 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2196 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2197 | return; |
| 2198 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2199 | 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] | 2200 | chv_set_memory_dvfs(dev_priv, false); |
| 2201 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2202 | 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] | 2203 | chv_set_memory_pm5(dev_priv, false); |
| 2204 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2205 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2206 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2207 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2208 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2209 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2210 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2211 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2212 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2213 | 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] | 2214 | chv_set_memory_pm5(dev_priv, true); |
| 2215 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2216 | 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] | 2217 | chv_set_memory_dvfs(dev_priv, true); |
| 2218 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2219 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2220 | } |
| 2221 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2222 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2223 | struct intel_crtc *crtc) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2224 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2225 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 2226 | const struct intel_crtc_state *crtc_state = |
| 2227 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2228 | |
| 2229 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2230 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2231 | vlv_program_watermarks(dev_priv); |
| 2232 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2233 | } |
| 2234 | |
| 2235 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2236 | struct intel_crtc *crtc) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2237 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2238 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 2239 | const struct intel_crtc_state *crtc_state = |
| 2240 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2241 | |
| 2242 | if (!crtc_state->wm.need_postvbl_update) |
| 2243 | return; |
| 2244 | |
| 2245 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 2246 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2247 | vlv_program_watermarks(dev_priv); |
| 2248 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2249 | } |
| 2250 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2251 | static void i965_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2252 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2253 | 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] | 2254 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2255 | int srwm = 1; |
| 2256 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2257 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2258 | |
| 2259 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2260 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2261 | if (crtc) { |
| 2262 | /* self-refresh has much higher latency */ |
| 2263 | static const int sr_latency_ns = 12000; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2264 | const struct drm_display_mode *pipe_mode = |
| 2265 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2266 | const struct drm_framebuffer *fb = |
| 2267 | crtc->base.primary->state->fb; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2268 | int clock = pipe_mode->crtc_clock; |
| 2269 | int htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2270 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2271 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2272 | int entries; |
| 2273 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2274 | entries = intel_wm_method2(clock, htotal, |
| 2275 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2276 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2277 | srwm = I965_FIFO_SIZE - entries; |
| 2278 | if (srwm < 0) |
| 2279 | srwm = 1; |
| 2280 | srwm &= 0x1ff; |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2281 | drm_dbg_kms(&dev_priv->drm, |
| 2282 | "self-refresh entries: %d, wm: %d\n", |
| 2283 | entries, srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2284 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2285 | entries = intel_wm_method2(clock, htotal, |
| 2286 | crtc->base.cursor->state->crtc_w, 4, |
| 2287 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2288 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2289 | i965_cursor_wm_info.cacheline_size) + |
| 2290 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2291 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2292 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2293 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2294 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2295 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2296 | drm_dbg_kms(&dev_priv->drm, |
| 2297 | "self-refresh watermark: display plane %d " |
| 2298 | "cursor %d\n", srwm, cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2299 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2300 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2301 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2302 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2303 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2304 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2305 | } |
| 2306 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2307 | drm_dbg_kms(&dev_priv->drm, |
| 2308 | "Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2309 | srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2310 | |
| 2311 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2312 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 2313 | FW_WM(8, CURSORB) | |
| 2314 | FW_WM(8, PLANEB) | |
| 2315 | FW_WM(8, PLANEA)); |
| 2316 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 2317 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2318 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2319 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2320 | |
| 2321 | if (cxsr_enabled) |
| 2322 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2323 | } |
| 2324 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2325 | #undef FW_WM |
| 2326 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2327 | static void i9xx_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2328 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2329 | struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2330 | const struct intel_watermark_params *wm_info; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2331 | u32 fwater_lo; |
| 2332 | u32 fwater_hi; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2333 | int cwm, srwm = 1; |
| 2334 | int fifo_size; |
| 2335 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2336 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2337 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2338 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2339 | wm_info = &i945_wm_info; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2340 | else if (!IS_GEN(dev_priv, 2)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2341 | wm_info = &i915_wm_info; |
| 2342 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2343 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2344 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2345 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_A); |
| 2346 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2347 | if (intel_crtc_active(crtc)) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2348 | const struct drm_display_mode *pipe_mode = |
| 2349 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2350 | const struct drm_framebuffer *fb = |
| 2351 | crtc->base.primary->state->fb; |
| 2352 | int cpp; |
| 2353 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2354 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2355 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2356 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2357 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2358 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2359 | planea_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2360 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2361 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2362 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2363 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2364 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2365 | if (planea_wm > (long)wm_info->max_wm) |
| 2366 | planea_wm = wm_info->max_wm; |
| 2367 | } |
| 2368 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2369 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2370 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2371 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2372 | fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_B); |
| 2373 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2374 | if (intel_crtc_active(crtc)) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2375 | const struct drm_display_mode *pipe_mode = |
| 2376 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2377 | const struct drm_framebuffer *fb = |
| 2378 | crtc->base.primary->state->fb; |
| 2379 | int cpp; |
| 2380 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2381 | if (IS_GEN(dev_priv, 2)) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2382 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2383 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2384 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2385 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2386 | planeb_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2387 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2388 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2389 | if (enabled == NULL) |
| 2390 | enabled = crtc; |
| 2391 | else |
| 2392 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2393 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2394 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2395 | if (planeb_wm > (long)wm_info->max_wm) |
| 2396 | planeb_wm = wm_info->max_wm; |
| 2397 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2398 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2399 | drm_dbg_kms(&dev_priv->drm, |
| 2400 | "FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2401 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2402 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2403 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2404 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2405 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2406 | |
| 2407 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2408 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2409 | enabled = NULL; |
| 2410 | } |
| 2411 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2412 | /* |
| 2413 | * Overlay gets an aggressive default since video jitter is bad. |
| 2414 | */ |
| 2415 | cwm = 2; |
| 2416 | |
| 2417 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2418 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2419 | |
| 2420 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2421 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2422 | /* self-refresh has much higher latency */ |
| 2423 | static const int sr_latency_ns = 6000; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2424 | const struct drm_display_mode *pipe_mode = |
| 2425 | &enabled->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2426 | const struct drm_framebuffer *fb = |
| 2427 | enabled->base.primary->state->fb; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2428 | int clock = pipe_mode->crtc_clock; |
| 2429 | int htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2430 | int hdisplay = enabled->config->pipe_src_w; |
| 2431 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2432 | int entries; |
| 2433 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2434 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2435 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2436 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2437 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2438 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2439 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2440 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2441 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2442 | drm_dbg_kms(&dev_priv->drm, |
| 2443 | "self-refresh entries: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2444 | srwm = wm_info->fifo_size - entries; |
| 2445 | if (srwm < 0) |
| 2446 | srwm = 1; |
| 2447 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2448 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2449 | I915_WRITE(FW_BLC_SELF, |
| 2450 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2451 | else |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2452 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 2453 | } |
| 2454 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2455 | drm_dbg_kms(&dev_priv->drm, |
| 2456 | "Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2457 | planea_wm, planeb_wm, cwm, srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2458 | |
| 2459 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2460 | fwater_hi = (cwm & 0x1f); |
| 2461 | |
| 2462 | /* Set request length to 8 cachelines per fetch */ |
| 2463 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2464 | fwater_hi = fwater_hi | (1 << 8); |
| 2465 | |
| 2466 | I915_WRITE(FW_BLC, fwater_lo); |
| 2467 | I915_WRITE(FW_BLC2, fwater_hi); |
| 2468 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2469 | if (enabled) |
| 2470 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2471 | } |
| 2472 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 2473 | static void i845_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2474 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2475 | 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] | 2476 | struct intel_crtc *crtc; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2477 | const struct drm_display_mode *pipe_mode; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2478 | u32 fwater_lo; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2479 | int planea_wm; |
| 2480 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2481 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2482 | if (crtc == NULL) |
| 2483 | return; |
| 2484 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2485 | pipe_mode = &crtc->config->hw.pipe_mode; |
| 2486 | planea_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2487 | &i845_wm_info, |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2488 | dev_priv->display.get_fifo_size(dev_priv, PLANE_A), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2489 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2490 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 2491 | fwater_lo |= (3<<8) | planea_wm; |
| 2492 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2493 | drm_dbg_kms(&dev_priv->drm, |
| 2494 | "Setting FIFO watermarks - A: %d\n", planea_wm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2495 | |
| 2496 | I915_WRITE(FW_BLC, fwater_lo); |
| 2497 | } |
| 2498 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2499 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2500 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 2501 | unsigned int cpp, |
| 2502 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2503 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2504 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2505 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2506 | ret = intel_wm_method1(pixel_rate, cpp, latency); |
| 2507 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2508 | |
| 2509 | return ret; |
| 2510 | } |
| 2511 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2512 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2513 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2514 | unsigned int htotal, |
| 2515 | unsigned int width, |
| 2516 | unsigned int cpp, |
| 2517 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2518 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2519 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2520 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2521 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2522 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2523 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2524 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2525 | return ret; |
| 2526 | } |
| 2527 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2528 | static u32 ilk_wm_fbc(u32 pri_val, u32 horiz_pixels, u8 cpp) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2529 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2530 | /* |
| 2531 | * Neither of these should be possible since this function shouldn't be |
| 2532 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2533 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2534 | * elsewhere in the driver. |
| 2535 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2536 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2537 | return 0; |
| 2538 | if (WARN_ON(!horiz_pixels)) |
| 2539 | return 0; |
| 2540 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2541 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2542 | } |
| 2543 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2544 | struct ilk_wm_maximums { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2545 | u16 pri; |
| 2546 | u16 spr; |
| 2547 | u16 cur; |
| 2548 | u16 fbc; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2549 | }; |
| 2550 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2551 | /* |
| 2552 | * For both WM_PIPE and WM_LP. |
| 2553 | * mem_value must be in 0.1us units. |
| 2554 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2555 | static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state, |
| 2556 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2557 | u32 mem_value, bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2558 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2559 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2560 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2561 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2562 | if (mem_value == 0) |
| 2563 | return U32_MAX; |
| 2564 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2565 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2566 | return 0; |
| 2567 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2568 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2569 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2570 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2571 | |
| 2572 | if (!is_lp) |
| 2573 | return method1; |
| 2574 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2575 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2576 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2577 | drm_rect_width(&plane_state->uapi.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2578 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2579 | |
| 2580 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2581 | } |
| 2582 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2583 | /* |
| 2584 | * For both WM_PIPE and WM_LP. |
| 2585 | * mem_value must be in 0.1us units. |
| 2586 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2587 | static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state, |
| 2588 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2589 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2590 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2591 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2592 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2593 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2594 | if (mem_value == 0) |
| 2595 | return U32_MAX; |
| 2596 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2597 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2598 | return 0; |
| 2599 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2600 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2601 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2602 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
| 2603 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2604 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2605 | drm_rect_width(&plane_state->uapi.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2606 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2607 | return min(method1, method2); |
| 2608 | } |
| 2609 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2610 | /* |
| 2611 | * For both WM_PIPE and WM_LP. |
| 2612 | * mem_value must be in 0.1us units. |
| 2613 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2614 | static u32 ilk_compute_cur_wm(const struct intel_crtc_state *crtc_state, |
| 2615 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2616 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2617 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2618 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2619 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2620 | if (mem_value == 0) |
| 2621 | return U32_MAX; |
| 2622 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2623 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2624 | return 0; |
| 2625 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2626 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2627 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2628 | return ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2629 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2630 | drm_rect_width(&plane_state->uapi.dst), |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 2631 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2632 | } |
| 2633 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2634 | /* Only for WM_LP. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2635 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 2636 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2637 | u32 pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2638 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2639 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2640 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2641 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2642 | return 0; |
| 2643 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2644 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2645 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2646 | return ilk_wm_fbc(pri_val, drm_rect_width(&plane_state->uapi.dst), |
| 2647 | cpp); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2648 | } |
| 2649 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2650 | static unsigned int |
| 2651 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2652 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2653 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2654 | return 3072; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2655 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2656 | return 768; |
| 2657 | else |
| 2658 | return 512; |
| 2659 | } |
| 2660 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2661 | static unsigned int |
| 2662 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2663 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2664 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2665 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2666 | /* BDW primary/sprite plane watermarks */ |
| 2667 | return level == 0 ? 255 : 2047; |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2668 | else if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2669 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2670 | return level == 0 ? 127 : 1023; |
| 2671 | else if (!is_sprite) |
| 2672 | /* ILK/SNB primary plane watermarks */ |
| 2673 | return level == 0 ? 127 : 511; |
| 2674 | else |
| 2675 | /* ILK/SNB sprite plane watermarks */ |
| 2676 | return level == 0 ? 63 : 255; |
| 2677 | } |
| 2678 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2679 | static unsigned int |
| 2680 | 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] | 2681 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2682 | if (INTEL_GEN(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2683 | return level == 0 ? 63 : 255; |
| 2684 | else |
| 2685 | return level == 0 ? 31 : 63; |
| 2686 | } |
| 2687 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2688 | 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] | 2689 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2690 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2691 | return 31; |
| 2692 | else |
| 2693 | return 15; |
| 2694 | } |
| 2695 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2696 | /* Calculate the maximum primary/sprite plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2697 | static unsigned int ilk_plane_wm_max(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2698 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2699 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2700 | enum intel_ddb_partitioning ddb_partitioning, |
| 2701 | bool is_sprite) |
| 2702 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2703 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2704 | |
| 2705 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2706 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2707 | return 0; |
| 2708 | |
| 2709 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2710 | if (level == 0 || config->num_pipes_active > 1) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 2711 | fifo_size /= INTEL_NUM_PIPES(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2712 | |
| 2713 | /* |
| 2714 | * For some reason the non self refresh |
| 2715 | * FIFO size is only half of the self |
| 2716 | * refresh FIFO size on ILK/SNB. |
| 2717 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2718 | if (INTEL_GEN(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2719 | fifo_size /= 2; |
| 2720 | } |
| 2721 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2722 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2723 | /* level 0 is always calculated with 1:1 split */ |
| 2724 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2725 | if (is_sprite) |
| 2726 | fifo_size *= 5; |
| 2727 | fifo_size /= 6; |
| 2728 | } else { |
| 2729 | fifo_size /= 2; |
| 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2734 | 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] | 2735 | } |
| 2736 | |
| 2737 | /* Calculate the maximum cursor plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2738 | static unsigned int ilk_cursor_wm_max(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2739 | int level, |
| 2740 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2741 | { |
| 2742 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2743 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2744 | return 64; |
| 2745 | |
| 2746 | /* otherwise just report max that registers can hold */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2747 | return ilk_cursor_wm_reg_max(dev_priv, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2748 | } |
| 2749 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2750 | static void ilk_compute_wm_maximums(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2751 | int level, |
| 2752 | const struct intel_wm_config *config, |
| 2753 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2754 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2755 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2756 | max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false); |
| 2757 | max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true); |
| 2758 | max->cur = ilk_cursor_wm_max(dev_priv, level, config); |
| 2759 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2760 | } |
| 2761 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2762 | 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] | 2763 | int level, |
| 2764 | struct ilk_wm_maximums *max) |
| 2765 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2766 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2767 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2768 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2769 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2770 | } |
| 2771 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2772 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2773 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2774 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2775 | { |
| 2776 | bool ret; |
| 2777 | |
| 2778 | /* already determined to be invalid? */ |
| 2779 | if (!result->enable) |
| 2780 | return false; |
| 2781 | |
| 2782 | result->enable = result->pri_val <= max->pri && |
| 2783 | result->spr_val <= max->spr && |
| 2784 | result->cur_val <= max->cur; |
| 2785 | |
| 2786 | ret = result->enable; |
| 2787 | |
| 2788 | /* |
| 2789 | * HACK until we can pre-compute everything, |
| 2790 | * and thus fail gracefully if LP0 watermarks |
| 2791 | * are exceeded... |
| 2792 | */ |
| 2793 | if (level == 0 && !result->enable) { |
| 2794 | if (result->pri_val > max->pri) |
| 2795 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2796 | level, result->pri_val, max->pri); |
| 2797 | if (result->spr_val > max->spr) |
| 2798 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2799 | level, result->spr_val, max->spr); |
| 2800 | if (result->cur_val > max->cur) |
| 2801 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2802 | level, result->cur_val, max->cur); |
| 2803 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2804 | result->pri_val = min_t(u32, result->pri_val, max->pri); |
| 2805 | result->spr_val = min_t(u32, result->spr_val, max->spr); |
| 2806 | result->cur_val = min_t(u32, result->cur_val, max->cur); |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2807 | result->enable = true; |
| 2808 | } |
| 2809 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2810 | return ret; |
| 2811 | } |
| 2812 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2813 | static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 2814 | const struct intel_crtc *crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2815 | int level, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2816 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2817 | const struct intel_plane_state *pristate, |
| 2818 | const struct intel_plane_state *sprstate, |
| 2819 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2820 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2821 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2822 | u16 pri_latency = dev_priv->wm.pri_latency[level]; |
| 2823 | u16 spr_latency = dev_priv->wm.spr_latency[level]; |
| 2824 | u16 cur_latency = dev_priv->wm.cur_latency[level]; |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2825 | |
| 2826 | /* WM1+ latency values stored in 0.5us units */ |
| 2827 | if (level > 0) { |
| 2828 | pri_latency *= 5; |
| 2829 | spr_latency *= 5; |
| 2830 | cur_latency *= 5; |
| 2831 | } |
| 2832 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2833 | if (pristate) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2834 | result->pri_val = ilk_compute_pri_wm(crtc_state, pristate, |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2835 | pri_latency, level); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2836 | result->fbc_val = ilk_compute_fbc_wm(crtc_state, pristate, result->pri_val); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | if (sprstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2840 | result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2841 | |
| 2842 | if (curstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2843 | result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2844 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2845 | result->enable = true; |
| 2846 | } |
| 2847 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2848 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2849 | u16 wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2850 | { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2851 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 2852 | |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2853 | if (INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2854 | u32 val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2855 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2856 | int level, max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2857 | |
| 2858 | /* read the first set of memory latencies[0:3] */ |
| 2859 | val = 0; /* data0 to be programmed to 0 for first set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2860 | ret = sandybridge_pcode_read(dev_priv, |
| 2861 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2862 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2863 | |
| 2864 | if (ret) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2865 | drm_err(&dev_priv->drm, |
| 2866 | "SKL Mailbox read error = %d\n", ret); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2867 | return; |
| 2868 | } |
| 2869 | |
| 2870 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2871 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2872 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2873 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2874 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2875 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2876 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2877 | |
| 2878 | /* read the second set of memory latencies[4:7] */ |
| 2879 | val = 1; /* data0 to be programmed to 1 for second set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2880 | ret = sandybridge_pcode_read(dev_priv, |
| 2881 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2882 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2883 | if (ret) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2884 | drm_err(&dev_priv->drm, |
| 2885 | "SKL Mailbox read error = %d\n", ret); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2886 | return; |
| 2887 | } |
| 2888 | |
| 2889 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2890 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2891 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2892 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2893 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2894 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2895 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2896 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2897 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2898 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2899 | * need to be disabled. We make sure to sanitize the values out |
| 2900 | * of the punit to satisfy this requirement. |
| 2901 | */ |
| 2902 | for (level = 1; level <= max_level; level++) { |
| 2903 | if (wm[level] == 0) { |
| 2904 | for (i = level + 1; i <= max_level; i++) |
| 2905 | wm[i] = 0; |
| 2906 | break; |
| 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | /* |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2911 | * WaWmMemoryReadLatency:skl+,glk |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2912 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2913 | * punit doesn't take into account the read latency so we need |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2914 | * to add 2us to the various latency levels we retrieve from the |
| 2915 | * punit when level 0 response data us 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2916 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2917 | if (wm[0] == 0) { |
| 2918 | wm[0] += 2; |
| 2919 | for (level = 1; level <= max_level; level++) { |
| 2920 | if (wm[level] == 0) |
| 2921 | break; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2922 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2923 | } |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2924 | } |
| 2925 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2926 | /* |
| 2927 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2928 | * If we could not get dimm info enable this WA to prevent from |
| 2929 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2930 | * to avoid any underrun. |
| 2931 | */ |
Ville Syrjälä | 5d6f36b | 2018-10-23 21:21:02 +0300 | [diff] [blame] | 2932 | if (dev_priv->dram_info.is_16gb_dimm) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2933 | wm[0] += 1; |
| 2934 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2935 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2936 | u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2937 | |
| 2938 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2939 | if (wm[0] == 0) |
| 2940 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2941 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2942 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2943 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2944 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2945 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2946 | u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2947 | |
| 2948 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2949 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2950 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2951 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2952 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2953 | u32 mltr = intel_uncore_read(uncore, MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2954 | |
| 2955 | /* ILK primary LP0 latency is 700 ns */ |
| 2956 | wm[0] = 7; |
| 2957 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2958 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2959 | } else { |
| 2960 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2964 | static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2965 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2966 | { |
| 2967 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2968 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2969 | wm[0] = 13; |
| 2970 | } |
| 2971 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2972 | static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2973 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2974 | { |
| 2975 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2976 | if (IS_GEN(dev_priv, 5)) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2977 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2978 | } |
| 2979 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2980 | 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] | 2981 | { |
| 2982 | /* how many WM levels are we expecting */ |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2983 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2984 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2985 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2986 | return 4; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2987 | else if (INTEL_GEN(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2988 | return 3; |
| 2989 | else |
| 2990 | return 2; |
| 2991 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2992 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2993 | 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] | 2994 | const char *name, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2995 | const u16 wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2996 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2997 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2998 | |
| 2999 | for (level = 0; level <= max_level; level++) { |
| 3000 | unsigned int latency = wm[level]; |
| 3001 | |
| 3002 | if (latency == 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3003 | drm_dbg_kms(&dev_priv->drm, |
| 3004 | "%s WM%d latency not provided\n", |
| 3005 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3006 | continue; |
| 3007 | } |
| 3008 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3009 | /* |
| 3010 | * - latencies are in us on gen9. |
| 3011 | * - before then, WM1+ latency values are in 0.5us units |
| 3012 | */ |
Paulo Zanoni | dfc267a | 2017-08-09 13:52:46 -0700 | [diff] [blame] | 3013 | if (INTEL_GEN(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3014 | latency *= 10; |
| 3015 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3016 | latency *= 5; |
| 3017 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3018 | drm_dbg_kms(&dev_priv->drm, |
| 3019 | "%s WM%d latency %u (%u.%u usec)\n", name, level, |
| 3020 | wm[level], latency / 10, latency % 10); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3024 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3025 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3026 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3027 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3028 | |
| 3029 | if (wm[0] >= min) |
| 3030 | return false; |
| 3031 | |
| 3032 | wm[0] = max(wm[0], min); |
| 3033 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3034 | wm[level] = max_t(u16, wm[level], DIV_ROUND_UP(min, 5)); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3035 | |
| 3036 | return true; |
| 3037 | } |
| 3038 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3039 | 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] | 3040 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3041 | bool changed; |
| 3042 | |
| 3043 | /* |
| 3044 | * The BIOS provided WM memory latency values are often |
| 3045 | * inadequate for high resolution displays. Adjust them. |
| 3046 | */ |
| 3047 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 3048 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 3049 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 3050 | |
| 3051 | if (!changed) |
| 3052 | return; |
| 3053 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3054 | drm_dbg_kms(&dev_priv->drm, |
| 3055 | "WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3056 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3057 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3058 | 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] | 3059 | } |
| 3060 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3061 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 3062 | { |
| 3063 | /* |
| 3064 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 3065 | * LP3 usage can cause vblank interrupts to be lost. |
| 3066 | * The DEIIR bit will go high but it looks like the CPU |
| 3067 | * never gets interrupted. |
| 3068 | * |
| 3069 | * It's not clear whether other interrupt source could |
| 3070 | * be affected or if this is somehow limited to vblank |
| 3071 | * interrupts only. To play it safe we disable LP3 |
| 3072 | * watermarks entirely. |
| 3073 | */ |
| 3074 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3075 | dev_priv->wm.spr_latency[3] == 0 && |
| 3076 | dev_priv->wm.cur_latency[3] == 0) |
| 3077 | return; |
| 3078 | |
| 3079 | dev_priv->wm.pri_latency[3] = 0; |
| 3080 | dev_priv->wm.spr_latency[3] = 0; |
| 3081 | dev_priv->wm.cur_latency[3] = 0; |
| 3082 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3083 | drm_dbg_kms(&dev_priv->drm, |
| 3084 | "LP3 watermarks disabled due to potential for lost interrupts\n"); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3085 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3086 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3087 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3088 | } |
| 3089 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3090 | 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] | 3091 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3092 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3093 | |
| 3094 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3095 | sizeof(dev_priv->wm.pri_latency)); |
| 3096 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3097 | sizeof(dev_priv->wm.pri_latency)); |
| 3098 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3099 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3100 | 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] | 3101 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3102 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3103 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3104 | 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] | 3105 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3106 | if (IS_GEN(dev_priv, 6)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3107 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3108 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3109 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3110 | } |
| 3111 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3112 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3113 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3114 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3115 | 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] | 3116 | } |
| 3117 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3118 | static bool ilk_validate_pipe_wm(const struct drm_i915_private *dev_priv, |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3119 | struct intel_pipe_wm *pipe_wm) |
| 3120 | { |
| 3121 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3122 | const struct intel_wm_config config = { |
| 3123 | .num_pipes_active = 1, |
| 3124 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3125 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3126 | }; |
| 3127 | struct ilk_wm_maximums max; |
| 3128 | |
| 3129 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3130 | ilk_compute_wm_maximums(dev_priv, 0, &config, INTEL_DDB_PART_1_2, &max); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3131 | |
| 3132 | /* At least LP0 must be valid */ |
| 3133 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3134 | drm_dbg_kms(&dev_priv->drm, "LP0 watermark invalid\n"); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3135 | return false; |
| 3136 | } |
| 3137 | |
| 3138 | return true; |
| 3139 | } |
| 3140 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3141 | /* Compute new watermarks for the pipe */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3142 | static int ilk_compute_pipe_wm(struct intel_crtc_state *crtc_state) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3143 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 3144 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3145 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3146 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3147 | struct intel_plane *plane; |
| 3148 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3149 | const struct intel_plane_state *pristate = NULL; |
| 3150 | const struct intel_plane_state *sprstate = NULL; |
| 3151 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3152 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3153 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3154 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3155 | pipe_wm = &crtc_state->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3156 | |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3157 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 3158 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 3159 | pristate = plane_state; |
| 3160 | else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
| 3161 | sprstate = plane_state; |
| 3162 | else if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 3163 | curstate = plane_state; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 3166 | pipe_wm->pipe_enabled = crtc_state->hw.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3167 | if (sprstate) { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 3168 | pipe_wm->sprites_enabled = sprstate->uapi.visible; |
| 3169 | pipe_wm->sprites_scaled = sprstate->uapi.visible && |
| 3170 | (drm_rect_width(&sprstate->uapi.dst) != drm_rect_width(&sprstate->uapi.src) >> 16 || |
| 3171 | drm_rect_height(&sprstate->uapi.dst) != drm_rect_height(&sprstate->uapi.src) >> 16); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3172 | } |
| 3173 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3174 | usable_level = max_level; |
| 3175 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3176 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3177 | if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3178 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3179 | |
| 3180 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3181 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3182 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3183 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3184 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3185 | ilk_compute_wm_level(dev_priv, crtc, 0, crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3186 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3187 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3188 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3189 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3190 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3191 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3192 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3193 | for (level = 1; level <= usable_level; level++) { |
| 3194 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3195 | |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3196 | ilk_compute_wm_level(dev_priv, crtc, level, crtc_state, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3197 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3198 | |
| 3199 | /* |
| 3200 | * Disable any watermark level that exceeds the |
| 3201 | * register maximums since such watermarks are |
| 3202 | * always invalid. |
| 3203 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3204 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3205 | memset(wm, 0, sizeof(*wm)); |
| 3206 | break; |
| 3207 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3208 | } |
| 3209 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3210 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3214 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3215 | * state and the new state. These can be programmed to the hardware |
| 3216 | * immediately. |
| 3217 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3218 | static int ilk_compute_intermediate_wm(struct intel_crtc_state *newstate) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3219 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 3220 | struct intel_crtc *intel_crtc = to_intel_crtc(newstate->uapi.crtc); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3221 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3222 | struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate; |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3223 | struct intel_atomic_state *intel_state = |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 3224 | to_intel_atomic_state(newstate->uapi.state); |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3225 | const struct intel_crtc_state *oldstate = |
| 3226 | intel_atomic_get_old_crtc_state(intel_state, intel_crtc); |
| 3227 | const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3228 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3229 | |
| 3230 | /* |
| 3231 | * Start with the final, target watermarks, then combine with the |
| 3232 | * currently active watermarks to get values that are safe both before |
| 3233 | * and after the vblank. |
| 3234 | */ |
Matt Roper | e8f1f02 | 2016-05-12 07:05:55 -0700 | [diff] [blame] | 3235 | *a = newstate->wm.ilk.optimal; |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 3236 | if (!newstate->hw.active || drm_atomic_crtc_needs_modeset(&newstate->uapi) || |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 3237 | intel_state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3238 | return 0; |
| 3239 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3240 | a->pipe_enabled |= b->pipe_enabled; |
| 3241 | a->sprites_enabled |= b->sprites_enabled; |
| 3242 | a->sprites_scaled |= b->sprites_scaled; |
| 3243 | |
| 3244 | for (level = 0; level <= max_level; level++) { |
| 3245 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3246 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3247 | |
| 3248 | a_wm->enable &= b_wm->enable; |
| 3249 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3250 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3251 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3252 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3253 | } |
| 3254 | |
| 3255 | /* |
| 3256 | * We need to make sure that these merged watermark values are |
| 3257 | * actually a valid configuration themselves. If they're not, |
| 3258 | * there's no safe way to transition from the old state to |
| 3259 | * the new state, so we need to fail the atomic transaction. |
| 3260 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3261 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3262 | return -EINVAL; |
| 3263 | |
| 3264 | /* |
| 3265 | * If our intermediate WM are identical to the final WM, then we can |
| 3266 | * omit the post-vblank programming; only update if it's different. |
| 3267 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 3268 | if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3269 | newstate->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3270 | |
| 3271 | return 0; |
| 3272 | } |
| 3273 | |
| 3274 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3275 | * Merge the watermarks from all active pipes for a specific level. |
| 3276 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3277 | static void ilk_merge_wm_level(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3278 | int level, |
| 3279 | struct intel_wm_level *ret_wm) |
| 3280 | { |
| 3281 | const struct intel_crtc *intel_crtc; |
| 3282 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3283 | ret_wm->enable = true; |
| 3284 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3285 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3286 | const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3287 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3288 | |
| 3289 | if (!active->pipe_enabled) |
| 3290 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3291 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3292 | /* |
| 3293 | * The watermark values may have been used in the past, |
| 3294 | * so we must maintain them in the registers for some |
| 3295 | * time even if the level is now disabled. |
| 3296 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3297 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3298 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3299 | |
| 3300 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3301 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3302 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3303 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3304 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | /* |
| 3308 | * Merge all low power watermarks for all active pipes. |
| 3309 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3310 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3311 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3312 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3313 | struct intel_pipe_wm *merged) |
| 3314 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3315 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3316 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3317 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3318 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3319 | if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3320 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3321 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3322 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3323 | /* ILK: FBC WM must be disabled always */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3324 | merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3325 | |
| 3326 | /* merge each WM1+ level */ |
| 3327 | for (level = 1; level <= max_level; level++) { |
| 3328 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3329 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3330 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3331 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3332 | if (level > last_enabled_level) |
| 3333 | wm->enable = false; |
| 3334 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3335 | /* make sure all following levels get disabled */ |
| 3336 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3337 | |
| 3338 | /* |
| 3339 | * The spec says it is preferred to disable |
| 3340 | * FBC WMs instead of disabling a WM level. |
| 3341 | */ |
| 3342 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3343 | if (wm->enable) |
| 3344 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3345 | wm->fbc_val = 0; |
| 3346 | } |
| 3347 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3348 | |
| 3349 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3350 | /* |
| 3351 | * FIXME this is racy. FBC might get enabled later. |
| 3352 | * What we should check here is whether FBC can be |
| 3353 | * enabled sometime later. |
| 3354 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3355 | if (IS_GEN(dev_priv, 5) && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3356 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3357 | for (level = 2; level <= max_level; level++) { |
| 3358 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3359 | |
| 3360 | wm->enable = false; |
| 3361 | } |
| 3362 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3363 | } |
| 3364 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3365 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3366 | { |
| 3367 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3368 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3369 | } |
| 3370 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3371 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3372 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3373 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3374 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3375 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3376 | return 2 * level; |
| 3377 | else |
| 3378 | return dev_priv->wm.pri_latency[level]; |
| 3379 | } |
| 3380 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3381 | static void ilk_compute_wm_results(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3382 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3383 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3384 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3385 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3386 | struct intel_crtc *intel_crtc; |
| 3387 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3388 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3389 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3390 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3391 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3392 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3393 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3394 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3395 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3396 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3397 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3398 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3399 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3400 | /* |
| 3401 | * Maintain the watermark values even if the level is |
| 3402 | * disabled. Doing otherwise could cause underruns. |
| 3403 | */ |
| 3404 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3405 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3406 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3407 | r->cur_val; |
| 3408 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3409 | if (r->enable) |
| 3410 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3411 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3412 | if (INTEL_GEN(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3413 | results->wm_lp[wm_lp - 1] |= |
| 3414 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3415 | else |
| 3416 | results->wm_lp[wm_lp - 1] |= |
| 3417 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3418 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3419 | /* |
| 3420 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3421 | * level is disabled. Doing otherwise could cause underruns. |
| 3422 | */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3423 | if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) { |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 3424 | drm_WARN_ON(&dev_priv->drm, wm_lp != 1); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3425 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3426 | } else |
| 3427 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3428 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3429 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3430 | /* LP0 register values */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3431 | for_each_intel_crtc(&dev_priv->drm, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3432 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 0560b0c | 2020-01-20 19:47:11 +0200 | [diff] [blame] | 3433 | const struct intel_pipe_wm *pipe_wm = &intel_crtc->wm.active.ilk; |
| 3434 | const struct intel_wm_level *r = &pipe_wm->wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3435 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 3436 | if (drm_WARN_ON(&dev_priv->drm, !r->enable)) |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3437 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3438 | |
| 3439 | results->wm_pipe[pipe] = |
| 3440 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3441 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3442 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3443 | } |
| 3444 | } |
| 3445 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3446 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3447 | * case both are at the same level. Prefer r1 in case they're the same. */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3448 | static struct intel_pipe_wm * |
| 3449 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3450 | struct intel_pipe_wm *r1, |
| 3451 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3452 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3453 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3454 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3455 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3456 | for (level = 1; level <= max_level; level++) { |
| 3457 | if (r1->wm[level].enable) |
| 3458 | level1 = level; |
| 3459 | if (r2->wm[level].enable) |
| 3460 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3461 | } |
| 3462 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3463 | if (level1 == level2) { |
| 3464 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3465 | return r2; |
| 3466 | else |
| 3467 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3468 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3469 | return r1; |
| 3470 | } else { |
| 3471 | return r2; |
| 3472 | } |
| 3473 | } |
| 3474 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3475 | /* dirty bits used to track which watermarks need changes */ |
| 3476 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3477 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3478 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3479 | #define WM_DIRTY_FBC (1 << 24) |
| 3480 | #define WM_DIRTY_DDB (1 << 25) |
| 3481 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3482 | 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] | 3483 | const struct ilk_wm_values *old, |
| 3484 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3485 | { |
| 3486 | unsigned int dirty = 0; |
| 3487 | enum pipe pipe; |
| 3488 | int wm_lp; |
| 3489 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3490 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3491 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3492 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3493 | /* Must disable LP1+ watermarks too */ |
| 3494 | dirty |= WM_DIRTY_LP_ALL; |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3499 | dirty |= WM_DIRTY_FBC; |
| 3500 | /* Must disable LP1+ watermarks too */ |
| 3501 | dirty |= WM_DIRTY_LP_ALL; |
| 3502 | } |
| 3503 | |
| 3504 | if (old->partitioning != new->partitioning) { |
| 3505 | dirty |= WM_DIRTY_DDB; |
| 3506 | /* Must disable LP1+ watermarks too */ |
| 3507 | dirty |= WM_DIRTY_LP_ALL; |
| 3508 | } |
| 3509 | |
| 3510 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3511 | if (dirty & WM_DIRTY_LP_ALL) |
| 3512 | return dirty; |
| 3513 | |
| 3514 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3515 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3516 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3517 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3518 | break; |
| 3519 | } |
| 3520 | |
| 3521 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3522 | for (; wm_lp <= 3; wm_lp++) |
| 3523 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3524 | |
| 3525 | return dirty; |
| 3526 | } |
| 3527 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3528 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3529 | unsigned int dirty) |
| 3530 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3531 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3532 | bool changed = false; |
| 3533 | |
| 3534 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3535 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 3536 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 3537 | changed = true; |
| 3538 | } |
| 3539 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3540 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 3541 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 3542 | changed = true; |
| 3543 | } |
| 3544 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3545 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 3546 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 3547 | changed = true; |
| 3548 | } |
| 3549 | |
| 3550 | /* |
| 3551 | * Don't touch WM1S_LP_EN here. |
| 3552 | * Doing so could cause underruns. |
| 3553 | */ |
| 3554 | |
| 3555 | return changed; |
| 3556 | } |
| 3557 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3558 | /* |
| 3559 | * The spec says we shouldn't write when we don't need, because every write |
| 3560 | * causes WMs to be re-evaluated, expending some power. |
| 3561 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3562 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3563 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3564 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3565 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3566 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3567 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3568 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3569 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3570 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3571 | return; |
| 3572 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3573 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3574 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3575 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Ville Syrjälä | 96eaeb3d | 2018-12-12 23:17:38 +0200 | [diff] [blame] | 3576 | I915_WRITE(WM0_PIPE_ILK(PIPE_A), results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3577 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Ville Syrjälä | 96eaeb3d | 2018-12-12 23:17:38 +0200 | [diff] [blame] | 3578 | I915_WRITE(WM0_PIPE_ILK(PIPE_B), results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3579 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Ville Syrjälä | 96eaeb3d | 2018-12-12 23:17:38 +0200 | [diff] [blame] | 3580 | I915_WRITE(WM0_PIPE_ILK(PIPE_C), results->wm_pipe[2]); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3581 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3582 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3583 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3584 | val = I915_READ(WM_MISC); |
| 3585 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3586 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3587 | else |
| 3588 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 3589 | I915_WRITE(WM_MISC, val); |
| 3590 | } else { |
| 3591 | val = I915_READ(DISP_ARB_CTL2); |
| 3592 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3593 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3594 | else |
| 3595 | val |= DISP_DATA_PARTITION_5_6; |
| 3596 | I915_WRITE(DISP_ARB_CTL2, val); |
| 3597 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3598 | } |
| 3599 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3600 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3601 | val = I915_READ(DISP_ARB_CTL); |
| 3602 | if (results->enable_fbc_wm) |
| 3603 | val &= ~DISP_FBC_WM_DIS; |
| 3604 | else |
| 3605 | val |= DISP_FBC_WM_DIS; |
| 3606 | I915_WRITE(DISP_ARB_CTL, val); |
| 3607 | } |
| 3608 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3609 | if (dirty & WM_DIRTY_LP(1) && |
| 3610 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 3611 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 3612 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3613 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3614 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 3615 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 3616 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 3617 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 3618 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3619 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3620 | 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] | 3621 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3622 | 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] | 3623 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3624 | 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] | 3625 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3626 | |
| 3627 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3628 | } |
| 3629 | |
Ville Syrjälä | 60aca57 | 2019-11-27 21:05:51 +0200 | [diff] [blame] | 3630 | bool ilk_disable_lp_wm(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3631 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3632 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3633 | } |
| 3634 | |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3635 | u8 intel_enabled_dbuf_slices_mask(struct drm_i915_private *dev_priv) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3636 | { |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3637 | int i; |
| 3638 | int max_slices = INTEL_INFO(dev_priv)->num_supported_dbuf_slices; |
| 3639 | u8 enabled_slices_mask = 0; |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3640 | |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3641 | for (i = 0; i < max_slices; i++) { |
| 3642 | if (I915_READ(DBUF_CTL_S(i)) & DBUF_POWER_STATE) |
| 3643 | enabled_slices_mask |= BIT(i); |
| 3644 | } |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3645 | |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3646 | return enabled_slices_mask; |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3647 | } |
| 3648 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3649 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3650 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3651 | * so assume we'll always need it in order to avoid underruns. |
| 3652 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3653 | static bool skl_needs_memory_bw_wa(struct drm_i915_private *dev_priv) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3654 | { |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3655 | return IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv); |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3656 | } |
| 3657 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3658 | static bool |
| 3659 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3660 | { |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3661 | return (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) && |
| 3662 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3663 | } |
| 3664 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3665 | static void |
| 3666 | skl_setup_sagv_block_time(struct drm_i915_private *dev_priv) |
| 3667 | { |
James Ausmus | da80f04 | 2019-10-09 10:23:15 -0700 | [diff] [blame] | 3668 | if (INTEL_GEN(dev_priv) >= 12) { |
| 3669 | u32 val = 0; |
| 3670 | int ret; |
| 3671 | |
| 3672 | ret = sandybridge_pcode_read(dev_priv, |
| 3673 | GEN12_PCODE_READ_SAGV_BLOCK_TIME_US, |
| 3674 | &val, NULL); |
| 3675 | if (!ret) { |
| 3676 | dev_priv->sagv_block_time_us = val; |
| 3677 | return; |
| 3678 | } |
| 3679 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3680 | drm_dbg(&dev_priv->drm, "Couldn't read SAGV block time!\n"); |
James Ausmus | da80f04 | 2019-10-09 10:23:15 -0700 | [diff] [blame] | 3681 | } else if (IS_GEN(dev_priv, 11)) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3682 | dev_priv->sagv_block_time_us = 10; |
| 3683 | return; |
| 3684 | } else if (IS_GEN(dev_priv, 10)) { |
| 3685 | dev_priv->sagv_block_time_us = 20; |
| 3686 | return; |
| 3687 | } else if (IS_GEN(dev_priv, 9)) { |
| 3688 | dev_priv->sagv_block_time_us = 30; |
| 3689 | return; |
| 3690 | } else { |
| 3691 | MISSING_CASE(INTEL_GEN(dev_priv)); |
| 3692 | } |
| 3693 | |
| 3694 | /* Default to an unusable block time */ |
| 3695 | dev_priv->sagv_block_time_us = -1; |
| 3696 | } |
| 3697 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3698 | /* |
| 3699 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3700 | * depending on power and performance requirements. The display engine access |
| 3701 | * to system memory is blocked during the adjustment time. Because of the |
| 3702 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3703 | * underruns if we don't meet all of the following requirements: |
| 3704 | * |
| 3705 | * - <= 1 pipe enabled |
| 3706 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3707 | * - We're not using an interlaced display configuration |
| 3708 | */ |
Ville Syrjälä | 7102404 | 2020-09-25 15:17:48 +0300 | [diff] [blame] | 3709 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3710 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3711 | { |
| 3712 | int ret; |
| 3713 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3714 | if (!intel_has_sagv(dev_priv)) |
| 3715 | return 0; |
| 3716 | |
| 3717 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3718 | return 0; |
| 3719 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3720 | drm_dbg_kms(&dev_priv->drm, "Enabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3721 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3722 | GEN9_SAGV_ENABLE); |
| 3723 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3724 | /* We don't need to wait for SAGV when enabling */ |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3725 | |
| 3726 | /* |
| 3727 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3728 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3729 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3730 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3731 | drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3732 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3733 | return 0; |
| 3734 | } else if (ret < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3735 | drm_err(&dev_priv->drm, "Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3736 | return ret; |
| 3737 | } |
| 3738 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3739 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3740 | return 0; |
| 3741 | } |
| 3742 | |
Ville Syrjälä | 7102404 | 2020-09-25 15:17:48 +0300 | [diff] [blame] | 3743 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3744 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3745 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3746 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3747 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3748 | if (!intel_has_sagv(dev_priv)) |
| 3749 | return 0; |
| 3750 | |
| 3751 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3752 | return 0; |
| 3753 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3754 | drm_dbg_kms(&dev_priv->drm, "Disabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3755 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3756 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3757 | GEN9_SAGV_DISABLE, |
| 3758 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3759 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3760 | /* |
| 3761 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3762 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3763 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3764 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3765 | drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3766 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3767 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3768 | } else if (ret < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3769 | drm_err(&dev_priv->drm, "Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3770 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3771 | } |
| 3772 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3773 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3774 | return 0; |
| 3775 | } |
| 3776 | |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3777 | void intel_sagv_pre_plane_update(struct intel_atomic_state *state) |
| 3778 | { |
| 3779 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3780 | const struct intel_bw_state *new_bw_state; |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3781 | const struct intel_bw_state *old_bw_state; |
| 3782 | u32 new_mask = 0; |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3783 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3784 | /* |
| 3785 | * Just return if we can't control SAGV or don't have it. |
| 3786 | * This is different from situation when we have SAGV but just can't |
| 3787 | * afford it due to DBuf limitation - in case if SAGV is completely |
| 3788 | * disabled in a BIOS, we are not even allowed to send a PCode request, |
| 3789 | * as it will throw an error. So have to check it here. |
| 3790 | */ |
| 3791 | if (!intel_has_sagv(dev_priv)) |
| 3792 | return; |
| 3793 | |
| 3794 | new_bw_state = intel_atomic_get_new_bw_state(state); |
| 3795 | if (!new_bw_state) |
| 3796 | return; |
| 3797 | |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3798 | if (INTEL_GEN(dev_priv) < 11 && !intel_can_enable_sagv(dev_priv, new_bw_state)) { |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3799 | intel_disable_sagv(dev_priv); |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3800 | return; |
| 3801 | } |
| 3802 | |
| 3803 | old_bw_state = intel_atomic_get_old_bw_state(state); |
| 3804 | /* |
| 3805 | * Nothing to mask |
| 3806 | */ |
| 3807 | if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask) |
| 3808 | return; |
| 3809 | |
| 3810 | new_mask = old_bw_state->qgv_points_mask | new_bw_state->qgv_points_mask; |
| 3811 | |
| 3812 | /* |
| 3813 | * If new mask is zero - means there is nothing to mask, |
| 3814 | * we can only unmask, which should be done in unmask. |
| 3815 | */ |
| 3816 | if (!new_mask) |
| 3817 | return; |
| 3818 | |
| 3819 | /* |
| 3820 | * Restrict required qgv points before updating the configuration. |
| 3821 | * According to BSpec we can't mask and unmask qgv points at the same |
| 3822 | * time. Also masking should be done before updating the configuration |
| 3823 | * and unmasking afterwards. |
| 3824 | */ |
| 3825 | icl_pcode_restrict_qgv_points(dev_priv, new_mask); |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | void intel_sagv_post_plane_update(struct intel_atomic_state *state) |
| 3829 | { |
| 3830 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3831 | const struct intel_bw_state *new_bw_state; |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3832 | const struct intel_bw_state *old_bw_state; |
| 3833 | u32 new_mask = 0; |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3834 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3835 | /* |
| 3836 | * Just return if we can't control SAGV or don't have it. |
| 3837 | * This is different from situation when we have SAGV but just can't |
| 3838 | * afford it due to DBuf limitation - in case if SAGV is completely |
| 3839 | * disabled in a BIOS, we are not even allowed to send a PCode request, |
| 3840 | * as it will throw an error. So have to check it here. |
| 3841 | */ |
| 3842 | if (!intel_has_sagv(dev_priv)) |
| 3843 | return; |
| 3844 | |
| 3845 | new_bw_state = intel_atomic_get_new_bw_state(state); |
| 3846 | if (!new_bw_state) |
| 3847 | return; |
| 3848 | |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3849 | if (INTEL_GEN(dev_priv) < 11 && intel_can_enable_sagv(dev_priv, new_bw_state)) { |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3850 | intel_enable_sagv(dev_priv); |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3851 | return; |
| 3852 | } |
| 3853 | |
| 3854 | old_bw_state = intel_atomic_get_old_bw_state(state); |
| 3855 | /* |
| 3856 | * Nothing to unmask |
| 3857 | */ |
| 3858 | if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask) |
| 3859 | return; |
| 3860 | |
| 3861 | new_mask = new_bw_state->qgv_points_mask; |
| 3862 | |
| 3863 | /* |
| 3864 | * Allow required qgv points after updating the configuration. |
| 3865 | * According to BSpec we can't mask and unmask qgv points at the same |
| 3866 | * time. Also masking should be done before updating the configuration |
| 3867 | * and unmasking afterwards. |
| 3868 | */ |
| 3869 | icl_pcode_restrict_qgv_points(dev_priv, new_mask); |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3870 | } |
| 3871 | |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3872 | static bool skl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3873 | { |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3874 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3875 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3876 | enum plane_id plane_id; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3877 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3878 | if (!intel_has_sagv(dev_priv)) |
| 3879 | return false; |
| 3880 | |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3881 | if (!crtc_state->hw.active) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3882 | return true; |
Lucas De Marchi | da17223 | 2019-04-04 16:04:26 -0700 | [diff] [blame] | 3883 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 3884 | if (crtc_state->hw.pipe_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3885 | return false; |
| 3886 | |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3887 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3888 | const struct skl_plane_wm *wm = |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3889 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3890 | int level; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3891 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3892 | /* Skip this plane if it's not enabled */ |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3893 | if (!wm->wm[0].plane_en) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3894 | continue; |
| 3895 | |
| 3896 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3897 | for (level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 3898 | !wm->wm[level].plane_en; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3899 | { } |
| 3900 | |
| 3901 | /* |
Paulo Zanoni | fdd11c2 | 2017-08-09 13:52:45 -0700 | [diff] [blame] | 3902 | * If any of the planes on this pipe don't enable wm levels that |
| 3903 | * incur memory latencies higher than sagv_block_time_us we |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3904 | * can't enable SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3905 | */ |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3906 | if (!wm->wm[level].can_sagv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3907 | return false; |
| 3908 | } |
| 3909 | |
| 3910 | return true; |
| 3911 | } |
| 3912 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3913 | static bool tgl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
| 3914 | { |
| 3915 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 3916 | enum plane_id plane_id; |
| 3917 | |
| 3918 | if (!crtc_state->hw.active) |
| 3919 | return true; |
| 3920 | |
| 3921 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 3922 | const struct skl_ddb_entry *plane_alloc = |
| 3923 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 3924 | const struct skl_plane_wm *wm = |
| 3925 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3926 | |
| 3927 | if (skl_ddb_entry_size(plane_alloc) < wm->sagv_wm0.min_ddb_alloc) |
| 3928 | return false; |
| 3929 | } |
| 3930 | |
| 3931 | return true; |
| 3932 | } |
| 3933 | |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3934 | static bool intel_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
| 3935 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3936 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 3937 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3938 | |
| 3939 | if (INTEL_GEN(dev_priv) >= 12) |
| 3940 | return tgl_crtc_can_enable_sagv(crtc_state); |
| 3941 | else |
| 3942 | return skl_crtc_can_enable_sagv(crtc_state); |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3943 | } |
| 3944 | |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3945 | bool intel_can_enable_sagv(struct drm_i915_private *dev_priv, |
| 3946 | const struct intel_bw_state *bw_state) |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3947 | { |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3948 | if (INTEL_GEN(dev_priv) < 11 && |
| 3949 | bw_state->active_pipes && !is_power_of_2(bw_state->active_pipes)) |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 3950 | return false; |
| 3951 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3952 | return bw_state->pipe_sagv_reject == 0; |
| 3953 | } |
| 3954 | |
| 3955 | static int intel_compute_sagv_mask(struct intel_atomic_state *state) |
| 3956 | { |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3957 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3958 | int ret; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3959 | struct intel_crtc *crtc; |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3960 | struct intel_crtc_state *new_crtc_state; |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3961 | struct intel_bw_state *new_bw_state = NULL; |
| 3962 | const struct intel_bw_state *old_bw_state = NULL; |
| 3963 | int i; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3964 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3965 | for_each_new_intel_crtc_in_state(state, crtc, |
| 3966 | new_crtc_state, i) { |
| 3967 | new_bw_state = intel_atomic_get_bw_state(state); |
| 3968 | if (IS_ERR(new_bw_state)) |
| 3969 | return PTR_ERR(new_bw_state); |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3970 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3971 | old_bw_state = intel_atomic_get_old_bw_state(state); |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3972 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3973 | if (intel_crtc_can_enable_sagv(new_crtc_state)) |
| 3974 | new_bw_state->pipe_sagv_reject &= ~BIT(crtc->pipe); |
| 3975 | else |
| 3976 | new_bw_state->pipe_sagv_reject |= BIT(crtc->pipe); |
| 3977 | } |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3978 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3979 | if (!new_bw_state) |
| 3980 | return 0; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3981 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 3982 | new_bw_state->active_pipes = |
| 3983 | intel_calc_active_pipes(state, old_bw_state->active_pipes); |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3984 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 3985 | if (new_bw_state->active_pipes != old_bw_state->active_pipes) { |
| 3986 | ret = intel_atomic_lock_global_state(&new_bw_state->base); |
| 3987 | if (ret) |
| 3988 | return ret; |
| 3989 | } |
| 3990 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3991 | for_each_new_intel_crtc_in_state(state, crtc, |
| 3992 | new_crtc_state, i) { |
| 3993 | struct skl_pipe_wm *pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 3994 | |
| 3995 | /* |
| 3996 | * We store use_sagv_wm in the crtc state rather than relying on |
| 3997 | * that bw state since we have no convenient way to get at the |
| 3998 | * latter from the plane commit hooks (especially in the legacy |
| 3999 | * cursor case) |
| 4000 | */ |
| 4001 | pipe_wm->use_sagv_wm = INTEL_GEN(dev_priv) >= 12 && |
| 4002 | intel_can_enable_sagv(dev_priv, new_bw_state); |
| 4003 | } |
| 4004 | |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 4005 | if (intel_can_enable_sagv(dev_priv, new_bw_state) != |
| 4006 | intel_can_enable_sagv(dev_priv, old_bw_state)) { |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4007 | ret = intel_atomic_serialize_global_state(&new_bw_state->base); |
| 4008 | if (ret) |
| 4009 | return ret; |
| 4010 | } else if (new_bw_state->pipe_sagv_reject != old_bw_state->pipe_sagv_reject) { |
| 4011 | ret = intel_atomic_lock_global_state(&new_bw_state->base); |
| 4012 | if (ret) |
| 4013 | return ret; |
| 4014 | } |
| 4015 | |
| 4016 | return 0; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4017 | } |
| 4018 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4019 | /* |
| 4020 | * Calculate initial DBuf slice offset, based on slice size |
| 4021 | * and mask(i.e if slice size is 1024 and second slice is enabled |
| 4022 | * offset would be 1024) |
| 4023 | */ |
| 4024 | static unsigned int |
| 4025 | icl_get_first_dbuf_slice_offset(u32 dbuf_slice_mask, |
| 4026 | u32 slice_size, |
| 4027 | u32 ddb_size) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 4028 | { |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4029 | unsigned int offset = 0; |
| 4030 | |
| 4031 | if (!dbuf_slice_mask) |
| 4032 | return 0; |
| 4033 | |
| 4034 | offset = (ffs(dbuf_slice_mask) - 1) * slice_size; |
| 4035 | |
| 4036 | WARN_ON(offset >= ddb_size); |
| 4037 | return offset; |
| 4038 | } |
| 4039 | |
Stanislav Lisovskiy | cd19154 | 2020-05-20 18:00:58 +0300 | [diff] [blame] | 4040 | u16 intel_get_ddb_size(struct drm_i915_private *dev_priv) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4041 | { |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 4042 | u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size; |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 4043 | drm_WARN_ON(&dev_priv->drm, ddb_size == 0); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 4044 | |
| 4045 | if (INTEL_GEN(dev_priv) < 11) |
| 4046 | return ddb_size - 4; /* 4 blocks for bypass path allocation */ |
| 4047 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 4048 | return ddb_size; |
| 4049 | } |
| 4050 | |
Stanislav Lisovskiy | cd19154 | 2020-05-20 18:00:58 +0300 | [diff] [blame] | 4051 | u32 skl_ddb_dbuf_slice_mask(struct drm_i915_private *dev_priv, |
| 4052 | const struct skl_ddb_entry *entry) |
| 4053 | { |
| 4054 | u32 slice_mask = 0; |
| 4055 | u16 ddb_size = intel_get_ddb_size(dev_priv); |
| 4056 | u16 num_supported_slices = INTEL_INFO(dev_priv)->num_supported_dbuf_slices; |
| 4057 | u16 slice_size = ddb_size / num_supported_slices; |
| 4058 | u16 start_slice; |
| 4059 | u16 end_slice; |
| 4060 | |
| 4061 | if (!skl_ddb_entry_size(entry)) |
| 4062 | return 0; |
| 4063 | |
| 4064 | start_slice = entry->start / slice_size; |
| 4065 | end_slice = (entry->end - 1) / slice_size; |
| 4066 | |
| 4067 | /* |
| 4068 | * Per plane DDB entry can in a really worst case be on multiple slices |
| 4069 | * but single entry is anyway contigious. |
| 4070 | */ |
| 4071 | while (start_slice <= end_slice) { |
| 4072 | slice_mask |= BIT(start_slice); |
| 4073 | start_slice++; |
| 4074 | } |
| 4075 | |
| 4076 | return slice_mask; |
| 4077 | } |
| 4078 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4079 | static u8 skl_compute_dbuf_slices(const struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4080 | u8 active_pipes); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4081 | |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4082 | static int |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4083 | skl_ddb_get_pipe_allocation_limits(struct drm_i915_private *dev_priv, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4084 | const struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4085 | const u64 total_data_rate, |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4086 | struct skl_ddb_entry *alloc, /* out */ |
| 4087 | int *num_active /* out */) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4088 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 4089 | struct drm_atomic_state *state = crtc_state->uapi.state; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4090 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 4091 | struct drm_crtc *for_crtc = crtc_state->uapi.crtc; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4092 | const struct intel_crtc *crtc; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4093 | u32 pipe_width = 0, total_width_in_range = 0, width_before_pipe_in_range = 0; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4094 | enum pipe for_pipe = to_intel_crtc(for_crtc)->pipe; |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4095 | struct intel_dbuf_state *new_dbuf_state = |
| 4096 | intel_atomic_get_new_dbuf_state(intel_state); |
| 4097 | const struct intel_dbuf_state *old_dbuf_state = |
| 4098 | intel_atomic_get_old_dbuf_state(intel_state); |
| 4099 | u8 active_pipes = new_dbuf_state->active_pipes; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4100 | u16 ddb_size; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4101 | u32 ddb_range_size; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4102 | u32 i; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4103 | u32 dbuf_slice_mask; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4104 | u32 offset; |
| 4105 | u32 slice_size; |
| 4106 | u32 total_slice_mask; |
| 4107 | u32 start, end; |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4108 | int ret; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4109 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4110 | *num_active = hweight8(active_pipes); |
| 4111 | |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4112 | if (!crtc_state->hw.active) { |
| 4113 | alloc->start = 0; |
| 4114 | alloc->end = 0; |
| 4115 | return 0; |
| 4116 | } |
| 4117 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4118 | ddb_size = intel_get_ddb_size(dev_priv); |
| 4119 | |
| 4120 | slice_size = ddb_size / INTEL_INFO(dev_priv)->num_supported_dbuf_slices; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4121 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4122 | /* |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4123 | * If the state doesn't change the active CRTC's or there is no |
| 4124 | * modeset request, then there's no need to recalculate; |
| 4125 | * the existing pipe allocation limits should remain unchanged. |
| 4126 | * Note that we're safe from racing commits since any racing commit |
| 4127 | * that changes the active CRTC list or do modeset would need to |
| 4128 | * grab _all_ crtc locks, including the one we currently hold. |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4129 | */ |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4130 | if (old_dbuf_state->active_pipes == new_dbuf_state->active_pipes && |
| 4131 | !dev_priv->wm.distrust_bios_wm) { |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 4132 | /* |
| 4133 | * alloc may be cleared by clear_intel_crtc_state, |
| 4134 | * copy from old state to be sure |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4135 | * |
| 4136 | * FIXME get rid of this mess |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 4137 | */ |
| 4138 | *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb; |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4139 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4140 | } |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4141 | |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4142 | /* |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4143 | * Get allowed DBuf slices for correspondent pipe and platform. |
| 4144 | */ |
| 4145 | dbuf_slice_mask = skl_compute_dbuf_slices(crtc_state, active_pipes); |
| 4146 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4147 | /* |
| 4148 | * Figure out at which DBuf slice we start, i.e if we start at Dbuf S2 |
| 4149 | * and slice size is 1024, the offset would be 1024 |
| 4150 | */ |
| 4151 | offset = icl_get_first_dbuf_slice_offset(dbuf_slice_mask, |
| 4152 | slice_size, ddb_size); |
| 4153 | |
| 4154 | /* |
| 4155 | * Figure out total size of allowed DBuf slices, which is basically |
| 4156 | * a number of allowed slices for that pipe multiplied by slice size. |
| 4157 | * Inside of this |
| 4158 | * range ddb entries are still allocated in proportion to display width. |
| 4159 | */ |
| 4160 | ddb_range_size = hweight8(dbuf_slice_mask) * slice_size; |
| 4161 | |
| 4162 | /* |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4163 | * Watermark/ddb requirement highly depends upon width of the |
| 4164 | * framebuffer, So instead of allocating DDB equally among pipes |
| 4165 | * distribute DDB based on resolution/width of the display. |
| 4166 | */ |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4167 | total_slice_mask = dbuf_slice_mask; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4168 | for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 4169 | const struct drm_display_mode *pipe_mode = |
| 4170 | &crtc_state->hw.pipe_mode; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4171 | enum pipe pipe = crtc->pipe; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4172 | int hdisplay, vdisplay; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4173 | u32 pipe_dbuf_slice_mask; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4174 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4175 | if (!crtc_state->hw.active) |
| 4176 | continue; |
| 4177 | |
| 4178 | pipe_dbuf_slice_mask = skl_compute_dbuf_slices(crtc_state, |
| 4179 | active_pipes); |
| 4180 | |
| 4181 | /* |
| 4182 | * According to BSpec pipe can share one dbuf slice with another |
| 4183 | * pipes or pipe can use multiple dbufs, in both cases we |
| 4184 | * account for other pipes only if they have exactly same mask. |
| 4185 | * However we need to account how many slices we should enable |
| 4186 | * in total. |
| 4187 | */ |
| 4188 | total_slice_mask |= pipe_dbuf_slice_mask; |
| 4189 | |
| 4190 | /* |
| 4191 | * Do not account pipes using other slice sets |
| 4192 | * luckily as of current BSpec slice sets do not partially |
| 4193 | * intersect(pipes share either same one slice or same slice set |
| 4194 | * i.e no partial intersection), so it is enough to check for |
| 4195 | * equality for now. |
| 4196 | */ |
| 4197 | if (dbuf_slice_mask != pipe_dbuf_slice_mask) |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4198 | continue; |
| 4199 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 4200 | drm_mode_get_hv_timing(pipe_mode, &hdisplay, &vdisplay); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4201 | |
| 4202 | total_width_in_range += hdisplay; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4203 | |
| 4204 | if (pipe < for_pipe) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4205 | width_before_pipe_in_range += hdisplay; |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4206 | else if (pipe == for_pipe) |
| 4207 | pipe_width = hdisplay; |
| 4208 | } |
| 4209 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4210 | /* |
| 4211 | * FIXME: For now we always enable slice S1 as per |
| 4212 | * the Bspec display initialization sequence. |
| 4213 | */ |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4214 | new_dbuf_state->enabled_slices = total_slice_mask | BIT(DBUF_S1); |
| 4215 | |
| 4216 | if (old_dbuf_state->enabled_slices != new_dbuf_state->enabled_slices) { |
| 4217 | ret = intel_atomic_serialize_global_state(&new_dbuf_state->base); |
| 4218 | if (ret) |
| 4219 | return ret; |
| 4220 | } |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4221 | |
| 4222 | start = ddb_range_size * width_before_pipe_in_range / total_width_in_range; |
| 4223 | end = ddb_range_size * |
| 4224 | (width_before_pipe_in_range + pipe_width) / total_width_in_range; |
| 4225 | |
| 4226 | alloc->start = offset + start; |
| 4227 | alloc->end = offset + end; |
| 4228 | |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 4229 | drm_dbg_kms(&dev_priv->drm, |
| 4230 | "[CRTC:%d:%s] dbuf slices 0x%x, ddb (%d - %d), active pipes 0x%x\n", |
| 4231 | for_crtc->base.id, for_crtc->name, |
| 4232 | dbuf_slice_mask, alloc->start, alloc->end, active_pipes); |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4233 | |
| 4234 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4235 | } |
| 4236 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4237 | static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 4238 | int width, const struct drm_format_info *format, |
| 4239 | u64 modifier, unsigned int rotation, |
| 4240 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 4241 | int color_plane); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4242 | static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state, |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4243 | int level, |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 4244 | unsigned int latency, |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4245 | const struct skl_wm_params *wp, |
| 4246 | const struct skl_wm_level *result_prev, |
| 4247 | struct skl_wm_level *result /* out */); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4248 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4249 | static unsigned int |
| 4250 | skl_cursor_allocation(const struct intel_crtc_state *crtc_state, |
| 4251 | int num_active) |
| 4252 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 4253 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4254 | int level, max_level = ilk_wm_max_level(dev_priv); |
| 4255 | struct skl_wm_level wm = {}; |
| 4256 | int ret, min_ddb_alloc = 0; |
| 4257 | struct skl_wm_params wp; |
| 4258 | |
| 4259 | ret = skl_compute_wm_params(crtc_state, 256, |
| 4260 | drm_format_info(DRM_FORMAT_ARGB8888), |
| 4261 | DRM_FORMAT_MOD_LINEAR, |
| 4262 | DRM_MODE_ROTATE_0, |
| 4263 | crtc_state->pixel_rate, &wp, 0); |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 4264 | drm_WARN_ON(&dev_priv->drm, ret); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4265 | |
| 4266 | for (level = 0; level <= max_level; level++) { |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 4267 | unsigned int latency = dev_priv->wm.skl_latency[level]; |
| 4268 | |
| 4269 | skl_compute_plane_wm(crtc_state, level, latency, &wp, &wm, &wm); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4270 | if (wm.min_ddb_alloc == U16_MAX) |
| 4271 | break; |
| 4272 | |
| 4273 | min_ddb_alloc = wm.min_ddb_alloc; |
| 4274 | } |
| 4275 | |
| 4276 | return max(num_active == 1 ? 32 : 8, min_ddb_alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4277 | } |
| 4278 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4279 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 4280 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4281 | { |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4282 | |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 4283 | entry->start = reg & DDB_ENTRY_MASK; |
| 4284 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4285 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 4286 | if (entry->end) |
| 4287 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4288 | } |
| 4289 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4290 | static void |
| 4291 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 4292 | const enum pipe pipe, |
| 4293 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4294 | struct skl_ddb_entry *ddb_y, |
| 4295 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4296 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4297 | u32 val, val2; |
| 4298 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4299 | |
| 4300 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 4301 | if (plane_id == PLANE_CURSOR) { |
| 4302 | val = I915_READ(CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4303 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4304 | return; |
| 4305 | } |
| 4306 | |
| 4307 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
| 4308 | |
| 4309 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4310 | if (val & PLANE_CTL_ENABLE) |
| 4311 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 4312 | val & PLANE_CTL_ORDER_RGBX, |
| 4313 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4314 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4315 | if (INTEL_GEN(dev_priv) >= 11) { |
| 4316 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
| 4317 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4318 | } else { |
| 4319 | val = I915_READ(PLANE_BUF_CFG(pipe, plane_id)); |
Paulo Zanoni | 12a6c93 | 2018-07-31 17:46:14 -0700 | [diff] [blame] | 4320 | val2 = I915_READ(PLANE_NV12_BUF_CFG(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4321 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4322 | if (fourcc && |
| 4323 | drm_format_info_is_yuv_semiplanar(drm_format_info(fourcc))) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4324 | swap(val, val2); |
| 4325 | |
| 4326 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4327 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4328 | } |
| 4329 | } |
| 4330 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4331 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 4332 | struct skl_ddb_entry *ddb_y, |
| 4333 | struct skl_ddb_entry *ddb_uv) |
| 4334 | { |
| 4335 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4336 | enum intel_display_power_domain power_domain; |
| 4337 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4338 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4339 | enum plane_id plane_id; |
| 4340 | |
| 4341 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4342 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 4343 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4344 | return; |
| 4345 | |
| 4346 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4347 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4348 | plane_id, |
| 4349 | &ddb_y[plane_id], |
| 4350 | &ddb_uv[plane_id]); |
| 4351 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4352 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4353 | } |
| 4354 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4355 | /* |
| 4356 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4357 | * The bspec defines downscale amount as: |
| 4358 | * |
| 4359 | * """ |
| 4360 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4361 | * Horizontal destination size] |
| 4362 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4363 | * Vertical destination size] |
| 4364 | * Total down scale amount = Horizontal down scale amount * |
| 4365 | * Vertical down scale amount |
| 4366 | * """ |
| 4367 | * |
| 4368 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4369 | * Caller should take care of dividing & rounding off the value. |
| 4370 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4371 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4372 | skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state, |
| 4373 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4374 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 4375 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4376 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4377 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4378 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4379 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 4380 | if (drm_WARN_ON(&dev_priv->drm, |
| 4381 | !intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4382 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4383 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 4384 | /* |
| 4385 | * Src coordinates are already rotated by 270 degrees for |
| 4386 | * the 90/270 degree plane rotation cases (to match the |
| 4387 | * GTT mapping), hence no need to account for rotation here. |
| 4388 | * |
| 4389 | * n.b., src is 16.16 fixed point, dst is whole integer. |
| 4390 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4391 | src_w = drm_rect_width(&plane_state->uapi.src) >> 16; |
| 4392 | src_h = drm_rect_height(&plane_state->uapi.src) >> 16; |
| 4393 | dst_w = drm_rect_width(&plane_state->uapi.dst); |
| 4394 | dst_h = drm_rect_height(&plane_state->uapi.dst); |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4395 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4396 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4397 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4398 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4399 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4400 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4401 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4402 | } |
| 4403 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4404 | struct dbuf_slice_conf_entry { |
| 4405 | u8 active_pipes; |
| 4406 | u8 dbuf_mask[I915_MAX_PIPES]; |
| 4407 | }; |
| 4408 | |
| 4409 | /* |
| 4410 | * Table taken from Bspec 12716 |
| 4411 | * Pipes do have some preferred DBuf slice affinity, |
| 4412 | * plus there are some hardcoded requirements on how |
| 4413 | * those should be distributed for multipipe scenarios. |
| 4414 | * For more DBuf slices algorithm can get even more messy |
| 4415 | * and less readable, so decided to use a table almost |
| 4416 | * as is from BSpec itself - that way it is at least easier |
| 4417 | * to compare, change and check. |
| 4418 | */ |
Jani Nikula | f8226d0 | 2020-02-19 17:45:42 +0200 | [diff] [blame] | 4419 | static const struct dbuf_slice_conf_entry icl_allowed_dbufs[] = |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4420 | /* Autogenerated with igt/tools/intel_dbuf_map tool: */ |
| 4421 | { |
| 4422 | { |
| 4423 | .active_pipes = BIT(PIPE_A), |
| 4424 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4425 | [PIPE_A] = BIT(DBUF_S1), |
| 4426 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4427 | }, |
| 4428 | { |
| 4429 | .active_pipes = BIT(PIPE_B), |
| 4430 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4431 | [PIPE_B] = BIT(DBUF_S1), |
| 4432 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4433 | }, |
| 4434 | { |
| 4435 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4436 | .dbuf_mask = { |
| 4437 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4438 | [PIPE_B] = BIT(DBUF_S2), |
| 4439 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4440 | }, |
| 4441 | { |
| 4442 | .active_pipes = BIT(PIPE_C), |
| 4443 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4444 | [PIPE_C] = BIT(DBUF_S2), |
| 4445 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4446 | }, |
| 4447 | { |
| 4448 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4449 | .dbuf_mask = { |
| 4450 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4451 | [PIPE_C] = BIT(DBUF_S2), |
| 4452 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4453 | }, |
| 4454 | { |
| 4455 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4456 | .dbuf_mask = { |
| 4457 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4458 | [PIPE_C] = BIT(DBUF_S2), |
| 4459 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4460 | }, |
| 4461 | { |
| 4462 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4463 | .dbuf_mask = { |
| 4464 | [PIPE_A] = BIT(DBUF_S1), |
| 4465 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4466 | [PIPE_C] = BIT(DBUF_S2), |
| 4467 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4468 | }, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4469 | {} |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4470 | }; |
| 4471 | |
| 4472 | /* |
| 4473 | * Table taken from Bspec 49255 |
| 4474 | * Pipes do have some preferred DBuf slice affinity, |
| 4475 | * plus there are some hardcoded requirements on how |
| 4476 | * those should be distributed for multipipe scenarios. |
| 4477 | * For more DBuf slices algorithm can get even more messy |
| 4478 | * and less readable, so decided to use a table almost |
| 4479 | * as is from BSpec itself - that way it is at least easier |
| 4480 | * to compare, change and check. |
| 4481 | */ |
Jani Nikula | f8226d0 | 2020-02-19 17:45:42 +0200 | [diff] [blame] | 4482 | static const struct dbuf_slice_conf_entry tgl_allowed_dbufs[] = |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4483 | /* Autogenerated with igt/tools/intel_dbuf_map tool: */ |
| 4484 | { |
| 4485 | { |
| 4486 | .active_pipes = BIT(PIPE_A), |
| 4487 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4488 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4489 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4490 | }, |
| 4491 | { |
| 4492 | .active_pipes = BIT(PIPE_B), |
| 4493 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4494 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4495 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4496 | }, |
| 4497 | { |
| 4498 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4499 | .dbuf_mask = { |
| 4500 | [PIPE_A] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4501 | [PIPE_B] = BIT(DBUF_S1), |
| 4502 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4503 | }, |
| 4504 | { |
| 4505 | .active_pipes = BIT(PIPE_C), |
| 4506 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4507 | [PIPE_C] = BIT(DBUF_S2) | BIT(DBUF_S1), |
| 4508 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4509 | }, |
| 4510 | { |
| 4511 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4512 | .dbuf_mask = { |
| 4513 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4514 | [PIPE_C] = BIT(DBUF_S2), |
| 4515 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4516 | }, |
| 4517 | { |
| 4518 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4519 | .dbuf_mask = { |
| 4520 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4521 | [PIPE_C] = BIT(DBUF_S2), |
| 4522 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4523 | }, |
| 4524 | { |
| 4525 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4526 | .dbuf_mask = { |
| 4527 | [PIPE_A] = BIT(DBUF_S1), |
| 4528 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4529 | [PIPE_C] = BIT(DBUF_S2), |
| 4530 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4531 | }, |
| 4532 | { |
| 4533 | .active_pipes = BIT(PIPE_D), |
| 4534 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4535 | [PIPE_D] = BIT(DBUF_S2) | BIT(DBUF_S1), |
| 4536 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4537 | }, |
| 4538 | { |
| 4539 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4540 | .dbuf_mask = { |
| 4541 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4542 | [PIPE_D] = BIT(DBUF_S2), |
| 4543 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4544 | }, |
| 4545 | { |
| 4546 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4547 | .dbuf_mask = { |
| 4548 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4549 | [PIPE_D] = BIT(DBUF_S2), |
| 4550 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4551 | }, |
| 4552 | { |
| 4553 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D), |
| 4554 | .dbuf_mask = { |
| 4555 | [PIPE_A] = BIT(DBUF_S1), |
| 4556 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4557 | [PIPE_D] = BIT(DBUF_S2), |
| 4558 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4559 | }, |
| 4560 | { |
| 4561 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4562 | .dbuf_mask = { |
| 4563 | [PIPE_C] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4564 | [PIPE_D] = BIT(DBUF_S2), |
| 4565 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4566 | }, |
| 4567 | { |
| 4568 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4569 | .dbuf_mask = { |
| 4570 | [PIPE_A] = BIT(DBUF_S1), |
| 4571 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4572 | [PIPE_D] = BIT(DBUF_S2), |
| 4573 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4574 | }, |
| 4575 | { |
| 4576 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4577 | .dbuf_mask = { |
| 4578 | [PIPE_B] = BIT(DBUF_S1), |
| 4579 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4580 | [PIPE_D] = BIT(DBUF_S2), |
| 4581 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4582 | }, |
| 4583 | { |
| 4584 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4585 | .dbuf_mask = { |
| 4586 | [PIPE_A] = BIT(DBUF_S1), |
| 4587 | [PIPE_B] = BIT(DBUF_S1), |
| 4588 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4589 | [PIPE_D] = BIT(DBUF_S2), |
| 4590 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4591 | }, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4592 | {} |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4593 | }; |
| 4594 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4595 | static u8 compute_dbuf_slices(enum pipe pipe, u8 active_pipes, |
| 4596 | const struct dbuf_slice_conf_entry *dbuf_slices) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4597 | { |
| 4598 | int i; |
| 4599 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4600 | for (i = 0; i < dbuf_slices[i].active_pipes; i++) { |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4601 | if (dbuf_slices[i].active_pipes == active_pipes) |
| 4602 | return dbuf_slices[i].dbuf_mask[pipe]; |
| 4603 | } |
| 4604 | return 0; |
| 4605 | } |
| 4606 | |
| 4607 | /* |
| 4608 | * This function finds an entry with same enabled pipe configuration and |
| 4609 | * returns correspondent DBuf slice mask as stated in BSpec for particular |
| 4610 | * platform. |
| 4611 | */ |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4612 | static u8 icl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4613 | { |
| 4614 | /* |
| 4615 | * FIXME: For ICL this is still a bit unclear as prev BSpec revision |
| 4616 | * required calculating "pipe ratio" in order to determine |
| 4617 | * if one or two slices can be used for single pipe configurations |
| 4618 | * as additional constraint to the existing table. |
| 4619 | * However based on recent info, it should be not "pipe ratio" |
| 4620 | * but rather ratio between pixel_rate and cdclk with additional |
| 4621 | * constants, so for now we are using only table until this is |
| 4622 | * clarified. Also this is the reason why crtc_state param is |
| 4623 | * still here - we will need it once those additional constraints |
| 4624 | * pop up. |
| 4625 | */ |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4626 | return compute_dbuf_slices(pipe, active_pipes, icl_allowed_dbufs); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4627 | } |
| 4628 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4629 | static u8 tgl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4630 | { |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4631 | return compute_dbuf_slices(pipe, active_pipes, tgl_allowed_dbufs); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | static u8 skl_compute_dbuf_slices(const struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4635 | u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4636 | { |
| 4637 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 4638 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4639 | enum pipe pipe = crtc->pipe; |
| 4640 | |
| 4641 | if (IS_GEN(dev_priv, 12)) |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4642 | return tgl_compute_dbuf_slices(pipe, active_pipes); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4643 | else if (IS_GEN(dev_priv, 11)) |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4644 | return icl_compute_dbuf_slices(pipe, active_pipes); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4645 | /* |
| 4646 | * For anything else just return one slice yet. |
| 4647 | * Should be extended for other platforms. |
| 4648 | */ |
Ville Syrjälä | 2f9078c | 2020-02-25 19:11:10 +0200 | [diff] [blame] | 4649 | return active_pipes & BIT(pipe) ? BIT(DBUF_S1) : 0; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4650 | } |
| 4651 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4652 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4653 | skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state, |
| 4654 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4655 | int color_plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4656 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4657 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 4658 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4659 | u32 data_rate; |
| 4660 | u32 width = 0, height = 0; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4661 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4662 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4663 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4664 | if (!plane_state->uapi.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4665 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4666 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4667 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4668 | return 0; |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4669 | |
| 4670 | if (color_plane == 1 && |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 4671 | !intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4672 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4673 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4674 | /* |
| 4675 | * Src coordinates are already rotated by 270 degrees for |
| 4676 | * the 90/270 degree plane rotation cases (to match the |
| 4677 | * GTT mapping), hence no need to account for rotation here. |
| 4678 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4679 | width = drm_rect_width(&plane_state->uapi.src) >> 16; |
| 4680 | height = drm_rect_height(&plane_state->uapi.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4681 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4682 | /* UV plane does 1/2 pixel sub-sampling */ |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4683 | if (color_plane == 1) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4684 | width /= 2; |
| 4685 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4686 | } |
| 4687 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4688 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4689 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4690 | down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4691 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4692 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4693 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4694 | rate *= fb->format->cpp[color_plane]; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4695 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4698 | static u64 |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4699 | skl_get_total_relative_data_rate(struct intel_atomic_state *state, |
| 4700 | struct intel_crtc *crtc) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4701 | { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4702 | struct intel_crtc_state *crtc_state = |
| 4703 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4704 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4705 | struct intel_plane *plane; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4706 | u64 total_data_rate = 0; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4707 | enum plane_id plane_id; |
| 4708 | int i; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4709 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4710 | /* Calculate and cache data rate for each plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4711 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 4712 | if (plane->pipe != crtc->pipe) |
| 4713 | continue; |
| 4714 | |
| 4715 | plane_id = plane->id; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4716 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4717 | /* packed/y */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4718 | crtc_state->plane_data_rate[plane_id] = |
| 4719 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4720 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4721 | /* uv-plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4722 | crtc_state->uv_plane_data_rate[plane_id] = |
| 4723 | skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
| 4724 | } |
| 4725 | |
| 4726 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 4727 | total_data_rate += crtc_state->plane_data_rate[plane_id]; |
| 4728 | total_data_rate += crtc_state->uv_plane_data_rate[plane_id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | return total_data_rate; |
| 4732 | } |
| 4733 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4734 | static u64 |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4735 | icl_get_total_relative_data_rate(struct intel_atomic_state *state, |
| 4736 | struct intel_crtc *crtc) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4737 | { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4738 | struct intel_crtc_state *crtc_state = |
| 4739 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4740 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4741 | struct intel_plane *plane; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4742 | u64 total_data_rate = 0; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4743 | enum plane_id plane_id; |
| 4744 | int i; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4745 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4746 | /* Calculate and cache data rate for each plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4747 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 4748 | if (plane->pipe != crtc->pipe) |
| 4749 | continue; |
| 4750 | |
| 4751 | plane_id = plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4752 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4753 | if (!plane_state->planar_linked_plane) { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4754 | crtc_state->plane_data_rate[plane_id] = |
| 4755 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4756 | } else { |
| 4757 | enum plane_id y_plane_id; |
| 4758 | |
| 4759 | /* |
| 4760 | * The slave plane might not iterate in |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4761 | * intel_atomic_crtc_state_for_each_plane_state(), |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4762 | * and needs the master plane state which may be |
| 4763 | * NULL if we try get_new_plane_state(), so we |
| 4764 | * always calculate from the master. |
| 4765 | */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4766 | if (plane_state->planar_slave) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4767 | continue; |
| 4768 | |
| 4769 | /* Y plane rate is calculated on the slave */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4770 | y_plane_id = plane_state->planar_linked_plane->id; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4771 | crtc_state->plane_data_rate[y_plane_id] = |
| 4772 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4773 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4774 | crtc_state->plane_data_rate[plane_id] = |
| 4775 | skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4776 | } |
| 4777 | } |
| 4778 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4779 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4780 | total_data_rate += crtc_state->plane_data_rate[plane_id]; |
| 4781 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4782 | return total_data_rate; |
| 4783 | } |
| 4784 | |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 4785 | static const struct skl_wm_level * |
| 4786 | skl_plane_wm_level(const struct intel_crtc_state *crtc_state, |
| 4787 | enum plane_id plane_id, |
| 4788 | int level) |
| 4789 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 4790 | const struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
| 4791 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 4792 | |
| 4793 | if (level == 0 && pipe_wm->use_sagv_wm) |
| 4794 | return &wm->sagv_wm0; |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 4795 | |
| 4796 | return &wm->wm[level]; |
| 4797 | } |
| 4798 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4799 | static int |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 4800 | skl_allocate_pipe_ddb(struct intel_atomic_state *state, |
| 4801 | struct intel_crtc *crtc) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4802 | { |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 4803 | struct intel_crtc_state *crtc_state = |
| 4804 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 4805 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4806 | struct skl_ddb_entry *alloc = &crtc_state->wm.skl.ddb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4807 | u16 alloc_size, start = 0; |
| 4808 | u16 total[I915_MAX_PLANES] = {}; |
| 4809 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4810 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4811 | enum plane_id plane_id; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4812 | int num_active; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 4813 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4814 | int level; |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4815 | int ret; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4816 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4817 | /* Clear the partitioning for disabled planes. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4818 | memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y)); |
| 4819 | memset(crtc_state->wm.skl.plane_ddb_uv, 0, sizeof(crtc_state->wm.skl.plane_ddb_uv)); |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 4820 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 4821 | if (!crtc_state->hw.active) { |
Ville Syrjälä | b6a13a3 | 2020-05-18 15:13:54 +0300 | [diff] [blame] | 4822 | struct intel_atomic_state *state = |
| 4823 | to_intel_atomic_state(crtc_state->uapi.state); |
| 4824 | struct intel_dbuf_state *new_dbuf_state = |
| 4825 | intel_atomic_get_new_dbuf_state(state); |
| 4826 | const struct intel_dbuf_state *old_dbuf_state = |
| 4827 | intel_atomic_get_old_dbuf_state(state); |
| 4828 | |
| 4829 | /* |
| 4830 | * FIXME hack to make sure we compute this sensibly when |
| 4831 | * turning off all the pipes. Otherwise we leave it at |
| 4832 | * whatever we had previously, and then runtime PM will |
| 4833 | * mess it up by turning off all but S1. Remove this |
| 4834 | * once the dbuf state computation flow becomes sane. |
| 4835 | */ |
| 4836 | if (new_dbuf_state->active_pipes == 0) { |
| 4837 | new_dbuf_state->enabled_slices = BIT(DBUF_S1); |
| 4838 | |
| 4839 | if (old_dbuf_state->enabled_slices != new_dbuf_state->enabled_slices) { |
| 4840 | ret = intel_atomic_serialize_global_state(&new_dbuf_state->base); |
| 4841 | if (ret) |
| 4842 | return ret; |
| 4843 | } |
| 4844 | } |
| 4845 | |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 4846 | alloc->start = alloc->end = 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4847 | return 0; |
| 4848 | } |
| 4849 | |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4850 | if (INTEL_GEN(dev_priv) >= 11) |
| 4851 | total_data_rate = |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4852 | icl_get_total_relative_data_rate(state, crtc); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4853 | else |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4854 | total_data_rate = |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4855 | skl_get_total_relative_data_rate(state, crtc); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 4856 | |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4857 | ret = skl_ddb_get_pipe_allocation_limits(dev_priv, crtc_state, |
| 4858 | total_data_rate, |
| 4859 | alloc, &num_active); |
| 4860 | if (ret) |
| 4861 | return ret; |
| 4862 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 4863 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 4864 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4865 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4866 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4867 | /* Allocate fixed number of blocks for cursor. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4868 | total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4869 | alloc_size -= total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4870 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4871 | alloc->end - total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4872 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4873 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4874 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4875 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4876 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4877 | /* |
| 4878 | * Find the highest watermark level for which we can satisfy the block |
| 4879 | * requirement of active planes. |
| 4880 | */ |
| 4881 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 4882 | blocks = 0; |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 4883 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4884 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4885 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 4886 | |
| 4887 | if (plane_id == PLANE_CURSOR) { |
Vandita Kulkarni | 4ba4870 | 2019-12-16 13:36:19 +0530 | [diff] [blame] | 4888 | if (wm->wm[level].min_ddb_alloc > total[PLANE_CURSOR]) { |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 4889 | drm_WARN_ON(&dev_priv->drm, |
| 4890 | wm->wm[level].min_ddb_alloc != U16_MAX); |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 4891 | blocks = U32_MAX; |
| 4892 | break; |
| 4893 | } |
| 4894 | continue; |
| 4895 | } |
| 4896 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4897 | blocks += wm->wm[level].min_ddb_alloc; |
| 4898 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4899 | } |
| 4900 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame] | 4901 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4902 | alloc_size -= blocks; |
| 4903 | break; |
| 4904 | } |
| 4905 | } |
| 4906 | |
| 4907 | if (level < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 4908 | drm_dbg_kms(&dev_priv->drm, |
| 4909 | "Requested display configuration exceeds system DDB limitations"); |
| 4910 | drm_dbg_kms(&dev_priv->drm, "minimum required %d/%d\n", |
| 4911 | blocks, alloc_size); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4912 | return -EINVAL; |
| 4913 | } |
| 4914 | |
| 4915 | /* |
| 4916 | * Grant each plane the blocks it requires at the highest achievable |
| 4917 | * watermark level, plus an extra share of the leftover blocks |
| 4918 | * proportional to its relative data rate. |
| 4919 | */ |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 4920 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4921 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4922 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4923 | u64 rate; |
| 4924 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4925 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 4926 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 4927 | continue; |
| 4928 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4929 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4930 | * We've accounted for all active planes; remaining planes are |
| 4931 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4932 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4933 | if (total_data_rate == 0) |
| 4934 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4935 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4936 | rate = crtc_state->plane_data_rate[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4937 | extra = min_t(u16, alloc_size, |
| 4938 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4939 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4940 | total[plane_id] = wm->wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4941 | alloc_size -= extra; |
| 4942 | total_data_rate -= rate; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4943 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4944 | if (total_data_rate == 0) |
| 4945 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4946 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame^] | 4947 | rate = crtc_state->uv_plane_data_rate[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4948 | extra = min_t(u16, alloc_size, |
| 4949 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 4950 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 4951 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4952 | alloc_size -= extra; |
| 4953 | total_data_rate -= rate; |
| 4954 | } |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 4955 | drm_WARN_ON(&dev_priv->drm, alloc_size != 0 || total_data_rate != 0); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4956 | |
| 4957 | /* Set the actual DDB start/end points for each plane */ |
| 4958 | start = alloc->start; |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 4959 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4960 | struct skl_ddb_entry *plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4961 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4962 | struct skl_ddb_entry *uv_plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4963 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4964 | |
| 4965 | if (plane_id == PLANE_CURSOR) |
| 4966 | continue; |
| 4967 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4968 | /* Gen11+ uses a separate plane for UV watermarks */ |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 4969 | drm_WARN_ON(&dev_priv->drm, |
| 4970 | INTEL_GEN(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4971 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4972 | /* Leave disabled planes at (0,0) */ |
| 4973 | if (total[plane_id]) { |
| 4974 | plane_alloc->start = start; |
| 4975 | start += total[plane_id]; |
| 4976 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 4977 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 4978 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 4979 | if (uv_total[plane_id]) { |
| 4980 | uv_plane_alloc->start = start; |
| 4981 | start += uv_total[plane_id]; |
| 4982 | uv_plane_alloc->end = start; |
| 4983 | } |
| 4984 | } |
| 4985 | |
| 4986 | /* |
| 4987 | * When we calculated watermark values we didn't know how high |
| 4988 | * of a level we'd actually be able to hit, so we just marked |
| 4989 | * all levels as "enabled." Go back now and disable the ones |
| 4990 | * that aren't actually possible. |
| 4991 | */ |
| 4992 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 4993 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 4994 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4995 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | a301cb0 | 2019-03-12 22:58:41 +0200 | [diff] [blame] | 4996 | |
| 4997 | /* |
| 4998 | * We only disable the watermarks for each plane if |
| 4999 | * they exceed the ddb allocation of said plane. This |
| 5000 | * is done so that we don't end up touching cursor |
| 5001 | * watermarks needlessly when some other plane reduces |
| 5002 | * our max possible watermark level. |
| 5003 | * |
| 5004 | * Bspec has this to say about the PLANE_WM enable bit: |
| 5005 | * "All the watermarks at this level for all enabled |
| 5006 | * planes must be enabled before the level will be used." |
| 5007 | * So this is actually safe to do. |
| 5008 | */ |
| 5009 | if (wm->wm[level].min_ddb_alloc > total[plane_id] || |
| 5010 | wm->uv_wm[level].min_ddb_alloc > uv_total[plane_id]) |
| 5011 | memset(&wm->wm[level], 0, sizeof(wm->wm[level])); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5012 | |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5013 | /* |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 5014 | * Wa_1408961008:icl, ehl |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5015 | * Underruns with WM1+ disabled |
| 5016 | */ |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 5017 | if (IS_GEN(dev_priv, 11) && |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5018 | level == 1 && wm->wm[0].plane_en) { |
| 5019 | wm->wm[level].plane_res_b = wm->wm[0].plane_res_b; |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5020 | wm->wm[level].plane_res_l = wm->wm[0].plane_res_l; |
| 5021 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5022 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5023 | } |
| 5024 | } |
| 5025 | |
| 5026 | /* |
| 5027 | * Go back and disable the transition watermark if it turns out we |
| 5028 | * don't have enough DDB blocks for it. |
| 5029 | */ |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5030 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5031 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5032 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5033 | |
Ville Syrjälä | b19c9bc | 2018-12-21 19:14:31 +0200 | [diff] [blame] | 5034 | if (wm->trans_wm.plane_res_b >= total[plane_id]) |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5035 | memset(&wm->trans_wm, 0, sizeof(wm->trans_wm)); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5036 | } |
| 5037 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5038 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5039 | } |
| 5040 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5041 | /* |
| 5042 | * 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] | 5043 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5044 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 5045 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 5046 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5047 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5048 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 5049 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5050 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5051 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5052 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5053 | |
| 5054 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5055 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5056 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5057 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5058 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5059 | |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5060 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5061 | ret = add_fixed16_u32(ret, 1); |
| 5062 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5063 | return ret; |
| 5064 | } |
| 5065 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5066 | static uint_fixed_16_16_t |
| 5067 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 5068 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5069 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5070 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5071 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5072 | |
| 5073 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5074 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5075 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5076 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5077 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 5078 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5079 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5080 | return ret; |
| 5081 | } |
| 5082 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5083 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5084 | intel_get_linetime_us(const struct intel_crtc_state *crtc_state) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5085 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5086 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5087 | u32 pixel_rate; |
| 5088 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5089 | uint_fixed_16_16_t linetime_us; |
| 5090 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 5091 | if (!crtc_state->hw.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5092 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5093 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5094 | pixel_rate = crtc_state->pixel_rate; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5095 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5096 | if (drm_WARN_ON(&dev_priv->drm, pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5097 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5098 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5099 | crtc_htotal = crtc_state->hw.pipe_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5100 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5101 | |
| 5102 | return linetime_us; |
| 5103 | } |
| 5104 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5105 | static u32 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5106 | skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *crtc_state, |
| 5107 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 5108 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5109 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5110 | u64 adjusted_pixel_rate; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 5111 | uint_fixed_16_16_t downscale_amount; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 5112 | |
| 5113 | /* Shouldn't reach here on disabled planes... */ |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5114 | if (drm_WARN_ON(&dev_priv->drm, |
| 5115 | !intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 5116 | return 0; |
| 5117 | |
| 5118 | /* |
| 5119 | * Adjusted plane pixel rate is just the pipe's adjusted pixel rate |
| 5120 | * with additional adjustments for plane-specific scaling. |
| 5121 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5122 | adjusted_pixel_rate = crtc_state->pixel_rate; |
| 5123 | downscale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 5124 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 5125 | return mul_round_up_u32_fixed16(adjusted_pixel_rate, |
| 5126 | downscale_amount); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5129 | static int |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5130 | skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 5131 | int width, const struct drm_format_info *format, |
| 5132 | u64 modifier, unsigned int rotation, |
| 5133 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 5134 | int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5135 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5136 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5137 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5138 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5139 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 5140 | /* only planar format has two planes */ |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 5141 | if (color_plane == 1 && |
| 5142 | !intel_format_info_is_yuv_semiplanar(format, modifier)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5143 | drm_dbg_kms(&dev_priv->drm, |
| 5144 | "Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5145 | return -EINVAL; |
| 5146 | } |
| 5147 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5148 | wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED || |
| 5149 | modifier == I915_FORMAT_MOD_Yf_TILED || |
| 5150 | modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 5151 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 5152 | wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED; |
| 5153 | wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 5154 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 5155 | wp->is_planar = intel_format_info_is_yuv_semiplanar(format, modifier); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5156 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5157 | wp->width = width; |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 5158 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5159 | wp->width /= 2; |
| 5160 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5161 | wp->cpp = format->cpp[color_plane]; |
| 5162 | wp->plane_pixel_rate = plane_pixel_rate; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5163 | |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5164 | if (INTEL_GEN(dev_priv) >= 11 && |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5165 | modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5166 | wp->dbuf_block_size = 256; |
| 5167 | else |
| 5168 | wp->dbuf_block_size = 512; |
| 5169 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5170 | if (drm_rotation_90_or_270(rotation)) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5171 | switch (wp->cpp) { |
| 5172 | case 1: |
| 5173 | wp->y_min_scanlines = 16; |
| 5174 | break; |
| 5175 | case 2: |
| 5176 | wp->y_min_scanlines = 8; |
| 5177 | break; |
| 5178 | case 4: |
| 5179 | wp->y_min_scanlines = 4; |
| 5180 | break; |
| 5181 | default: |
| 5182 | MISSING_CASE(wp->cpp); |
| 5183 | return -EINVAL; |
| 5184 | } |
| 5185 | } else { |
| 5186 | wp->y_min_scanlines = 4; |
| 5187 | } |
| 5188 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 5189 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5190 | wp->y_min_scanlines *= 2; |
| 5191 | |
| 5192 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 5193 | if (wp->y_tiled) { |
| 5194 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5195 | wp->y_min_scanlines, |
| 5196 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5197 | |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5198 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5199 | interm_pbpl++; |
| 5200 | |
| 5201 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 5202 | wp->y_min_scanlines); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5203 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5204 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5205 | wp->dbuf_block_size); |
| 5206 | |
| 5207 | if (!wp->x_tiled || |
| 5208 | INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 5209 | interm_pbpl++; |
| 5210 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5211 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 5212 | } |
| 5213 | |
| 5214 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 5215 | wp->plane_blocks_per_line); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5216 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5217 | wp->linetime_us = fixed16_to_u32_round_up( |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5218 | intel_get_linetime_us(crtc_state)); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5219 | |
| 5220 | return 0; |
| 5221 | } |
| 5222 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5223 | static int |
| 5224 | skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state, |
| 5225 | const struct intel_plane_state *plane_state, |
| 5226 | struct skl_wm_params *wp, int color_plane) |
| 5227 | { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5228 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5229 | int width; |
| 5230 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 5231 | /* |
| 5232 | * Src coordinates are already rotated by 270 degrees for |
| 5233 | * the 90/270 degree plane rotation cases (to match the |
| 5234 | * GTT mapping), hence no need to account for rotation here. |
| 5235 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 5236 | width = drm_rect_width(&plane_state->uapi.src) >> 16; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5237 | |
| 5238 | return skl_compute_wm_params(crtc_state, width, |
| 5239 | fb->format, fb->modifier, |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5240 | plane_state->hw.rotation, |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5241 | skl_adjusted_plane_pixel_rate(crtc_state, plane_state), |
| 5242 | wp, color_plane); |
| 5243 | } |
| 5244 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5245 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 5246 | { |
| 5247 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 5248 | return true; |
| 5249 | |
| 5250 | /* The number of lines are ignored for the level 0 watermark. */ |
| 5251 | return level > 0; |
| 5252 | } |
| 5253 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5254 | static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5255 | int level, |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5256 | unsigned int latency, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5257 | const struct skl_wm_params *wp, |
| 5258 | const struct skl_wm_level *result_prev, |
| 5259 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5260 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5261 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5262 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5263 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5264 | u32 res_blocks, res_lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 5265 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5266 | if (latency == 0) { |
| 5267 | /* reject it */ |
| 5268 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 5269 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5270 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 5271 | |
Ville Syrjälä | 25312ef | 2019-05-03 20:38:05 +0300 | [diff] [blame] | 5272 | /* |
| 5273 | * WaIncreaseLatencyIPCEnabled: kbl,cfl |
| 5274 | * Display WA #1141: kbl,cfl |
| 5275 | */ |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 5276 | if ((IS_KABYLAKE(dev_priv) || |
| 5277 | IS_COFFEELAKE(dev_priv) || |
| 5278 | IS_COMETLAKE(dev_priv)) && |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 5279 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 5280 | latency += 4; |
| 5281 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 5282 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 5283 | latency += 15; |
| 5284 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5285 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5286 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5287 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5288 | crtc_state->hw.pipe_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 5289 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5290 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5291 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5292 | if (wp->y_tiled) { |
| 5293 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5294 | } else { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5295 | if ((wp->cpp * crtc_state->hw.pipe_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5296 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5297 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 5298 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5299 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5300 | if (IS_GEN(dev_priv, 9) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5301 | !IS_GEMINILAKE(dev_priv)) |
| 5302 | selected_result = min_fixed16(method1, method2); |
| 5303 | else |
| 5304 | selected_result = method2; |
| 5305 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5306 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5307 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5308 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5309 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5310 | res_blocks = fixed16_to_u32_round_up(selected_result) + 1; |
Kumar, Mahesh | d273ecc | 2017-05-17 17:28:22 +0530 | [diff] [blame] | 5311 | res_lines = div_round_up_fixed16(selected_result, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5312 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 5313 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5314 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) { |
| 5315 | /* Display WA #1125: skl,bxt,kbl */ |
| 5316 | if (level == 0 && wp->rc_surface) |
| 5317 | res_blocks += |
| 5318 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 5319 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5320 | /* Display WA #1126: skl,bxt,kbl */ |
| 5321 | if (level >= 1 && level <= 7) { |
| 5322 | if (wp->y_tiled) { |
| 5323 | res_blocks += |
| 5324 | fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 5325 | res_lines += wp->y_min_scanlines; |
| 5326 | } else { |
| 5327 | res_blocks++; |
| 5328 | } |
| 5329 | |
| 5330 | /* |
| 5331 | * Make sure result blocks for higher latency levels are |
| 5332 | * atleast as high as level below the current level. |
| 5333 | * Assumption in DDB algorithm optimization for special |
| 5334 | * cases. Also covers Display WA #1125 for RC. |
| 5335 | */ |
| 5336 | if (result_prev->plane_res_b > res_blocks) |
| 5337 | res_blocks = result_prev->plane_res_b; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 5338 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5339 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 5340 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5341 | if (INTEL_GEN(dev_priv) >= 11) { |
| 5342 | if (wp->y_tiled) { |
| 5343 | int extra_lines; |
| 5344 | |
| 5345 | if (res_lines % wp->y_min_scanlines == 0) |
| 5346 | extra_lines = wp->y_min_scanlines; |
| 5347 | else |
| 5348 | extra_lines = wp->y_min_scanlines * 2 - |
| 5349 | res_lines % wp->y_min_scanlines; |
| 5350 | |
| 5351 | min_ddb_alloc = mul_round_up_u32_fixed16(res_lines + extra_lines, |
| 5352 | wp->plane_blocks_per_line); |
| 5353 | } else { |
| 5354 | min_ddb_alloc = res_blocks + |
| 5355 | DIV_ROUND_UP(res_blocks, 10); |
| 5356 | } |
| 5357 | } |
| 5358 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5359 | if (!skl_wm_has_lines(dev_priv, level)) |
| 5360 | res_lines = 0; |
| 5361 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5362 | if (res_lines > 31) { |
| 5363 | /* reject it */ |
| 5364 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5365 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5366 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5367 | |
| 5368 | /* |
| 5369 | * If res_lines is valid, assume we can use this watermark level |
| 5370 | * for now. We'll come back and disable it after we calculate the |
| 5371 | * DDB allocation if it turns out we don't actually have enough |
| 5372 | * blocks to satisfy it. |
| 5373 | */ |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 5374 | result->plane_res_b = res_blocks; |
| 5375 | result->plane_res_l = res_lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5376 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
| 5377 | result->min_ddb_alloc = max(min_ddb_alloc, res_blocks) + 1; |
Mahesh Kumar | 62027b7 | 2018-04-09 09:11:05 +0530 | [diff] [blame] | 5378 | result->plane_en = true; |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 5379 | |
| 5380 | if (INTEL_GEN(dev_priv) < 12) |
| 5381 | result->can_sagv = latency >= dev_priv->sagv_block_time_us; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5384 | static void |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5385 | skl_compute_wm_levels(const struct intel_crtc_state *crtc_state, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5386 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5387 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5388 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5389 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5390 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5391 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 5392 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5393 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5394 | struct skl_wm_level *result = &levels[level]; |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5395 | unsigned int latency = dev_priv->wm.skl_latency[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5396 | |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5397 | skl_compute_plane_wm(crtc_state, level, latency, |
| 5398 | wm_params, result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5399 | |
| 5400 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5401 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5402 | } |
| 5403 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5404 | static void tgl_compute_sagv_wm(const struct intel_crtc_state *crtc_state, |
| 5405 | const struct skl_wm_params *wm_params, |
| 5406 | struct skl_plane_wm *plane_wm) |
| 5407 | { |
| 5408 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
| 5409 | struct skl_wm_level *sagv_wm = &plane_wm->sagv_wm0; |
| 5410 | struct skl_wm_level *levels = plane_wm->wm; |
| 5411 | unsigned int latency = dev_priv->wm.skl_latency[0] + dev_priv->sagv_block_time_us; |
| 5412 | |
| 5413 | skl_compute_plane_wm(crtc_state, 0, latency, |
| 5414 | wm_params, &levels[0], |
| 5415 | sagv_wm); |
| 5416 | } |
| 5417 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5418 | static void skl_compute_transition_wm(const struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 5419 | const struct skl_wm_params *wp, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5420 | struct skl_plane_wm *wm) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 5421 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5422 | struct drm_device *dev = crtc_state->uapi.crtc->dev; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5423 | const struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5424 | u16 trans_min, trans_amount, trans_y_tile_min; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5425 | u16 wm0_sel_res_b, trans_offset_b, res_blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 5426 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5427 | /* Transition WM don't make any sense if ipc is disabled */ |
| 5428 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 5429 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5430 | |
Ville Syrjälä | a7f1e8e | 2020-02-28 22:35:51 +0200 | [diff] [blame] | 5431 | /* |
| 5432 | * WaDisableTWM:skl,kbl,cfl,bxt |
| 5433 | * Transition WM are not recommended by HW team for GEN9 |
| 5434 | */ |
| 5435 | if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) |
| 5436 | return; |
| 5437 | |
Paulo Zanoni | 91961a8 | 2018-10-04 16:15:56 -0700 | [diff] [blame] | 5438 | if (INTEL_GEN(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5439 | trans_min = 4; |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5440 | else |
| 5441 | trans_min = 14; |
| 5442 | |
| 5443 | /* Display WA #1140: glk,cnl */ |
| 5444 | if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) |
| 5445 | trans_amount = 0; |
| 5446 | else |
| 5447 | trans_amount = 10; /* This is configurable amount */ |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5448 | |
| 5449 | trans_offset_b = trans_min + trans_amount; |
| 5450 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5451 | /* |
| 5452 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 5453 | * not Result Blocks (the integer value). Pay attention to the capital |
| 5454 | * letters. The value wm_l0->plane_res_b is actually Result Blocks, but |
| 5455 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 5456 | * and since we later will have to get the ceiling of the sum in the |
| 5457 | * transition watermarks calculation, we can just pretend Selected |
| 5458 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 5459 | * current platforms. |
| 5460 | */ |
Ville Syrjälä | 6a3c910b | 2018-11-14 23:07:23 +0200 | [diff] [blame] | 5461 | wm0_sel_res_b = wm->wm[0].plane_res_b - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5462 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5463 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5464 | trans_y_tile_min = |
| 5465 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5466 | res_blocks = max(wm0_sel_res_b, trans_y_tile_min) + |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5467 | trans_offset_b; |
| 5468 | } else { |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5469 | res_blocks = wm0_sel_res_b + trans_offset_b; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5470 | } |
| 5471 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5472 | /* |
| 5473 | * Just assume we can enable the transition watermark. After |
| 5474 | * computing the DDB we'll come back and disable it if that |
| 5475 | * assumption turns out to be false. |
| 5476 | */ |
| 5477 | wm->trans_wm.plane_res_b = res_blocks + 1; |
| 5478 | wm->trans_wm.plane_en = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 5479 | } |
| 5480 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5481 | static int skl_build_plane_wm_single(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5482 | const struct intel_plane_state *plane_state, |
| 5483 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5484 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5485 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 5486 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5487 | struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id]; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5488 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5489 | int ret; |
| 5490 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5491 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5492 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5493 | if (ret) |
| 5494 | return ret; |
| 5495 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5496 | skl_compute_wm_levels(crtc_state, &wm_params, wm->wm); |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5497 | |
| 5498 | if (INTEL_GEN(dev_priv) >= 12) |
| 5499 | tgl_compute_sagv_wm(crtc_state, &wm_params, wm); |
| 5500 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5501 | skl_compute_transition_wm(crtc_state, &wm_params, wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5502 | |
| 5503 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5504 | } |
| 5505 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5506 | static int skl_build_plane_wm_uv(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5507 | const struct intel_plane_state *plane_state, |
| 5508 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5509 | { |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5510 | struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id]; |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5511 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5512 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5513 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5514 | wm->is_planar = true; |
| 5515 | |
| 5516 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5517 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5518 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5519 | if (ret) |
| 5520 | return ret; |
| 5521 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5522 | skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5523 | |
| 5524 | return 0; |
| 5525 | } |
| 5526 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5527 | static int skl_build_plane_wm(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5528 | const struct intel_plane_state *plane_state) |
| 5529 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 5530 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5531 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5532 | struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id]; |
| 5533 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5534 | int ret; |
| 5535 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5536 | memset(wm, 0, sizeof(*wm)); |
| 5537 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5538 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 5539 | return 0; |
| 5540 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5541 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5542 | plane_id, 0); |
| 5543 | if (ret) |
| 5544 | return ret; |
| 5545 | |
| 5546 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5547 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5548 | plane_id); |
| 5549 | if (ret) |
| 5550 | return ret; |
| 5551 | } |
| 5552 | |
| 5553 | return 0; |
| 5554 | } |
| 5555 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5556 | static int icl_build_plane_wm(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5557 | const struct intel_plane_state *plane_state) |
| 5558 | { |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5559 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
| 5560 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 5561 | enum plane_id plane_id = plane->id; |
| 5562 | struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id]; |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5563 | int ret; |
| 5564 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5565 | memset(wm, 0, sizeof(*wm)); |
| 5566 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5567 | /* Watermarks calculated in master */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5568 | if (plane_state->planar_slave) |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5569 | return 0; |
| 5570 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5571 | if (plane_state->planar_linked_plane) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5572 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5573 | enum plane_id y_plane_id = plane_state->planar_linked_plane->id; |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5574 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5575 | drm_WARN_ON(&dev_priv->drm, |
| 5576 | !intel_wm_plane_visible(crtc_state, plane_state)); |
| 5577 | drm_WARN_ON(&dev_priv->drm, !fb->format->is_yuv || |
| 5578 | fb->format->num_planes == 1); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5579 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5580 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5581 | y_plane_id, 0); |
| 5582 | if (ret) |
| 5583 | return ret; |
| 5584 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5585 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5586 | plane_id, 1); |
| 5587 | if (ret) |
| 5588 | return ret; |
| 5589 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5590 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5591 | plane_id, 0); |
| 5592 | if (ret) |
| 5593 | return ret; |
| 5594 | } |
| 5595 | |
| 5596 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5597 | } |
| 5598 | |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5599 | static int skl_build_pipe_wm(struct intel_atomic_state *state, |
| 5600 | struct intel_crtc *crtc) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5601 | { |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5602 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5603 | struct intel_crtc_state *crtc_state = |
| 5604 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5605 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5606 | struct intel_plane *plane; |
| 5607 | int ret, i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5608 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5609 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 5610 | /* |
| 5611 | * FIXME should perhaps check {old,new}_plane_crtc->hw.crtc |
| 5612 | * instead but we don't populate that correctly for NV12 Y |
| 5613 | * planes so for now hack this. |
| 5614 | */ |
| 5615 | if (plane->pipe != crtc->pipe) |
| 5616 | continue; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5617 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5618 | if (INTEL_GEN(dev_priv) >= 11) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5619 | ret = icl_build_plane_wm(crtc_state, plane_state); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5620 | else |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5621 | ret = skl_build_plane_wm(crtc_state, plane_state); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5622 | if (ret) |
| 5623 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5624 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5625 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5626 | crtc_state->wm.skl.optimal = crtc_state->wm.skl.raw; |
| 5627 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5628 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5629 | } |
| 5630 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5631 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 5632 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5633 | const struct skl_ddb_entry *entry) |
| 5634 | { |
| 5635 | if (entry->end) |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5636 | intel_de_write_fw(dev_priv, reg, |
| 5637 | (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5638 | else |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5639 | intel_de_write_fw(dev_priv, reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5640 | } |
| 5641 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5642 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5643 | i915_reg_t reg, |
| 5644 | const struct skl_wm_level *level) |
| 5645 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5646 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5647 | |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5648 | if (level->plane_en) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5649 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5650 | if (level->ignore_lines) |
| 5651 | val |= PLANE_WM_IGNORE_LINES; |
| 5652 | val |= level->plane_res_b; |
| 5653 | val |= level->plane_res_l << PLANE_WM_LINES_SHIFT; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5654 | |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5655 | intel_de_write_fw(dev_priv, reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5656 | } |
| 5657 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5658 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5659 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5660 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5661 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5662 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5663 | enum plane_id plane_id = plane->id; |
| 5664 | enum pipe pipe = plane->pipe; |
| 5665 | const struct skl_plane_wm *wm = |
| 5666 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5667 | const struct skl_ddb_entry *ddb_y = |
| 5668 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5669 | const struct skl_ddb_entry *ddb_uv = |
| 5670 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5671 | |
| 5672 | for (level = 0; level <= max_level; level++) { |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5673 | const struct skl_wm_level *wm_level; |
| 5674 | |
| 5675 | wm_level = skl_plane_wm_level(crtc_state, plane_id, level); |
| 5676 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5677 | skl_write_wm_level(dev_priv, PLANE_WM(pipe, plane_id, level), |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5678 | wm_level); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5679 | } |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5680 | 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] | 5681 | &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5682 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5683 | if (INTEL_GEN(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5684 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5685 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5686 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5687 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5688 | |
| 5689 | if (wm->is_planar) |
| 5690 | swap(ddb_y, ddb_uv); |
| 5691 | |
| 5692 | skl_ddb_entry_write(dev_priv, |
| 5693 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5694 | skl_ddb_entry_write(dev_priv, |
| 5695 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5696 | } |
| 5697 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5698 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5699 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5700 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5701 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5702 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5703 | enum plane_id plane_id = plane->id; |
| 5704 | enum pipe pipe = plane->pipe; |
| 5705 | const struct skl_plane_wm *wm = |
| 5706 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 5707 | const struct skl_ddb_entry *ddb = |
| 5708 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5709 | |
| 5710 | for (level = 0; level <= max_level; level++) { |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5711 | const struct skl_wm_level *wm_level; |
| 5712 | |
| 5713 | wm_level = skl_plane_wm_level(crtc_state, plane_id, level); |
| 5714 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5715 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5716 | wm_level); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5717 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5718 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5719 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5720 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5721 | } |
| 5722 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5723 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5724 | const struct skl_wm_level *l2) |
| 5725 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5726 | return l1->plane_en == l2->plane_en && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5727 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5728 | l1->plane_res_l == l2->plane_res_l && |
| 5729 | l1->plane_res_b == l2->plane_res_b; |
| 5730 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5731 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5732 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5733 | const struct skl_plane_wm *wm1, |
| 5734 | const struct skl_plane_wm *wm2) |
| 5735 | { |
| 5736 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5737 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5738 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | e7f54e6 | 2020-02-28 22:35:49 +0200 | [diff] [blame] | 5739 | /* |
| 5740 | * We don't check uv_wm as the hardware doesn't actually |
| 5741 | * use it. It only gets used for calculating the required |
| 5742 | * ddb allocation. |
| 5743 | */ |
| 5744 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level])) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5745 | return false; |
| 5746 | } |
| 5747 | |
| 5748 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5749 | } |
| 5750 | |
Jani Nikula | 81b55ef | 2020-04-20 17:04:38 +0300 | [diff] [blame] | 5751 | static bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 5752 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5753 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5754 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5755 | } |
| 5756 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5757 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 5758 | const struct skl_ddb_entry *entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5759 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5760 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5761 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5762 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 5763 | for (i = 0; i < num_entries; i++) { |
| 5764 | if (i != ignore_idx && |
| 5765 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5766 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 5767 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5768 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5769 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5770 | } |
| 5771 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 5772 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5773 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 5774 | struct intel_crtc_state *new_crtc_state) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5775 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5776 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->uapi.state); |
| 5777 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5778 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5779 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5780 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5781 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5782 | struct intel_plane_state *plane_state; |
| 5783 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5784 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5785 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 5786 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 5787 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 5788 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5789 | continue; |
| 5790 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5791 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5792 | if (IS_ERR(plane_state)) |
| 5793 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 5794 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5795 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | return 0; |
| 5799 | } |
| 5800 | |
| 5801 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5802 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5803 | { |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 5804 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5805 | const struct intel_dbuf_state *old_dbuf_state; |
| 5806 | const struct intel_dbuf_state *new_dbuf_state; |
| 5807 | const struct intel_crtc_state *old_crtc_state; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5808 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5809 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5810 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5811 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 5812 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5813 | new_crtc_state, i) { |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5814 | ret = skl_allocate_pipe_ddb(state, crtc); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5815 | if (ret) |
| 5816 | return ret; |
| 5817 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5818 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 5819 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5820 | if (ret) |
| 5821 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5822 | } |
| 5823 | |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 5824 | old_dbuf_state = intel_atomic_get_old_dbuf_state(state); |
| 5825 | new_dbuf_state = intel_atomic_get_new_dbuf_state(state); |
| 5826 | |
| 5827 | if (new_dbuf_state && |
| 5828 | new_dbuf_state->enabled_slices != old_dbuf_state->enabled_slices) |
| 5829 | drm_dbg_kms(&dev_priv->drm, |
| 5830 | "Enabled dbuf slices 0x%x -> 0x%x (out of %d dbuf slices)\n", |
| 5831 | old_dbuf_state->enabled_slices, |
| 5832 | new_dbuf_state->enabled_slices, |
| 5833 | INTEL_INFO(dev_priv)->num_supported_dbuf_slices); |
| 5834 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5835 | return 0; |
| 5836 | } |
| 5837 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5838 | static char enast(bool enable) |
| 5839 | { |
| 5840 | return enable ? '*' : ' '; |
| 5841 | } |
| 5842 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 5843 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5844 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5845 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5846 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5847 | const struct intel_crtc_state *old_crtc_state; |
| 5848 | const struct intel_crtc_state *new_crtc_state; |
| 5849 | struct intel_plane *plane; |
| 5850 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 5851 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5852 | |
Jani Nikula | bdbf43d | 2019-10-28 12:38:15 +0200 | [diff] [blame] | 5853 | if (!drm_debug_enabled(DRM_UT_KMS)) |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5854 | return; |
| 5855 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5856 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 5857 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5858 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 5859 | |
| 5860 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 5861 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 5862 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5863 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5864 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5865 | const struct skl_ddb_entry *old, *new; |
| 5866 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5867 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5868 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5869 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5870 | if (skl_ddb_entry_equal(old, new)) |
| 5871 | continue; |
| 5872 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5873 | drm_dbg_kms(&dev_priv->drm, |
| 5874 | "[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n", |
| 5875 | plane->base.base.id, plane->base.name, |
| 5876 | old->start, old->end, new->start, new->end, |
| 5877 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5878 | } |
| 5879 | |
| 5880 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 5881 | enum plane_id plane_id = plane->id; |
| 5882 | const struct skl_plane_wm *old_wm, *new_wm; |
| 5883 | |
| 5884 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 5885 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 5886 | |
| 5887 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 5888 | continue; |
| 5889 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5890 | drm_dbg_kms(&dev_priv->drm, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5891 | "[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm" |
| 5892 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5893 | plane->base.base.id, plane->base.name, |
| 5894 | enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en), |
| 5895 | enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en), |
| 5896 | enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en), |
| 5897 | enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en), |
| 5898 | enast(old_wm->trans_wm.plane_en), |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5899 | enast(old_wm->sagv_wm0.plane_en), |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5900 | enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en), |
| 5901 | enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en), |
| 5902 | enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en), |
| 5903 | enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en), |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5904 | enast(new_wm->trans_wm.plane_en), |
| 5905 | enast(new_wm->sagv_wm0.plane_en)); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5906 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5907 | drm_dbg_kms(&dev_priv->drm, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5908 | "[PLANE:%d:%s] lines %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d" |
| 5909 | " -> %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5910 | plane->base.base.id, plane->base.name, |
| 5911 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l, |
| 5912 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l, |
| 5913 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l, |
| 5914 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l, |
| 5915 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l, |
| 5916 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l, |
| 5917 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l, |
| 5918 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l, |
| 5919 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5920 | enast(old_wm->sagv_wm0.ignore_lines), old_wm->sagv_wm0.plane_res_l, |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5921 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5922 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l, |
| 5923 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l, |
| 5924 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l, |
| 5925 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l, |
| 5926 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l, |
| 5927 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l, |
| 5928 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l, |
| 5929 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5930 | enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.plane_res_l, |
| 5931 | enast(new_wm->sagv_wm0.ignore_lines), new_wm->sagv_wm0.plane_res_l); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5932 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5933 | drm_dbg_kms(&dev_priv->drm, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5934 | "[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5935 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5936 | plane->base.base.id, plane->base.name, |
| 5937 | old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b, |
| 5938 | old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b, |
| 5939 | old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b, |
| 5940 | old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b, |
| 5941 | old_wm->trans_wm.plane_res_b, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5942 | old_wm->sagv_wm0.plane_res_b, |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5943 | new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b, |
| 5944 | new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b, |
| 5945 | new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b, |
| 5946 | new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5947 | new_wm->trans_wm.plane_res_b, |
| 5948 | new_wm->sagv_wm0.plane_res_b); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 5949 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5950 | drm_dbg_kms(&dev_priv->drm, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5951 | "[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" |
| 5952 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5953 | plane->base.base.id, plane->base.name, |
| 5954 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 5955 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 5956 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 5957 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 5958 | old_wm->trans_wm.min_ddb_alloc, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5959 | old_wm->sagv_wm0.min_ddb_alloc, |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5960 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 5961 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 5962 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 5963 | new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc, |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5964 | new_wm->trans_wm.min_ddb_alloc, |
| 5965 | new_wm->sagv_wm0.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 5966 | } |
| 5967 | } |
| 5968 | } |
| 5969 | |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 5970 | static int intel_add_affected_pipes(struct intel_atomic_state *state, |
| 5971 | u8 pipe_mask) |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5972 | { |
| 5973 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 5974 | struct intel_crtc *crtc; |
| 5975 | |
| 5976 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 5977 | struct intel_crtc_state *crtc_state; |
| 5978 | |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 5979 | if ((pipe_mask & BIT(crtc->pipe)) == 0) |
| 5980 | continue; |
| 5981 | |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5982 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 5983 | if (IS_ERR(crtc_state)) |
| 5984 | return PTR_ERR(crtc_state); |
| 5985 | } |
| 5986 | |
| 5987 | return 0; |
| 5988 | } |
| 5989 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5990 | static int |
Ville Syrjälä | d7a1458 | 2019-10-11 23:09:42 +0300 | [diff] [blame] | 5991 | skl_ddb_add_affected_pipes(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5992 | { |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 5993 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 5994 | struct intel_crtc_state *crtc_state; |
| 5995 | struct intel_crtc *crtc; |
| 5996 | int i, ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 5997 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 5998 | if (dev_priv->wm.distrust_bios_wm) { |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 5999 | /* |
| 6000 | * skl_ddb_get_pipe_allocation_limits() currently requires |
| 6001 | * all active pipes to be included in the state so that |
| 6002 | * it can redistribute the dbuf among them, and it really |
| 6003 | * wants to recompute things when distrust_bios_wm is set |
| 6004 | * so we add all the pipes to the state. |
| 6005 | */ |
| 6006 | ret = intel_add_affected_pipes(state, ~0); |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6007 | if (ret) |
| 6008 | return ret; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6009 | } |
| 6010 | |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 6011 | for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { |
| 6012 | struct intel_dbuf_state *new_dbuf_state; |
| 6013 | const struct intel_dbuf_state *old_dbuf_state; |
| 6014 | |
| 6015 | new_dbuf_state = intel_atomic_get_dbuf_state(state); |
| 6016 | if (IS_ERR(new_dbuf_state)) |
Chris Wilson | cba597a | 2020-05-16 20:09:40 +0100 | [diff] [blame] | 6017 | return PTR_ERR(new_dbuf_state); |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 6018 | |
| 6019 | old_dbuf_state = intel_atomic_get_old_dbuf_state(state); |
| 6020 | |
| 6021 | new_dbuf_state->active_pipes = |
| 6022 | intel_calc_active_pipes(state, old_dbuf_state->active_pipes); |
| 6023 | |
| 6024 | if (old_dbuf_state->active_pipes == new_dbuf_state->active_pipes) |
| 6025 | break; |
| 6026 | |
| 6027 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
Ville Syrjälä | 49e0ed3 | 2019-10-11 23:09:43 +0300 | [diff] [blame] | 6028 | if (ret) |
| 6029 | return ret; |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 6030 | |
| 6031 | /* |
| 6032 | * skl_ddb_get_pipe_allocation_limits() currently requires |
| 6033 | * all active pipes to be included in the state so that |
| 6034 | * it can redistribute the dbuf among them. |
| 6035 | */ |
| 6036 | ret = intel_add_affected_pipes(state, |
| 6037 | new_dbuf_state->active_pipes); |
| 6038 | if (ret) |
| 6039 | return ret; |
| 6040 | |
| 6041 | break; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | return 0; |
| 6045 | } |
| 6046 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6047 | /* |
| 6048 | * To make sure the cursor watermark registers are always consistent |
| 6049 | * with our computed state the following scenario needs special |
| 6050 | * treatment: |
| 6051 | * |
| 6052 | * 1. enable cursor |
| 6053 | * 2. move cursor entirely offscreen |
| 6054 | * 3. disable cursor |
| 6055 | * |
| 6056 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 6057 | * (since we consider an offscreen cursor still active for the purposes |
| 6058 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 6059 | * because the actual plane visibility isn't changing, and we don't |
| 6060 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 6061 | * force step 3. to call .disable_plane() to update the watermark |
| 6062 | * registers properly. |
| 6063 | * |
| 6064 | * Other planes do not suffer from this issues as their watermarks are |
| 6065 | * calculated based on the actual plane visibility. The only time this |
| 6066 | * can trigger for the other planes is during the initial readout as the |
| 6067 | * default value of the watermarks registers is not zero. |
| 6068 | */ |
| 6069 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 6070 | struct intel_crtc *crtc) |
| 6071 | { |
| 6072 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6073 | const struct intel_crtc_state *old_crtc_state = |
| 6074 | intel_atomic_get_old_crtc_state(state, crtc); |
| 6075 | struct intel_crtc_state *new_crtc_state = |
| 6076 | intel_atomic_get_new_crtc_state(state, crtc); |
| 6077 | struct intel_plane *plane; |
| 6078 | |
| 6079 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6080 | struct intel_plane_state *plane_state; |
| 6081 | enum plane_id plane_id = plane->id; |
| 6082 | |
| 6083 | /* |
| 6084 | * Force a full wm update for every plane on modeset. |
| 6085 | * Required because the reset value of the wm registers |
| 6086 | * is non-zero, whereas we want all disabled planes to |
| 6087 | * have zero watermarks. So if we turn off the relevant |
| 6088 | * power well the hardware state will go out of sync |
| 6089 | * with the software state. |
| 6090 | */ |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 6091 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) && |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6092 | skl_plane_wm_equals(dev_priv, |
| 6093 | &old_crtc_state->wm.skl.optimal.planes[plane_id], |
| 6094 | &new_crtc_state->wm.skl.optimal.planes[plane_id])) |
| 6095 | continue; |
| 6096 | |
| 6097 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 6098 | if (IS_ERR(plane_state)) |
| 6099 | return PTR_ERR(plane_state); |
| 6100 | |
| 6101 | new_crtc_state->update_planes |= BIT(plane_id); |
| 6102 | } |
| 6103 | |
| 6104 | return 0; |
| 6105 | } |
| 6106 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6107 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6108 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6109 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6110 | struct intel_crtc *crtc; |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 6111 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6112 | int ret, i; |
| 6113 | |
Ville Syrjälä | d7a1458 | 2019-10-11 23:09:42 +0300 | [diff] [blame] | 6114 | ret = skl_ddb_add_affected_pipes(state); |
| 6115 | if (ret) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6116 | return ret; |
| 6117 | |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 6118 | /* |
| 6119 | * Calculate WM's for all pipes that are part of this transaction. |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 6120 | * Note that skl_ddb_add_affected_pipes may have added more CRTC's that |
Ville Syrjälä | f119a5e | 2020-01-20 19:47:13 +0200 | [diff] [blame] | 6121 | * weren't otherwise being modified if pipe allocations had to change. |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 6122 | */ |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 6123 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6124 | ret = skl_build_pipe_wm(state, crtc); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6125 | if (ret) |
| 6126 | return ret; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 6127 | } |
| 6128 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 6129 | ret = skl_compute_ddb(state); |
| 6130 | if (ret) |
| 6131 | return ret; |
| 6132 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 6133 | ret = intel_compute_sagv_mask(state); |
| 6134 | if (ret) |
| 6135 | return ret; |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 6136 | |
Ville Syrjälä | 23baedd | 2020-02-28 22:35:50 +0200 | [diff] [blame] | 6137 | /* |
| 6138 | * skl_compute_ddb() will have adjusted the final watermarks |
| 6139 | * based on how much ddb is available. Now we can actually |
| 6140 | * check if the final watermarks changed. |
| 6141 | */ |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 6142 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
Ville Syrjälä | 23baedd | 2020-02-28 22:35:50 +0200 | [diff] [blame] | 6143 | ret = skl_wm_add_affected_planes(state, crtc); |
| 6144 | if (ret) |
| 6145 | return ret; |
| 6146 | } |
| 6147 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6148 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6149 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6150 | return 0; |
| 6151 | } |
| 6152 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6153 | static void ilk_compute_wm_config(struct drm_i915_private *dev_priv, |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6154 | struct intel_wm_config *config) |
| 6155 | { |
| 6156 | struct intel_crtc *crtc; |
| 6157 | |
| 6158 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6159 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6160 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 6161 | |
| 6162 | if (!wm->pipe_enabled) |
| 6163 | continue; |
| 6164 | |
| 6165 | config->sprites_enabled |= wm->sprites_enabled; |
| 6166 | config->sprites_scaled |= wm->sprites_scaled; |
| 6167 | config->num_pipes_active++; |
| 6168 | } |
| 6169 | } |
| 6170 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6171 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 6172 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6173 | 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] | 6174 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6175 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6176 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 6177 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 6178 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6179 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6180 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6181 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 6182 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 6183 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 6184 | /* 5/6 split only in single pipe config on IVB+ */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 6185 | if (INTEL_GEN(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6186 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6187 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 6188 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 6189 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6190 | best_lp_wm = ilk_find_best_result(dev_priv, &lp_wm_1_2, &lp_wm_5_6); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6191 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 6192 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6193 | } |
| 6194 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 6195 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 6196 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6197 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6198 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 6199 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6200 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 6201 | } |
| 6202 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 6203 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6204 | struct intel_crtc *crtc) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6205 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6206 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6207 | const struct intel_crtc_state *crtc_state = |
| 6208 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6209 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6210 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6211 | crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6212 | ilk_program_watermarks(dev_priv); |
| 6213 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6214 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6215 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 6216 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6217 | struct intel_crtc *crtc) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6218 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6219 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6220 | const struct intel_crtc_state *crtc_state = |
| 6221 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6222 | |
| 6223 | if (!crtc_state->wm.need_postvbl_update) |
| 6224 | return; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6225 | |
| 6226 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6227 | crtc->wm.active.ilk = crtc_state->wm.ilk.optimal; |
| 6228 | ilk_program_watermarks(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6229 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6230 | } |
| 6231 | |
Jani Nikula | 81b55ef | 2020-04-20 17:04:38 +0300 | [diff] [blame] | 6232 | static void skl_wm_level_from_reg_val(u32 val, struct skl_wm_level *level) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6233 | { |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6234 | level->plane_en = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 6235 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6236 | level->plane_res_b = val & PLANE_WM_BLOCKS_MASK; |
| 6237 | level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) & |
| 6238 | PLANE_WM_LINES_MASK; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6239 | } |
| 6240 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6241 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6242 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6243 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6244 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6245 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6246 | int level, max_level; |
| 6247 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6248 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6249 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6250 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6251 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6252 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6253 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6254 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6255 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6256 | if (plane_id != PLANE_CURSOR) |
| 6257 | val = I915_READ(PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6258 | else |
| 6259 | val = I915_READ(CUR_WM(pipe, level)); |
| 6260 | |
| 6261 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 6262 | } |
| 6263 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 6264 | if (INTEL_GEN(dev_priv) >= 12) |
| 6265 | wm->sagv_wm0 = wm->wm[0]; |
| 6266 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6267 | if (plane_id != PLANE_CURSOR) |
| 6268 | val = I915_READ(PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6269 | else |
| 6270 | val = I915_READ(CUR_WM_TRANS(pipe)); |
| 6271 | |
| 6272 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
| 6273 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6274 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6275 | if (!crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6276 | return; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6277 | } |
| 6278 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6279 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6280 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6281 | struct intel_crtc *crtc; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6282 | struct intel_crtc_state *crtc_state; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6283 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6284 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6285 | crtc_state = to_intel_crtc_state(crtc->base.state); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6286 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6287 | skl_pipe_wm_get_hw_state(crtc, &crtc_state->wm.skl.optimal); |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 6288 | crtc_state->wm.skl.raw = crtc_state->wm.skl.optimal; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6289 | } |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 6290 | |
Ville Syrjälä | d06a79d | 2019-08-21 20:30:29 +0300 | [diff] [blame] | 6291 | if (dev_priv->active_pipes) { |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 6292 | /* Fully recompute DDB on first atomic commit */ |
| 6293 | dev_priv->wm.distrust_bios_wm = true; |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 6294 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6295 | } |
| 6296 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6297 | static void ilk_pipe_wm_get_hw_state(struct intel_crtc *crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6298 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6299 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6300 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6301 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6302 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 6303 | struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6304 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6305 | |
Ville Syrjälä | 96eaeb3d | 2018-12-12 23:17:38 +0200 | [diff] [blame] | 6306 | hw->wm_pipe[pipe] = I915_READ(WM0_PIPE_ILK(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6307 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 6308 | memset(active, 0, sizeof(*active)); |
| 6309 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6310 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 6311 | |
| 6312 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6313 | u32 tmp = hw->wm_pipe[pipe]; |
| 6314 | |
| 6315 | /* |
| 6316 | * For active pipes LP0 watermark is marked as |
| 6317 | * enabled, and LP1+ watermaks as disabled since |
| 6318 | * we can't really reverse compute them in case |
| 6319 | * multiple pipes are active. |
| 6320 | */ |
| 6321 | active->wm[0].enable = true; |
| 6322 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 6323 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 6324 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6325 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6326 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6327 | |
| 6328 | /* |
| 6329 | * For inactive pipes, all watermark levels |
| 6330 | * should be marked as enabled but zeroed, |
| 6331 | * which is what we'd compute them to. |
| 6332 | */ |
| 6333 | for (level = 0; level <= max_level; level++) |
| 6334 | active->wm[level].enable = true; |
| 6335 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 6336 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6337 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6338 | } |
| 6339 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6340 | #define _FW_WM(value, plane) \ |
| 6341 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 6342 | #define _FW_WM_VLV(value, plane) \ |
| 6343 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 6344 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6345 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 6346 | struct g4x_wm_values *wm) |
| 6347 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6348 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6349 | |
| 6350 | tmp = I915_READ(DSPFW1); |
| 6351 | wm->sr.plane = _FW_WM(tmp, SR); |
| 6352 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 6353 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 6354 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 6355 | |
| 6356 | tmp = I915_READ(DSPFW2); |
| 6357 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 6358 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 6359 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 6360 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 6361 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 6362 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 6363 | |
| 6364 | tmp = I915_READ(DSPFW3); |
| 6365 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 6366 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 6367 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 6368 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 6369 | } |
| 6370 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6371 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 6372 | struct vlv_wm_values *wm) |
| 6373 | { |
| 6374 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6375 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6376 | |
| 6377 | for_each_pipe(dev_priv, pipe) { |
| 6378 | tmp = I915_READ(VLV_DDL(pipe)); |
| 6379 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6380 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6381 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6382 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6383 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6384 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6385 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6386 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6387 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 6388 | } |
| 6389 | |
| 6390 | tmp = I915_READ(DSPFW1); |
| 6391 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6392 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 6393 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 6394 | 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] | 6395 | |
| 6396 | tmp = I915_READ(DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6397 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 6398 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 6399 | 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] | 6400 | |
| 6401 | tmp = I915_READ(DSPFW3); |
| 6402 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 6403 | |
| 6404 | if (IS_CHERRYVIEW(dev_priv)) { |
| 6405 | tmp = I915_READ(DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6406 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 6407 | 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] | 6408 | |
| 6409 | tmp = I915_READ(DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6410 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 6411 | 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] | 6412 | |
| 6413 | tmp = I915_READ(DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6414 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 6415 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6416 | |
| 6417 | tmp = I915_READ(DSPHOWM); |
| 6418 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6419 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 6420 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 6421 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 6422 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 6423 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 6424 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 6425 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 6426 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 6427 | 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] | 6428 | } else { |
| 6429 | tmp = I915_READ(DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6430 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 6431 | 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] | 6432 | |
| 6433 | tmp = I915_READ(DSPHOWM); |
| 6434 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6435 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 6436 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 6437 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 6438 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 6439 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 6440 | 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] | 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | #undef _FW_WM |
| 6445 | #undef _FW_WM_VLV |
| 6446 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6447 | void g4x_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6448 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6449 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 6450 | struct intel_crtc *crtc; |
| 6451 | |
| 6452 | g4x_read_wm_values(dev_priv, wm); |
| 6453 | |
| 6454 | wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 6455 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6456 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6457 | struct intel_crtc_state *crtc_state = |
| 6458 | to_intel_crtc_state(crtc->base.state); |
| 6459 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 6460 | struct g4x_pipe_wm *raw; |
| 6461 | enum pipe pipe = crtc->pipe; |
| 6462 | enum plane_id plane_id; |
| 6463 | int level, max_level; |
| 6464 | |
| 6465 | active->cxsr = wm->cxsr; |
| 6466 | active->hpll_en = wm->hpll_en; |
| 6467 | active->fbc_en = wm->fbc_en; |
| 6468 | |
| 6469 | active->sr = wm->sr; |
| 6470 | active->hpll = wm->hpll; |
| 6471 | |
| 6472 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6473 | active->wm.plane[plane_id] = |
| 6474 | wm->pipe[pipe].plane[plane_id]; |
| 6475 | } |
| 6476 | |
| 6477 | if (wm->cxsr && wm->hpll_en) |
| 6478 | max_level = G4X_WM_LEVEL_HPLL; |
| 6479 | else if (wm->cxsr) |
| 6480 | max_level = G4X_WM_LEVEL_SR; |
| 6481 | else |
| 6482 | max_level = G4X_WM_LEVEL_NORMAL; |
| 6483 | |
| 6484 | level = G4X_WM_LEVEL_NORMAL; |
| 6485 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6486 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6487 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 6488 | |
| 6489 | if (++level > max_level) |
| 6490 | goto out; |
| 6491 | |
| 6492 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6493 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 6494 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 6495 | raw->plane[PLANE_SPRITE0] = 0; |
| 6496 | raw->fbc = active->sr.fbc; |
| 6497 | |
| 6498 | if (++level > max_level) |
| 6499 | goto out; |
| 6500 | |
| 6501 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6502 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 6503 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 6504 | raw->plane[PLANE_SPRITE0] = 0; |
| 6505 | raw->fbc = active->hpll.fbc; |
| 6506 | |
| 6507 | out: |
| 6508 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6509 | g4x_raw_plane_wm_set(crtc_state, level, |
| 6510 | plane_id, USHRT_MAX); |
| 6511 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 6512 | |
| 6513 | crtc_state->wm.g4x.optimal = *active; |
| 6514 | crtc_state->wm.g4x.intermediate = *active; |
| 6515 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6516 | drm_dbg_kms(&dev_priv->drm, |
| 6517 | "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 6518 | pipe_name(pipe), |
| 6519 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6520 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6521 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6522 | } |
| 6523 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6524 | drm_dbg_kms(&dev_priv->drm, |
| 6525 | "Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 6526 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 6527 | drm_dbg_kms(&dev_priv->drm, |
| 6528 | "Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 6529 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 6530 | drm_dbg_kms(&dev_priv->drm, "Initial SR=%s HPLL=%s FBC=%s\n", |
| 6531 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6532 | } |
| 6533 | |
| 6534 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6535 | { |
| 6536 | struct intel_plane *plane; |
| 6537 | struct intel_crtc *crtc; |
| 6538 | |
| 6539 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6540 | |
| 6541 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6542 | struct intel_crtc *crtc = |
| 6543 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6544 | struct intel_crtc_state *crtc_state = |
| 6545 | to_intel_crtc_state(crtc->base.state); |
| 6546 | struct intel_plane_state *plane_state = |
| 6547 | to_intel_plane_state(plane->base.state); |
| 6548 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 6549 | enum plane_id plane_id = plane->id; |
| 6550 | int level; |
| 6551 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 6552 | if (plane_state->uapi.visible) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6553 | continue; |
| 6554 | |
| 6555 | for (level = 0; level < 3; level++) { |
| 6556 | struct g4x_pipe_wm *raw = |
| 6557 | &crtc_state->wm.g4x.raw[level]; |
| 6558 | |
| 6559 | raw->plane[plane_id] = 0; |
| 6560 | wm_state->wm.plane[plane_id] = 0; |
| 6561 | } |
| 6562 | |
| 6563 | if (plane_id == PLANE_PRIMARY) { |
| 6564 | for (level = 0; level < 3; level++) { |
| 6565 | struct g4x_pipe_wm *raw = |
| 6566 | &crtc_state->wm.g4x.raw[level]; |
| 6567 | raw->fbc = 0; |
| 6568 | } |
| 6569 | |
| 6570 | wm_state->sr.fbc = 0; |
| 6571 | wm_state->hpll.fbc = 0; |
| 6572 | wm_state->fbc_en = false; |
| 6573 | } |
| 6574 | } |
| 6575 | |
| 6576 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6577 | struct intel_crtc_state *crtc_state = |
| 6578 | to_intel_crtc_state(crtc->base.state); |
| 6579 | |
| 6580 | crtc_state->wm.g4x.intermediate = |
| 6581 | crtc_state->wm.g4x.optimal; |
| 6582 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 6583 | } |
| 6584 | |
| 6585 | g4x_program_watermarks(dev_priv); |
| 6586 | |
| 6587 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6588 | } |
| 6589 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6590 | void vlv_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6591 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6592 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 6593 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6594 | u32 val; |
| 6595 | |
| 6596 | vlv_read_wm_values(dev_priv, wm); |
| 6597 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6598 | wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 6599 | wm->level = VLV_WM_LEVEL_PM2; |
| 6600 | |
| 6601 | if (IS_CHERRYVIEW(dev_priv)) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6602 | vlv_punit_get(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6603 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 6604 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6605 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 6606 | wm->level = VLV_WM_LEVEL_PM5; |
| 6607 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6608 | /* |
| 6609 | * If DDR DVFS is disabled in the BIOS, Punit |
| 6610 | * will never ack the request. So if that happens |
| 6611 | * assume we don't have to enable/disable DDR DVFS |
| 6612 | * dynamically. To test that just set the REQ_ACK |
| 6613 | * bit to poke the Punit, but don't change the |
| 6614 | * HIGH/LOW bits so that we don't actually change |
| 6615 | * the current state. |
| 6616 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6617 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6618 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 6619 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 6620 | |
| 6621 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 6622 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6623 | drm_dbg_kms(&dev_priv->drm, |
| 6624 | "Punit not acking DDR DVFS request, " |
| 6625 | "assuming DDR DVFS is disabled\n"); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6626 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 6627 | } else { |
| 6628 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 6629 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 6630 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 6631 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6632 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6633 | vlv_punit_put(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6634 | } |
| 6635 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6636 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6637 | struct intel_crtc_state *crtc_state = |
| 6638 | to_intel_crtc_state(crtc->base.state); |
| 6639 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 6640 | const struct vlv_fifo_state *fifo_state = |
| 6641 | &crtc_state->wm.vlv.fifo_state; |
| 6642 | enum pipe pipe = crtc->pipe; |
| 6643 | enum plane_id plane_id; |
| 6644 | int level; |
| 6645 | |
| 6646 | vlv_get_fifo_size(crtc_state); |
| 6647 | |
| 6648 | active->num_levels = wm->level + 1; |
| 6649 | active->cxsr = wm->cxsr; |
| 6650 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6651 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6652 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6653 | &crtc_state->wm.vlv.raw[level]; |
| 6654 | |
| 6655 | active->sr[level].plane = wm->sr.plane; |
| 6656 | active->sr[level].cursor = wm->sr.cursor; |
| 6657 | |
| 6658 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6659 | active->wm[level].plane[plane_id] = |
| 6660 | wm->pipe[pipe].plane[plane_id]; |
| 6661 | |
| 6662 | raw->plane[plane_id] = |
| 6663 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 6664 | fifo_state->plane[plane_id]); |
| 6665 | } |
| 6666 | } |
| 6667 | |
| 6668 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6669 | vlv_raw_plane_wm_set(crtc_state, level, |
| 6670 | plane_id, USHRT_MAX); |
| 6671 | vlv_invalidate_wms(crtc, active, level); |
| 6672 | |
| 6673 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 6674 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6675 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6676 | drm_dbg_kms(&dev_priv->drm, |
| 6677 | "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n", |
| 6678 | pipe_name(pipe), |
| 6679 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6680 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6681 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 6682 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6683 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6684 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6685 | drm_dbg_kms(&dev_priv->drm, |
| 6686 | "Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 6687 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6688 | } |
| 6689 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6690 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6691 | { |
| 6692 | struct intel_plane *plane; |
| 6693 | struct intel_crtc *crtc; |
| 6694 | |
| 6695 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6696 | |
| 6697 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6698 | struct intel_crtc *crtc = |
| 6699 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6700 | struct intel_crtc_state *crtc_state = |
| 6701 | to_intel_crtc_state(crtc->base.state); |
| 6702 | struct intel_plane_state *plane_state = |
| 6703 | to_intel_plane_state(plane->base.state); |
| 6704 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 6705 | const struct vlv_fifo_state *fifo_state = |
| 6706 | &crtc_state->wm.vlv.fifo_state; |
| 6707 | enum plane_id plane_id = plane->id; |
| 6708 | int level; |
| 6709 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 6710 | if (plane_state->uapi.visible) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6711 | continue; |
| 6712 | |
| 6713 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6714 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 6715 | &crtc_state->wm.vlv.raw[level]; |
| 6716 | |
| 6717 | raw->plane[plane_id] = 0; |
| 6718 | |
| 6719 | wm_state->wm[level].plane[plane_id] = |
| 6720 | vlv_invert_wm_value(raw->plane[plane_id], |
| 6721 | fifo_state->plane[plane_id]); |
| 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6726 | struct intel_crtc_state *crtc_state = |
| 6727 | to_intel_crtc_state(crtc->base.state); |
| 6728 | |
| 6729 | crtc_state->wm.vlv.intermediate = |
| 6730 | crtc_state->wm.vlv.optimal; |
| 6731 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 6732 | } |
| 6733 | |
| 6734 | vlv_program_watermarks(dev_priv); |
| 6735 | |
| 6736 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6737 | } |
| 6738 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6739 | /* |
| 6740 | * FIXME should probably kill this and improve |
| 6741 | * the real watermark readout/sanitation instead |
| 6742 | */ |
| 6743 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 6744 | { |
| 6745 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 6746 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 6747 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 6748 | |
| 6749 | /* |
| 6750 | * Don't touch WM1S_LP_EN here. |
| 6751 | * Doing so could cause underruns. |
| 6752 | */ |
| 6753 | } |
| 6754 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6755 | void ilk_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6756 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6757 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6758 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6759 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 6760 | ilk_init_lp_watermarks(dev_priv); |
| 6761 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6762 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6763 | ilk_pipe_wm_get_hw_state(crtc); |
| 6764 | |
| 6765 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 6766 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 6767 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 6768 | |
| 6769 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 6770 | if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 6771 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 6772 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 6773 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6774 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6775 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6776 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 6777 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 6778 | else if (IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 6779 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 6780 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6781 | |
| 6782 | hw->enable_fbc_wm = |
| 6783 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 6784 | } |
| 6785 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6786 | /** |
| 6787 | * intel_update_watermarks - update FIFO watermark values based on current modes |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 6788 | * @crtc: the #intel_crtc on which to compute the WM |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6789 | * |
| 6790 | * Calculate watermark values for the various WM regs based on current mode |
| 6791 | * and plane configuration. |
| 6792 | * |
| 6793 | * There are several cases to deal with here: |
| 6794 | * - normal (i.e. non-self-refresh) |
| 6795 | * - self-refresh (SR) mode |
| 6796 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 6797 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 6798 | * lines), so need to account for TLB latency |
| 6799 | * |
| 6800 | * The normal calculation is: |
| 6801 | * watermark = dotclock * bytes per pixel * latency |
| 6802 | * where latency is platform & configuration dependent (we assume pessimal |
| 6803 | * values here). |
| 6804 | * |
| 6805 | * The SR calculation is: |
| 6806 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 6807 | * bytes per pixel |
| 6808 | * where |
| 6809 | * line time = htotal / dotclock |
| 6810 | * surface width = hdisplay for normal plane and 64 for cursor |
| 6811 | * and latency is assumed to be high, as above. |
| 6812 | * |
| 6813 | * The final value programmed to the register should always be rounded up, |
| 6814 | * and include an extra 2 entries to account for clock crossings. |
| 6815 | * |
| 6816 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 6817 | * to set the non-SR watermarks to 8. |
| 6818 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6819 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6820 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6821 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6822 | |
| 6823 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 6824 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 6825 | } |
| 6826 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6827 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 6828 | { |
| 6829 | u32 val; |
| 6830 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 6831 | if (!HAS_IPC(dev_priv)) |
| 6832 | return; |
| 6833 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6834 | val = I915_READ(DISP_ARB_CTL2); |
| 6835 | |
| 6836 | if (dev_priv->ipc_enabled) |
| 6837 | val |= DISP_IPC_ENABLE; |
| 6838 | else |
| 6839 | val &= ~DISP_IPC_ENABLE; |
| 6840 | |
| 6841 | I915_WRITE(DISP_ARB_CTL2, val); |
| 6842 | } |
| 6843 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6844 | static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv) |
| 6845 | { |
| 6846 | /* Display WA #0477 WaDisableIPC: skl */ |
| 6847 | if (IS_SKYLAKE(dev_priv)) |
| 6848 | return false; |
| 6849 | |
| 6850 | /* Display WA #1141: SKL:all KBL:all CFL */ |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 6851 | if (IS_KABYLAKE(dev_priv) || |
| 6852 | IS_COFFEELAKE(dev_priv) || |
| 6853 | IS_COMETLAKE(dev_priv)) |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6854 | return dev_priv->dram_info.symmetric_memory; |
| 6855 | |
| 6856 | return true; |
| 6857 | } |
| 6858 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6859 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 6860 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6861 | if (!HAS_IPC(dev_priv)) |
| 6862 | return; |
| 6863 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 6864 | dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv); |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 6865 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 6866 | intel_enable_ipc(dev_priv); |
| 6867 | } |
| 6868 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6869 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6870 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6871 | /* |
| 6872 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6873 | * gating for the panel power sequencer or it will fail to |
| 6874 | * start up when no ports are active. |
| 6875 | */ |
| 6876 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 6877 | } |
| 6878 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6879 | 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] | 6880 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 6881 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6882 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6883 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6884 | I915_WRITE(DSPCNTR(pipe), |
| 6885 | I915_READ(DSPCNTR(pipe)) | |
| 6886 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 6887 | |
| 6888 | I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe))); |
| 6889 | POSTING_READ(DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6890 | } |
| 6891 | } |
| 6892 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 6893 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6894 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6895 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6896 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 6897 | /* |
| 6898 | * Required for FBC |
| 6899 | * WaFbcDisableDpfcClockGating:ilk |
| 6900 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6901 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 6902 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 6903 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6904 | |
| 6905 | I915_WRITE(PCH_3DCGDIS0, |
| 6906 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 6907 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 6908 | I915_WRITE(PCH_3DCGDIS1, |
| 6909 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 6910 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6911 | /* |
| 6912 | * According to the spec the following bits should be set in |
| 6913 | * order to enable memory self-refresh |
| 6914 | * The bit 22/21 of 0x42004 |
| 6915 | * The bit 5 of 0x42020 |
| 6916 | * The bit 15 of 0x45000 |
| 6917 | */ |
| 6918 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6919 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6920 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6921 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6922 | I915_WRITE(DISP_ARB_CTL, |
| 6923 | (I915_READ(DISP_ARB_CTL) | |
| 6924 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6925 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6926 | /* |
| 6927 | * Based on the document from hardware guys the following bits |
| 6928 | * should be set unconditionally in order to enable FBC. |
| 6929 | * The bit 22 of 0x42000 |
| 6930 | * The bit 22 of 0x42004 |
| 6931 | * The bit 7,8,9 of 0x42020. |
| 6932 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 6933 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6934 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6935 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6936 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6937 | ILK_FBCQ_DIS); |
| 6938 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6939 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6940 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6941 | } |
| 6942 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6943 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 6944 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6945 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6946 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6947 | ILK_ELPIN_409_SELECT); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6948 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6949 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 6950 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6951 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6952 | } |
| 6953 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6954 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6955 | { |
Ville Syrjälä | d048a26 | 2019-08-21 20:30:31 +0300 | [diff] [blame] | 6956 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6957 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6958 | |
| 6959 | /* |
| 6960 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6961 | * gating for the panel power sequencer or it will fail to |
| 6962 | * start up when no ports are active. |
| 6963 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 6964 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 6965 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 6966 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6967 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 6968 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 6969 | /* The below fixes the weird display corruption, a few pixels shifted |
| 6970 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 6971 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6972 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 6973 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 6974 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 6975 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6976 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 6977 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 6978 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 6979 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 6980 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 6981 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6982 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6983 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6984 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 6985 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 6986 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6987 | } |
| 6988 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 6989 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6990 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6991 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6992 | |
| 6993 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 6994 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6995 | drm_dbg_kms(&dev_priv->drm, |
| 6996 | "Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 6997 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6998 | } |
| 6999 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7000 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7001 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7002 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7003 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7004 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7005 | |
| 7006 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 7007 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 7008 | ILK_ELPIN_409_SELECT); |
| 7009 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7010 | I915_WRITE(GEN6_UCGCTL1, |
| 7011 | I915_READ(GEN6_UCGCTL1) | |
| 7012 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 7013 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 7014 | |
| 7015 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 7016 | * gating disable must be set. Failure to set it results in |
| 7017 | * flickering pixels due to Z write ordering failures after |
| 7018 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 7019 | * Sanctuary and Tropics, and apparently anything else with |
| 7020 | * alpha test or pixel discard. |
| 7021 | * |
| 7022 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 7023 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7024 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 7025 | * WaDisableRCCUnitClockGating:snb |
| 7026 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7027 | */ |
| 7028 | I915_WRITE(GEN6_UCGCTL2, |
| 7029 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 7030 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 7031 | |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 7032 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7033 | * According to the spec the following bits should be |
| 7034 | * set in order to enable memory self-refresh and fbc: |
| 7035 | * The bit21 and bit22 of 0x42000 |
| 7036 | * The bit21 and bit22 of 0x42004 |
| 7037 | * The bit5 and bit7 of 0x42020 |
| 7038 | * The bit14 of 0x70180 |
| 7039 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7040 | * |
| 7041 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7042 | */ |
| 7043 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 7044 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 7045 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 7046 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 7047 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 7048 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7049 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 7050 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 7051 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 7052 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7053 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7054 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 7055 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7056 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7057 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7058 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7059 | } |
| 7060 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7061 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7062 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7063 | /* |
| 7064 | * TODO: this bit should only be enabled when really needed, then |
| 7065 | * disabled when not needed anymore in order to save power. |
| 7066 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7067 | if (HAS_PCH_LPT_LP(dev_priv)) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7068 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 7069 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 7070 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7071 | |
| 7072 | /* WADPOClockGatingDisable:hsw */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 7073 | I915_WRITE(TRANS_CHICKEN1(PIPE_A), |
| 7074 | I915_READ(TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7075 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7076 | } |
| 7077 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7078 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7079 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7080 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7081 | u32 val = I915_READ(SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7082 | |
| 7083 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 7084 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 7085 | } |
| 7086 | } |
| 7087 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7088 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 7089 | int general_prio_credits, |
| 7090 | int high_prio_credits) |
| 7091 | { |
| 7092 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 7093 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7094 | |
| 7095 | /* WaTempDisableDOPClkGating:bdw */ |
| 7096 | misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 7097 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 7098 | |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 7099 | val = I915_READ(GEN8_L3SQCREG1); |
| 7100 | val &= ~L3_PRIO_CREDITS_MASK; |
| 7101 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 7102 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
| 7103 | I915_WRITE(GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7104 | |
| 7105 | /* |
| 7106 | * Wait at least 100 clocks before re-enabling clock gating. |
| 7107 | * See the definition of L3SQCREG1 in BSpec. |
| 7108 | */ |
| 7109 | POSTING_READ(GEN8_L3SQCREG1); |
| 7110 | udelay(1); |
| 7111 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); |
| 7112 | } |
| 7113 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7114 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7115 | { |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7116 | /* Wa_1409120013:icl,ehl */ |
| 7117 | I915_WRITE(ILK_DPFC_CHICKEN, |
| 7118 | ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL); |
| 7119 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7120 | /* This is not an Wa. Enable to reduce Sampler power */ |
| 7121 | I915_WRITE(GEN10_DFR_RATIO_EN_AND_CHICKEN, |
| 7122 | I915_READ(GEN10_DFR_RATIO_EN_AND_CHICKEN) & ~DFR_DISABLE); |
Radhakrishna Sripada | 622b3f6 | 2018-10-30 01:45:01 -0700 | [diff] [blame] | 7123 | |
Matt Atwood | 6f4194c | 2020-01-13 23:11:28 -0500 | [diff] [blame] | 7124 | /*Wa_14010594013:icl, ehl */ |
| 7125 | intel_uncore_rmw(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1, |
| 7126 | 0, CNL_DELAY_PMRSP); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7127 | } |
| 7128 | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7129 | static void gen12_init_clock_gating(struct drm_i915_private *i915) |
| 7130 | { |
| 7131 | unsigned int i; |
| 7132 | |
| 7133 | /* This is not a WA. Enable VD HCP & MFX_ENC powergate */ |
| 7134 | for (i = 0; i < I915_MAX_VCS; i++) |
| 7135 | if (HAS_ENGINE(&i915->gt, _VCS(i))) |
| 7136 | intel_uncore_rmw(&i915->uncore, POWERGATE_ENABLE, 0, |
| 7137 | VDN_HCP_POWERGATE_ENABLE(i) | |
| 7138 | VDN_MFX_POWERGATE_ENABLE(i)); |
| 7139 | } |
| 7140 | |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7141 | static void tgl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7142 | { |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7143 | gen12_init_clock_gating(dev_priv); |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7144 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7145 | /* Wa_1409120013:tgl */ |
| 7146 | I915_WRITE(ILK_DPFC_CHICKEN, |
| 7147 | ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL); |
| 7148 | |
Radhakrishna Sripada | f78d5da | 2020-01-09 14:37:27 -0800 | [diff] [blame] | 7149 | /* Wa_1409825376:tgl (pre-prod)*/ |
José Roberto de Souza | c33298c | 2020-08-27 16:39:43 -0700 | [diff] [blame] | 7150 | if (IS_TGL_DISP_REVID(dev_priv, TGL_REVID_A0, TGL_REVID_B1)) |
Radhakrishna Sripada | f78d5da | 2020-01-09 14:37:27 -0800 | [diff] [blame] | 7151 | I915_WRITE(GEN9_CLKGATE_DIS_3, I915_READ(GEN9_CLKGATE_DIS_3) | |
| 7152 | TGL_VRH_GATING_DIS); |
Matt Atwood | f9d7742 | 2020-04-15 15:35:35 -0400 | [diff] [blame] | 7153 | |
| 7154 | /* Wa_14011059788:tgl */ |
| 7155 | intel_uncore_rmw(&dev_priv->uncore, GEN10_DFR_RATIO_EN_AND_CHICKEN, |
| 7156 | 0, DFR_DISABLE); |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7157 | } |
| 7158 | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7159 | static void dg1_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7160 | { |
| 7161 | gen12_init_clock_gating(dev_priv); |
| 7162 | |
| 7163 | /* Wa_1409836686:dg1[a0] */ |
| 7164 | if (IS_DG1_REVID(dev_priv, DG1_REVID_A0, DG1_REVID_A0)) |
| 7165 | I915_WRITE(GEN9_CLKGATE_DIS_3, I915_READ(GEN9_CLKGATE_DIS_3) | |
| 7166 | DPT_GATING_DIS); |
| 7167 | } |
| 7168 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7169 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7170 | { |
| 7171 | if (!HAS_PCH_CNP(dev_priv)) |
| 7172 | return; |
| 7173 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 7174 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Rodrigo Vivi | 4cc6feb | 2017-09-08 16:45:33 -0700 | [diff] [blame] | 7175 | I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 7176 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7177 | } |
| 7178 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7179 | static void cnl_init_clock_gating(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7180 | { |
Rodrigo Vivi | 8f06783 | 2017-09-05 12:30:13 -0700 | [diff] [blame] | 7181 | u32 val; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7182 | cnp_init_clock_gating(dev_priv); |
| 7183 | |
Rodrigo Vivi | 1a25db6 | 2017-08-15 16:16:51 -0700 | [diff] [blame] | 7184 | /* This is not an Wa. Enable for better image quality */ |
| 7185 | I915_WRITE(_3D_CHICKEN3, |
| 7186 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE)); |
| 7187 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7188 | /* WaEnableChickenDCPR:cnl */ |
| 7189 | I915_WRITE(GEN8_CHICKEN_DCPR_1, |
| 7190 | I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
| 7191 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7192 | /* |
| 7193 | * WaFbcWakeMemOn:cnl |
| 7194 | * Display WA #0859: cnl |
| 7195 | */ |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7196 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 7197 | DISP_FBC_MEMORY_WAKE); |
| 7198 | |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 7199 | val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE); |
| 7200 | /* ReadHitWriteOnlyDisable:cnl */ |
| 7201 | val |= RCCUNIT_CLKGATE_DIS; |
Chris Wilson | 34991bd | 2017-11-11 10:03:36 +0000 | [diff] [blame] | 7202 | I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val); |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 7203 | |
Rodrigo Vivi | a4713c5 | 2018-03-07 14:09:12 -0800 | [diff] [blame] | 7204 | /* Wa_2201832410:cnl */ |
| 7205 | val = I915_READ(SUBSLICE_UNIT_LEVEL_CLKGATE); |
| 7206 | val |= GWUNIT_CLKGATE_DIS; |
| 7207 | I915_WRITE(SUBSLICE_UNIT_LEVEL_CLKGATE, val); |
| 7208 | |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 7209 | /* WaDisableVFclkgate:cnl */ |
Rodrigo Vivi | 14941b6 | 2018-03-05 17:20:00 -0800 | [diff] [blame] | 7210 | /* WaVFUnitClockGatingDisable:cnl */ |
Rafael Antognolli | 01ab0f9 | 2017-12-15 16:11:16 -0800 | [diff] [blame] | 7211 | val = I915_READ(UNSLICE_UNIT_LEVEL_CLKGATE); |
| 7212 | val |= VFUNIT_CLKGATE_DIS; |
| 7213 | I915_WRITE(UNSLICE_UNIT_LEVEL_CLKGATE, val); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7214 | } |
| 7215 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7216 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7217 | { |
| 7218 | cnp_init_clock_gating(dev_priv); |
| 7219 | gen9_init_clock_gating(dev_priv); |
| 7220 | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7221 | /* WAC6entrylatency:cfl */ |
| 7222 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 7223 | FBC_LLC_FULLY_OPEN); |
| 7224 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7225 | /* |
| 7226 | * WaFbcTurnOffFbcWatermark:cfl |
| 7227 | * Display WA #0562: cfl |
| 7228 | */ |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 7229 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 7230 | DISP_FBC_WM_DIS); |
| 7231 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7232 | /* |
| 7233 | * WaFbcNukeOnHostModify:cfl |
| 7234 | * Display WA #0873: cfl |
| 7235 | */ |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7236 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 7237 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 7238 | } |
| 7239 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7240 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7241 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7242 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7243 | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7244 | /* WAC6entrylatency:kbl */ |
| 7245 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 7246 | FBC_LLC_FULLY_OPEN); |
| 7247 | |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7248 | /* WaDisableSDEUnitClockGating:kbl */ |
Matt Roper | 96c5a15 | 2020-08-10 20:21:05 -0700 | [diff] [blame] | 7249 | if (IS_KBL_GT_REVID(dev_priv, 0, KBL_REVID_B0)) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7250 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 7251 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 7252 | |
| 7253 | /* WaDisableGamClockGating:kbl */ |
Matt Roper | 96c5a15 | 2020-08-10 20:21:05 -0700 | [diff] [blame] | 7254 | if (IS_KBL_GT_REVID(dev_priv, 0, KBL_REVID_B0)) |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 7255 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 7256 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7257 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7258 | /* |
| 7259 | * WaFbcTurnOffFbcWatermark:kbl |
| 7260 | * Display WA #0562: kbl |
| 7261 | */ |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 7262 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 7263 | DISP_FBC_WM_DIS); |
| 7264 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7265 | /* |
| 7266 | * WaFbcNukeOnHostModify:kbl |
| 7267 | * Display WA #0873: kbl |
| 7268 | */ |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7269 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 7270 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7271 | } |
| 7272 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7273 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7274 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7275 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7276 | |
Ville Syrjälä | f142119 | 2020-07-16 22:04:25 +0300 | [diff] [blame] | 7277 | /* WaDisableDopClockGating:skl */ |
| 7278 | I915_WRITE(GEN7_MISCCPCTL, I915_READ(GEN7_MISCCPCTL) & |
| 7279 | ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 7280 | |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7281 | /* WAC6entrylatency:skl */ |
| 7282 | I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) | |
| 7283 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7284 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7285 | /* |
| 7286 | * WaFbcTurnOffFbcWatermark:skl |
| 7287 | * Display WA #0562: skl |
| 7288 | */ |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 7289 | I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) | |
| 7290 | DISP_FBC_WM_DIS); |
| 7291 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7292 | /* |
| 7293 | * WaFbcNukeOnHostModify:skl |
| 7294 | * Display WA #0873: skl |
| 7295 | */ |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7296 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 7297 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 7298 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7299 | /* |
| 7300 | * WaFbcHighMemBwCorruptionAvoidance:skl |
| 7301 | * Display WA #0883: skl |
| 7302 | */ |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 7303 | I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) | |
| 7304 | ILK_DPFC_DISABLE_DUMMY0); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7305 | } |
| 7306 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7307 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7308 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 7309 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7310 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7311 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
| 7312 | I915_WRITE(CHICKEN_PIPESL_1(PIPE_A), |
| 7313 | I915_READ(CHICKEN_PIPESL_1(PIPE_A)) | |
| 7314 | HSW_FBCQ_DIS); |
| 7315 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7316 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 7317 | 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] | 7318 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7319 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7320 | I915_WRITE(CHICKEN_PAR1_1, |
| 7321 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 7322 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7323 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7324 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 7325 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 7326 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 7327 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7328 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 7329 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7330 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 7331 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 7332 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 7333 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 7334 | ~(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] | 7335 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 7336 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 7337 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 7338 | |
| 7339 | /* WaDisableSDEUnitClockGating:bdw */ |
| 7340 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 7341 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 7342 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7343 | /* WaProgramL3SqcReg1Default:bdw */ |
| 7344 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 7345 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 7346 | /* WaKVMNotificationOnConfigChange:bdw */ |
| 7347 | I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1) |
| 7348 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 7349 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7350 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 7351 | |
| 7352 | /* WaDisableDopClockGating:bdw |
| 7353 | * |
| 7354 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 7355 | * clock gating. |
| 7356 | */ |
| 7357 | I915_WRITE(GEN6_UCGCTL1, |
| 7358 | I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7359 | } |
| 7360 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7361 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7362 | { |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7363 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
| 7364 | I915_WRITE(CHICKEN_PIPESL_1(PIPE_A), |
| 7365 | I915_READ(CHICKEN_PIPESL_1(PIPE_A)) | |
| 7366 | HSW_FBCQ_DIS); |
| 7367 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7368 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7369 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
Chris Wilson | f93ec5f | 2020-06-11 10:30:15 +0100 | [diff] [blame] | 7370 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 7371 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 7372 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7373 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 7374 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 7375 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7376 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7377 | } |
| 7378 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7379 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7380 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7381 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7382 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7383 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7384 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7385 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
| 7386 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 7387 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 7388 | ILK_FBCQ_DIS); |
| 7389 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7390 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7391 | I915_WRITE(IVB_CHICKEN3, |
| 7392 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7393 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7394 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7395 | if (IS_IVB_GT1(dev_priv)) |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7396 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 7397 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7398 | else { |
| 7399 | /* must write both registers */ |
| 7400 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 7401 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7402 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 7403 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7404 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7405 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 7406 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7407 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7408 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7409 | */ |
| 7410 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 7411 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7412 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7413 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7414 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7415 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 7416 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7417 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7418 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7419 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 7420 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 7421 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 7422 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 7423 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7424 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7425 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7426 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7427 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7428 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7429 | } |
| 7430 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7431 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7432 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7433 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7434 | I915_WRITE(IVB_CHICKEN3, |
| 7435 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7436 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7437 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7438 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7439 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 7440 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 7441 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7442 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7443 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7444 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 7445 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7446 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7447 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7448 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7449 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7450 | */ |
| 7451 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7452 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7453 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 7454 | /* WaDisableL3Bank2xClockGate:vlv |
| 7455 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 7456 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 7457 | I915_WRITE(GEN7_UCGCTL4, |
| 7458 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 7459 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 7460 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7461 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 7462 | * Disable clock gating on th GCFG unit to prevent a delay |
| 7463 | * in the reporting of vblank events. |
| 7464 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 7465 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7466 | } |
| 7467 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7468 | static void chv_init_clock_gating(struct drm_i915_private *dev_priv) |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7469 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 7470 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 7471 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 7472 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 7473 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 7474 | ~(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] | 7475 | |
| 7476 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 7477 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 7478 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 7479 | |
| 7480 | /* WaDisableCSUnitClockGating:chv */ |
| 7481 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 7482 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 7483 | |
| 7484 | /* WaDisableSDEUnitClockGating:chv */ |
| 7485 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 7486 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 7487 | |
| 7488 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7489 | * WaProgramL3SqcReg1Default:chv |
| 7490 | * See gfxspecs/Related Documents/Performance Guide/ |
| 7491 | * LSQC Setting Recommendations. |
| 7492 | */ |
| 7493 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7494 | } |
| 7495 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7496 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7497 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7498 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7499 | |
| 7500 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 7501 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 7502 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 7503 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 7504 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 7505 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 7506 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 7507 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7508 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7509 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 7510 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 7511 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7512 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7513 | } |
| 7514 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7515 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7516 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 7517 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 7518 | |
| 7519 | intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 7520 | intel_uncore_write(uncore, RENCLK_GATE_D2, 0); |
| 7521 | intel_uncore_write(uncore, DSPCLK_GATE_D, 0); |
| 7522 | intel_uncore_write(uncore, RAMCLK_GATE_D, 0); |
| 7523 | intel_uncore_write16(uncore, DEUC, 0); |
| 7524 | intel_uncore_write(uncore, |
| 7525 | MI_ARB_STATE, |
| 7526 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7527 | } |
| 7528 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7529 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7530 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7531 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 7532 | I965_RCC_CLOCK_GATE_DISABLE | |
| 7533 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 7534 | I965_ISC_CLOCK_GATE_DISABLE | |
| 7535 | I965_FBC_CLOCK_GATE_DISABLE); |
| 7536 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 7537 | I915_WRITE(MI_ARB_STATE, |
| 7538 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7539 | } |
| 7540 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7541 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7542 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7543 | u32 dstate = I915_READ(D_STATE); |
| 7544 | |
| 7545 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 7546 | DSTATE_DOT_CLOCK_GATING; |
| 7547 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 7548 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7549 | if (IS_PINEVIEW(dev_priv)) |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 7550 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 7551 | |
| 7552 | /* IIR "flip pending" means done if this bit is set */ |
| 7553 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 7554 | |
| 7555 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 7556 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 7557 | |
| 7558 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 7559 | 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] | 7560 | |
| 7561 | I915_WRITE(MI_ARB_STATE, |
| 7562 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7563 | } |
| 7564 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7565 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7566 | { |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7567 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 7568 | |
| 7569 | /* interrupts should cause a wake up from C3 */ |
| 7570 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 7571 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7572 | |
| 7573 | I915_WRITE(MEM_MODE, |
| 7574 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Ville Syrjälä | 5cecf50 | 2020-07-02 18:37:23 +0300 | [diff] [blame] | 7575 | |
| 7576 | /* |
| 7577 | * Have FBC ignore 3D activity since we use software |
| 7578 | * render tracking, and otherwise a pure 3D workload |
| 7579 | * (even if it just renders a single frame and then does |
| 7580 | * abosultely nothing) would not allow FBC to recompress |
| 7581 | * until a 2D blit occurs. |
| 7582 | */ |
| 7583 | I915_WRITE(SCPD0, |
| 7584 | _MASKED_BIT_ENABLE(SCPD_FBC_IGNORE_3D)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7585 | } |
| 7586 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7587 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7588 | { |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7589 | I915_WRITE(MEM_MODE, |
| 7590 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 7591 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7592 | } |
| 7593 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7594 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7595 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7596 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7597 | } |
| 7598 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7599 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7600 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7601 | if (HAS_PCH_LPT(dev_priv)) |
| 7602 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7603 | } |
| 7604 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7605 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7606 | { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7607 | drm_dbg_kms(&dev_priv->drm, |
| 7608 | "No clock gating settings or workarounds applied.\n"); |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7609 | } |
| 7610 | |
| 7611 | /** |
| 7612 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 7613 | * @dev_priv: device private |
| 7614 | * |
| 7615 | * Setup the hooks that configure which clocks of a given platform can be |
| 7616 | * gated and also apply various GT and display specific workarounds for these |
| 7617 | * platforms. Note that some GT specific workarounds are applied separately |
| 7618 | * when GPU contexts or batchbuffers start their execution. |
| 7619 | */ |
| 7620 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 7621 | { |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7622 | if (IS_DG1(dev_priv)) |
| 7623 | dev_priv->display.init_clock_gating = dg1_init_clock_gating; |
| 7624 | else if (IS_GEN(dev_priv, 12)) |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7625 | dev_priv->display.init_clock_gating = tgl_init_clock_gating; |
Lucas De Marchi | 13e53c5 | 2019-08-17 02:38:42 -0700 | [diff] [blame] | 7626 | else if (IS_GEN(dev_priv, 11)) |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7627 | dev_priv->display.init_clock_gating = icl_init_clock_gating; |
Oscar Mateo | cc38cae | 2018-05-08 14:29:23 -0700 | [diff] [blame] | 7628 | else if (IS_CANNONLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7629 | dev_priv->display.init_clock_gating = cnl_init_clock_gating; |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 7630 | else if (IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7631 | dev_priv->display.init_clock_gating = cfl_init_clock_gating; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7632 | else if (IS_SKYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7633 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7634 | else if (IS_KABYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7635 | dev_priv->display.init_clock_gating = kbl_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7636 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7637 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7638 | else if (IS_GEMINILAKE(dev_priv)) |
| 7639 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7640 | else if (IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7641 | dev_priv->display.init_clock_gating = bdw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7642 | else if (IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7643 | dev_priv->display.init_clock_gating = chv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7644 | else if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7645 | dev_priv->display.init_clock_gating = hsw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7646 | else if (IS_IVYBRIDGE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7647 | dev_priv->display.init_clock_gating = ivb_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7648 | else if (IS_VALLEYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7649 | dev_priv->display.init_clock_gating = vlv_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7650 | else if (IS_GEN(dev_priv, 6)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7651 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7652 | else if (IS_GEN(dev_priv, 5)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7653 | dev_priv->display.init_clock_gating = ilk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7654 | else if (IS_G4X(dev_priv)) |
| 7655 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7656 | else if (IS_I965GM(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7657 | dev_priv->display.init_clock_gating = i965gm_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7658 | else if (IS_I965G(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7659 | dev_priv->display.init_clock_gating = i965g_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7660 | else if (IS_GEN(dev_priv, 3)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7661 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 7662 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 7663 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7664 | else if (IS_GEN(dev_priv, 2)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7665 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 7666 | else { |
| 7667 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 7668 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 7669 | } |
| 7670 | } |
| 7671 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7672 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 7673 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7674 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7675 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7676 | if (IS_PINEVIEW(dev_priv)) |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 7677 | pnv_get_mem_freq(dev_priv); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7678 | else if (IS_GEN(dev_priv, 5)) |
Lucas De Marchi | 9eae5e2 | 2019-12-24 00:40:09 -0800 | [diff] [blame] | 7679 | ilk_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7680 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 7681 | if (intel_has_sagv(dev_priv)) |
| 7682 | skl_setup_sagv_block_time(dev_priv); |
| 7683 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7684 | /* For FIFO watermark updates */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 7685 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 7686 | skl_setup_wm_latency(dev_priv); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 7687 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7688 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 7689 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 7690 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7691 | if ((IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[1] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7692 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7693 | (!IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7694 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 7695 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 7696 | dev_priv->display.compute_intermediate_wm = |
| 7697 | ilk_compute_intermediate_wm; |
| 7698 | dev_priv->display.initial_watermarks = |
| 7699 | ilk_initial_watermarks; |
| 7700 | dev_priv->display.optimize_watermarks = |
| 7701 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7702 | } else { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7703 | drm_dbg_kms(&dev_priv->drm, |
| 7704 | "Failed to read display plane latency. " |
| 7705 | "Disable CxSR\n"); |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7706 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 7707 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 7708 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7709 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 7710 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7711 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 7712 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7713 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 7714 | } else if (IS_G4X(dev_priv)) { |
| 7715 | g4x_setup_wm_latency(dev_priv); |
| 7716 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 7717 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 7718 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 7719 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7720 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 7721 | if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7722 | dev_priv->is_ddr3, |
| 7723 | dev_priv->fsb_freq, |
| 7724 | dev_priv->mem_freq)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7725 | drm_info(&dev_priv->drm, |
| 7726 | "failed to find known CxSR latency " |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7727 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 7728 | "disabling CxSR\n", |
| 7729 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 7730 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 7731 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 7732 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7733 | dev_priv->display.update_wm = NULL; |
| 7734 | } else |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 7735 | dev_priv->display.update_wm = pnv_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7736 | } else if (IS_GEN(dev_priv, 4)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7737 | dev_priv->display.update_wm = i965_update_wm; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7738 | } else if (IS_GEN(dev_priv, 3)) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7739 | dev_priv->display.update_wm = i9xx_update_wm; |
| 7740 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7741 | } else if (IS_GEN(dev_priv, 2)) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 7742 | if (INTEL_NUM_PIPES(dev_priv) == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7743 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7744 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7745 | } else { |
| 7746 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7747 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7748 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7749 | } else { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7750 | drm_err(&dev_priv->drm, |
| 7751 | "unexpected fall-through in %s\n", __func__); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7752 | } |
| 7753 | } |
| 7754 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 7755 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7756 | { |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 7757 | dev_priv->runtime_pm.suspended = false; |
| 7758 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7759 | } |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 7760 | |
| 7761 | static struct intel_global_state *intel_dbuf_duplicate_state(struct intel_global_obj *obj) |
| 7762 | { |
| 7763 | struct intel_dbuf_state *dbuf_state; |
| 7764 | |
| 7765 | dbuf_state = kmemdup(obj->state, sizeof(*dbuf_state), GFP_KERNEL); |
| 7766 | if (!dbuf_state) |
| 7767 | return NULL; |
| 7768 | |
| 7769 | return &dbuf_state->base; |
| 7770 | } |
| 7771 | |
| 7772 | static void intel_dbuf_destroy_state(struct intel_global_obj *obj, |
| 7773 | struct intel_global_state *state) |
| 7774 | { |
| 7775 | kfree(state); |
| 7776 | } |
| 7777 | |
| 7778 | static const struct intel_global_state_funcs intel_dbuf_funcs = { |
| 7779 | .atomic_duplicate_state = intel_dbuf_duplicate_state, |
| 7780 | .atomic_destroy_state = intel_dbuf_destroy_state, |
| 7781 | }; |
| 7782 | |
| 7783 | struct intel_dbuf_state * |
| 7784 | intel_atomic_get_dbuf_state(struct intel_atomic_state *state) |
| 7785 | { |
| 7786 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 7787 | struct intel_global_state *dbuf_state; |
| 7788 | |
| 7789 | dbuf_state = intel_atomic_get_global_obj_state(state, &dev_priv->dbuf.obj); |
| 7790 | if (IS_ERR(dbuf_state)) |
| 7791 | return ERR_CAST(dbuf_state); |
| 7792 | |
| 7793 | return to_intel_dbuf_state(dbuf_state); |
| 7794 | } |
| 7795 | |
| 7796 | int intel_dbuf_init(struct drm_i915_private *dev_priv) |
| 7797 | { |
| 7798 | struct intel_dbuf_state *dbuf_state; |
| 7799 | |
| 7800 | dbuf_state = kzalloc(sizeof(*dbuf_state), GFP_KERNEL); |
| 7801 | if (!dbuf_state) |
| 7802 | return -ENOMEM; |
| 7803 | |
| 7804 | intel_atomic_global_obj_init(dev_priv, &dev_priv->dbuf.obj, |
| 7805 | &dbuf_state->base, &intel_dbuf_funcs); |
| 7806 | |
| 7807 | return 0; |
| 7808 | } |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 7809 | |
| 7810 | void intel_dbuf_pre_plane_update(struct intel_atomic_state *state) |
| 7811 | { |
| 7812 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 7813 | const struct intel_dbuf_state *new_dbuf_state = |
| 7814 | intel_atomic_get_new_dbuf_state(state); |
| 7815 | const struct intel_dbuf_state *old_dbuf_state = |
| 7816 | intel_atomic_get_old_dbuf_state(state); |
| 7817 | |
| 7818 | if (!new_dbuf_state || |
| 7819 | new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices) |
| 7820 | return; |
| 7821 | |
| 7822 | WARN_ON(!new_dbuf_state->base.changed); |
| 7823 | |
| 7824 | gen9_dbuf_slices_update(dev_priv, |
| 7825 | old_dbuf_state->enabled_slices | |
| 7826 | new_dbuf_state->enabled_slices); |
| 7827 | } |
| 7828 | |
| 7829 | void intel_dbuf_post_plane_update(struct intel_atomic_state *state) |
| 7830 | { |
| 7831 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 7832 | const struct intel_dbuf_state *new_dbuf_state = |
| 7833 | intel_atomic_get_new_dbuf_state(state); |
| 7834 | const struct intel_dbuf_state *old_dbuf_state = |
| 7835 | intel_atomic_get_old_dbuf_state(state); |
| 7836 | |
| 7837 | if (!new_dbuf_state || |
| 7838 | new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices) |
| 7839 | return; |
| 7840 | |
| 7841 | WARN_ON(!new_dbuf_state->base.changed); |
| 7842 | |
| 7843 | gen9_dbuf_slices_update(dev_priv, |
| 7844 | new_dbuf_state->enabled_slices); |
| 7845 | } |