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" |
Ville Syrjälä | 3df3fe2 | 2020-11-06 19:30:42 +0200 | [diff] [blame] | 36 | #include "display/intel_atomic_plane.h" |
Stanislav Lisovskiy | cac91e6 | 2020-05-22 16:18:43 +0300 | [diff] [blame] | 37 | #include "display/intel_bw.h" |
Ville Syrjälä | 7785ae0 | 2021-04-30 17:39:44 +0300 | [diff] [blame] | 38 | #include "display/intel_de.h" |
Jani Nikula | 1d455f8 | 2019-08-06 14:39:33 +0300 | [diff] [blame] | 39 | #include "display/intel_display_types.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 40 | #include "display/intel_fbc.h" |
| 41 | #include "display/intel_sprite.h" |
Dave Airlie | 46d12f9 | 2021-02-05 16:48:36 +0200 | [diff] [blame] | 42 | #include "display/skl_universal_plane.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 43 | |
Andi Shyti | 0dc3c56 | 2019-10-20 19:41:39 +0100 | [diff] [blame] | 44 | #include "gt/intel_llc.h" |
| 45 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 46 | #include "i915_drv.h" |
Jani Nikula | a10510a | 2020-02-27 19:00:47 +0200 | [diff] [blame] | 47 | #include "i915_fixed.h" |
Jani Nikula | 440e2b3 | 2019-04-29 15:29:27 +0300 | [diff] [blame] | 48 | #include "i915_irq.h" |
Jani Nikula | a09d9a8 | 2019-08-06 13:07:28 +0300 | [diff] [blame] | 49 | #include "i915_trace.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 50 | #include "intel_pm.h" |
Chris Wilson | 56c5098 | 2019-04-26 09:17:22 +0100 | [diff] [blame] | 51 | #include "intel_sideband.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 52 | #include "../../../platform/x86/intel_ips.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 53 | |
Jani Nikula | a10510a | 2020-02-27 19:00:47 +0200 | [diff] [blame] | 54 | /* Stores plane specific WM parameters */ |
| 55 | struct skl_wm_params { |
| 56 | bool x_tiled, y_tiled; |
| 57 | bool rc_surface; |
| 58 | bool is_planar; |
| 59 | u32 width; |
| 60 | u8 cpp; |
| 61 | u32 plane_pixel_rate; |
| 62 | u32 y_min_scanlines; |
| 63 | u32 plane_bytes_per_line; |
| 64 | uint_fixed_16_16_t plane_blocks_per_line; |
| 65 | uint_fixed_16_16_t y_tile_minimum; |
| 66 | u32 linetime_us; |
| 67 | u32 dbuf_block_size; |
| 68 | }; |
| 69 | |
| 70 | /* used in computing the new watermarks state */ |
| 71 | struct intel_wm_config { |
| 72 | unsigned int num_pipes_active; |
| 73 | bool sprites_enabled; |
| 74 | bool sprites_scaled; |
| 75 | }; |
| 76 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 77 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 78 | { |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 79 | if (HAS_LLC(dev_priv)) { |
| 80 | /* |
| 81 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
Lucas De Marchi | e0403cb | 2017-12-05 11:01:17 -0800 | [diff] [blame] | 82 | * Display WA #0390: skl,kbl |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 83 | * |
| 84 | * Must match Sampler, Pixel Back End, and Media. See |
| 85 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 86 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 87 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 88 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR1_1) | |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 89 | SKL_DE_COMPRESSED_HASH_MODE); |
| 90 | } |
| 91 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 92 | /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl,cfl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 93 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 94 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP); |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 95 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 96 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 97 | intel_uncore_write(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1, |
| 98 | intel_uncore_read(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 99 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 100 | /* |
| 101 | * WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl |
| 102 | * Display WA #0859: skl,bxt,kbl,glk,cfl |
| 103 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 104 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) | |
Mika Kuoppala | 303d4ea | 2016-06-07 17:19:17 +0300 | [diff] [blame] | 105 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 106 | } |
| 107 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 108 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 109 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 110 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 111 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 112 | /* WaDisableSDEUnitClockGating:bxt */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 113 | intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 114 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 115 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 116 | /* |
| 117 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 118 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 119 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 120 | intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) | |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 121 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 125 | * to stay fully on. |
| 126 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 127 | intel_uncore_write(&dev_priv->uncore, GEN9_CLKGATE_DIS_0, intel_uncore_read(&dev_priv->uncore, GEN9_CLKGATE_DIS_0) | |
Jani Nikula | 8aeaf64 | 2017-02-15 17:21:37 +0200 | [diff] [blame] | 128 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Uma Shankar | 1d85a29 | 2018-08-07 21:15:35 +0530 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * Lower the display internal timeout. |
| 132 | * This is needed to avoid any hard hangs when DSI port PLL |
| 133 | * is off and a MMIO access is attempted by any privilege |
| 134 | * application, using batch buffers or any other means. |
| 135 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 136 | intel_uncore_write(&dev_priv->uncore, RM_TIMEOUT, MMIO_TIMEOUT_US(950)); |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 137 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 138 | /* |
| 139 | * WaFbcTurnOffFbcWatermark:bxt |
| 140 | * Display WA #0562: bxt |
| 141 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 142 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) | |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 143 | DISP_FBC_WM_DIS); |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 144 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 145 | /* |
| 146 | * WaFbcHighMemBwCorruptionAvoidance:bxt |
| 147 | * Display WA #0883: bxt |
| 148 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 149 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 150 | ILK_DPFC_DISABLE_DUMMY0); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 151 | } |
| 152 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 153 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 154 | { |
| 155 | gen9_init_clock_gating(dev_priv); |
| 156 | |
| 157 | /* |
| 158 | * WaDisablePWMClockGating:glk |
| 159 | * Backlight PWM may stop in the asserted state, causing backlight |
| 160 | * to stay fully on. |
| 161 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 162 | intel_uncore_write(&dev_priv->uncore, GEN9_CLKGATE_DIS_0, intel_uncore_read(&dev_priv->uncore, GEN9_CLKGATE_DIS_0) | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 163 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
| 164 | } |
| 165 | |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 166 | static void pnv_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 167 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 168 | u32 tmp; |
| 169 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 170 | tmp = intel_uncore_read(&dev_priv->uncore, CLKCFG); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 171 | |
| 172 | switch (tmp & CLKCFG_FSB_MASK) { |
| 173 | case CLKCFG_FSB_533: |
| 174 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 175 | break; |
| 176 | case CLKCFG_FSB_800: |
| 177 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 178 | break; |
| 179 | case CLKCFG_FSB_667: |
| 180 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 181 | break; |
| 182 | case CLKCFG_FSB_400: |
| 183 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | switch (tmp & CLKCFG_MEM_MASK) { |
| 188 | case CLKCFG_MEM_533: |
| 189 | dev_priv->mem_freq = 533; |
| 190 | break; |
| 191 | case CLKCFG_MEM_667: |
| 192 | dev_priv->mem_freq = 667; |
| 193 | break; |
| 194 | case CLKCFG_MEM_800: |
| 195 | dev_priv->mem_freq = 800; |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | /* detect pineview DDR3 setting */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 200 | tmp = intel_uncore_read(&dev_priv->uncore, CSHRDDR3CTL); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 201 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 202 | } |
| 203 | |
Lucas De Marchi | 9eae5e2 | 2019-12-24 00:40:09 -0800 | [diff] [blame] | 204 | static void ilk_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 205 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 206 | u16 ddrpll, csipll; |
| 207 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 208 | ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1); |
| 209 | csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 210 | |
| 211 | switch (ddrpll & 0xff) { |
| 212 | case 0xc: |
| 213 | dev_priv->mem_freq = 800; |
| 214 | break; |
| 215 | case 0x10: |
| 216 | dev_priv->mem_freq = 1066; |
| 217 | break; |
| 218 | case 0x14: |
| 219 | dev_priv->mem_freq = 1333; |
| 220 | break; |
| 221 | case 0x18: |
| 222 | dev_priv->mem_freq = 1600; |
| 223 | break; |
| 224 | default: |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 225 | drm_dbg(&dev_priv->drm, "unknown memory frequency 0x%02x\n", |
| 226 | ddrpll & 0xff); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 227 | dev_priv->mem_freq = 0; |
| 228 | break; |
| 229 | } |
| 230 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 231 | switch (csipll & 0x3ff) { |
| 232 | case 0x00c: |
| 233 | dev_priv->fsb_freq = 3200; |
| 234 | break; |
| 235 | case 0x00e: |
| 236 | dev_priv->fsb_freq = 3733; |
| 237 | break; |
| 238 | case 0x010: |
| 239 | dev_priv->fsb_freq = 4266; |
| 240 | break; |
| 241 | case 0x012: |
| 242 | dev_priv->fsb_freq = 4800; |
| 243 | break; |
| 244 | case 0x014: |
| 245 | dev_priv->fsb_freq = 5333; |
| 246 | break; |
| 247 | case 0x016: |
| 248 | dev_priv->fsb_freq = 5866; |
| 249 | break; |
| 250 | case 0x018: |
| 251 | dev_priv->fsb_freq = 6400; |
| 252 | break; |
| 253 | default: |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 254 | drm_dbg(&dev_priv->drm, "unknown fsb frequency 0x%04x\n", |
| 255 | csipll & 0x3ff); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 256 | dev_priv->fsb_freq = 0; |
| 257 | break; |
| 258 | } |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 261 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 262 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 263 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 264 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 265 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 266 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 267 | |
| 268 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 269 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 270 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 271 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 272 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 273 | |
| 274 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 275 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 276 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 277 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 278 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 279 | |
| 280 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 281 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 282 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 283 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 284 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 285 | |
| 286 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 287 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 288 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 289 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 290 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 291 | |
| 292 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 293 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 294 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 295 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 296 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 297 | }; |
| 298 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 299 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 300 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 301 | int fsb, |
| 302 | int mem) |
| 303 | { |
| 304 | const struct cxsr_latency *latency; |
| 305 | int i; |
| 306 | |
| 307 | if (fsb == 0 || mem == 0) |
| 308 | return NULL; |
| 309 | |
| 310 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 311 | latency = &cxsr_latency_table[i]; |
| 312 | if (is_desktop == latency->is_desktop && |
| 313 | is_ddr3 == latency->is_ddr3 && |
| 314 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 315 | return latency; |
| 316 | } |
| 317 | |
| 318 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 319 | |
| 320 | return NULL; |
| 321 | } |
| 322 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 323 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 324 | { |
| 325 | u32 val; |
| 326 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 327 | vlv_punit_get(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 328 | |
| 329 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 330 | if (enable) |
| 331 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 332 | else |
| 333 | val |= FORCE_DDR_HIGH_FREQ; |
| 334 | val &= ~FORCE_DDR_LOW_FREQ; |
| 335 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 336 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 337 | |
| 338 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 339 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 340 | drm_err(&dev_priv->drm, |
| 341 | "timed out waiting for Punit DDR DVFS request\n"); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 342 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 343 | vlv_punit_put(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 346 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 347 | { |
| 348 | u32 val; |
| 349 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 350 | vlv_punit_get(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 351 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 352 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 353 | if (enable) |
| 354 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 355 | else |
| 356 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 357 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 358 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 359 | vlv_punit_put(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 360 | } |
| 361 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 362 | #define FW_WM(value, plane) \ |
| 363 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 364 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 365 | 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] | 366 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 367 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 368 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 369 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 370 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 371 | was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 372 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 373 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 374 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 375 | was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 376 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 377 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 378 | } else if (IS_PINEVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 379 | val = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 380 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 381 | if (enable) |
| 382 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 383 | else |
| 384 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 385 | intel_uncore_write(&dev_priv->uncore, DSPFW3, val); |
| 386 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 387 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 388 | was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF) & FW_BLC_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 389 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 390 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 391 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, val); |
| 392 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 393 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 394 | /* |
| 395 | * FIXME can't find a bit like this for 915G, and |
| 396 | * and yet it does have the related watermark in |
| 397 | * FW_BLC_SELF. What's going on? |
| 398 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 399 | was_enabled = intel_uncore_read(&dev_priv->uncore, INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 400 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 401 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 402 | intel_uncore_write(&dev_priv->uncore, INSTPM, val); |
| 403 | intel_uncore_posting_read(&dev_priv->uncore, INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 404 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 405 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 406 | } |
| 407 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 408 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 409 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 410 | drm_dbg_kms(&dev_priv->drm, "memory self-refresh is %s (was %s)\n", |
| 411 | enableddisabled(enable), |
| 412 | enableddisabled(was_enabled)); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 413 | |
| 414 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 415 | } |
| 416 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 417 | /** |
| 418 | * intel_set_memory_cxsr - Configure CxSR state |
| 419 | * @dev_priv: i915 device |
| 420 | * @enable: Allow vs. disallow CxSR |
| 421 | * |
| 422 | * Allow or disallow the system to enter a special CxSR |
| 423 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 424 | * is that several display FIFOs may get combined into a single larger |
| 425 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 426 | * system to defer memory fetches longer, and the memory will enter |
| 427 | * self refresh. |
| 428 | * |
| 429 | * Note that enabling CxSR does not guarantee that the system enter |
| 430 | * this special mode, nor does it guarantee that the system stays |
| 431 | * in that mode once entered. So this just allows/disallows the system |
| 432 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 433 | * C-states will affect when/if the system actually enters/exits the |
| 434 | * CxSR mode. |
| 435 | * |
| 436 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 437 | * and the system is free to enter/exit memory self refresh at any time |
| 438 | * even when the use of CxSR has been disallowed. |
| 439 | * |
| 440 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 441 | * control registers will not get latched on vblank. Thus in order to |
| 442 | * guarantee the system will respond to changes in the plane registers |
| 443 | * we must always disallow CxSR prior to making changes to those registers. |
| 444 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 445 | * frame start which happens after vblank start (which is when the plane |
| 446 | * registers would get latched), so we can't proceed with the plane update |
| 447 | * during the same frame where we disallowed CxSR. |
| 448 | * |
| 449 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 450 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 451 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 452 | * Disallowing just CxSR is sufficient. |
| 453 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 454 | 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] | 455 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 456 | bool ret; |
| 457 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 458 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 459 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 460 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 461 | dev_priv->wm.vlv.cxsr = enable; |
| 462 | else if (IS_G4X(dev_priv)) |
| 463 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 464 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 465 | |
| 466 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 467 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 468 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 469 | /* |
| 470 | * Latency for FIFO fetches is dependent on several factors: |
| 471 | * - memory configuration (speed, channels) |
| 472 | * - chipset |
| 473 | * - current MCH state |
| 474 | * It can be fairly high in some situations, so here we assume a fairly |
| 475 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 476 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 477 | * and power consumption (set it too low to save power and we might see |
| 478 | * FIFO underruns and display "flicker"). |
| 479 | * |
| 480 | * A value of 5us seems to be a good balance; safe for very low end |
| 481 | * platforms but not overly aggressive on lower latency configs. |
| 482 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 483 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 484 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 485 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 486 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 487 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 488 | 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] | 489 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 490 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 491 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 492 | 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] | 493 | enum pipe pipe = crtc->pipe; |
| 494 | int sprite0_start, sprite1_start; |
Kees Cook | 2713eb4 | 2020-02-20 16:05:17 -0800 | [diff] [blame] | 495 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 496 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 497 | switch (pipe) { |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 498 | case PIPE_A: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 499 | dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
| 500 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 501 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 502 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 503 | break; |
| 504 | case PIPE_B: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 505 | dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
| 506 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 507 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 508 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 509 | break; |
| 510 | case PIPE_C: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 511 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
| 512 | dsparb3 = intel_uncore_read(&dev_priv->uncore, DSPARB3); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 513 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 514 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 515 | break; |
| 516 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 517 | MISSING_CASE(pipe); |
| 518 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 521 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 522 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 523 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 524 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 527 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 528 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 529 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 530 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 531 | int size; |
| 532 | |
| 533 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 534 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 535 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 536 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 537 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 538 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 539 | |
| 540 | return size; |
| 541 | } |
| 542 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 543 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 544 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 545 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 546 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 547 | int size; |
| 548 | |
| 549 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 550 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 551 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 552 | size >>= 1; /* Convert to cachelines */ |
| 553 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 554 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 555 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 556 | |
| 557 | return size; |
| 558 | } |
| 559 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 560 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 561 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 562 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 563 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 564 | int size; |
| 565 | |
| 566 | size = dsparb & 0x7f; |
| 567 | size >>= 2; /* Convert to cachelines */ |
| 568 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 569 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 570 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 571 | |
| 572 | return size; |
| 573 | } |
| 574 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 575 | /* Pineview has different values for various configs */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 576 | static const struct intel_watermark_params pnv_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 577 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 578 | .max_wm = PINEVIEW_MAX_WM, |
| 579 | .default_wm = PINEVIEW_DFT_WM, |
| 580 | .guard_size = PINEVIEW_GUARD_WM, |
| 581 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 582 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 583 | |
| 584 | static const struct intel_watermark_params pnv_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 585 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 586 | .max_wm = PINEVIEW_MAX_WM, |
| 587 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 588 | .guard_size = PINEVIEW_GUARD_WM, |
| 589 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 590 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 591 | |
| 592 | static const struct intel_watermark_params pnv_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 593 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 594 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 595 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 596 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 597 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 598 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 599 | |
| 600 | static const struct intel_watermark_params pnv_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 601 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 602 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 603 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 604 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 605 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 606 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 607 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 608 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 609 | .fifo_size = I965_CURSOR_FIFO, |
| 610 | .max_wm = I965_CURSOR_MAX_WM, |
| 611 | .default_wm = I965_CURSOR_DFT_WM, |
| 612 | .guard_size = 2, |
| 613 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 614 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 615 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 616 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 617 | .fifo_size = I945_FIFO_SIZE, |
| 618 | .max_wm = I915_MAX_WM, |
| 619 | .default_wm = 1, |
| 620 | .guard_size = 2, |
| 621 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 622 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 623 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 624 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 625 | .fifo_size = I915_FIFO_SIZE, |
| 626 | .max_wm = I915_MAX_WM, |
| 627 | .default_wm = 1, |
| 628 | .guard_size = 2, |
| 629 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 630 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 631 | |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 632 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 633 | .fifo_size = I855GM_FIFO_SIZE, |
| 634 | .max_wm = I915_MAX_WM, |
| 635 | .default_wm = 1, |
| 636 | .guard_size = 2, |
| 637 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 638 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 639 | |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 640 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 641 | .fifo_size = I855GM_FIFO_SIZE, |
| 642 | .max_wm = I915_MAX_WM/2, |
| 643 | .default_wm = 1, |
| 644 | .guard_size = 2, |
| 645 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 646 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 647 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 648 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 649 | .fifo_size = I830_FIFO_SIZE, |
| 650 | .max_wm = I915_MAX_WM, |
| 651 | .default_wm = 1, |
| 652 | .guard_size = 2, |
| 653 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 654 | }; |
| 655 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 656 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 657 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 658 | * @pixel_rate: Pipe pixel rate in kHz |
| 659 | * @cpp: Plane bytes per pixel |
| 660 | * @latency: Memory wakeup latency in 0.1us units |
| 661 | * |
| 662 | * Compute the watermark using the method 1 or "small buffer" |
| 663 | * formula. The caller may additonally add extra cachelines |
| 664 | * to account for TLB misses and clock crossings. |
| 665 | * |
| 666 | * This method is concerned with the short term drain rate |
| 667 | * of the FIFO, ie. it does not account for blanking periods |
| 668 | * which would effectively reduce the average drain rate across |
| 669 | * a longer period. The name "small" refers to the fact the |
| 670 | * FIFO is relatively small compared to the amount of data |
| 671 | * fetched. |
| 672 | * |
| 673 | * The FIFO level vs. time graph might look something like: |
| 674 | * |
| 675 | * |\ |\ |
| 676 | * | \ | \ |
| 677 | * __---__---__ (- plane active, _ blanking) |
| 678 | * -> time |
| 679 | * |
| 680 | * or perhaps like this: |
| 681 | * |
| 682 | * |\|\ |\|\ |
| 683 | * __----__----__ (- plane active, _ blanking) |
| 684 | * -> time |
| 685 | * |
| 686 | * Returns: |
| 687 | * The watermark in bytes |
| 688 | */ |
| 689 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 690 | unsigned int cpp, |
| 691 | unsigned int latency) |
| 692 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 693 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 694 | |
Ville Syrjälä | d492a29 | 2019-04-08 18:27:01 +0300 | [diff] [blame] | 695 | ret = mul_u32_u32(pixel_rate, cpp * latency); |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 696 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 697 | |
| 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 703 | * @pixel_rate: Pipe pixel rate in kHz |
| 704 | * @htotal: Pipe horizontal total |
| 705 | * @width: Plane width in pixels |
| 706 | * @cpp: Plane bytes per pixel |
| 707 | * @latency: Memory wakeup latency in 0.1us units |
| 708 | * |
| 709 | * Compute the watermark using the method 2 or "large buffer" |
| 710 | * formula. The caller may additonally add extra cachelines |
| 711 | * to account for TLB misses and clock crossings. |
| 712 | * |
| 713 | * This method is concerned with the long term drain rate |
| 714 | * of the FIFO, ie. it does account for blanking periods |
| 715 | * which effectively reduce the average drain rate across |
| 716 | * a longer period. The name "large" refers to the fact the |
| 717 | * FIFO is relatively large compared to the amount of data |
| 718 | * fetched. |
| 719 | * |
| 720 | * The FIFO level vs. time graph might look something like: |
| 721 | * |
| 722 | * |\___ |\___ |
| 723 | * | \___ | \___ |
| 724 | * | \ | \ |
| 725 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 726 | * -> time |
| 727 | * |
| 728 | * Returns: |
| 729 | * The watermark in bytes |
| 730 | */ |
| 731 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 732 | unsigned int htotal, |
| 733 | unsigned int width, |
| 734 | unsigned int cpp, |
| 735 | unsigned int latency) |
| 736 | { |
| 737 | unsigned int ret; |
| 738 | |
| 739 | /* |
| 740 | * FIXME remove once all users are computing |
| 741 | * watermarks in the correct place. |
| 742 | */ |
| 743 | if (WARN_ON_ONCE(htotal == 0)) |
| 744 | htotal = 1; |
| 745 | |
| 746 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 747 | ret = (ret + 1) * width * cpp; |
| 748 | |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 753 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 754 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 755 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 756 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 757 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 758 | * @latency_ns: memory latency for the platform |
| 759 | * |
| 760 | * Calculate the watermark level (the level at which the display plane will |
| 761 | * start fetching from memory again). Each chip has a different display |
| 762 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 763 | * in the correct intel_watermark_params structure. |
| 764 | * |
| 765 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 766 | * on the pixel size. When it reaches the watermark level, it'll start |
| 767 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 768 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 769 | * will occur, and a display engine hang could result. |
| 770 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 771 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 772 | const struct intel_watermark_params *wm, |
| 773 | int fifo_size, int cpp, |
| 774 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 775 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 776 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 777 | |
| 778 | /* |
| 779 | * Note: we need to make sure we don't overflow for various clock & |
| 780 | * latency values. |
| 781 | * clocks go from a few thousand to several hundred thousand. |
| 782 | * latency is usually a few thousand |
| 783 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 784 | entries = intel_wm_method1(pixel_rate, cpp, |
| 785 | latency_ns / 100); |
| 786 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 787 | wm->guard_size; |
| 788 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 789 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 790 | wm_size = fifo_size - entries; |
| 791 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 792 | |
| 793 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 794 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 795 | wm_size = wm->max_wm; |
| 796 | if (wm_size <= 0) |
| 797 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * Bspec seems to indicate that the value shouldn't be lower than |
| 801 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 802 | * Lets go for 8 which is the burst size since certain platforms |
| 803 | * already use a hardcoded 8 (which is what the spec says should be |
| 804 | * done). |
| 805 | */ |
| 806 | if (wm_size <= 8) |
| 807 | wm_size = 8; |
| 808 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 809 | return wm_size; |
| 810 | } |
| 811 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 812 | static bool is_disabling(int old, int new, int threshold) |
| 813 | { |
| 814 | return old >= threshold && new < threshold; |
| 815 | } |
| 816 | |
| 817 | static bool is_enabling(int old, int new, int threshold) |
| 818 | { |
| 819 | return old < threshold && new >= threshold; |
| 820 | } |
| 821 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 822 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 823 | { |
| 824 | return dev_priv->wm.max_level + 1; |
| 825 | } |
| 826 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 827 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 828 | const struct intel_plane_state *plane_state) |
| 829 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 830 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 831 | |
| 832 | /* FIXME check the 'enable' instead */ |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 833 | if (!crtc_state->hw.active) |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 834 | return false; |
| 835 | |
| 836 | /* |
| 837 | * Treat cursor with fb as always visible since cursor updates |
| 838 | * can happen faster than the vrefresh rate, and the current |
| 839 | * watermark code doesn't handle that correctly. Cursor updates |
| 840 | * which set/clear the fb or change the cursor size are going |
| 841 | * to get throttled by intel_legacy_cursor_update() to work |
| 842 | * around this problem with the watermark code. |
| 843 | */ |
| 844 | if (plane->id == PLANE_CURSOR) |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 845 | return plane_state->hw.fb != NULL; |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 846 | else |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 847 | return plane_state->uapi.visible; |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 848 | } |
| 849 | |
Ville Syrjälä | 04da7b9 | 2019-11-27 22:12:11 +0200 | [diff] [blame] | 850 | static bool intel_crtc_active(struct intel_crtc *crtc) |
| 851 | { |
| 852 | /* Be paranoid as we can arrive here with only partial |
| 853 | * state retrieved from the hardware during setup. |
| 854 | * |
| 855 | * We can ditch the adjusted_mode.crtc_clock check as soon |
| 856 | * as Haswell has gained clock readout/fastboot support. |
| 857 | * |
| 858 | * We can ditch the crtc->primary->state->fb check as soon as we can |
| 859 | * properly reconstruct framebuffers. |
| 860 | * |
| 861 | * FIXME: The intel_crtc->active here should be switched to |
| 862 | * crtc->state->active once we have proper CRTC states wired up |
| 863 | * for atomic. |
| 864 | */ |
| 865 | return crtc->active && crtc->base.primary->state->fb && |
| 866 | crtc->config->hw.adjusted_mode.crtc_clock; |
| 867 | } |
| 868 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 869 | 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] | 870 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 871 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 872 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 873 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 874 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 875 | if (enabled) |
| 876 | return NULL; |
| 877 | enabled = crtc; |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | return enabled; |
| 882 | } |
| 883 | |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 884 | static void pnv_update_wm(struct intel_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 885 | { |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 886 | 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] | 887 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 888 | const struct cxsr_latency *latency; |
| 889 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 890 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 891 | |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 892 | latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 893 | dev_priv->is_ddr3, |
| 894 | dev_priv->fsb_freq, |
| 895 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 896 | if (!latency) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 897 | drm_dbg_kms(&dev_priv->drm, |
| 898 | "Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 899 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 900 | return; |
| 901 | } |
| 902 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 903 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 904 | if (crtc) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 905 | const struct drm_display_mode *pipe_mode = |
| 906 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 907 | const struct drm_framebuffer *fb = |
| 908 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 909 | int cpp = fb->format->cpp[0]; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 910 | int clock = pipe_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 911 | |
| 912 | /* Display SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 913 | wm = intel_calculate_wm(clock, &pnv_display_wm, |
| 914 | pnv_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 915 | cpp, latency->display_sr); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 916 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 917 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 918 | reg |= FW_WM(wm, SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 919 | intel_uncore_write(&dev_priv->uncore, DSPFW1, reg); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 920 | drm_dbg_kms(&dev_priv->drm, "DSPFW1 register is %x\n", reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 921 | |
| 922 | /* cursor SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 923 | wm = intel_calculate_wm(clock, &pnv_cursor_wm, |
| 924 | pnv_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 925 | 4, latency->cursor_sr); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 926 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 927 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 928 | reg |= FW_WM(wm, CURSOR_SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 929 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 930 | |
| 931 | /* Display HPLL off SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 932 | wm = intel_calculate_wm(clock, &pnv_display_hplloff_wm, |
| 933 | pnv_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 934 | cpp, latency->display_hpll_disable); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 935 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 936 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 937 | reg |= FW_WM(wm, HPLL_SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 938 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 939 | |
| 940 | /* cursor HPLL off SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 941 | wm = intel_calculate_wm(clock, &pnv_cursor_hplloff_wm, |
| 942 | pnv_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 943 | 4, latency->cursor_hpll_disable); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 944 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 945 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 946 | reg |= FW_WM(wm, HPLL_CURSOR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 947 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 948 | drm_dbg_kms(&dev_priv->drm, "DSPFW3 register is %x\n", reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 949 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 950 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 951 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 952 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 956 | /* |
| 957 | * Documentation says: |
| 958 | * "If the line size is small, the TLB fetches can get in the way of the |
| 959 | * data fetches, causing some lag in the pixel data return which is not |
| 960 | * accounted for in the above formulas. The following adjustment only |
| 961 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 962 | * The WM is adjusted upwards by the difference between the FIFO size |
| 963 | * and the size of 8 whole lines. This adjustment is always performed |
| 964 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 965 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 966 | 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] | 967 | { |
| 968 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 969 | |
| 970 | return max(0, tlb_miss); |
| 971 | } |
| 972 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 973 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 974 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 975 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 976 | enum pipe pipe; |
| 977 | |
| 978 | for_each_pipe(dev_priv, pipe) |
| 979 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 980 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 981 | intel_uncore_write(&dev_priv->uncore, DSPFW1, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 982 | FW_WM(wm->sr.plane, SR) | |
| 983 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 984 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 985 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 986 | intel_uncore_write(&dev_priv->uncore, DSPFW2, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 987 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 988 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 989 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 990 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 991 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 992 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 993 | intel_uncore_write(&dev_priv->uncore, DSPFW3, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 994 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 995 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 996 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 997 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 998 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 999 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1000 | } |
| 1001 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1002 | #define FW_WM_VLV(value, plane) \ |
| 1003 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 1004 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1005 | 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] | 1006 | const struct vlv_wm_values *wm) |
| 1007 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1008 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1009 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1010 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1011 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 1012 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1013 | intel_uncore_write(&dev_priv->uncore, VLV_DDL(pipe), |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1014 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 1015 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 1016 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 1017 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 1018 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1019 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 1020 | /* |
| 1021 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 1022 | * high order bits so that there are no out of bounds values |
| 1023 | * present in the registers during the reprogramming. |
| 1024 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1025 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, 0); |
| 1026 | intel_uncore_write(&dev_priv->uncore, DSPHOWM1, 0); |
| 1027 | intel_uncore_write(&dev_priv->uncore, DSPFW4, 0); |
| 1028 | intel_uncore_write(&dev_priv->uncore, DSPFW5, 0); |
| 1029 | intel_uncore_write(&dev_priv->uncore, DSPFW6, 0); |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 1030 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1031 | intel_uncore_write(&dev_priv->uncore, DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1032 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1033 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 1034 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 1035 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1036 | intel_uncore_write(&dev_priv->uncore, DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1037 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 1038 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1039 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1040 | intel_uncore_write(&dev_priv->uncore, DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1041 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1042 | |
| 1043 | if (IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1044 | intel_uncore_write(&dev_priv->uncore, DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1045 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1046 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1047 | intel_uncore_write(&dev_priv->uncore, DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1048 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 1049 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1050 | intel_uncore_write(&dev_priv->uncore, DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1051 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1052 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1053 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1054 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1055 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1056 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1057 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 1058 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1059 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1060 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1061 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1062 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1063 | 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] | 1064 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1065 | intel_uncore_write(&dev_priv->uncore, DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1066 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1067 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1068 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1069 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1070 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1071 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1072 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1073 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1074 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1075 | 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] | 1076 | } |
| 1077 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1078 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1079 | } |
| 1080 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1081 | #undef FW_WM_VLV |
| 1082 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1083 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1084 | { |
| 1085 | /* all latencies in usec */ |
| 1086 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1087 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1088 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1089 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1090 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1094 | { |
| 1095 | /* |
| 1096 | * DSPCNTR[13] supposedly controls whether the |
| 1097 | * primary plane can use the FIFO space otherwise |
| 1098 | * reserved for the sprite plane. It's not 100% clear |
| 1099 | * what the actual FIFO size is, but it looks like we |
| 1100 | * can happily set both primary and sprite watermarks |
| 1101 | * up to 127 cachelines. So that would seem to mean |
| 1102 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1103 | * the total FIFO is >= 256 cachelines in size. Either |
| 1104 | * way, we don't seem to have to worry about this |
| 1105 | * repartitioning as the maximum watermark value the |
| 1106 | * register can hold for each plane is lower than the |
| 1107 | * minimum FIFO size. |
| 1108 | */ |
| 1109 | switch (plane_id) { |
| 1110 | case PLANE_CURSOR: |
| 1111 | return 63; |
| 1112 | case PLANE_PRIMARY: |
| 1113 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1114 | case PLANE_SPRITE0: |
| 1115 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1116 | default: |
| 1117 | MISSING_CASE(plane_id); |
| 1118 | return 0; |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | static int g4x_fbc_fifo_size(int level) |
| 1123 | { |
| 1124 | switch (level) { |
| 1125 | case G4X_WM_LEVEL_SR: |
| 1126 | return 7; |
| 1127 | case G4X_WM_LEVEL_HPLL: |
| 1128 | return 15; |
| 1129 | default: |
| 1130 | MISSING_CASE(level); |
| 1131 | return 0; |
| 1132 | } |
| 1133 | } |
| 1134 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1135 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1136 | const struct intel_plane_state *plane_state, |
| 1137 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1138 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1139 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1140 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1141 | const struct drm_display_mode *pipe_mode = |
| 1142 | &crtc_state->hw.pipe_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1143 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1144 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1145 | |
| 1146 | if (latency == 0) |
| 1147 | return USHRT_MAX; |
| 1148 | |
| 1149 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1150 | return 0; |
| 1151 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1152 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1153 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1154 | /* |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1155 | * WaUse32BppForSRWM:ctg,elk |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1156 | * |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1157 | * The spec fails to list this restriction for the |
| 1158 | * HPLL watermark, which seems a little strange. |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1159 | * Let's use 32bpp for the HPLL watermark as well. |
| 1160 | */ |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1161 | if (plane->id == PLANE_PRIMARY && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1162 | level != G4X_WM_LEVEL_NORMAL) |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1163 | cpp = max(cpp, 4u); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1164 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1165 | clock = pipe_mode->crtc_clock; |
| 1166 | htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1167 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1168 | width = drm_rect_width(&plane_state->uapi.dst); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1169 | |
| 1170 | if (plane->id == PLANE_CURSOR) { |
| 1171 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1172 | } else if (plane->id == PLANE_PRIMARY && |
| 1173 | level == G4X_WM_LEVEL_NORMAL) { |
| 1174 | wm = intel_wm_method1(clock, cpp, latency); |
| 1175 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1176 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1177 | |
| 1178 | small = intel_wm_method1(clock, cpp, latency); |
| 1179 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1180 | |
| 1181 | wm = min(small, large); |
| 1182 | } |
| 1183 | |
| 1184 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1185 | width, cpp); |
| 1186 | |
| 1187 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1188 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1189 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1193 | int level, enum plane_id plane_id, u16 value) |
| 1194 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1195 | 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] | 1196 | bool dirty = false; |
| 1197 | |
| 1198 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1199 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1200 | |
| 1201 | dirty |= raw->plane[plane_id] != value; |
| 1202 | raw->plane[plane_id] = value; |
| 1203 | } |
| 1204 | |
| 1205 | return dirty; |
| 1206 | } |
| 1207 | |
| 1208 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1209 | int level, u16 value) |
| 1210 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1211 | 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] | 1212 | bool dirty = false; |
| 1213 | |
| 1214 | /* NORMAL level doesn't have an FBC watermark */ |
| 1215 | level = max(level, G4X_WM_LEVEL_SR); |
| 1216 | |
| 1217 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1218 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1219 | |
| 1220 | dirty |= raw->fbc != value; |
| 1221 | raw->fbc = value; |
| 1222 | } |
| 1223 | |
| 1224 | return dirty; |
| 1225 | } |
| 1226 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 1227 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 1228 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1229 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1230 | |
| 1231 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1232 | const struct intel_plane_state *plane_state) |
| 1233 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1234 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1235 | 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] | 1236 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1237 | enum plane_id plane_id = plane->id; |
| 1238 | bool dirty = false; |
| 1239 | int level; |
| 1240 | |
| 1241 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1242 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1243 | if (plane_id == PLANE_PRIMARY) |
| 1244 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1245 | goto out; |
| 1246 | } |
| 1247 | |
| 1248 | for (level = 0; level < num_levels; level++) { |
| 1249 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1250 | int wm, max_wm; |
| 1251 | |
| 1252 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1253 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1254 | |
| 1255 | if (wm > max_wm) |
| 1256 | break; |
| 1257 | |
| 1258 | dirty |= raw->plane[plane_id] != wm; |
| 1259 | raw->plane[plane_id] = wm; |
| 1260 | |
| 1261 | if (plane_id != PLANE_PRIMARY || |
| 1262 | level == G4X_WM_LEVEL_NORMAL) |
| 1263 | continue; |
| 1264 | |
| 1265 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1266 | raw->plane[plane_id]); |
| 1267 | max_wm = g4x_fbc_fifo_size(level); |
| 1268 | |
| 1269 | /* |
| 1270 | * FBC wm is not mandatory as we |
| 1271 | * can always just disable its use. |
| 1272 | */ |
| 1273 | if (wm > max_wm) |
| 1274 | wm = USHRT_MAX; |
| 1275 | |
| 1276 | dirty |= raw->fbc != wm; |
| 1277 | raw->fbc = wm; |
| 1278 | } |
| 1279 | |
| 1280 | /* mark watermarks as invalid */ |
| 1281 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1282 | |
| 1283 | if (plane_id == PLANE_PRIMARY) |
| 1284 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1285 | |
| 1286 | out: |
| 1287 | if (dirty) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1288 | drm_dbg_kms(&dev_priv->drm, |
| 1289 | "%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1290 | plane->base.name, |
| 1291 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1292 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1293 | 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] | 1294 | |
| 1295 | if (plane_id == PLANE_PRIMARY) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1296 | drm_dbg_kms(&dev_priv->drm, |
| 1297 | "FBC watermarks: SR=%d, HPLL=%d\n", |
| 1298 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1299 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | return dirty; |
| 1303 | } |
| 1304 | |
| 1305 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1306 | enum plane_id plane_id, int level) |
| 1307 | { |
| 1308 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1309 | |
| 1310 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1311 | } |
| 1312 | |
| 1313 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1314 | int level) |
| 1315 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1316 | 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] | 1317 | |
| 1318 | if (level > dev_priv->wm.max_level) |
| 1319 | return false; |
| 1320 | |
| 1321 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1322 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1323 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1324 | } |
| 1325 | |
| 1326 | /* mark all levels starting from 'level' as invalid */ |
| 1327 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1328 | struct g4x_wm_state *wm_state, int level) |
| 1329 | { |
| 1330 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1331 | enum plane_id plane_id; |
| 1332 | |
| 1333 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1334 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1335 | } |
| 1336 | |
| 1337 | if (level <= G4X_WM_LEVEL_SR) { |
| 1338 | wm_state->cxsr = false; |
| 1339 | wm_state->sr.cursor = USHRT_MAX; |
| 1340 | wm_state->sr.plane = USHRT_MAX; |
| 1341 | wm_state->sr.fbc = USHRT_MAX; |
| 1342 | } |
| 1343 | |
| 1344 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1345 | wm_state->hpll_en = false; |
| 1346 | wm_state->hpll.cursor = USHRT_MAX; |
| 1347 | wm_state->hpll.plane = USHRT_MAX; |
| 1348 | wm_state->hpll.fbc = USHRT_MAX; |
| 1349 | } |
| 1350 | } |
| 1351 | |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1352 | static bool g4x_compute_fbc_en(const struct g4x_wm_state *wm_state, |
| 1353 | int level) |
| 1354 | { |
| 1355 | if (level < G4X_WM_LEVEL_SR) |
| 1356 | return false; |
| 1357 | |
| 1358 | if (level >= G4X_WM_LEVEL_SR && |
| 1359 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1360 | return false; |
| 1361 | |
| 1362 | if (level >= G4X_WM_LEVEL_HPLL && |
| 1363 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1364 | return false; |
| 1365 | |
| 1366 | return true; |
| 1367 | } |
| 1368 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1369 | static int g4x_compute_pipe_wm(struct intel_atomic_state *state, |
| 1370 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1371 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1372 | struct intel_crtc_state *crtc_state = |
| 1373 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1374 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 0cf771b | 2021-05-14 15:57:39 +0300 | [diff] [blame] | 1375 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1376 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1377 | const struct intel_plane_state *old_plane_state; |
| 1378 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1379 | struct intel_plane *plane; |
| 1380 | enum plane_id plane_id; |
| 1381 | int i, level; |
| 1382 | unsigned int dirty = 0; |
| 1383 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1384 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1385 | old_plane_state, |
| 1386 | new_plane_state, i) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1387 | if (new_plane_state->hw.crtc != &crtc->base && |
| 1388 | old_plane_state->hw.crtc != &crtc->base) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1389 | continue; |
| 1390 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1391 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1392 | dirty |= BIT(plane->id); |
| 1393 | } |
| 1394 | |
| 1395 | if (!dirty) |
| 1396 | return 0; |
| 1397 | |
| 1398 | level = G4X_WM_LEVEL_NORMAL; |
| 1399 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1400 | goto out; |
| 1401 | |
| 1402 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1403 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1404 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1405 | |
| 1406 | level = G4X_WM_LEVEL_SR; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1407 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1408 | goto out; |
| 1409 | |
| 1410 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1411 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1412 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1413 | wm_state->sr.fbc = raw->fbc; |
| 1414 | |
Ville Syrjälä | 0cf771b | 2021-05-14 15:57:39 +0300 | [diff] [blame] | 1415 | wm_state->cxsr = active_planes == BIT(PLANE_PRIMARY); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1416 | |
| 1417 | level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1418 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1419 | goto out; |
| 1420 | |
| 1421 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1422 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1423 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1424 | wm_state->hpll.fbc = raw->fbc; |
| 1425 | |
| 1426 | wm_state->hpll_en = wm_state->cxsr; |
| 1427 | |
| 1428 | level++; |
| 1429 | |
| 1430 | out: |
| 1431 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1432 | return -EINVAL; |
| 1433 | |
| 1434 | /* invalidate the higher levels */ |
| 1435 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1436 | |
| 1437 | /* |
| 1438 | * Determine if the FBC watermark(s) can be used. IF |
| 1439 | * this isn't the case we prefer to disable the FBC |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1440 | * watermark(s) rather than disable the SR/HPLL |
| 1441 | * level(s) entirely. 'level-1' is the highest valid |
| 1442 | * level here. |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1443 | */ |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1444 | 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] | 1445 | |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1449 | static int g4x_compute_intermediate_wm(struct intel_atomic_state *state, |
| 1450 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1451 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1452 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1453 | struct intel_crtc_state *new_crtc_state = |
| 1454 | intel_atomic_get_new_crtc_state(state, crtc); |
| 1455 | const struct intel_crtc_state *old_crtc_state = |
| 1456 | intel_atomic_get_old_crtc_state(state, crtc); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1457 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1458 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1459 | 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] | 1460 | enum plane_id plane_id; |
| 1461 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1462 | if (!new_crtc_state->hw.active || |
| 1463 | drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) { |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1464 | *intermediate = *optimal; |
| 1465 | |
| 1466 | intermediate->cxsr = false; |
| 1467 | intermediate->hpll_en = false; |
| 1468 | goto out; |
| 1469 | } |
| 1470 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1471 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1472 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1473 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1474 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1475 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1476 | |
| 1477 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1478 | intermediate->wm.plane[plane_id] = |
| 1479 | max(optimal->wm.plane[plane_id], |
| 1480 | active->wm.plane[plane_id]); |
| 1481 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1482 | drm_WARN_ON(&dev_priv->drm, intermediate->wm.plane[plane_id] > |
| 1483 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1487 | active->sr.plane); |
| 1488 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1489 | active->sr.cursor); |
| 1490 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1491 | active->sr.fbc); |
| 1492 | |
| 1493 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1494 | active->hpll.plane); |
| 1495 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1496 | active->hpll.cursor); |
| 1497 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1498 | active->hpll.fbc); |
| 1499 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1500 | drm_WARN_ON(&dev_priv->drm, |
| 1501 | (intermediate->sr.plane > |
| 1502 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1503 | intermediate->sr.cursor > |
| 1504 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1505 | intermediate->cxsr); |
| 1506 | drm_WARN_ON(&dev_priv->drm, |
| 1507 | (intermediate->sr.plane > |
| 1508 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1509 | intermediate->sr.cursor > |
| 1510 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1511 | intermediate->hpll_en); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1512 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1513 | drm_WARN_ON(&dev_priv->drm, |
| 1514 | intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1515 | intermediate->fbc_en && intermediate->cxsr); |
| 1516 | drm_WARN_ON(&dev_priv->drm, |
| 1517 | intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1518 | intermediate->fbc_en && intermediate->hpll_en); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1519 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1520 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1521 | /* |
| 1522 | * If our intermediate WM are identical to the final WM, then we can |
| 1523 | * omit the post-vblank programming; only update if it's different. |
| 1524 | */ |
| 1525 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1526 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1527 | |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
| 1531 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1532 | struct g4x_wm_values *wm) |
| 1533 | { |
| 1534 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1535 | int num_active_pipes = 0; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1536 | |
| 1537 | wm->cxsr = true; |
| 1538 | wm->hpll_en = true; |
| 1539 | wm->fbc_en = true; |
| 1540 | |
| 1541 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1542 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1543 | |
| 1544 | if (!crtc->active) |
| 1545 | continue; |
| 1546 | |
| 1547 | if (!wm_state->cxsr) |
| 1548 | wm->cxsr = false; |
| 1549 | if (!wm_state->hpll_en) |
| 1550 | wm->hpll_en = false; |
| 1551 | if (!wm_state->fbc_en) |
| 1552 | wm->fbc_en = false; |
| 1553 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1554 | num_active_pipes++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1555 | } |
| 1556 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1557 | if (num_active_pipes != 1) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1558 | wm->cxsr = false; |
| 1559 | wm->hpll_en = false; |
| 1560 | wm->fbc_en = false; |
| 1561 | } |
| 1562 | |
| 1563 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1564 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1565 | enum pipe pipe = crtc->pipe; |
| 1566 | |
| 1567 | wm->pipe[pipe] = wm_state->wm; |
| 1568 | if (crtc->active && wm->cxsr) |
| 1569 | wm->sr = wm_state->sr; |
| 1570 | if (crtc->active && wm->hpll_en) |
| 1571 | wm->hpll = wm_state->hpll; |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1576 | { |
| 1577 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1578 | struct g4x_wm_values new_wm = {}; |
| 1579 | |
| 1580 | g4x_merge_wm(dev_priv, &new_wm); |
| 1581 | |
| 1582 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1583 | return; |
| 1584 | |
| 1585 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1586 | _intel_set_memory_cxsr(dev_priv, false); |
| 1587 | |
| 1588 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1589 | |
| 1590 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1591 | _intel_set_memory_cxsr(dev_priv, true); |
| 1592 | |
| 1593 | *old_wm = new_wm; |
| 1594 | } |
| 1595 | |
| 1596 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1597 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1598 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1599 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1600 | const struct intel_crtc_state *crtc_state = |
| 1601 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1602 | |
| 1603 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1604 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1605 | g4x_program_watermarks(dev_priv); |
| 1606 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1607 | } |
| 1608 | |
| 1609 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1610 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1611 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1612 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1613 | const struct intel_crtc_state *crtc_state = |
| 1614 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1615 | |
| 1616 | if (!crtc_state->wm.need_postvbl_update) |
| 1617 | return; |
| 1618 | |
| 1619 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 1620 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1621 | g4x_program_watermarks(dev_priv); |
| 1622 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1623 | } |
| 1624 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1625 | /* latency must be in 0.1us units. */ |
| 1626 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1627 | unsigned int htotal, |
| 1628 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1629 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1630 | unsigned int latency) |
| 1631 | { |
| 1632 | unsigned int ret; |
| 1633 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1634 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1635 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1636 | ret = DIV_ROUND_UP(ret, 64); |
| 1637 | |
| 1638 | return ret; |
| 1639 | } |
| 1640 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1641 | 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] | 1642 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1643 | /* all latencies in usec */ |
| 1644 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1645 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1646 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1647 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1648 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1649 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1650 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1651 | |
| 1652 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1656 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1657 | const struct intel_plane_state *plane_state, |
| 1658 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1659 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1660 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1661 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1662 | const struct drm_display_mode *pipe_mode = |
| 1663 | &crtc_state->hw.pipe_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1664 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1665 | |
| 1666 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1667 | return USHRT_MAX; |
| 1668 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1669 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1670 | return 0; |
| 1671 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1672 | cpp = plane_state->hw.fb->format->cpp[0]; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1673 | clock = pipe_mode->crtc_clock; |
| 1674 | htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1675 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1676 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1677 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1678 | /* |
| 1679 | * FIXME the formula gives values that are |
| 1680 | * too big for the cursor FIFO, and hence we |
| 1681 | * would never be able to use cursors. For |
| 1682 | * now just hardcode the watermark. |
| 1683 | */ |
| 1684 | wm = 63; |
| 1685 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1686 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1687 | dev_priv->wm.pri_latency[level] * 10); |
| 1688 | } |
| 1689 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1690 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1691 | } |
| 1692 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1693 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1694 | { |
| 1695 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1696 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1697 | } |
| 1698 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1699 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1700 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1701 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1702 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1703 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1704 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1705 | struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | 8f27dbf | 2021-05-14 15:57:40 +0300 | [diff] [blame] | 1706 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1707 | int num_active_planes = hweight8(active_planes); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1708 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1709 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1710 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1711 | unsigned int total_rate; |
| 1712 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1713 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1714 | /* |
| 1715 | * When enabling sprite0 after sprite1 has already been enabled |
| 1716 | * we tend to get an underrun unless sprite0 already has some |
| 1717 | * FIFO space allcoated. Hence we always allocate at least one |
| 1718 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1719 | * |
| 1720 | * All other plane enable sequences appear immune to this problem. |
| 1721 | */ |
| 1722 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1723 | sprite0_fifo_extra = 1; |
| 1724 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1725 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1726 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1727 | raw->plane[PLANE_SPRITE1] + |
| 1728 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1729 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1730 | if (total_rate > fifo_size) |
| 1731 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1732 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1733 | if (total_rate == 0) |
| 1734 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1735 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1736 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1737 | unsigned int rate; |
| 1738 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1739 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1740 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1741 | continue; |
| 1742 | } |
| 1743 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1744 | rate = raw->plane[plane_id]; |
| 1745 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1746 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1747 | } |
| 1748 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1749 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1750 | fifo_left -= sprite0_fifo_extra; |
| 1751 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1752 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1753 | |
| 1754 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1755 | |
| 1756 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1757 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1758 | int plane_extra; |
| 1759 | |
| 1760 | if (fifo_left == 0) |
| 1761 | break; |
| 1762 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1763 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1764 | continue; |
| 1765 | |
| 1766 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1767 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1768 | fifo_left -= plane_extra; |
| 1769 | } |
| 1770 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1771 | 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] | 1772 | |
| 1773 | /* give it all to the first plane if none are active */ |
| 1774 | if (active_planes == 0) { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1775 | drm_WARN_ON(&dev_priv->drm, fifo_left != fifo_size); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1776 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1777 | } |
| 1778 | |
| 1779 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1780 | } |
| 1781 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1782 | /* mark all levels starting from 'level' as invalid */ |
| 1783 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1784 | struct vlv_wm_state *wm_state, int level) |
| 1785 | { |
| 1786 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1787 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1788 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1789 | enum plane_id plane_id; |
| 1790 | |
| 1791 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1792 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1793 | |
| 1794 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1795 | wm_state->sr[level].plane = USHRT_MAX; |
| 1796 | } |
| 1797 | } |
| 1798 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1799 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1800 | { |
| 1801 | if (wm > fifo_size) |
| 1802 | return USHRT_MAX; |
| 1803 | else |
| 1804 | return fifo_size - wm; |
| 1805 | } |
| 1806 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1807 | /* |
| 1808 | * Starting from 'level' set all higher |
| 1809 | * levels to 'value' in the "raw" watermarks. |
| 1810 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1811 | 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] | 1812 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1813 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1814 | 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] | 1815 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1816 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1817 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1818 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1819 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1820 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1821 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1822 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1823 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1824 | |
| 1825 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1826 | } |
| 1827 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1828 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1829 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1830 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1831 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1832 | 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] | 1833 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1834 | 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] | 1835 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1836 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1837 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1838 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1839 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1840 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1844 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1845 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1846 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1847 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1848 | if (wm > max_wm) |
| 1849 | break; |
| 1850 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1851 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1852 | raw->plane[plane_id] = wm; |
| 1853 | } |
| 1854 | |
| 1855 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1856 | 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] | 1857 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1858 | out: |
| 1859 | if (dirty) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1860 | drm_dbg_kms(&dev_priv->drm, |
| 1861 | "%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n", |
| 1862 | plane->base.name, |
| 1863 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1864 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1865 | 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] | 1866 | |
| 1867 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1870 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1871 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1872 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1873 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1874 | &crtc_state->wm.vlv.raw[level]; |
| 1875 | const struct vlv_fifo_state *fifo_state = |
| 1876 | &crtc_state->wm.vlv.fifo_state; |
| 1877 | |
| 1878 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1879 | } |
| 1880 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1881 | 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] | 1882 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1883 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1884 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1885 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1886 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1889 | static int vlv_compute_pipe_wm(struct intel_atomic_state *state, |
| 1890 | struct intel_crtc *crtc) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1891 | { |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1892 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1893 | struct intel_crtc_state *crtc_state = |
| 1894 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1895 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1896 | const struct vlv_fifo_state *fifo_state = |
| 1897 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | 8f27dbf | 2021-05-14 15:57:40 +0300 | [diff] [blame] | 1898 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1899 | int num_active_planes = hweight8(active_planes); |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1900 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->uapi); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1901 | const struct intel_plane_state *old_plane_state; |
| 1902 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1903 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1904 | enum plane_id plane_id; |
| 1905 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1906 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1907 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1908 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1909 | old_plane_state, |
| 1910 | new_plane_state, i) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1911 | if (new_plane_state->hw.crtc != &crtc->base && |
| 1912 | old_plane_state->hw.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1913 | continue; |
| 1914 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1915 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1916 | dirty |= BIT(plane->id); |
| 1917 | } |
| 1918 | |
| 1919 | /* |
| 1920 | * DSPARB registers may have been reset due to the |
| 1921 | * power well being turned off. Make sure we restore |
| 1922 | * them to a consistent state even if no primary/sprite |
| 1923 | * planes are initially active. |
| 1924 | */ |
| 1925 | if (needs_modeset) |
| 1926 | crtc_state->fifo_changed = true; |
| 1927 | |
| 1928 | if (!dirty) |
| 1929 | return 0; |
| 1930 | |
| 1931 | /* cursor changes don't warrant a FIFO recompute */ |
| 1932 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1933 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1934 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1935 | const struct vlv_fifo_state *old_fifo_state = |
| 1936 | &old_crtc_state->wm.vlv.fifo_state; |
| 1937 | |
| 1938 | ret = vlv_compute_fifo(crtc_state); |
| 1939 | if (ret) |
| 1940 | return ret; |
| 1941 | |
| 1942 | if (needs_modeset || |
| 1943 | memcmp(old_fifo_state, fifo_state, |
| 1944 | sizeof(*fifo_state)) != 0) |
| 1945 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1946 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1947 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1948 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1949 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1950 | /* |
| 1951 | * Note that enabling cxsr with no primary/sprite planes |
| 1952 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1953 | * with exactly one enabled primary/sprite plane. |
| 1954 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1955 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1956 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1957 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1958 | const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 1959 | 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] | 1960 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1961 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1962 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1963 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1964 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1965 | wm_state->wm[level].plane[plane_id] = |
| 1966 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1967 | fifo_state->plane[plane_id]); |
| 1968 | } |
| 1969 | |
| 1970 | wm_state->sr[level].plane = |
| 1971 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1972 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1973 | raw->plane[PLANE_SPRITE1]), |
| 1974 | sr_fifo_size); |
| 1975 | |
| 1976 | wm_state->sr[level].cursor = |
| 1977 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1978 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1979 | } |
| 1980 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1981 | if (level == 0) |
| 1982 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1983 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1984 | /* limit to only levels we can actually handle */ |
| 1985 | wm_state->num_levels = level; |
| 1986 | |
| 1987 | /* invalidate the higher levels */ |
| 1988 | vlv_invalidate_wms(crtc, wm_state, level); |
| 1989 | |
| 1990 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1991 | } |
| 1992 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1993 | #define VLV_FIFO(plane, value) \ |
| 1994 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 1995 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1996 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1997 | struct intel_crtc *crtc) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1998 | { |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 1999 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2000 | struct intel_uncore *uncore = &dev_priv->uncore; |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2001 | const struct intel_crtc_state *crtc_state = |
| 2002 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 2003 | const struct vlv_fifo_state *fifo_state = |
| 2004 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2005 | int sprite0_start, sprite1_start, fifo_size; |
Kees Cook | 2713eb4 | 2020-02-20 16:05:17 -0800 | [diff] [blame] | 2006 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2007 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 2008 | if (!crtc_state->fifo_changed) |
| 2009 | return; |
| 2010 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2011 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 2012 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 2013 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2014 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 2015 | drm_WARN_ON(&dev_priv->drm, fifo_state->plane[PLANE_CURSOR] != 63); |
| 2016 | drm_WARN_ON(&dev_priv->drm, fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2017 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 2018 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 2019 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2020 | /* |
| 2021 | * uncore.lock serves a double purpose here. It allows us to |
| 2022 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 2023 | * it protects the DSPARB registers from getting clobbered by |
| 2024 | * parallel updates from multiple pipes. |
| 2025 | * |
| 2026 | * intel_pipe_update_start() has already disabled interrupts |
| 2027 | * for us, so a plain spin_lock() is sufficient here. |
| 2028 | */ |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2029 | spin_lock(&uncore->lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2030 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2031 | switch (crtc->pipe) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2032 | case PIPE_A: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2033 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2034 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2035 | |
| 2036 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 2037 | VLV_FIFO(SPRITEB, 0xff)); |
| 2038 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 2039 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 2040 | |
| 2041 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 2042 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 2043 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 2044 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 2045 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2046 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2047 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2048 | break; |
| 2049 | case PIPE_B: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2050 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2051 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2052 | |
| 2053 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 2054 | VLV_FIFO(SPRITED, 0xff)); |
| 2055 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 2056 | VLV_FIFO(SPRITED, sprite1_start)); |
| 2057 | |
| 2058 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 2059 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 2060 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 2061 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 2062 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2063 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2064 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2065 | break; |
| 2066 | case PIPE_C: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2067 | dsparb3 = intel_uncore_read_fw(uncore, DSPARB3); |
| 2068 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2069 | |
| 2070 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2071 | VLV_FIFO(SPRITEF, 0xff)); |
| 2072 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2073 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2074 | |
| 2075 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2076 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2077 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2078 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2079 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2080 | intel_uncore_write_fw(uncore, DSPARB3, dsparb3); |
| 2081 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2082 | break; |
| 2083 | default: |
| 2084 | break; |
| 2085 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2086 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2087 | intel_uncore_posting_read_fw(uncore, DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2088 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2089 | spin_unlock(&uncore->lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | #undef VLV_FIFO |
| 2093 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2094 | static int vlv_compute_intermediate_wm(struct intel_atomic_state *state, |
| 2095 | struct intel_crtc *crtc) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2096 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2097 | struct intel_crtc_state *new_crtc_state = |
| 2098 | intel_atomic_get_new_crtc_state(state, crtc); |
| 2099 | const struct intel_crtc_state *old_crtc_state = |
| 2100 | intel_atomic_get_old_crtc_state(state, crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2101 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2102 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2103 | 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] | 2104 | int level; |
| 2105 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2106 | if (!new_crtc_state->hw.active || |
| 2107 | 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... */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2312 | intel_uncore_write(&dev_priv->uncore, DSPFW1, FW_WM(srwm, SR) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2313 | FW_WM(8, CURSORB) | |
| 2314 | FW_WM(8, PLANEB) | |
| 2315 | FW_WM(8, PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2316 | intel_uncore_write(&dev_priv->uncore, DSPFW2, FW_WM(8, CURSORA) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2317 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2318 | /* update cursor SR watermark */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2319 | intel_uncore_write(&dev_priv->uncore, 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 | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2340 | else if (DISPLAY_VER(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 | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2354 | if (DISPLAY_VER(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 | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2369 | if (DISPLAY_VER(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 | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2381 | if (DISPLAY_VER(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)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2449 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2450 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2451 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2452 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, srwm & 0x3f); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 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 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2466 | intel_uncore_write(&dev_priv->uncore, FW_BLC, fwater_lo); |
| 2467 | intel_uncore_write(&dev_priv->uncore, FW_BLC2, fwater_hi); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 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); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2490 | fwater_lo = intel_uncore_read(&dev_priv->uncore, FW_BLC) & ~0xfff; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 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 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2496 | intel_uncore_write(&dev_priv->uncore, FW_BLC, fwater_lo); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 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 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2653 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2654 | return 3072; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2655 | else if (DISPLAY_VER(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 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2665 | if (DISPLAY_VER(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; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2668 | else if (DISPLAY_VER(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 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2682 | if (DISPLAY_VER(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 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2690 | if (DISPLAY_VER(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 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2718 | if (DISPLAY_VER(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 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2853 | if (DISPLAY_VER(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); |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2857 | int mult = IS_DG2(dev_priv) ? 2 : 1; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2858 | |
| 2859 | /* read the first set of memory latencies[0:3] */ |
| 2860 | val = 0; /* data0 to be programmed to 0 for first set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2861 | ret = sandybridge_pcode_read(dev_priv, |
| 2862 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2863 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2864 | |
| 2865 | if (ret) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2866 | drm_err(&dev_priv->drm, |
| 2867 | "SKL Mailbox read error = %d\n", ret); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2868 | return; |
| 2869 | } |
| 2870 | |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2871 | wm[0] = (val & GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2872 | wm[1] = ((val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2873 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2874 | wm[2] = ((val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2875 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2876 | wm[3] = ((val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2877 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2878 | |
| 2879 | /* read the second set of memory latencies[4:7] */ |
| 2880 | val = 1; /* data0 to be programmed to 1 for second set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2881 | ret = sandybridge_pcode_read(dev_priv, |
| 2882 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2883 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2884 | if (ret) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2885 | drm_err(&dev_priv->drm, |
| 2886 | "SKL Mailbox read error = %d\n", ret); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2887 | return; |
| 2888 | } |
| 2889 | |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2890 | wm[4] = (val & GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2891 | wm[5] = ((val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2892 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2893 | wm[6] = ((val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2894 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2895 | wm[7] = ((val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2896 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2897 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2898 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2899 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2900 | * need to be disabled. We make sure to sanitize the values out |
| 2901 | * of the punit to satisfy this requirement. |
| 2902 | */ |
| 2903 | for (level = 1; level <= max_level; level++) { |
| 2904 | if (wm[level] == 0) { |
| 2905 | for (i = level + 1; i <= max_level; i++) |
| 2906 | wm[i] = 0; |
Lucas De Marchi | 0bc3a4e | 2021-06-22 14:22:10 -0700 | [diff] [blame] | 2907 | |
| 2908 | max_level = level - 1; |
| 2909 | |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2910 | break; |
| 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | /* |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2915 | * WaWmMemoryReadLatency |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2916 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2917 | * punit doesn't take into account the read latency so we need |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2918 | * to add proper adjustement to each valid level we retrieve |
| 2919 | * from the punit when level 0 response data is 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2920 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2921 | if (wm[0] == 0) { |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2922 | u8 adjust = DISPLAY_VER(dev_priv) >= 12 ? 3 : 2; |
| 2923 | |
Lucas De Marchi | 0bc3a4e | 2021-06-22 14:22:10 -0700 | [diff] [blame] | 2924 | for (level = 0; level <= max_level; level++) |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2925 | wm[level] += adjust; |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2926 | } |
| 2927 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2928 | /* |
| 2929 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2930 | * If we could not get dimm info enable this WA to prevent from |
| 2931 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2932 | * to avoid any underrun. |
| 2933 | */ |
José Roberto de Souza | 66a2450 | 2021-01-28 08:43:12 -0800 | [diff] [blame] | 2934 | if (dev_priv->dram_info.wm_lv_0_adjust_needed) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2935 | wm[0] += 1; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2936 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2937 | u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2938 | |
| 2939 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2940 | if (wm[0] == 0) |
| 2941 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2942 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2943 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2944 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2945 | wm[4] = (sskpd >> 32) & 0x1FF; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2946 | } else if (DISPLAY_VER(dev_priv) >= 6) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2947 | u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2948 | |
| 2949 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2950 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2951 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2952 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2953 | } else if (DISPLAY_VER(dev_priv) >= 5) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2954 | u32 mltr = intel_uncore_read(uncore, MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2955 | |
| 2956 | /* ILK primary LP0 latency is 700 ns */ |
| 2957 | wm[0] = 7; |
| 2958 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2959 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2960 | } else { |
| 2961 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2962 | } |
| 2963 | } |
| 2964 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2965 | 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] | 2966 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2967 | { |
| 2968 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2969 | if (DISPLAY_VER(dev_priv) == 5) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2970 | wm[0] = 13; |
| 2971 | } |
| 2972 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2973 | 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] | 2974 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2975 | { |
| 2976 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2977 | if (DISPLAY_VER(dev_priv) == 5) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2978 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2979 | } |
| 2980 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2981 | 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] | 2982 | { |
| 2983 | /* how many WM levels are we expecting */ |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 2984 | if (HAS_HW_SAGV_WM(dev_priv)) |
| 2985 | return 5; |
| 2986 | else if (DISPLAY_VER(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2987 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2988 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2989 | return 4; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2990 | else if (DISPLAY_VER(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2991 | return 3; |
| 2992 | else |
| 2993 | return 2; |
| 2994 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2995 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2996 | 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] | 2997 | const char *name, |
Linus Torvalds | e7c6e40 | 2021-04-27 17:05:53 -0700 | [diff] [blame] | 2998 | const u16 wm[]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2999 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3000 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3001 | |
| 3002 | for (level = 0; level <= max_level; level++) { |
| 3003 | unsigned int latency = wm[level]; |
| 3004 | |
| 3005 | if (latency == 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3006 | drm_dbg_kms(&dev_priv->drm, |
| 3007 | "%s WM%d latency not provided\n", |
| 3008 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3009 | continue; |
| 3010 | } |
| 3011 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3012 | /* |
| 3013 | * - latencies are in us on gen9. |
| 3014 | * - before then, WM1+ latency values are in 0.5us units |
| 3015 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3016 | if (DISPLAY_VER(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3017 | latency *= 10; |
| 3018 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3019 | latency *= 5; |
| 3020 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3021 | drm_dbg_kms(&dev_priv->drm, |
| 3022 | "%s WM%d latency %u (%u.%u usec)\n", name, level, |
| 3023 | wm[level], latency / 10, latency % 10); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3024 | } |
| 3025 | } |
| 3026 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3027 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3028 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3029 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3030 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3031 | |
| 3032 | if (wm[0] >= min) |
| 3033 | return false; |
| 3034 | |
| 3035 | wm[0] = max(wm[0], min); |
| 3036 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3037 | 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] | 3038 | |
| 3039 | return true; |
| 3040 | } |
| 3041 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3042 | 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] | 3043 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3044 | bool changed; |
| 3045 | |
| 3046 | /* |
| 3047 | * The BIOS provided WM memory latency values are often |
| 3048 | * inadequate for high resolution displays. Adjust them. |
| 3049 | */ |
| 3050 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 3051 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 3052 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 3053 | |
| 3054 | if (!changed) |
| 3055 | return; |
| 3056 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3057 | drm_dbg_kms(&dev_priv->drm, |
| 3058 | "WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3059 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3060 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3061 | 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] | 3062 | } |
| 3063 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3064 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 3065 | { |
| 3066 | /* |
| 3067 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 3068 | * LP3 usage can cause vblank interrupts to be lost. |
| 3069 | * The DEIIR bit will go high but it looks like the CPU |
| 3070 | * never gets interrupted. |
| 3071 | * |
| 3072 | * It's not clear whether other interrupt source could |
| 3073 | * be affected or if this is somehow limited to vblank |
| 3074 | * interrupts only. To play it safe we disable LP3 |
| 3075 | * watermarks entirely. |
| 3076 | */ |
| 3077 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3078 | dev_priv->wm.spr_latency[3] == 0 && |
| 3079 | dev_priv->wm.cur_latency[3] == 0) |
| 3080 | return; |
| 3081 | |
| 3082 | dev_priv->wm.pri_latency[3] = 0; |
| 3083 | dev_priv->wm.spr_latency[3] = 0; |
| 3084 | dev_priv->wm.cur_latency[3] = 0; |
| 3085 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3086 | drm_dbg_kms(&dev_priv->drm, |
| 3087 | "LP3 watermarks disabled due to potential for lost interrupts\n"); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3088 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3089 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3090 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3091 | } |
| 3092 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3093 | 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] | 3094 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3095 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3096 | |
| 3097 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3098 | sizeof(dev_priv->wm.pri_latency)); |
| 3099 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3100 | sizeof(dev_priv->wm.pri_latency)); |
| 3101 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3102 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3103 | 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] | 3104 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3105 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3106 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3107 | 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] | 3108 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3109 | if (DISPLAY_VER(dev_priv) == 6) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3110 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3111 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3112 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3113 | } |
| 3114 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3115 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3116 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3117 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3118 | 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] | 3119 | } |
| 3120 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3121 | 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] | 3122 | struct intel_pipe_wm *pipe_wm) |
| 3123 | { |
| 3124 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3125 | const struct intel_wm_config config = { |
| 3126 | .num_pipes_active = 1, |
| 3127 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3128 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3129 | }; |
| 3130 | struct ilk_wm_maximums max; |
| 3131 | |
| 3132 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3133 | 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] | 3134 | |
| 3135 | /* At least LP0 must be valid */ |
| 3136 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3137 | drm_dbg_kms(&dev_priv->drm, "LP0 watermark invalid\n"); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3138 | return false; |
| 3139 | } |
| 3140 | |
| 3141 | return true; |
| 3142 | } |
| 3143 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3144 | /* Compute new watermarks for the pipe */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3145 | static int ilk_compute_pipe_wm(struct intel_atomic_state *state, |
| 3146 | struct intel_crtc *crtc) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3147 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3148 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 3149 | struct intel_crtc_state *crtc_state = |
| 3150 | intel_atomic_get_new_crtc_state(state, crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3151 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3152 | struct intel_plane *plane; |
| 3153 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3154 | const struct intel_plane_state *pristate = NULL; |
| 3155 | const struct intel_plane_state *sprstate = NULL; |
| 3156 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3157 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3158 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3159 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3160 | pipe_wm = &crtc_state->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3161 | |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3162 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 3163 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 3164 | pristate = plane_state; |
| 3165 | else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
| 3166 | sprstate = plane_state; |
| 3167 | else if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 3168 | curstate = plane_state; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3169 | } |
| 3170 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 3171 | pipe_wm->pipe_enabled = crtc_state->hw.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3172 | if (sprstate) { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 3173 | pipe_wm->sprites_enabled = sprstate->uapi.visible; |
| 3174 | pipe_wm->sprites_scaled = sprstate->uapi.visible && |
| 3175 | (drm_rect_width(&sprstate->uapi.dst) != drm_rect_width(&sprstate->uapi.src) >> 16 || |
| 3176 | 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] | 3177 | } |
| 3178 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3179 | usable_level = max_level; |
| 3180 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3181 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3182 | if (DISPLAY_VER(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3183 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3184 | |
| 3185 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3186 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3187 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3188 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3189 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3190 | ilk_compute_wm_level(dev_priv, crtc, 0, crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3191 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3192 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3193 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3194 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3195 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3196 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3197 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3198 | for (level = 1; level <= usable_level; level++) { |
| 3199 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3200 | |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3201 | ilk_compute_wm_level(dev_priv, crtc, level, crtc_state, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3202 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3203 | |
| 3204 | /* |
| 3205 | * Disable any watermark level that exceeds the |
| 3206 | * register maximums since such watermarks are |
| 3207 | * always invalid. |
| 3208 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3209 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3210 | memset(wm, 0, sizeof(*wm)); |
| 3211 | break; |
| 3212 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3213 | } |
| 3214 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3215 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3219 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3220 | * state and the new state. These can be programmed to the hardware |
| 3221 | * immediately. |
| 3222 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3223 | static int ilk_compute_intermediate_wm(struct intel_atomic_state *state, |
| 3224 | struct intel_crtc *crtc) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3225 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3226 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3227 | struct intel_crtc_state *new_crtc_state = |
| 3228 | intel_atomic_get_new_crtc_state(state, crtc); |
| 3229 | const struct intel_crtc_state *old_crtc_state = |
| 3230 | intel_atomic_get_old_crtc_state(state, crtc); |
| 3231 | struct intel_pipe_wm *a = &new_crtc_state->wm.ilk.intermediate; |
| 3232 | const struct intel_pipe_wm *b = &old_crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3233 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3234 | |
| 3235 | /* |
| 3236 | * Start with the final, target watermarks, then combine with the |
| 3237 | * currently active watermarks to get values that are safe both before |
| 3238 | * and after the vblank. |
| 3239 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3240 | *a = new_crtc_state->wm.ilk.optimal; |
| 3241 | if (!new_crtc_state->hw.active || |
| 3242 | drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) || |
| 3243 | state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3244 | return 0; |
| 3245 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3246 | a->pipe_enabled |= b->pipe_enabled; |
| 3247 | a->sprites_enabled |= b->sprites_enabled; |
| 3248 | a->sprites_scaled |= b->sprites_scaled; |
| 3249 | |
| 3250 | for (level = 0; level <= max_level; level++) { |
| 3251 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3252 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3253 | |
| 3254 | a_wm->enable &= b_wm->enable; |
| 3255 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3256 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3257 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3258 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3259 | } |
| 3260 | |
| 3261 | /* |
| 3262 | * We need to make sure that these merged watermark values are |
| 3263 | * actually a valid configuration themselves. If they're not, |
| 3264 | * there's no safe way to transition from the old state to |
| 3265 | * the new state, so we need to fail the atomic transaction. |
| 3266 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3267 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3268 | return -EINVAL; |
| 3269 | |
| 3270 | /* |
| 3271 | * If our intermediate WM are identical to the final WM, then we can |
| 3272 | * omit the post-vblank programming; only update if it's different. |
| 3273 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3274 | if (memcmp(a, &new_crtc_state->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3275 | new_crtc_state->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3276 | |
| 3277 | return 0; |
| 3278 | } |
| 3279 | |
| 3280 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3281 | * Merge the watermarks from all active pipes for a specific level. |
| 3282 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3283 | 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] | 3284 | int level, |
| 3285 | struct intel_wm_level *ret_wm) |
| 3286 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3287 | const struct intel_crtc *crtc; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3288 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3289 | ret_wm->enable = true; |
| 3290 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3291 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 3292 | const struct intel_pipe_wm *active = &crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3293 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3294 | |
| 3295 | if (!active->pipe_enabled) |
| 3296 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3297 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3298 | /* |
| 3299 | * The watermark values may have been used in the past, |
| 3300 | * so we must maintain them in the registers for some |
| 3301 | * time even if the level is now disabled. |
| 3302 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3303 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3304 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3305 | |
| 3306 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3307 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3308 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3309 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3310 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | /* |
| 3314 | * Merge all low power watermarks for all active pipes. |
| 3315 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3316 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3317 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3318 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3319 | struct intel_pipe_wm *merged) |
| 3320 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3321 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3322 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3323 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3324 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3325 | if ((DISPLAY_VER(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3326 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3327 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3328 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3329 | /* ILK: FBC WM must be disabled always */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3330 | merged->fbc_wm_enabled = DISPLAY_VER(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3331 | |
| 3332 | /* merge each WM1+ level */ |
| 3333 | for (level = 1; level <= max_level; level++) { |
| 3334 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3335 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3336 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3337 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3338 | if (level > last_enabled_level) |
| 3339 | wm->enable = false; |
| 3340 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3341 | /* make sure all following levels get disabled */ |
| 3342 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3343 | |
| 3344 | /* |
| 3345 | * The spec says it is preferred to disable |
| 3346 | * FBC WMs instead of disabling a WM level. |
| 3347 | */ |
| 3348 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3349 | if (wm->enable) |
| 3350 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3351 | wm->fbc_val = 0; |
| 3352 | } |
| 3353 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3354 | |
| 3355 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3356 | /* |
| 3357 | * FIXME this is racy. FBC might get enabled later. |
| 3358 | * What we should check here is whether FBC can be |
| 3359 | * enabled sometime later. |
| 3360 | */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3361 | if (DISPLAY_VER(dev_priv) == 5 && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3362 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3363 | for (level = 2; level <= max_level; level++) { |
| 3364 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3365 | |
| 3366 | wm->enable = false; |
| 3367 | } |
| 3368 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3369 | } |
| 3370 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3371 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3372 | { |
| 3373 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3374 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3375 | } |
| 3376 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3377 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3378 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3379 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3380 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3381 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3382 | return 2 * level; |
| 3383 | else |
| 3384 | return dev_priv->wm.pri_latency[level]; |
| 3385 | } |
| 3386 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3387 | 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] | 3388 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3389 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3390 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3391 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3392 | struct intel_crtc *crtc; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3393 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3394 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3395 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3396 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3397 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3398 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3399 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3400 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3401 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3402 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3403 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3404 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3405 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3406 | /* |
| 3407 | * Maintain the watermark values even if the level is |
| 3408 | * disabled. Doing otherwise could cause underruns. |
| 3409 | */ |
| 3410 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3411 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3412 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3413 | r->cur_val; |
| 3414 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3415 | if (r->enable) |
| 3416 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3417 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3418 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3419 | results->wm_lp[wm_lp - 1] |= |
| 3420 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3421 | else |
| 3422 | results->wm_lp[wm_lp - 1] |= |
| 3423 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3424 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3425 | /* |
| 3426 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3427 | * level is disabled. Doing otherwise could cause underruns. |
| 3428 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3429 | if (DISPLAY_VER(dev_priv) <= 6 && r->spr_val) { |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 3430 | drm_WARN_ON(&dev_priv->drm, wm_lp != 1); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3431 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3432 | } else |
| 3433 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3434 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3435 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3436 | /* LP0 register values */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3437 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 3438 | enum pipe pipe = crtc->pipe; |
| 3439 | const struct intel_pipe_wm *pipe_wm = &crtc->wm.active.ilk; |
Ville Syrjälä | 0560b0c | 2020-01-20 19:47:11 +0200 | [diff] [blame] | 3440 | const struct intel_wm_level *r = &pipe_wm->wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3441 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 3442 | if (drm_WARN_ON(&dev_priv->drm, !r->enable)) |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3443 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3444 | |
| 3445 | results->wm_pipe[pipe] = |
| 3446 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3447 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3448 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3449 | } |
| 3450 | } |
| 3451 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3452 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3453 | * 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] | 3454 | static struct intel_pipe_wm * |
| 3455 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3456 | struct intel_pipe_wm *r1, |
| 3457 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3458 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3459 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3460 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3461 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3462 | for (level = 1; level <= max_level; level++) { |
| 3463 | if (r1->wm[level].enable) |
| 3464 | level1 = level; |
| 3465 | if (r2->wm[level].enable) |
| 3466 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3467 | } |
| 3468 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3469 | if (level1 == level2) { |
| 3470 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3471 | return r2; |
| 3472 | else |
| 3473 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3474 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3475 | return r1; |
| 3476 | } else { |
| 3477 | return r2; |
| 3478 | } |
| 3479 | } |
| 3480 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3481 | /* dirty bits used to track which watermarks need changes */ |
| 3482 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3483 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3484 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3485 | #define WM_DIRTY_FBC (1 << 24) |
| 3486 | #define WM_DIRTY_DDB (1 << 25) |
| 3487 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3488 | 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] | 3489 | const struct ilk_wm_values *old, |
| 3490 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3491 | { |
| 3492 | unsigned int dirty = 0; |
| 3493 | enum pipe pipe; |
| 3494 | int wm_lp; |
| 3495 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3496 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3497 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3498 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3499 | /* Must disable LP1+ watermarks too */ |
| 3500 | dirty |= WM_DIRTY_LP_ALL; |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3505 | dirty |= WM_DIRTY_FBC; |
| 3506 | /* Must disable LP1+ watermarks too */ |
| 3507 | dirty |= WM_DIRTY_LP_ALL; |
| 3508 | } |
| 3509 | |
| 3510 | if (old->partitioning != new->partitioning) { |
| 3511 | dirty |= WM_DIRTY_DDB; |
| 3512 | /* Must disable LP1+ watermarks too */ |
| 3513 | dirty |= WM_DIRTY_LP_ALL; |
| 3514 | } |
| 3515 | |
| 3516 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3517 | if (dirty & WM_DIRTY_LP_ALL) |
| 3518 | return dirty; |
| 3519 | |
| 3520 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3521 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3522 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3523 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3524 | break; |
| 3525 | } |
| 3526 | |
| 3527 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3528 | for (; wm_lp <= 3; wm_lp++) |
| 3529 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3530 | |
| 3531 | return dirty; |
| 3532 | } |
| 3533 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3534 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3535 | unsigned int dirty) |
| 3536 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3537 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3538 | bool changed = false; |
| 3539 | |
| 3540 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3541 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3542 | intel_uncore_write(&dev_priv->uncore, WM3_LP_ILK, previous->wm_lp[2]); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3543 | changed = true; |
| 3544 | } |
| 3545 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3546 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3547 | intel_uncore_write(&dev_priv->uncore, WM2_LP_ILK, previous->wm_lp[1]); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3548 | changed = true; |
| 3549 | } |
| 3550 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3551 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3552 | intel_uncore_write(&dev_priv->uncore, WM1_LP_ILK, previous->wm_lp[0]); |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3553 | changed = true; |
| 3554 | } |
| 3555 | |
| 3556 | /* |
| 3557 | * Don't touch WM1S_LP_EN here. |
| 3558 | * Doing so could cause underruns. |
| 3559 | */ |
| 3560 | |
| 3561 | return changed; |
| 3562 | } |
| 3563 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3564 | /* |
| 3565 | * The spec says we shouldn't write when we don't need, because every write |
| 3566 | * causes WMs to be re-evaluated, expending some power. |
| 3567 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3568 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3569 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3570 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3571 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3572 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3573 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3574 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3575 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3576 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3577 | return; |
| 3578 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3579 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3580 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3581 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3582 | intel_uncore_write(&dev_priv->uncore, WM0_PIPE_ILK(PIPE_A), results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3583 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3584 | intel_uncore_write(&dev_priv->uncore, WM0_PIPE_ILK(PIPE_B), results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3585 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3586 | intel_uncore_write(&dev_priv->uncore, WM0_PIPE_ILK(PIPE_C), results->wm_pipe[2]); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3587 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3588 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3589 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3590 | val = intel_uncore_read(&dev_priv->uncore, WM_MISC); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3591 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3592 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3593 | else |
| 3594 | val |= WM_MISC_DATA_PARTITION_5_6; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3595 | intel_uncore_write(&dev_priv->uncore, WM_MISC, val); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3596 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3597 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3598 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3599 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3600 | else |
| 3601 | val |= DISP_DATA_PARTITION_5_6; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3602 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL2, val); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3603 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3604 | } |
| 3605 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3606 | if (dirty & WM_DIRTY_FBC) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3607 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3608 | if (results->enable_fbc_wm) |
| 3609 | val &= ~DISP_FBC_WM_DIS; |
| 3610 | else |
| 3611 | val |= DISP_FBC_WM_DIS; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3612 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, val); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3613 | } |
| 3614 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3615 | if (dirty & WM_DIRTY_LP(1) && |
| 3616 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3617 | intel_uncore_write(&dev_priv->uncore, WM1S_LP_ILK, results->wm_lp_spr[0]); |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3618 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3619 | if (DISPLAY_VER(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3620 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3621 | intel_uncore_write(&dev_priv->uncore, WM2S_LP_IVB, results->wm_lp_spr[1]); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3622 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3623 | intel_uncore_write(&dev_priv->uncore, WM3S_LP_IVB, results->wm_lp_spr[2]); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3624 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3625 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3626 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] != results->wm_lp[0]) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3627 | intel_uncore_write(&dev_priv->uncore, WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3628 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] != results->wm_lp[1]) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3629 | intel_uncore_write(&dev_priv->uncore, WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3630 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] != results->wm_lp[2]) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3631 | intel_uncore_write(&dev_priv->uncore, WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3632 | |
| 3633 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3634 | } |
| 3635 | |
Ville Syrjälä | 60aca57 | 2019-11-27 21:05:51 +0200 | [diff] [blame] | 3636 | bool ilk_disable_lp_wm(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3637 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3638 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3639 | } |
| 3640 | |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3641 | u8 intel_enabled_dbuf_slices_mask(struct drm_i915_private *dev_priv) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3642 | { |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3643 | u8 enabled_slices = 0; |
| 3644 | enum dbuf_slice slice; |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3645 | |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3646 | for_each_dbuf_slice(dev_priv, slice) { |
| 3647 | if (intel_uncore_read(&dev_priv->uncore, |
| 3648 | DBUF_CTL_S(slice)) & DBUF_POWER_STATE) |
| 3649 | enabled_slices |= BIT(slice); |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3650 | } |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3651 | |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3652 | return enabled_slices; |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3653 | } |
| 3654 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3655 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3656 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3657 | * so assume we'll always need it in order to avoid underruns. |
| 3658 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3659 | 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] | 3660 | { |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3661 | return DISPLAY_VER(dev_priv) == 9; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3662 | } |
| 3663 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3664 | static bool |
| 3665 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3666 | { |
Matt Roper | 70bfb30 | 2021-04-07 13:39:45 -0700 | [diff] [blame] | 3667 | return DISPLAY_VER(dev_priv) >= 9 && !IS_LP(dev_priv) && |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3668 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3669 | } |
| 3670 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3671 | static void |
| 3672 | skl_setup_sagv_block_time(struct drm_i915_private *dev_priv) |
| 3673 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3674 | if (DISPLAY_VER(dev_priv) >= 12) { |
James Ausmus | da80f04 | 2019-10-09 10:23:15 -0700 | [diff] [blame] | 3675 | u32 val = 0; |
| 3676 | int ret; |
| 3677 | |
| 3678 | ret = sandybridge_pcode_read(dev_priv, |
| 3679 | GEN12_PCODE_READ_SAGV_BLOCK_TIME_US, |
| 3680 | &val, NULL); |
| 3681 | if (!ret) { |
| 3682 | dev_priv->sagv_block_time_us = val; |
| 3683 | return; |
| 3684 | } |
| 3685 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3686 | drm_dbg(&dev_priv->drm, "Couldn't read SAGV block time!\n"); |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3687 | } else if (DISPLAY_VER(dev_priv) == 11) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3688 | dev_priv->sagv_block_time_us = 10; |
| 3689 | return; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3690 | } else if (DISPLAY_VER(dev_priv) == 10) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3691 | dev_priv->sagv_block_time_us = 20; |
| 3692 | return; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3693 | } else if (DISPLAY_VER(dev_priv) == 9) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3694 | dev_priv->sagv_block_time_us = 30; |
| 3695 | return; |
| 3696 | } else { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3697 | MISSING_CASE(DISPLAY_VER(dev_priv)); |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | /* Default to an unusable block time */ |
| 3701 | dev_priv->sagv_block_time_us = -1; |
| 3702 | } |
| 3703 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3704 | /* |
| 3705 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3706 | * depending on power and performance requirements. The display engine access |
| 3707 | * to system memory is blocked during the adjustment time. Because of the |
| 3708 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3709 | * underruns if we don't meet all of the following requirements: |
| 3710 | * |
| 3711 | * - <= 1 pipe enabled |
| 3712 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3713 | * - We're not using an interlaced display configuration |
| 3714 | */ |
Ville Syrjälä | 7102404 | 2020-09-25 15:17:48 +0300 | [diff] [blame] | 3715 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3716 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3717 | { |
| 3718 | int ret; |
| 3719 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3720 | if (!intel_has_sagv(dev_priv)) |
| 3721 | return 0; |
| 3722 | |
| 3723 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3724 | return 0; |
| 3725 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3726 | drm_dbg_kms(&dev_priv->drm, "Enabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3727 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3728 | GEN9_SAGV_ENABLE); |
| 3729 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3730 | /* We don't need to wait for SAGV when enabling */ |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3731 | |
| 3732 | /* |
| 3733 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3734 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3735 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3736 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3737 | drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3738 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3739 | return 0; |
| 3740 | } else if (ret < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3741 | drm_err(&dev_priv->drm, "Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3742 | return ret; |
| 3743 | } |
| 3744 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3745 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3746 | return 0; |
| 3747 | } |
| 3748 | |
Ville Syrjälä | 7102404 | 2020-09-25 15:17:48 +0300 | [diff] [blame] | 3749 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3750 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3751 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3752 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3753 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3754 | if (!intel_has_sagv(dev_priv)) |
| 3755 | return 0; |
| 3756 | |
| 3757 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3758 | return 0; |
| 3759 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3760 | drm_dbg_kms(&dev_priv->drm, "Disabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3761 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3762 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3763 | GEN9_SAGV_DISABLE, |
| 3764 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3765 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3766 | /* |
| 3767 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3768 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3769 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3770 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3771 | drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3772 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3773 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3774 | } else if (ret < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3775 | drm_err(&dev_priv->drm, "Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3776 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3777 | } |
| 3778 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3779 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3780 | return 0; |
| 3781 | } |
| 3782 | |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3783 | void intel_sagv_pre_plane_update(struct intel_atomic_state *state) |
| 3784 | { |
| 3785 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3786 | const struct intel_bw_state *new_bw_state; |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3787 | const struct intel_bw_state *old_bw_state; |
| 3788 | u32 new_mask = 0; |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3789 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3790 | /* |
| 3791 | * Just return if we can't control SAGV or don't have it. |
| 3792 | * This is different from situation when we have SAGV but just can't |
| 3793 | * afford it due to DBuf limitation - in case if SAGV is completely |
| 3794 | * disabled in a BIOS, we are not even allowed to send a PCode request, |
| 3795 | * as it will throw an error. So have to check it here. |
| 3796 | */ |
| 3797 | if (!intel_has_sagv(dev_priv)) |
| 3798 | return; |
| 3799 | |
| 3800 | new_bw_state = intel_atomic_get_new_bw_state(state); |
| 3801 | if (!new_bw_state) |
| 3802 | return; |
| 3803 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3804 | if (DISPLAY_VER(dev_priv) < 11 && !intel_can_enable_sagv(dev_priv, new_bw_state)) { |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3805 | intel_disable_sagv(dev_priv); |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3806 | return; |
| 3807 | } |
| 3808 | |
| 3809 | old_bw_state = intel_atomic_get_old_bw_state(state); |
| 3810 | /* |
| 3811 | * Nothing to mask |
| 3812 | */ |
| 3813 | if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask) |
| 3814 | return; |
| 3815 | |
| 3816 | new_mask = old_bw_state->qgv_points_mask | new_bw_state->qgv_points_mask; |
| 3817 | |
| 3818 | /* |
| 3819 | * If new mask is zero - means there is nothing to mask, |
| 3820 | * we can only unmask, which should be done in unmask. |
| 3821 | */ |
| 3822 | if (!new_mask) |
| 3823 | return; |
| 3824 | |
| 3825 | /* |
| 3826 | * Restrict required qgv points before updating the configuration. |
| 3827 | * According to BSpec we can't mask and unmask qgv points at the same |
| 3828 | * time. Also masking should be done before updating the configuration |
| 3829 | * and unmasking afterwards. |
| 3830 | */ |
| 3831 | icl_pcode_restrict_qgv_points(dev_priv, new_mask); |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | void intel_sagv_post_plane_update(struct intel_atomic_state *state) |
| 3835 | { |
| 3836 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3837 | const struct intel_bw_state *new_bw_state; |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3838 | const struct intel_bw_state *old_bw_state; |
| 3839 | u32 new_mask = 0; |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3840 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3841 | /* |
| 3842 | * Just return if we can't control SAGV or don't have it. |
| 3843 | * This is different from situation when we have SAGV but just can't |
| 3844 | * afford it due to DBuf limitation - in case if SAGV is completely |
| 3845 | * disabled in a BIOS, we are not even allowed to send a PCode request, |
| 3846 | * as it will throw an error. So have to check it here. |
| 3847 | */ |
| 3848 | if (!intel_has_sagv(dev_priv)) |
| 3849 | return; |
| 3850 | |
| 3851 | new_bw_state = intel_atomic_get_new_bw_state(state); |
| 3852 | if (!new_bw_state) |
| 3853 | return; |
| 3854 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3855 | if (DISPLAY_VER(dev_priv) < 11 && intel_can_enable_sagv(dev_priv, new_bw_state)) { |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3856 | intel_enable_sagv(dev_priv); |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3857 | return; |
| 3858 | } |
| 3859 | |
| 3860 | old_bw_state = intel_atomic_get_old_bw_state(state); |
| 3861 | /* |
| 3862 | * Nothing to unmask |
| 3863 | */ |
| 3864 | if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask) |
| 3865 | return; |
| 3866 | |
| 3867 | new_mask = new_bw_state->qgv_points_mask; |
| 3868 | |
| 3869 | /* |
| 3870 | * Allow required qgv points after updating the configuration. |
| 3871 | * According to BSpec we can't mask and unmask qgv points at the same |
| 3872 | * time. Also masking should be done before updating the configuration |
| 3873 | * and unmasking afterwards. |
| 3874 | */ |
| 3875 | icl_pcode_restrict_qgv_points(dev_priv, new_mask); |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3876 | } |
| 3877 | |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3878 | 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] | 3879 | { |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3880 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3881 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3882 | enum plane_id plane_id; |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3883 | int max_level = INT_MAX; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3884 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3885 | if (!intel_has_sagv(dev_priv)) |
| 3886 | return false; |
| 3887 | |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3888 | if (!crtc_state->hw.active) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3889 | return true; |
Lucas De Marchi | da17223 | 2019-04-04 16:04:26 -0700 | [diff] [blame] | 3890 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 3891 | if (crtc_state->hw.pipe_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3892 | return false; |
| 3893 | |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3894 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3895 | const struct skl_plane_wm *wm = |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3896 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3897 | int level; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3898 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3899 | /* Skip this plane if it's not enabled */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3900 | if (!wm->wm[0].enable) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3901 | continue; |
| 3902 | |
| 3903 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3904 | for (level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3905 | !wm->wm[level].enable; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3906 | { } |
| 3907 | |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3908 | /* Highest common enabled wm level for all planes */ |
| 3909 | max_level = min(level, max_level); |
| 3910 | } |
| 3911 | |
| 3912 | /* No enabled planes? */ |
| 3913 | if (max_level == INT_MAX) |
| 3914 | return true; |
| 3915 | |
| 3916 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 3917 | const struct skl_plane_wm *wm = |
| 3918 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3919 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3920 | /* |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3921 | * All enabled planes must have enabled a common wm level that |
| 3922 | * can tolerate memory latencies higher than sagv_block_time_us |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3923 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3924 | if (wm->wm[0].enable && !wm->wm[max_level].can_sagv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3925 | return false; |
| 3926 | } |
| 3927 | |
| 3928 | return true; |
| 3929 | } |
| 3930 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3931 | static bool tgl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
| 3932 | { |
| 3933 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 3934 | enum plane_id plane_id; |
| 3935 | |
| 3936 | if (!crtc_state->hw.active) |
| 3937 | return true; |
| 3938 | |
| 3939 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3940 | const struct skl_plane_wm *wm = |
| 3941 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3942 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3943 | if (wm->wm[0].enable && !wm->sagv.wm0.enable) |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3944 | return false; |
| 3945 | } |
| 3946 | |
| 3947 | return true; |
| 3948 | } |
| 3949 | |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3950 | static bool intel_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
| 3951 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3952 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 3953 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3954 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3955 | if (DISPLAY_VER(dev_priv) >= 12) |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3956 | return tgl_crtc_can_enable_sagv(crtc_state); |
| 3957 | else |
| 3958 | return skl_crtc_can_enable_sagv(crtc_state); |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3959 | } |
| 3960 | |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3961 | bool intel_can_enable_sagv(struct drm_i915_private *dev_priv, |
| 3962 | const struct intel_bw_state *bw_state) |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3963 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3964 | if (DISPLAY_VER(dev_priv) < 11 && |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3965 | bw_state->active_pipes && !is_power_of_2(bw_state->active_pipes)) |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 3966 | return false; |
| 3967 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3968 | return bw_state->pipe_sagv_reject == 0; |
| 3969 | } |
| 3970 | |
| 3971 | static int intel_compute_sagv_mask(struct intel_atomic_state *state) |
| 3972 | { |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3973 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3974 | int ret; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3975 | struct intel_crtc *crtc; |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3976 | struct intel_crtc_state *new_crtc_state; |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3977 | struct intel_bw_state *new_bw_state = NULL; |
| 3978 | const struct intel_bw_state *old_bw_state = NULL; |
| 3979 | int i; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3980 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3981 | for_each_new_intel_crtc_in_state(state, crtc, |
| 3982 | new_crtc_state, i) { |
| 3983 | new_bw_state = intel_atomic_get_bw_state(state); |
| 3984 | if (IS_ERR(new_bw_state)) |
| 3985 | return PTR_ERR(new_bw_state); |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3986 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3987 | old_bw_state = intel_atomic_get_old_bw_state(state); |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3988 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3989 | if (intel_crtc_can_enable_sagv(new_crtc_state)) |
| 3990 | new_bw_state->pipe_sagv_reject &= ~BIT(crtc->pipe); |
| 3991 | else |
| 3992 | new_bw_state->pipe_sagv_reject |= BIT(crtc->pipe); |
| 3993 | } |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3994 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3995 | if (!new_bw_state) |
| 3996 | return 0; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3997 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 3998 | new_bw_state->active_pipes = |
| 3999 | intel_calc_active_pipes(state, old_bw_state->active_pipes); |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 4000 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 4001 | if (new_bw_state->active_pipes != old_bw_state->active_pipes) { |
| 4002 | ret = intel_atomic_lock_global_state(&new_bw_state->base); |
| 4003 | if (ret) |
| 4004 | return ret; |
| 4005 | } |
| 4006 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 4007 | for_each_new_intel_crtc_in_state(state, crtc, |
| 4008 | new_crtc_state, i) { |
| 4009 | struct skl_pipe_wm *pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 4010 | |
| 4011 | /* |
| 4012 | * We store use_sagv_wm in the crtc state rather than relying on |
| 4013 | * that bw state since we have no convenient way to get at the |
| 4014 | * latter from the plane commit hooks (especially in the legacy |
| 4015 | * cursor case) |
| 4016 | */ |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 4017 | pipe_wm->use_sagv_wm = !HAS_HW_SAGV_WM(dev_priv) && |
| 4018 | DISPLAY_VER(dev_priv) >= 12 && |
| 4019 | intel_can_enable_sagv(dev_priv, new_bw_state); |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 4020 | } |
| 4021 | |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 4022 | if (intel_can_enable_sagv(dev_priv, new_bw_state) != |
| 4023 | intel_can_enable_sagv(dev_priv, old_bw_state)) { |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4024 | ret = intel_atomic_serialize_global_state(&new_bw_state->base); |
| 4025 | if (ret) |
| 4026 | return ret; |
| 4027 | } else if (new_bw_state->pipe_sagv_reject != old_bw_state->pipe_sagv_reject) { |
| 4028 | ret = intel_atomic_lock_global_state(&new_bw_state->base); |
| 4029 | if (ret) |
| 4030 | return ret; |
| 4031 | } |
| 4032 | |
| 4033 | return 0; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4034 | } |
| 4035 | |
Ville Syrjälä | 944a5e3 | 2021-01-22 22:56:28 +0200 | [diff] [blame] | 4036 | static int intel_dbuf_slice_size(struct drm_i915_private *dev_priv) |
| 4037 | { |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 4038 | return INTEL_INFO(dev_priv)->dbuf.size / |
| 4039 | hweight8(INTEL_INFO(dev_priv)->dbuf.slice_mask); |
Ville Syrjälä | 944a5e3 | 2021-01-22 22:56:28 +0200 | [diff] [blame] | 4040 | } |
| 4041 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4042 | static void |
| 4043 | skl_ddb_entry_for_slices(struct drm_i915_private *dev_priv, u8 slice_mask, |
| 4044 | struct skl_ddb_entry *ddb) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 4045 | { |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4046 | int slice_size = intel_dbuf_slice_size(dev_priv); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4047 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4048 | if (!slice_mask) { |
| 4049 | ddb->start = 0; |
| 4050 | ddb->end = 0; |
| 4051 | return; |
| 4052 | } |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4053 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4054 | ddb->start = (ffs(slice_mask) - 1) * slice_size; |
| 4055 | ddb->end = fls(slice_mask) * slice_size; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4056 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4057 | WARN_ON(ddb->start >= ddb->end); |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 4058 | WARN_ON(ddb->end > INTEL_INFO(dev_priv)->dbuf.size); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4059 | } |
| 4060 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4061 | static unsigned int mbus_ddb_offset(struct drm_i915_private *i915, u8 slice_mask) |
| 4062 | { |
| 4063 | struct skl_ddb_entry ddb; |
| 4064 | |
| 4065 | if (slice_mask & (BIT(DBUF_S1) | BIT(DBUF_S2))) |
| 4066 | slice_mask = BIT(DBUF_S1); |
| 4067 | else if (slice_mask & (BIT(DBUF_S3) | BIT(DBUF_S4))) |
| 4068 | slice_mask = BIT(DBUF_S3); |
| 4069 | |
| 4070 | skl_ddb_entry_for_slices(i915, slice_mask, &ddb); |
| 4071 | |
| 4072 | return ddb.start; |
| 4073 | } |
| 4074 | |
Stanislav Lisovskiy | cd19154 | 2020-05-20 18:00:58 +0300 | [diff] [blame] | 4075 | u32 skl_ddb_dbuf_slice_mask(struct drm_i915_private *dev_priv, |
| 4076 | const struct skl_ddb_entry *entry) |
| 4077 | { |
Ville Syrjälä | 6390e5a | 2021-04-16 20:10:07 +0300 | [diff] [blame] | 4078 | int slice_size = intel_dbuf_slice_size(dev_priv); |
| 4079 | enum dbuf_slice start_slice, end_slice; |
| 4080 | u8 slice_mask = 0; |
Stanislav Lisovskiy | cd19154 | 2020-05-20 18:00:58 +0300 | [diff] [blame] | 4081 | |
| 4082 | if (!skl_ddb_entry_size(entry)) |
| 4083 | return 0; |
| 4084 | |
| 4085 | start_slice = entry->start / slice_size; |
| 4086 | end_slice = (entry->end - 1) / slice_size; |
| 4087 | |
| 4088 | /* |
| 4089 | * Per plane DDB entry can in a really worst case be on multiple slices |
| 4090 | * but single entry is anyway contigious. |
| 4091 | */ |
| 4092 | while (start_slice <= end_slice) { |
| 4093 | slice_mask |= BIT(start_slice); |
| 4094 | start_slice++; |
| 4095 | } |
| 4096 | |
| 4097 | return slice_mask; |
| 4098 | } |
| 4099 | |
Ville Syrjälä | 2791a40 | 2021-01-22 22:56:26 +0200 | [diff] [blame] | 4100 | static unsigned int intel_crtc_ddb_weight(const struct intel_crtc_state *crtc_state) |
| 4101 | { |
| 4102 | const struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode; |
| 4103 | int hdisplay, vdisplay; |
| 4104 | |
| 4105 | if (!crtc_state->hw.active) |
| 4106 | return 0; |
| 4107 | |
| 4108 | /* |
| 4109 | * Watermark/ddb requirement highly depends upon width of the |
| 4110 | * framebuffer, So instead of allocating DDB equally among pipes |
| 4111 | * distribute DDB based on resolution/width of the display. |
| 4112 | */ |
| 4113 | drm_mode_get_hv_timing(pipe_mode, &hdisplay, &vdisplay); |
| 4114 | |
| 4115 | return hdisplay; |
| 4116 | } |
| 4117 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4118 | static void intel_crtc_dbuf_weights(const struct intel_dbuf_state *dbuf_state, |
| 4119 | enum pipe for_pipe, |
| 4120 | unsigned int *weight_start, |
| 4121 | unsigned int *weight_end, |
| 4122 | unsigned int *weight_total) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4123 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4124 | struct drm_i915_private *dev_priv = |
| 4125 | to_i915(dbuf_state->base.state->base.dev); |
| 4126 | enum pipe pipe; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4127 | |
| 4128 | *weight_start = 0; |
| 4129 | *weight_end = 0; |
| 4130 | *weight_total = 0; |
| 4131 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4132 | for_each_pipe(dev_priv, pipe) { |
| 4133 | int weight = dbuf_state->weight[pipe]; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4134 | |
| 4135 | /* |
| 4136 | * Do not account pipes using other slice sets |
| 4137 | * luckily as of current BSpec slice sets do not partially |
| 4138 | * intersect(pipes share either same one slice or same slice set |
| 4139 | * i.e no partial intersection), so it is enough to check for |
| 4140 | * equality for now. |
| 4141 | */ |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4142 | if (dbuf_state->slices[pipe] != dbuf_state->slices[for_pipe]) |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4143 | continue; |
| 4144 | |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4145 | *weight_total += weight; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4146 | if (pipe < for_pipe) { |
| 4147 | *weight_start += weight; |
| 4148 | *weight_end += weight; |
| 4149 | } else if (pipe == for_pipe) { |
| 4150 | *weight_end += weight; |
| 4151 | } |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4152 | } |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | static int |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4156 | skl_crtc_allocate_ddb(struct intel_atomic_state *state, struct intel_crtc *crtc) |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4157 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4158 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4159 | unsigned int weight_total, weight_start, weight_end; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4160 | const struct intel_dbuf_state *old_dbuf_state = |
| 4161 | intel_atomic_get_old_dbuf_state(state); |
| 4162 | struct intel_dbuf_state *new_dbuf_state = |
| 4163 | intel_atomic_get_new_dbuf_state(state); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4164 | struct intel_crtc_state *crtc_state; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4165 | struct skl_ddb_entry ddb_slices; |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4166 | enum pipe pipe = crtc->pipe; |
Manasi Navare | e2bebb9 | 2021-06-03 14:53:38 -0700 | [diff] [blame] | 4167 | unsigned int mbus_offset = 0; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4168 | u32 ddb_range_size; |
| 4169 | u32 dbuf_slice_mask; |
| 4170 | u32 start, end; |
| 4171 | int ret; |
| 4172 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4173 | if (new_dbuf_state->weight[pipe] == 0) { |
| 4174 | new_dbuf_state->ddb[pipe].start = 0; |
| 4175 | new_dbuf_state->ddb[pipe].end = 0; |
| 4176 | goto out; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4177 | } |
| 4178 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4179 | dbuf_slice_mask = new_dbuf_state->slices[pipe]; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4180 | |
| 4181 | skl_ddb_entry_for_slices(dev_priv, dbuf_slice_mask, &ddb_slices); |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4182 | mbus_offset = mbus_ddb_offset(dev_priv, dbuf_slice_mask); |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4183 | ddb_range_size = skl_ddb_entry_size(&ddb_slices); |
| 4184 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4185 | intel_crtc_dbuf_weights(new_dbuf_state, pipe, |
| 4186 | &weight_start, &weight_end, &weight_total); |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4187 | |
| 4188 | start = ddb_range_size * weight_start / weight_total; |
| 4189 | end = ddb_range_size * weight_end / weight_total; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4190 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4191 | new_dbuf_state->ddb[pipe].start = ddb_slices.start - mbus_offset + start; |
| 4192 | new_dbuf_state->ddb[pipe].end = ddb_slices.start - mbus_offset + end; |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4193 | out: |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4194 | if (old_dbuf_state->slices[pipe] == new_dbuf_state->slices[pipe] && |
| 4195 | skl_ddb_entry_equal(&old_dbuf_state->ddb[pipe], |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4196 | &new_dbuf_state->ddb[pipe])) |
| 4197 | return 0; |
| 4198 | |
| 4199 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 4200 | if (ret) |
| 4201 | return ret; |
| 4202 | |
| 4203 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 4204 | if (IS_ERR(crtc_state)) |
| 4205 | return PTR_ERR(crtc_state); |
| 4206 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4207 | /* |
| 4208 | * Used for checking overlaps, so we need absolute |
| 4209 | * offsets instead of MBUS relative offsets. |
| 4210 | */ |
| 4211 | crtc_state->wm.skl.ddb.start = mbus_offset + new_dbuf_state->ddb[pipe].start; |
| 4212 | crtc_state->wm.skl.ddb.end = mbus_offset + new_dbuf_state->ddb[pipe].end; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4213 | |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 4214 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4215 | "[CRTC:%d:%s] dbuf slices 0x%x -> 0x%x, ddb (%d - %d) -> (%d - %d), active pipes 0x%x -> 0x%x\n", |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4216 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4217 | old_dbuf_state->slices[pipe], new_dbuf_state->slices[pipe], |
| 4218 | old_dbuf_state->ddb[pipe].start, old_dbuf_state->ddb[pipe].end, |
| 4219 | new_dbuf_state->ddb[pipe].start, new_dbuf_state->ddb[pipe].end, |
| 4220 | old_dbuf_state->active_pipes, new_dbuf_state->active_pipes); |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4221 | |
| 4222 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4225 | static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 4226 | int width, const struct drm_format_info *format, |
| 4227 | u64 modifier, unsigned int rotation, |
| 4228 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 4229 | int color_plane); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4230 | 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] | 4231 | int level, |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 4232 | unsigned int latency, |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4233 | const struct skl_wm_params *wp, |
| 4234 | const struct skl_wm_level *result_prev, |
| 4235 | struct skl_wm_level *result /* out */); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4236 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4237 | static unsigned int |
| 4238 | skl_cursor_allocation(const struct intel_crtc_state *crtc_state, |
| 4239 | int num_active) |
| 4240 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 4241 | 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] | 4242 | int level, max_level = ilk_wm_max_level(dev_priv); |
| 4243 | struct skl_wm_level wm = {}; |
| 4244 | int ret, min_ddb_alloc = 0; |
| 4245 | struct skl_wm_params wp; |
| 4246 | |
| 4247 | ret = skl_compute_wm_params(crtc_state, 256, |
| 4248 | drm_format_info(DRM_FORMAT_ARGB8888), |
| 4249 | DRM_FORMAT_MOD_LINEAR, |
| 4250 | DRM_MODE_ROTATE_0, |
| 4251 | crtc_state->pixel_rate, &wp, 0); |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 4252 | drm_WARN_ON(&dev_priv->drm, ret); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4253 | |
| 4254 | for (level = 0; level <= max_level; level++) { |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 4255 | unsigned int latency = dev_priv->wm.skl_latency[level]; |
| 4256 | |
| 4257 | skl_compute_plane_wm(crtc_state, level, latency, &wp, &wm, &wm); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4258 | if (wm.min_ddb_alloc == U16_MAX) |
| 4259 | break; |
| 4260 | |
| 4261 | min_ddb_alloc = wm.min_ddb_alloc; |
| 4262 | } |
| 4263 | |
| 4264 | return max(num_active == 1 ? 32 : 8, min_ddb_alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4265 | } |
| 4266 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4267 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 4268 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4269 | { |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 4270 | entry->start = reg & DDB_ENTRY_MASK; |
| 4271 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4272 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 4273 | if (entry->end) |
| 4274 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4277 | static void |
| 4278 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 4279 | const enum pipe pipe, |
| 4280 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4281 | struct skl_ddb_entry *ddb_y, |
| 4282 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4283 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4284 | u32 val, val2; |
| 4285 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4286 | |
| 4287 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 4288 | if (plane_id == PLANE_CURSOR) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4289 | val = intel_uncore_read(&dev_priv->uncore, CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4290 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4291 | return; |
| 4292 | } |
| 4293 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4294 | val = intel_uncore_read(&dev_priv->uncore, PLANE_CTL(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4295 | |
| 4296 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4297 | if (val & PLANE_CTL_ENABLE) |
| 4298 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 4299 | val & PLANE_CTL_ORDER_RGBX, |
| 4300 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4301 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 4302 | if (DISPLAY_VER(dev_priv) >= 11) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4303 | val = intel_uncore_read(&dev_priv->uncore, PLANE_BUF_CFG(pipe, plane_id)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4304 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4305 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4306 | val = intel_uncore_read(&dev_priv->uncore, PLANE_BUF_CFG(pipe, plane_id)); |
| 4307 | val2 = intel_uncore_read(&dev_priv->uncore, PLANE_NV12_BUF_CFG(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4308 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4309 | if (fourcc && |
| 4310 | drm_format_info_is_yuv_semiplanar(drm_format_info(fourcc))) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4311 | swap(val, val2); |
| 4312 | |
| 4313 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4314 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4315 | } |
| 4316 | } |
| 4317 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4318 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 4319 | struct skl_ddb_entry *ddb_y, |
| 4320 | struct skl_ddb_entry *ddb_uv) |
| 4321 | { |
| 4322 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4323 | enum intel_display_power_domain power_domain; |
| 4324 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4325 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4326 | enum plane_id plane_id; |
| 4327 | |
| 4328 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4329 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 4330 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4331 | return; |
| 4332 | |
| 4333 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4334 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4335 | plane_id, |
| 4336 | &ddb_y[plane_id], |
| 4337 | &ddb_uv[plane_id]); |
| 4338 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4339 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4340 | } |
| 4341 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4342 | /* |
| 4343 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4344 | * The bspec defines downscale amount as: |
| 4345 | * |
| 4346 | * """ |
| 4347 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4348 | * Horizontal destination size] |
| 4349 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4350 | * Vertical destination size] |
| 4351 | * Total down scale amount = Horizontal down scale amount * |
| 4352 | * Vertical down scale amount |
| 4353 | * """ |
| 4354 | * |
| 4355 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4356 | * Caller should take care of dividing & rounding off the value. |
| 4357 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4358 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4359 | skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state, |
| 4360 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4361 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 4362 | 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] | 4363 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4364 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4365 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4366 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 4367 | if (drm_WARN_ON(&dev_priv->drm, |
| 4368 | !intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4369 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4370 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 4371 | /* |
| 4372 | * Src coordinates are already rotated by 270 degrees for |
| 4373 | * the 90/270 degree plane rotation cases (to match the |
| 4374 | * GTT mapping), hence no need to account for rotation here. |
| 4375 | * |
| 4376 | * n.b., src is 16.16 fixed point, dst is whole integer. |
| 4377 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4378 | src_w = drm_rect_width(&plane_state->uapi.src) >> 16; |
| 4379 | src_h = drm_rect_height(&plane_state->uapi.src) >> 16; |
| 4380 | dst_w = drm_rect_width(&plane_state->uapi.dst); |
| 4381 | dst_h = drm_rect_height(&plane_state->uapi.dst); |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4382 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4383 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4384 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4385 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4386 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4387 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4388 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4391 | struct dbuf_slice_conf_entry { |
| 4392 | u8 active_pipes; |
| 4393 | u8 dbuf_mask[I915_MAX_PIPES]; |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4394 | bool join_mbus; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4395 | }; |
| 4396 | |
| 4397 | /* |
| 4398 | * Table taken from Bspec 12716 |
| 4399 | * Pipes do have some preferred DBuf slice affinity, |
| 4400 | * plus there are some hardcoded requirements on how |
| 4401 | * those should be distributed for multipipe scenarios. |
| 4402 | * For more DBuf slices algorithm can get even more messy |
| 4403 | * and less readable, so decided to use a table almost |
| 4404 | * as is from BSpec itself - that way it is at least easier |
| 4405 | * to compare, change and check. |
| 4406 | */ |
Jani Nikula | f8226d0 | 2020-02-19 17:45:42 +0200 | [diff] [blame] | 4407 | static const struct dbuf_slice_conf_entry icl_allowed_dbufs[] = |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4408 | /* Autogenerated with igt/tools/intel_dbuf_map tool: */ |
| 4409 | { |
| 4410 | { |
| 4411 | .active_pipes = BIT(PIPE_A), |
| 4412 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4413 | [PIPE_A] = BIT(DBUF_S1), |
| 4414 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4415 | }, |
| 4416 | { |
| 4417 | .active_pipes = BIT(PIPE_B), |
| 4418 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4419 | [PIPE_B] = BIT(DBUF_S1), |
| 4420 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4421 | }, |
| 4422 | { |
| 4423 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4424 | .dbuf_mask = { |
| 4425 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4426 | [PIPE_B] = BIT(DBUF_S2), |
| 4427 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4428 | }, |
| 4429 | { |
| 4430 | .active_pipes = BIT(PIPE_C), |
| 4431 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4432 | [PIPE_C] = BIT(DBUF_S2), |
| 4433 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4434 | }, |
| 4435 | { |
| 4436 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4437 | .dbuf_mask = { |
| 4438 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4439 | [PIPE_C] = BIT(DBUF_S2), |
| 4440 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4441 | }, |
| 4442 | { |
| 4443 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4444 | .dbuf_mask = { |
| 4445 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4446 | [PIPE_C] = BIT(DBUF_S2), |
| 4447 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4448 | }, |
| 4449 | { |
| 4450 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4451 | .dbuf_mask = { |
| 4452 | [PIPE_A] = BIT(DBUF_S1), |
| 4453 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4454 | [PIPE_C] = BIT(DBUF_S2), |
| 4455 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4456 | }, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4457 | {} |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4458 | }; |
| 4459 | |
| 4460 | /* |
| 4461 | * Table taken from Bspec 49255 |
| 4462 | * Pipes do have some preferred DBuf slice affinity, |
| 4463 | * plus there are some hardcoded requirements on how |
| 4464 | * those should be distributed for multipipe scenarios. |
| 4465 | * For more DBuf slices algorithm can get even more messy |
| 4466 | * and less readable, so decided to use a table almost |
| 4467 | * as is from BSpec itself - that way it is at least easier |
| 4468 | * to compare, change and check. |
| 4469 | */ |
Jani Nikula | f8226d0 | 2020-02-19 17:45:42 +0200 | [diff] [blame] | 4470 | static const struct dbuf_slice_conf_entry tgl_allowed_dbufs[] = |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4471 | /* Autogenerated with igt/tools/intel_dbuf_map tool: */ |
| 4472 | { |
| 4473 | { |
| 4474 | .active_pipes = BIT(PIPE_A), |
| 4475 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4476 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4477 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4478 | }, |
| 4479 | { |
| 4480 | .active_pipes = BIT(PIPE_B), |
| 4481 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4482 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4483 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4484 | }, |
| 4485 | { |
| 4486 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4487 | .dbuf_mask = { |
| 4488 | [PIPE_A] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4489 | [PIPE_B] = BIT(DBUF_S1), |
| 4490 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4491 | }, |
| 4492 | { |
| 4493 | .active_pipes = BIT(PIPE_C), |
| 4494 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4495 | [PIPE_C] = BIT(DBUF_S2) | BIT(DBUF_S1), |
| 4496 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4497 | }, |
| 4498 | { |
| 4499 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4500 | .dbuf_mask = { |
| 4501 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4502 | [PIPE_C] = BIT(DBUF_S2), |
| 4503 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4504 | }, |
| 4505 | { |
| 4506 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4507 | .dbuf_mask = { |
| 4508 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4509 | [PIPE_C] = BIT(DBUF_S2), |
| 4510 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4511 | }, |
| 4512 | { |
| 4513 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4514 | .dbuf_mask = { |
| 4515 | [PIPE_A] = BIT(DBUF_S1), |
| 4516 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4517 | [PIPE_C] = BIT(DBUF_S2), |
| 4518 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4519 | }, |
| 4520 | { |
| 4521 | .active_pipes = BIT(PIPE_D), |
| 4522 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4523 | [PIPE_D] = BIT(DBUF_S2) | BIT(DBUF_S1), |
| 4524 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4525 | }, |
| 4526 | { |
| 4527 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4528 | .dbuf_mask = { |
| 4529 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4530 | [PIPE_D] = BIT(DBUF_S2), |
| 4531 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4532 | }, |
| 4533 | { |
| 4534 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4535 | .dbuf_mask = { |
| 4536 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4537 | [PIPE_D] = BIT(DBUF_S2), |
| 4538 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4539 | }, |
| 4540 | { |
| 4541 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D), |
| 4542 | .dbuf_mask = { |
| 4543 | [PIPE_A] = BIT(DBUF_S1), |
| 4544 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4545 | [PIPE_D] = BIT(DBUF_S2), |
| 4546 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4547 | }, |
| 4548 | { |
| 4549 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4550 | .dbuf_mask = { |
| 4551 | [PIPE_C] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4552 | [PIPE_D] = BIT(DBUF_S2), |
| 4553 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4554 | }, |
| 4555 | { |
| 4556 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4557 | .dbuf_mask = { |
| 4558 | [PIPE_A] = BIT(DBUF_S1), |
| 4559 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4560 | [PIPE_D] = BIT(DBUF_S2), |
| 4561 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4562 | }, |
| 4563 | { |
| 4564 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4565 | .dbuf_mask = { |
| 4566 | [PIPE_B] = BIT(DBUF_S1), |
| 4567 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4568 | [PIPE_D] = BIT(DBUF_S2), |
| 4569 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4570 | }, |
| 4571 | { |
| 4572 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4573 | .dbuf_mask = { |
| 4574 | [PIPE_A] = BIT(DBUF_S1), |
| 4575 | [PIPE_B] = BIT(DBUF_S1), |
| 4576 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4577 | [PIPE_D] = BIT(DBUF_S2), |
| 4578 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4579 | }, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4580 | {} |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4581 | }; |
| 4582 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4583 | static const struct dbuf_slice_conf_entry dg2_allowed_dbufs[] = { |
| 4584 | { |
| 4585 | .active_pipes = BIT(PIPE_A), |
| 4586 | .dbuf_mask = { |
| 4587 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4588 | }, |
| 4589 | }, |
| 4590 | { |
| 4591 | .active_pipes = BIT(PIPE_B), |
| 4592 | .dbuf_mask = { |
| 4593 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4594 | }, |
| 4595 | }, |
| 4596 | { |
| 4597 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4598 | .dbuf_mask = { |
| 4599 | [PIPE_A] = BIT(DBUF_S1), |
| 4600 | [PIPE_B] = BIT(DBUF_S2), |
| 4601 | }, |
| 4602 | }, |
| 4603 | { |
| 4604 | .active_pipes = BIT(PIPE_C), |
| 4605 | .dbuf_mask = { |
| 4606 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4607 | }, |
| 4608 | }, |
| 4609 | { |
| 4610 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4611 | .dbuf_mask = { |
| 4612 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4613 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4614 | }, |
| 4615 | }, |
| 4616 | { |
| 4617 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4618 | .dbuf_mask = { |
| 4619 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4620 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4621 | }, |
| 4622 | }, |
| 4623 | { |
| 4624 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4625 | .dbuf_mask = { |
| 4626 | [PIPE_A] = BIT(DBUF_S1), |
| 4627 | [PIPE_B] = BIT(DBUF_S2), |
| 4628 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4629 | }, |
| 4630 | }, |
| 4631 | { |
| 4632 | .active_pipes = BIT(PIPE_D), |
| 4633 | .dbuf_mask = { |
| 4634 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4635 | }, |
| 4636 | }, |
| 4637 | { |
| 4638 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4639 | .dbuf_mask = { |
| 4640 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4641 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4642 | }, |
| 4643 | }, |
| 4644 | { |
| 4645 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4646 | .dbuf_mask = { |
| 4647 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4648 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4649 | }, |
| 4650 | }, |
| 4651 | { |
| 4652 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D), |
| 4653 | .dbuf_mask = { |
| 4654 | [PIPE_A] = BIT(DBUF_S1), |
| 4655 | [PIPE_B] = BIT(DBUF_S2), |
| 4656 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4657 | }, |
| 4658 | }, |
| 4659 | { |
| 4660 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4661 | .dbuf_mask = { |
| 4662 | [PIPE_C] = BIT(DBUF_S3), |
| 4663 | [PIPE_D] = BIT(DBUF_S4), |
| 4664 | }, |
| 4665 | }, |
| 4666 | { |
| 4667 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4668 | .dbuf_mask = { |
| 4669 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4670 | [PIPE_C] = BIT(DBUF_S3), |
| 4671 | [PIPE_D] = BIT(DBUF_S4), |
| 4672 | }, |
| 4673 | }, |
| 4674 | { |
| 4675 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4676 | .dbuf_mask = { |
| 4677 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4678 | [PIPE_C] = BIT(DBUF_S3), |
| 4679 | [PIPE_D] = BIT(DBUF_S4), |
| 4680 | }, |
| 4681 | }, |
| 4682 | { |
| 4683 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4684 | .dbuf_mask = { |
| 4685 | [PIPE_A] = BIT(DBUF_S1), |
| 4686 | [PIPE_B] = BIT(DBUF_S2), |
| 4687 | [PIPE_C] = BIT(DBUF_S3), |
| 4688 | [PIPE_D] = BIT(DBUF_S4), |
| 4689 | }, |
| 4690 | }, |
| 4691 | {} |
| 4692 | }; |
| 4693 | |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4694 | static const struct dbuf_slice_conf_entry adlp_allowed_dbufs[] = { |
| 4695 | { |
| 4696 | .active_pipes = BIT(PIPE_A), |
| 4697 | .dbuf_mask = { |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4698 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2) | BIT(DBUF_S3) | BIT(DBUF_S4), |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4699 | }, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4700 | .join_mbus = true, |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4701 | }, |
| 4702 | { |
| 4703 | .active_pipes = BIT(PIPE_B), |
| 4704 | .dbuf_mask = { |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4705 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2) | BIT(DBUF_S3) | BIT(DBUF_S4), |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4706 | }, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4707 | .join_mbus = true, |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4708 | }, |
| 4709 | { |
| 4710 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4711 | .dbuf_mask = { |
| 4712 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4713 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4714 | }, |
| 4715 | }, |
| 4716 | { |
| 4717 | .active_pipes = BIT(PIPE_C), |
| 4718 | .dbuf_mask = { |
| 4719 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4720 | }, |
| 4721 | }, |
| 4722 | { |
| 4723 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4724 | .dbuf_mask = { |
| 4725 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4726 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4727 | }, |
| 4728 | }, |
| 4729 | { |
| 4730 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4731 | .dbuf_mask = { |
| 4732 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4733 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4734 | }, |
| 4735 | }, |
| 4736 | { |
| 4737 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4738 | .dbuf_mask = { |
| 4739 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4740 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4741 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4742 | }, |
| 4743 | }, |
| 4744 | { |
| 4745 | .active_pipes = BIT(PIPE_D), |
| 4746 | .dbuf_mask = { |
| 4747 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4748 | }, |
| 4749 | }, |
| 4750 | { |
| 4751 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4752 | .dbuf_mask = { |
| 4753 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4754 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4755 | }, |
| 4756 | }, |
| 4757 | { |
| 4758 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4759 | .dbuf_mask = { |
| 4760 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4761 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4762 | }, |
| 4763 | }, |
| 4764 | { |
| 4765 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D), |
| 4766 | .dbuf_mask = { |
| 4767 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4768 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4769 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4770 | }, |
| 4771 | }, |
| 4772 | { |
| 4773 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4774 | .dbuf_mask = { |
| 4775 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4776 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4777 | }, |
| 4778 | }, |
| 4779 | { |
| 4780 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4781 | .dbuf_mask = { |
| 4782 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4783 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4784 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4785 | }, |
| 4786 | }, |
| 4787 | { |
| 4788 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4789 | .dbuf_mask = { |
| 4790 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4791 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4792 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4793 | }, |
| 4794 | }, |
| 4795 | { |
| 4796 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4797 | .dbuf_mask = { |
| 4798 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4799 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4800 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4801 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4802 | }, |
| 4803 | }, |
| 4804 | {} |
| 4805 | |
| 4806 | }; |
| 4807 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4808 | static bool check_mbus_joined(u8 active_pipes, |
| 4809 | const struct dbuf_slice_conf_entry *dbuf_slices) |
| 4810 | { |
| 4811 | int i; |
| 4812 | |
| 4813 | for (i = 0; i < dbuf_slices[i].active_pipes; i++) { |
| 4814 | if (dbuf_slices[i].active_pipes == active_pipes) |
| 4815 | return dbuf_slices[i].join_mbus; |
| 4816 | } |
| 4817 | return false; |
| 4818 | } |
| 4819 | |
| 4820 | static bool adlp_check_mbus_joined(u8 active_pipes) |
| 4821 | { |
| 4822 | return check_mbus_joined(active_pipes, adlp_allowed_dbufs); |
| 4823 | } |
| 4824 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4825 | static u8 compute_dbuf_slices(enum pipe pipe, u8 active_pipes, |
| 4826 | const struct dbuf_slice_conf_entry *dbuf_slices) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4827 | { |
| 4828 | int i; |
| 4829 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4830 | for (i = 0; i < dbuf_slices[i].active_pipes; i++) { |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4831 | if (dbuf_slices[i].active_pipes == active_pipes) |
| 4832 | return dbuf_slices[i].dbuf_mask[pipe]; |
| 4833 | } |
| 4834 | return 0; |
| 4835 | } |
| 4836 | |
| 4837 | /* |
| 4838 | * This function finds an entry with same enabled pipe configuration and |
| 4839 | * returns correspondent DBuf slice mask as stated in BSpec for particular |
| 4840 | * platform. |
| 4841 | */ |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4842 | static u8 icl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4843 | { |
| 4844 | /* |
| 4845 | * FIXME: For ICL this is still a bit unclear as prev BSpec revision |
| 4846 | * required calculating "pipe ratio" in order to determine |
| 4847 | * if one or two slices can be used for single pipe configurations |
| 4848 | * as additional constraint to the existing table. |
| 4849 | * However based on recent info, it should be not "pipe ratio" |
| 4850 | * but rather ratio between pixel_rate and cdclk with additional |
| 4851 | * constants, so for now we are using only table until this is |
| 4852 | * clarified. Also this is the reason why crtc_state param is |
| 4853 | * still here - we will need it once those additional constraints |
| 4854 | * pop up. |
| 4855 | */ |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4856 | return compute_dbuf_slices(pipe, active_pipes, icl_allowed_dbufs); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4857 | } |
| 4858 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4859 | static u8 tgl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4860 | { |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4861 | return compute_dbuf_slices(pipe, active_pipes, tgl_allowed_dbufs); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4862 | } |
| 4863 | |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4864 | static u32 adlp_compute_dbuf_slices(enum pipe pipe, u32 active_pipes) |
| 4865 | { |
| 4866 | return compute_dbuf_slices(pipe, active_pipes, adlp_allowed_dbufs); |
| 4867 | } |
| 4868 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4869 | static u32 dg2_compute_dbuf_slices(enum pipe pipe, u32 active_pipes) |
| 4870 | { |
| 4871 | return compute_dbuf_slices(pipe, active_pipes, dg2_allowed_dbufs); |
| 4872 | } |
| 4873 | |
Ville Syrjälä | 2d42f32 | 2021-01-22 22:56:27 +0200 | [diff] [blame] | 4874 | static u8 skl_compute_dbuf_slices(struct intel_crtc *crtc, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4875 | { |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4876 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4877 | enum pipe pipe = crtc->pipe; |
| 4878 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4879 | if (IS_DG2(dev_priv)) |
| 4880 | return dg2_compute_dbuf_slices(pipe, active_pipes); |
| 4881 | else if (IS_ALDERLAKE_P(dev_priv)) |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4882 | return adlp_compute_dbuf_slices(pipe, active_pipes); |
| 4883 | else if (DISPLAY_VER(dev_priv) == 12) |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4884 | return tgl_compute_dbuf_slices(pipe, active_pipes); |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 4885 | else if (DISPLAY_VER(dev_priv) == 11) |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4886 | return icl_compute_dbuf_slices(pipe, active_pipes); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4887 | /* |
| 4888 | * For anything else just return one slice yet. |
| 4889 | * Should be extended for other platforms. |
| 4890 | */ |
Ville Syrjälä | 2f9078c | 2020-02-25 19:11:10 +0200 | [diff] [blame] | 4891 | return active_pipes & BIT(pipe) ? BIT(DBUF_S1) : 0; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4892 | } |
| 4893 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4894 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4895 | skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state, |
| 4896 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4897 | int color_plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4898 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4899 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 4900 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4901 | u32 data_rate; |
| 4902 | u32 width = 0, height = 0; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4903 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4904 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4905 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4906 | if (!plane_state->uapi.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4907 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4908 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4909 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4910 | return 0; |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4911 | |
| 4912 | if (color_plane == 1 && |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 4913 | !intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4914 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4915 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4916 | /* |
| 4917 | * Src coordinates are already rotated by 270 degrees for |
| 4918 | * the 90/270 degree plane rotation cases (to match the |
| 4919 | * GTT mapping), hence no need to account for rotation here. |
| 4920 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4921 | width = drm_rect_width(&plane_state->uapi.src) >> 16; |
| 4922 | height = drm_rect_height(&plane_state->uapi.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4923 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4924 | /* UV plane does 1/2 pixel sub-sampling */ |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4925 | if (color_plane == 1) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4926 | width /= 2; |
| 4927 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4928 | } |
| 4929 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4930 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4931 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4932 | down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4933 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4934 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4935 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4936 | rate *= fb->format->cpp[color_plane]; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4937 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4938 | } |
| 4939 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4940 | static u64 |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4941 | skl_get_total_relative_data_rate(struct intel_atomic_state *state, |
| 4942 | struct intel_crtc *crtc) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4943 | { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4944 | struct intel_crtc_state *crtc_state = |
| 4945 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4946 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4947 | struct intel_plane *plane; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4948 | u64 total_data_rate = 0; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4949 | enum plane_id plane_id; |
| 4950 | int i; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4951 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4952 | /* Calculate and cache data rate for each plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4953 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 4954 | if (plane->pipe != crtc->pipe) |
| 4955 | continue; |
| 4956 | |
| 4957 | plane_id = plane->id; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4958 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4959 | /* packed/y */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4960 | crtc_state->plane_data_rate[plane_id] = |
| 4961 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4962 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4963 | /* uv-plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4964 | crtc_state->uv_plane_data_rate[plane_id] = |
| 4965 | skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
| 4966 | } |
| 4967 | |
| 4968 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 4969 | total_data_rate += crtc_state->plane_data_rate[plane_id]; |
| 4970 | total_data_rate += crtc_state->uv_plane_data_rate[plane_id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | return total_data_rate; |
| 4974 | } |
| 4975 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4976 | static u64 |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4977 | icl_get_total_relative_data_rate(struct intel_atomic_state *state, |
| 4978 | struct intel_crtc *crtc) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4979 | { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4980 | struct intel_crtc_state *crtc_state = |
| 4981 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4982 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4983 | struct intel_plane *plane; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4984 | u64 total_data_rate = 0; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4985 | enum plane_id plane_id; |
| 4986 | int i; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4987 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4988 | /* Calculate and cache data rate for each plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4989 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 4990 | if (plane->pipe != crtc->pipe) |
| 4991 | continue; |
| 4992 | |
| 4993 | plane_id = plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4994 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 4995 | if (!plane_state->planar_linked_plane) { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4996 | crtc_state->plane_data_rate[plane_id] = |
| 4997 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4998 | } else { |
| 4999 | enum plane_id y_plane_id; |
| 5000 | |
| 5001 | /* |
| 5002 | * The slave plane might not iterate in |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5003 | * intel_atomic_crtc_state_for_each_plane_state(), |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5004 | * and needs the master plane state which may be |
| 5005 | * NULL if we try get_new_plane_state(), so we |
| 5006 | * always calculate from the master. |
| 5007 | */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5008 | if (plane_state->planar_slave) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5009 | continue; |
| 5010 | |
| 5011 | /* Y plane rate is calculated on the slave */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5012 | y_plane_id = plane_state->planar_linked_plane->id; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5013 | crtc_state->plane_data_rate[y_plane_id] = |
| 5014 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5015 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5016 | crtc_state->plane_data_rate[plane_id] = |
| 5017 | skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5018 | } |
| 5019 | } |
| 5020 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5021 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5022 | total_data_rate += crtc_state->plane_data_rate[plane_id]; |
| 5023 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5024 | return total_data_rate; |
| 5025 | } |
| 5026 | |
Ville Syrjälä | 5516e89 | 2021-02-26 17:32:03 +0200 | [diff] [blame] | 5027 | const struct skl_wm_level * |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5028 | skl_plane_wm_level(const struct skl_pipe_wm *pipe_wm, |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5029 | enum plane_id plane_id, |
| 5030 | int level) |
| 5031 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5032 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5033 | |
| 5034 | if (level == 0 && pipe_wm->use_sagv_wm) |
Ville Syrjälä | a68aa48 | 2021-02-26 17:32:01 +0200 | [diff] [blame] | 5035 | return &wm->sagv.wm0; |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5036 | |
| 5037 | return &wm->wm[level]; |
| 5038 | } |
| 5039 | |
Ville Syrjälä | 5516e89 | 2021-02-26 17:32:03 +0200 | [diff] [blame] | 5040 | const struct skl_wm_level * |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5041 | skl_plane_trans_wm(const struct skl_pipe_wm *pipe_wm, |
| 5042 | enum plane_id plane_id) |
| 5043 | { |
| 5044 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5045 | |
| 5046 | if (pipe_wm->use_sagv_wm) |
| 5047 | return &wm->sagv.trans_wm; |
| 5048 | |
| 5049 | return &wm->trans_wm; |
| 5050 | } |
| 5051 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5052 | /* |
| 5053 | * We only disable the watermarks for each plane if |
| 5054 | * they exceed the ddb allocation of said plane. This |
| 5055 | * is done so that we don't end up touching cursor |
| 5056 | * watermarks needlessly when some other plane reduces |
| 5057 | * our max possible watermark level. |
| 5058 | * |
| 5059 | * Bspec has this to say about the PLANE_WM enable bit: |
| 5060 | * "All the watermarks at this level for all enabled |
| 5061 | * planes must be enabled before the level will be used." |
| 5062 | * So this is actually safe to do. |
| 5063 | */ |
| 5064 | static void |
| 5065 | skl_check_wm_level(struct skl_wm_level *wm, u64 total) |
| 5066 | { |
| 5067 | if (wm->min_ddb_alloc > total) |
| 5068 | memset(wm, 0, sizeof(*wm)); |
| 5069 | } |
| 5070 | |
| 5071 | static void |
| 5072 | skl_check_nv12_wm_level(struct skl_wm_level *wm, struct skl_wm_level *uv_wm, |
| 5073 | u64 total, u64 uv_total) |
| 5074 | { |
| 5075 | if (wm->min_ddb_alloc > total || |
| 5076 | uv_wm->min_ddb_alloc > uv_total) { |
| 5077 | memset(wm, 0, sizeof(*wm)); |
| 5078 | memset(uv_wm, 0, sizeof(*uv_wm)); |
| 5079 | } |
| 5080 | } |
| 5081 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5082 | static int |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5083 | skl_allocate_plane_ddb(struct intel_atomic_state *state, |
| 5084 | struct intel_crtc *crtc) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5085 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5086 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5087 | struct intel_crtc_state *crtc_state = |
| 5088 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5089 | const struct intel_dbuf_state *dbuf_state = |
Ville Syrjälä | 47a1495 | 2021-01-22 22:56:30 +0200 | [diff] [blame] | 5090 | intel_atomic_get_new_dbuf_state(state); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5091 | const struct skl_ddb_entry *alloc = &dbuf_state->ddb[crtc->pipe]; |
| 5092 | int num_active = hweight8(dbuf_state->active_pipes); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5093 | u16 alloc_size, start = 0; |
| 5094 | u16 total[I915_MAX_PLANES] = {}; |
| 5095 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 5096 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5097 | enum plane_id plane_id; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5098 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5099 | int level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5100 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 5101 | /* Clear the partitioning for disabled planes. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5102 | memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y)); |
| 5103 | 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] | 5104 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5105 | if (!crtc_state->hw.active) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5106 | return 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5107 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5108 | if (DISPLAY_VER(dev_priv) >= 11) |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5109 | total_data_rate = |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5110 | icl_get_total_relative_data_rate(state, crtc); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5111 | else |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5112 | total_data_rate = |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5113 | skl_get_total_relative_data_rate(state, crtc); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5114 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 5115 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 5116 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5117 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5118 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5119 | /* Allocate fixed number of blocks for cursor. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5120 | total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5121 | alloc_size -= total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5122 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5123 | alloc->end - total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5124 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 5125 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5126 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5127 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5128 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5129 | /* |
| 5130 | * Find the highest watermark level for which we can satisfy the block |
| 5131 | * requirement of active planes. |
| 5132 | */ |
| 5133 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 5134 | blocks = 0; |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5135 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5136 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5137 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 5138 | |
| 5139 | if (plane_id == PLANE_CURSOR) { |
Vandita Kulkarni | 4ba4870 | 2019-12-16 13:36:19 +0530 | [diff] [blame] | 5140 | if (wm->wm[level].min_ddb_alloc > total[PLANE_CURSOR]) { |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5141 | drm_WARN_ON(&dev_priv->drm, |
| 5142 | wm->wm[level].min_ddb_alloc != U16_MAX); |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 5143 | blocks = U32_MAX; |
| 5144 | break; |
| 5145 | } |
| 5146 | continue; |
| 5147 | } |
| 5148 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5149 | blocks += wm->wm[level].min_ddb_alloc; |
| 5150 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5151 | } |
| 5152 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame] | 5153 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5154 | alloc_size -= blocks; |
| 5155 | break; |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | if (level < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5160 | drm_dbg_kms(&dev_priv->drm, |
| 5161 | "Requested display configuration exceeds system DDB limitations"); |
| 5162 | drm_dbg_kms(&dev_priv->drm, "minimum required %d/%d\n", |
| 5163 | blocks, alloc_size); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5164 | return -EINVAL; |
| 5165 | } |
| 5166 | |
| 5167 | /* |
| 5168 | * Grant each plane the blocks it requires at the highest achievable |
| 5169 | * watermark level, plus an extra share of the leftover blocks |
| 5170 | * proportional to its relative data rate. |
| 5171 | */ |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5172 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5173 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5174 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5175 | u64 rate; |
| 5176 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5177 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5178 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 5179 | continue; |
| 5180 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5181 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5182 | * We've accounted for all active planes; remaining planes are |
| 5183 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5184 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5185 | if (total_data_rate == 0) |
| 5186 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5187 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5188 | rate = crtc_state->plane_data_rate[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5189 | extra = min_t(u16, alloc_size, |
| 5190 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 5191 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5192 | total[plane_id] = wm->wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5193 | alloc_size -= extra; |
| 5194 | total_data_rate -= rate; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5195 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5196 | if (total_data_rate == 0) |
| 5197 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 5198 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5199 | rate = crtc_state->uv_plane_data_rate[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5200 | extra = min_t(u16, alloc_size, |
| 5201 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 5202 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5203 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5204 | alloc_size -= extra; |
| 5205 | total_data_rate -= rate; |
| 5206 | } |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5207 | 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] | 5208 | |
| 5209 | /* Set the actual DDB start/end points for each plane */ |
| 5210 | start = alloc->start; |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5211 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5212 | struct skl_ddb_entry *plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5213 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5214 | struct skl_ddb_entry *uv_plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5215 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5216 | |
| 5217 | if (plane_id == PLANE_CURSOR) |
| 5218 | continue; |
| 5219 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5220 | /* Gen11+ uses a separate plane for UV watermarks */ |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5221 | drm_WARN_ON(&dev_priv->drm, |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5222 | DISPLAY_VER(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5223 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5224 | /* Leave disabled planes at (0,0) */ |
| 5225 | if (total[plane_id]) { |
| 5226 | plane_alloc->start = start; |
| 5227 | start += total[plane_id]; |
| 5228 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5229 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5230 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5231 | if (uv_total[plane_id]) { |
| 5232 | uv_plane_alloc->start = start; |
| 5233 | start += uv_total[plane_id]; |
| 5234 | uv_plane_alloc->end = start; |
| 5235 | } |
| 5236 | } |
| 5237 | |
| 5238 | /* |
| 5239 | * When we calculated watermark values we didn't know how high |
| 5240 | * of a level we'd actually be able to hit, so we just marked |
| 5241 | * all levels as "enabled." Go back now and disable the ones |
| 5242 | * that aren't actually possible. |
| 5243 | */ |
| 5244 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5245 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5246 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5247 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | a301cb0 | 2019-03-12 22:58:41 +0200 | [diff] [blame] | 5248 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5249 | skl_check_nv12_wm_level(&wm->wm[level], &wm->uv_wm[level], |
| 5250 | total[plane_id], uv_total[plane_id]); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5251 | |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5252 | /* |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 5253 | * Wa_1408961008:icl, ehl |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5254 | * Underruns with WM1+ disabled |
| 5255 | */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5256 | if (DISPLAY_VER(dev_priv) == 11 && |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5257 | level == 1 && wm->wm[0].enable) { |
| 5258 | wm->wm[level].blocks = wm->wm[0].blocks; |
| 5259 | wm->wm[level].lines = wm->wm[0].lines; |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5260 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5261 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5262 | } |
| 5263 | } |
| 5264 | |
| 5265 | /* |
Ville Syrjälä | df4a50a | 2021-02-26 17:31:59 +0200 | [diff] [blame] | 5266 | * Go back and disable the transition and SAGV watermarks |
| 5267 | * if it turns out we don't have enough DDB blocks for them. |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5268 | */ |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5269 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5270 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5271 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5272 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5273 | skl_check_wm_level(&wm->trans_wm, total[plane_id]); |
| 5274 | skl_check_wm_level(&wm->sagv.wm0, total[plane_id]); |
| 5275 | skl_check_wm_level(&wm->sagv.trans_wm, total[plane_id]); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5276 | } |
| 5277 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5278 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5279 | } |
| 5280 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5281 | /* |
| 5282 | * 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] | 5283 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5284 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 5285 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 5286 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5287 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5288 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 5289 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5290 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5291 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5292 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5293 | |
| 5294 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5295 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5296 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5297 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5298 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5299 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5300 | if (DISPLAY_VER(dev_priv) >= 10) |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5301 | ret = add_fixed16_u32(ret, 1); |
| 5302 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5303 | return ret; |
| 5304 | } |
| 5305 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5306 | static uint_fixed_16_16_t |
| 5307 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 5308 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5309 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5310 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5311 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5312 | |
| 5313 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5314 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5315 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5316 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5317 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 5318 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5319 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5320 | return ret; |
| 5321 | } |
| 5322 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5323 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5324 | intel_get_linetime_us(const struct intel_crtc_state *crtc_state) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5325 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5326 | 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] | 5327 | u32 pixel_rate; |
| 5328 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5329 | uint_fixed_16_16_t linetime_us; |
| 5330 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 5331 | if (!crtc_state->hw.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5332 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5333 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5334 | pixel_rate = crtc_state->pixel_rate; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5335 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5336 | if (drm_WARN_ON(&dev_priv->drm, pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5337 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5338 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5339 | crtc_htotal = crtc_state->hw.pipe_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5340 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5341 | |
| 5342 | return linetime_us; |
| 5343 | } |
| 5344 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5345 | static int |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5346 | skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 5347 | int width, const struct drm_format_info *format, |
| 5348 | u64 modifier, unsigned int rotation, |
| 5349 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 5350 | int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5351 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5352 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5353 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5354 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5355 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 5356 | /* only planar format has two planes */ |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 5357 | if (color_plane == 1 && |
| 5358 | !intel_format_info_is_yuv_semiplanar(format, modifier)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5359 | drm_dbg_kms(&dev_priv->drm, |
| 5360 | "Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5361 | return -EINVAL; |
| 5362 | } |
| 5363 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5364 | wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED || |
| 5365 | modifier == I915_FORMAT_MOD_Yf_TILED || |
| 5366 | modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 5367 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 5368 | wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED; |
| 5369 | wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 5370 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 5371 | wp->is_planar = intel_format_info_is_yuv_semiplanar(format, modifier); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5372 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5373 | wp->width = width; |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 5374 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5375 | wp->width /= 2; |
| 5376 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5377 | wp->cpp = format->cpp[color_plane]; |
| 5378 | wp->plane_pixel_rate = plane_pixel_rate; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5379 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5380 | if (DISPLAY_VER(dev_priv) >= 11 && |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5381 | modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5382 | wp->dbuf_block_size = 256; |
| 5383 | else |
| 5384 | wp->dbuf_block_size = 512; |
| 5385 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5386 | if (drm_rotation_90_or_270(rotation)) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5387 | switch (wp->cpp) { |
| 5388 | case 1: |
| 5389 | wp->y_min_scanlines = 16; |
| 5390 | break; |
| 5391 | case 2: |
| 5392 | wp->y_min_scanlines = 8; |
| 5393 | break; |
| 5394 | case 4: |
| 5395 | wp->y_min_scanlines = 4; |
| 5396 | break; |
| 5397 | default: |
| 5398 | MISSING_CASE(wp->cpp); |
| 5399 | return -EINVAL; |
| 5400 | } |
| 5401 | } else { |
| 5402 | wp->y_min_scanlines = 4; |
| 5403 | } |
| 5404 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 5405 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5406 | wp->y_min_scanlines *= 2; |
| 5407 | |
| 5408 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 5409 | if (wp->y_tiled) { |
| 5410 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5411 | wp->y_min_scanlines, |
| 5412 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5413 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5414 | if (DISPLAY_VER(dev_priv) >= 10) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5415 | interm_pbpl++; |
| 5416 | |
| 5417 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 5418 | wp->y_min_scanlines); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5419 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5420 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5421 | wp->dbuf_block_size); |
| 5422 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5423 | if (!wp->x_tiled || DISPLAY_VER(dev_priv) >= 10) |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5424 | interm_pbpl++; |
| 5425 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5426 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 5427 | } |
| 5428 | |
| 5429 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 5430 | wp->plane_blocks_per_line); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5431 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5432 | wp->linetime_us = fixed16_to_u32_round_up( |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5433 | intel_get_linetime_us(crtc_state)); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5434 | |
| 5435 | return 0; |
| 5436 | } |
| 5437 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5438 | static int |
| 5439 | skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state, |
| 5440 | const struct intel_plane_state *plane_state, |
| 5441 | struct skl_wm_params *wp, int color_plane) |
| 5442 | { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5443 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5444 | int width; |
| 5445 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 5446 | /* |
| 5447 | * Src coordinates are already rotated by 270 degrees for |
| 5448 | * the 90/270 degree plane rotation cases (to match the |
| 5449 | * GTT mapping), hence no need to account for rotation here. |
| 5450 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 5451 | width = drm_rect_width(&plane_state->uapi.src) >> 16; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5452 | |
| 5453 | return skl_compute_wm_params(crtc_state, width, |
| 5454 | fb->format, fb->modifier, |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5455 | plane_state->hw.rotation, |
Ville Syrjälä | 3df3fe2 | 2020-11-06 19:30:42 +0200 | [diff] [blame] | 5456 | intel_plane_pixel_rate(crtc_state, plane_state), |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5457 | wp, color_plane); |
| 5458 | } |
| 5459 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5460 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 5461 | { |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5462 | if (DISPLAY_VER(dev_priv) >= 10) |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5463 | return true; |
| 5464 | |
| 5465 | /* The number of lines are ignored for the level 0 watermark. */ |
| 5466 | return level > 0; |
| 5467 | } |
| 5468 | |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5469 | static int skl_wm_max_lines(struct drm_i915_private *dev_priv) |
| 5470 | { |
| 5471 | if (DISPLAY_VER(dev_priv) >= 13) |
| 5472 | return 255; |
| 5473 | else |
| 5474 | return 31; |
| 5475 | } |
| 5476 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5477 | 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] | 5478 | int level, |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5479 | unsigned int latency, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5480 | const struct skl_wm_params *wp, |
| 5481 | const struct skl_wm_level *result_prev, |
| 5482 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5483 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5484 | 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] | 5485 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5486 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5487 | u32 blocks, lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 5488 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5489 | if (latency == 0) { |
| 5490 | /* reject it */ |
| 5491 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 5492 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5493 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 5494 | |
Ville Syrjälä | 25312ef | 2019-05-03 20:38:05 +0300 | [diff] [blame] | 5495 | /* |
| 5496 | * WaIncreaseLatencyIPCEnabled: kbl,cfl |
| 5497 | * Display WA #1141: kbl,cfl |
| 5498 | */ |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 5499 | if ((IS_KABYLAKE(dev_priv) || |
| 5500 | IS_COFFEELAKE(dev_priv) || |
| 5501 | IS_COMETLAKE(dev_priv)) && |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 5502 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 5503 | latency += 4; |
| 5504 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 5505 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 5506 | latency += 15; |
| 5507 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5508 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5509 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5510 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5511 | crtc_state->hw.pipe_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 5512 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5513 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5514 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5515 | if (wp->y_tiled) { |
| 5516 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5517 | } else { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5518 | if ((wp->cpp * crtc_state->hw.pipe_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5519 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5520 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 5521 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5522 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5523 | if (DISPLAY_VER(dev_priv) == 9) |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5524 | selected_result = min_fixed16(method1, method2); |
| 5525 | else |
| 5526 | selected_result = method2; |
| 5527 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5528 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5529 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5530 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5531 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5532 | blocks = fixed16_to_u32_round_up(selected_result) + 1; |
| 5533 | lines = div_round_up_fixed16(selected_result, |
| 5534 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 5535 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5536 | if (DISPLAY_VER(dev_priv) == 9) { |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5537 | /* Display WA #1125: skl,bxt,kbl */ |
| 5538 | if (level == 0 && wp->rc_surface) |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5539 | blocks += fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 5540 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5541 | /* Display WA #1126: skl,bxt,kbl */ |
| 5542 | if (level >= 1 && level <= 7) { |
| 5543 | if (wp->y_tiled) { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5544 | blocks += fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 5545 | lines += wp->y_min_scanlines; |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5546 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5547 | blocks++; |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | /* |
| 5551 | * Make sure result blocks for higher latency levels are |
| 5552 | * atleast as high as level below the current level. |
| 5553 | * Assumption in DDB algorithm optimization for special |
| 5554 | * cases. Also covers Display WA #1125 for RC. |
| 5555 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5556 | if (result_prev->blocks > blocks) |
| 5557 | blocks = result_prev->blocks; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 5558 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5559 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 5560 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5561 | if (DISPLAY_VER(dev_priv) >= 11) { |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5562 | if (wp->y_tiled) { |
| 5563 | int extra_lines; |
| 5564 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5565 | if (lines % wp->y_min_scanlines == 0) |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5566 | extra_lines = wp->y_min_scanlines; |
| 5567 | else |
| 5568 | extra_lines = wp->y_min_scanlines * 2 - |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5569 | lines % wp->y_min_scanlines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5570 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5571 | min_ddb_alloc = mul_round_up_u32_fixed16(lines + extra_lines, |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5572 | wp->plane_blocks_per_line); |
| 5573 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5574 | min_ddb_alloc = blocks + DIV_ROUND_UP(blocks, 10); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5575 | } |
| 5576 | } |
| 5577 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5578 | if (!skl_wm_has_lines(dev_priv, level)) |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5579 | lines = 0; |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5580 | |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5581 | if (lines > skl_wm_max_lines(dev_priv)) { |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5582 | /* reject it */ |
| 5583 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5584 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5585 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5586 | |
| 5587 | /* |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5588 | * If lines is valid, assume we can use this watermark level |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5589 | * for now. We'll come back and disable it after we calculate the |
| 5590 | * DDB allocation if it turns out we don't actually have enough |
| 5591 | * blocks to satisfy it. |
| 5592 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5593 | result->blocks = blocks; |
| 5594 | result->lines = lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5595 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5596 | result->min_ddb_alloc = max(min_ddb_alloc, blocks) + 1; |
| 5597 | result->enable = true; |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 5598 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5599 | if (DISPLAY_VER(dev_priv) < 12) |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 5600 | result->can_sagv = latency >= dev_priv->sagv_block_time_us; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5601 | } |
| 5602 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5603 | static void |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5604 | skl_compute_wm_levels(const struct intel_crtc_state *crtc_state, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5605 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5606 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5607 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5608 | 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] | 5609 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5610 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 5611 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5612 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5613 | struct skl_wm_level *result = &levels[level]; |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5614 | unsigned int latency = dev_priv->wm.skl_latency[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5615 | |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5616 | skl_compute_plane_wm(crtc_state, level, latency, |
| 5617 | wm_params, result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5618 | |
| 5619 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5620 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5621 | } |
| 5622 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5623 | static void tgl_compute_sagv_wm(const struct intel_crtc_state *crtc_state, |
| 5624 | const struct skl_wm_params *wm_params, |
| 5625 | struct skl_plane_wm *plane_wm) |
| 5626 | { |
| 5627 | struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); |
Ville Syrjälä | a68aa48 | 2021-02-26 17:32:01 +0200 | [diff] [blame] | 5628 | struct skl_wm_level *sagv_wm = &plane_wm->sagv.wm0; |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5629 | struct skl_wm_level *levels = plane_wm->wm; |
| 5630 | unsigned int latency = dev_priv->wm.skl_latency[0] + dev_priv->sagv_block_time_us; |
| 5631 | |
| 5632 | skl_compute_plane_wm(crtc_state, 0, latency, |
| 5633 | wm_params, &levels[0], |
| 5634 | sagv_wm); |
| 5635 | } |
| 5636 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5637 | static void skl_compute_transition_wm(struct drm_i915_private *dev_priv, |
| 5638 | struct skl_wm_level *trans_wm, |
| 5639 | const struct skl_wm_level *wm0, |
| 5640 | const struct skl_wm_params *wp) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 5641 | { |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5642 | u16 trans_min, trans_amount, trans_y_tile_min; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5643 | u16 wm0_blocks, trans_offset, blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 5644 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5645 | /* Transition WM don't make any sense if ipc is disabled */ |
| 5646 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 5647 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5648 | |
Ville Syrjälä | a7f1e8e | 2020-02-28 22:35:51 +0200 | [diff] [blame] | 5649 | /* |
| 5650 | * WaDisableTWM:skl,kbl,cfl,bxt |
| 5651 | * Transition WM are not recommended by HW team for GEN9 |
| 5652 | */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5653 | if (DISPLAY_VER(dev_priv) == 9) |
Ville Syrjälä | a7f1e8e | 2020-02-28 22:35:51 +0200 | [diff] [blame] | 5654 | return; |
| 5655 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5656 | if (DISPLAY_VER(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5657 | trans_min = 4; |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5658 | else |
| 5659 | trans_min = 14; |
| 5660 | |
| 5661 | /* Display WA #1140: glk,cnl */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5662 | if (DISPLAY_VER(dev_priv) == 10) |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5663 | trans_amount = 0; |
| 5664 | else |
| 5665 | trans_amount = 10; /* This is configurable amount */ |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5666 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5667 | trans_offset = trans_min + trans_amount; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5668 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5669 | /* |
| 5670 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 5671 | * not Result Blocks (the integer value). Pay attention to the capital |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5672 | * letters. The value wm_l0->blocks is actually Result Blocks, but |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5673 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 5674 | * and since we later will have to get the ceiling of the sum in the |
| 5675 | * transition watermarks calculation, we can just pretend Selected |
| 5676 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 5677 | * current platforms. |
| 5678 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5679 | wm0_blocks = wm0->blocks - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5680 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5681 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5682 | trans_y_tile_min = |
| 5683 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5684 | blocks = max(wm0_blocks, trans_y_tile_min) + trans_offset; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5685 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5686 | blocks = wm0_blocks + trans_offset; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5687 | } |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5688 | blocks++; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5689 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5690 | /* |
| 5691 | * Just assume we can enable the transition watermark. After |
| 5692 | * computing the DDB we'll come back and disable it if that |
| 5693 | * assumption turns out to be false. |
| 5694 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5695 | trans_wm->blocks = blocks; |
| 5696 | trans_wm->min_ddb_alloc = max_t(u16, wm0->min_ddb_alloc, blocks + 1); |
| 5697 | trans_wm->enable = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 5698 | } |
| 5699 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5700 | 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] | 5701 | const struct intel_plane_state *plane_state, |
| 5702 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5703 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5704 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 5705 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5706 | 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] | 5707 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5708 | int ret; |
| 5709 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5710 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5711 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5712 | if (ret) |
| 5713 | return ret; |
| 5714 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5715 | skl_compute_wm_levels(crtc_state, &wm_params, wm->wm); |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5716 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5717 | skl_compute_transition_wm(dev_priv, &wm->trans_wm, |
| 5718 | &wm->wm[0], &wm_params); |
| 5719 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5720 | if (DISPLAY_VER(dev_priv) >= 12) { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5721 | tgl_compute_sagv_wm(crtc_state, &wm_params, wm); |
| 5722 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5723 | skl_compute_transition_wm(dev_priv, &wm->sagv.trans_wm, |
| 5724 | &wm->sagv.wm0, &wm_params); |
| 5725 | } |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5726 | |
| 5727 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5728 | } |
| 5729 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5730 | 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] | 5731 | const struct intel_plane_state *plane_state, |
| 5732 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5733 | { |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5734 | 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] | 5735 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5736 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5737 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5738 | wm->is_planar = true; |
| 5739 | |
| 5740 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5741 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5742 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5743 | if (ret) |
| 5744 | return ret; |
| 5745 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5746 | skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5747 | |
| 5748 | return 0; |
| 5749 | } |
| 5750 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5751 | 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] | 5752 | const struct intel_plane_state *plane_state) |
| 5753 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 5754 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5755 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5756 | struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id]; |
| 5757 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5758 | int ret; |
| 5759 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5760 | memset(wm, 0, sizeof(*wm)); |
| 5761 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5762 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 5763 | return 0; |
| 5764 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5765 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5766 | plane_id, 0); |
| 5767 | if (ret) |
| 5768 | return ret; |
| 5769 | |
| 5770 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5771 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5772 | plane_id); |
| 5773 | if (ret) |
| 5774 | return ret; |
| 5775 | } |
| 5776 | |
| 5777 | return 0; |
| 5778 | } |
| 5779 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5780 | 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] | 5781 | const struct intel_plane_state *plane_state) |
| 5782 | { |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5783 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
| 5784 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 5785 | enum plane_id plane_id = plane->id; |
| 5786 | 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] | 5787 | int ret; |
| 5788 | |
| 5789 | /* Watermarks calculated in master */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5790 | if (plane_state->planar_slave) |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5791 | return 0; |
| 5792 | |
Ville Syrjälä | f99b805 | 2021-03-27 02:59:45 +0200 | [diff] [blame] | 5793 | memset(wm, 0, sizeof(*wm)); |
| 5794 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5795 | if (plane_state->planar_linked_plane) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5796 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5797 | 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] | 5798 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5799 | drm_WARN_ON(&dev_priv->drm, |
| 5800 | !intel_wm_plane_visible(crtc_state, plane_state)); |
| 5801 | drm_WARN_ON(&dev_priv->drm, !fb->format->is_yuv || |
| 5802 | fb->format->num_planes == 1); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5803 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5804 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5805 | y_plane_id, 0); |
| 5806 | if (ret) |
| 5807 | return ret; |
| 5808 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5809 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5810 | plane_id, 1); |
| 5811 | if (ret) |
| 5812 | return ret; |
| 5813 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5814 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5815 | plane_id, 0); |
| 5816 | if (ret) |
| 5817 | return ret; |
| 5818 | } |
| 5819 | |
| 5820 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5821 | } |
| 5822 | |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5823 | static int skl_build_pipe_wm(struct intel_atomic_state *state, |
| 5824 | struct intel_crtc *crtc) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5825 | { |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5826 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5827 | struct intel_crtc_state *crtc_state = |
| 5828 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5829 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5830 | struct intel_plane *plane; |
| 5831 | int ret, i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5832 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5833 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 5834 | /* |
| 5835 | * FIXME should perhaps check {old,new}_plane_crtc->hw.crtc |
| 5836 | * instead but we don't populate that correctly for NV12 Y |
| 5837 | * planes so for now hack this. |
| 5838 | */ |
| 5839 | if (plane->pipe != crtc->pipe) |
| 5840 | continue; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5841 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5842 | if (DISPLAY_VER(dev_priv) >= 11) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5843 | ret = icl_build_plane_wm(crtc_state, plane_state); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5844 | else |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5845 | ret = skl_build_plane_wm(crtc_state, plane_state); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5846 | if (ret) |
| 5847 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5848 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5849 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5850 | crtc_state->wm.skl.optimal = crtc_state->wm.skl.raw; |
| 5851 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5852 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5853 | } |
| 5854 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5855 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 5856 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5857 | const struct skl_ddb_entry *entry) |
| 5858 | { |
| 5859 | if (entry->end) |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5860 | intel_de_write_fw(dev_priv, reg, |
| 5861 | (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5862 | else |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5863 | intel_de_write_fw(dev_priv, reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5866 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5867 | i915_reg_t reg, |
| 5868 | const struct skl_wm_level *level) |
| 5869 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5870 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5871 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5872 | if (level->enable) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5873 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5874 | if (level->ignore_lines) |
| 5875 | val |= PLANE_WM_IGNORE_LINES; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5876 | val |= level->blocks; |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5877 | val |= REG_FIELD_PREP(PLANE_WM_LINES_MASK, level->lines); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5878 | |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5879 | intel_de_write_fw(dev_priv, reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5880 | } |
| 5881 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5882 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5883 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5884 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5885 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5886 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5887 | enum plane_id plane_id = plane->id; |
| 5888 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5889 | const struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
| 5890 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5891 | const struct skl_ddb_entry *ddb_y = |
| 5892 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5893 | const struct skl_ddb_entry *ddb_uv = |
| 5894 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5895 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5896 | for (level = 0; level <= max_level; level++) |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5897 | skl_write_wm_level(dev_priv, PLANE_WM(pipe, plane_id, level), |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5898 | skl_plane_wm_level(pipe_wm, plane_id, level)); |
| 5899 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5900 | skl_write_wm_level(dev_priv, PLANE_WM_TRANS(pipe, plane_id), |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5901 | skl_plane_trans_wm(pipe_wm, plane_id)); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5902 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 5903 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 5904 | skl_write_wm_level(dev_priv, PLANE_WM_SAGV(pipe, plane_id), |
| 5905 | &wm->sagv.wm0); |
| 5906 | skl_write_wm_level(dev_priv, PLANE_WM_SAGV_TRANS(pipe, plane_id), |
| 5907 | &wm->sagv.trans_wm); |
| 5908 | } |
| 5909 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5910 | if (DISPLAY_VER(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5911 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5912 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5913 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5914 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5915 | |
| 5916 | if (wm->is_planar) |
| 5917 | swap(ddb_y, ddb_uv); |
| 5918 | |
| 5919 | skl_ddb_entry_write(dev_priv, |
| 5920 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5921 | skl_ddb_entry_write(dev_priv, |
| 5922 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5923 | } |
| 5924 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5925 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5926 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5927 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5928 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5929 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5930 | enum plane_id plane_id = plane->id; |
| 5931 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5932 | const struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5933 | const struct skl_ddb_entry *ddb = |
| 5934 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5935 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5936 | for (level = 0; level <= max_level; level++) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5937 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5938 | skl_plane_wm_level(pipe_wm, plane_id, level)); |
| 5939 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5940 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), |
| 5941 | skl_plane_trans_wm(pipe_wm, plane_id)); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5942 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 5943 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 5944 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5945 | |
| 5946 | skl_write_wm_level(dev_priv, CUR_WM_SAGV(pipe), |
| 5947 | &wm->sagv.wm0); |
| 5948 | skl_write_wm_level(dev_priv, CUR_WM_SAGV_TRANS(pipe), |
| 5949 | &wm->sagv.trans_wm); |
| 5950 | } |
| 5951 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5952 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5953 | } |
| 5954 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5955 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5956 | const struct skl_wm_level *l2) |
| 5957 | { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5958 | return l1->enable == l2->enable && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5959 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5960 | l1->lines == l2->lines && |
| 5961 | l1->blocks == l2->blocks; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5962 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5963 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5964 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5965 | const struct skl_plane_wm *wm1, |
| 5966 | const struct skl_plane_wm *wm2) |
| 5967 | { |
| 5968 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5969 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5970 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | e7f54e6 | 2020-02-28 22:35:49 +0200 | [diff] [blame] | 5971 | /* |
| 5972 | * We don't check uv_wm as the hardware doesn't actually |
| 5973 | * use it. It only gets used for calculating the required |
| 5974 | * ddb allocation. |
| 5975 | */ |
| 5976 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level])) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5977 | return false; |
| 5978 | } |
| 5979 | |
Ville Syrjälä | f11449d | 2021-02-26 17:32:00 +0200 | [diff] [blame] | 5980 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm) && |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5981 | skl_wm_level_equals(&wm1->sagv.wm0, &wm2->sagv.wm0) && |
| 5982 | skl_wm_level_equals(&wm1->sagv.trans_wm, &wm2->sagv.trans_wm); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5983 | } |
| 5984 | |
Jani Nikula | 81b55ef | 2020-04-20 17:04:38 +0300 | [diff] [blame] | 5985 | static bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 5986 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5987 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5988 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 5991 | static void skl_ddb_entry_union(struct skl_ddb_entry *a, |
| 5992 | const struct skl_ddb_entry *b) |
| 5993 | { |
| 5994 | if (a->end && b->end) { |
| 5995 | a->start = min(a->start, b->start); |
| 5996 | a->end = max(a->end, b->end); |
| 5997 | } else if (b->end) { |
| 5998 | a->start = b->start; |
| 5999 | a->end = b->end; |
| 6000 | } |
| 6001 | } |
| 6002 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6003 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 6004 | const struct skl_ddb_entry *entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6005 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6006 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6007 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6008 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6009 | for (i = 0; i < num_entries; i++) { |
| 6010 | if (i != ignore_idx && |
| 6011 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 6012 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 6013 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6014 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 6015 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6016 | } |
| 6017 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 6018 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6019 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 6020 | struct intel_crtc_state *new_crtc_state) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6021 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 6022 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->uapi.state); |
| 6023 | 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] | 6024 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6025 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6026 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6027 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6028 | struct intel_plane_state *plane_state; |
| 6029 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6030 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6031 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 6032 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 6033 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 6034 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6035 | continue; |
| 6036 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6037 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6038 | if (IS_ERR(plane_state)) |
| 6039 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 6040 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6041 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | return 0; |
| 6045 | } |
| 6046 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6047 | static u8 intel_dbuf_enabled_slices(const struct intel_dbuf_state *dbuf_state) |
| 6048 | { |
| 6049 | struct drm_i915_private *dev_priv = to_i915(dbuf_state->base.state->base.dev); |
| 6050 | u8 enabled_slices; |
| 6051 | enum pipe pipe; |
| 6052 | |
| 6053 | /* |
| 6054 | * FIXME: For now we always enable slice S1 as per |
| 6055 | * the Bspec display initialization sequence. |
| 6056 | */ |
| 6057 | enabled_slices = BIT(DBUF_S1); |
| 6058 | |
| 6059 | for_each_pipe(dev_priv, pipe) |
| 6060 | enabled_slices |= dbuf_state->slices[pipe]; |
| 6061 | |
| 6062 | return enabled_slices; |
| 6063 | } |
| 6064 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6065 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6066 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6067 | { |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 6068 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 6069 | const struct intel_dbuf_state *old_dbuf_state; |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6070 | struct intel_dbuf_state *new_dbuf_state = NULL; |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 6071 | const struct intel_crtc_state *old_crtc_state; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6072 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6073 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6074 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6075 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6076 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6077 | new_dbuf_state = intel_atomic_get_dbuf_state(state); |
| 6078 | if (IS_ERR(new_dbuf_state)) |
| 6079 | return PTR_ERR(new_dbuf_state); |
| 6080 | |
| 6081 | old_dbuf_state = intel_atomic_get_old_dbuf_state(state); |
| 6082 | break; |
| 6083 | } |
| 6084 | |
| 6085 | if (!new_dbuf_state) |
| 6086 | return 0; |
| 6087 | |
| 6088 | new_dbuf_state->active_pipes = |
| 6089 | intel_calc_active_pipes(state, old_dbuf_state->active_pipes); |
| 6090 | |
| 6091 | if (old_dbuf_state->active_pipes != new_dbuf_state->active_pipes) { |
| 6092 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6093 | if (ret) |
| 6094 | return ret; |
| 6095 | } |
| 6096 | |
| 6097 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6098 | enum pipe pipe = crtc->pipe; |
| 6099 | |
| 6100 | new_dbuf_state->slices[pipe] = |
| 6101 | skl_compute_dbuf_slices(crtc, new_dbuf_state->active_pipes); |
| 6102 | |
| 6103 | if (old_dbuf_state->slices[pipe] == new_dbuf_state->slices[pipe]) |
| 6104 | continue; |
| 6105 | |
| 6106 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6107 | if (ret) |
| 6108 | return ret; |
| 6109 | } |
| 6110 | |
| 6111 | new_dbuf_state->enabled_slices = intel_dbuf_enabled_slices(new_dbuf_state); |
| 6112 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6113 | if (IS_ALDERLAKE_P(dev_priv)) |
| 6114 | new_dbuf_state->joined_mbus = adlp_check_mbus_joined(new_dbuf_state->active_pipes); |
| 6115 | |
| 6116 | if (old_dbuf_state->enabled_slices != new_dbuf_state->enabled_slices || |
| 6117 | old_dbuf_state->joined_mbus != new_dbuf_state->joined_mbus) { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6118 | ret = intel_atomic_serialize_global_state(&new_dbuf_state->base); |
| 6119 | if (ret) |
| 6120 | return ret; |
| 6121 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6122 | if (old_dbuf_state->joined_mbus != new_dbuf_state->joined_mbus) { |
| 6123 | /* TODO: Implement vblank synchronized MBUS joining changes */ |
| 6124 | ret = intel_modeset_all_pipes(state); |
| 6125 | if (ret) |
| 6126 | return ret; |
| 6127 | } |
| 6128 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6129 | drm_dbg_kms(&dev_priv->drm, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6130 | "Enabled dbuf slices 0x%x -> 0x%x (total dbuf slices 0x%x), mbus joined? %s->%s\n", |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6131 | old_dbuf_state->enabled_slices, |
| 6132 | new_dbuf_state->enabled_slices, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6133 | INTEL_INFO(dev_priv)->dbuf.slice_mask, |
| 6134 | yesno(old_dbuf_state->joined_mbus), |
| 6135 | yesno(new_dbuf_state->joined_mbus)); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6136 | } |
| 6137 | |
| 6138 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6139 | enum pipe pipe = crtc->pipe; |
| 6140 | |
| 6141 | new_dbuf_state->weight[pipe] = intel_crtc_ddb_weight(new_crtc_state); |
| 6142 | |
| 6143 | if (old_dbuf_state->weight[pipe] == new_dbuf_state->weight[pipe]) |
| 6144 | continue; |
| 6145 | |
| 6146 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6147 | if (ret) |
| 6148 | return ret; |
| 6149 | } |
| 6150 | |
| 6151 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6152 | ret = skl_crtc_allocate_ddb(state, crtc); |
| 6153 | if (ret) |
| 6154 | return ret; |
| 6155 | } |
| 6156 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6157 | 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] | 6158 | new_crtc_state, i) { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6159 | ret = skl_allocate_plane_ddb(state, crtc); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6160 | if (ret) |
| 6161 | return ret; |
| 6162 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6163 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 6164 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6165 | if (ret) |
| 6166 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6167 | } |
| 6168 | |
| 6169 | return 0; |
| 6170 | } |
| 6171 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6172 | static char enast(bool enable) |
| 6173 | { |
| 6174 | return enable ? '*' : ' '; |
| 6175 | } |
| 6176 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 6177 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6178 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6179 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6180 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 6181 | const struct intel_crtc_state *old_crtc_state; |
| 6182 | const struct intel_crtc_state *new_crtc_state; |
| 6183 | struct intel_plane *plane; |
| 6184 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 6185 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6186 | |
Jani Nikula | bdbf43d | 2019-10-28 12:38:15 +0200 | [diff] [blame] | 6187 | if (!drm_debug_enabled(DRM_UT_KMS)) |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6188 | return; |
| 6189 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6190 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 6191 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6192 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 6193 | |
| 6194 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 6195 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 6196 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6197 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6198 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6199 | const struct skl_ddb_entry *old, *new; |
| 6200 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6201 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 6202 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6203 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6204 | if (skl_ddb_entry_equal(old, new)) |
| 6205 | continue; |
| 6206 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6207 | drm_dbg_kms(&dev_priv->drm, |
| 6208 | "[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n", |
| 6209 | plane->base.base.id, plane->base.name, |
| 6210 | old->start, old->end, new->start, new->end, |
| 6211 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6212 | } |
| 6213 | |
| 6214 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6215 | enum plane_id plane_id = plane->id; |
| 6216 | const struct skl_plane_wm *old_wm, *new_wm; |
| 6217 | |
| 6218 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 6219 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 6220 | |
| 6221 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 6222 | continue; |
| 6223 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6224 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6225 | "[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm,%cstwm" |
| 6226 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm,%cstwm\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6227 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6228 | enast(old_wm->wm[0].enable), enast(old_wm->wm[1].enable), |
| 6229 | enast(old_wm->wm[2].enable), enast(old_wm->wm[3].enable), |
| 6230 | enast(old_wm->wm[4].enable), enast(old_wm->wm[5].enable), |
| 6231 | enast(old_wm->wm[6].enable), enast(old_wm->wm[7].enable), |
| 6232 | enast(old_wm->trans_wm.enable), |
| 6233 | enast(old_wm->sagv.wm0.enable), |
| 6234 | enast(old_wm->sagv.trans_wm.enable), |
| 6235 | enast(new_wm->wm[0].enable), enast(new_wm->wm[1].enable), |
| 6236 | enast(new_wm->wm[2].enable), enast(new_wm->wm[3].enable), |
| 6237 | enast(new_wm->wm[4].enable), enast(new_wm->wm[5].enable), |
| 6238 | enast(new_wm->wm[6].enable), enast(new_wm->wm[7].enable), |
| 6239 | enast(new_wm->trans_wm.enable), |
| 6240 | enast(new_wm->sagv.wm0.enable), |
| 6241 | enast(new_wm->sagv.trans_wm.enable)); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6242 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6243 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6244 | "[PLANE:%d:%s] lines %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%4d" |
| 6245 | " -> %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%4d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6246 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6247 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].lines, |
| 6248 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].lines, |
| 6249 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].lines, |
| 6250 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].lines, |
| 6251 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].lines, |
| 6252 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].lines, |
| 6253 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].lines, |
| 6254 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].lines, |
| 6255 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.lines, |
| 6256 | enast(old_wm->sagv.wm0.ignore_lines), old_wm->sagv.wm0.lines, |
| 6257 | enast(old_wm->sagv.trans_wm.ignore_lines), old_wm->sagv.trans_wm.lines, |
| 6258 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].lines, |
| 6259 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].lines, |
| 6260 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].lines, |
| 6261 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].lines, |
| 6262 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].lines, |
| 6263 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].lines, |
| 6264 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].lines, |
| 6265 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].lines, |
| 6266 | enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.lines, |
| 6267 | enast(new_wm->sagv.wm0.ignore_lines), new_wm->sagv.wm0.lines, |
| 6268 | enast(new_wm->sagv.trans_wm.ignore_lines), new_wm->sagv.trans_wm.lines); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6269 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6270 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6271 | "[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d" |
| 6272 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6273 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6274 | old_wm->wm[0].blocks, old_wm->wm[1].blocks, |
| 6275 | old_wm->wm[2].blocks, old_wm->wm[3].blocks, |
| 6276 | old_wm->wm[4].blocks, old_wm->wm[5].blocks, |
| 6277 | old_wm->wm[6].blocks, old_wm->wm[7].blocks, |
| 6278 | old_wm->trans_wm.blocks, |
| 6279 | old_wm->sagv.wm0.blocks, |
| 6280 | old_wm->sagv.trans_wm.blocks, |
| 6281 | new_wm->wm[0].blocks, new_wm->wm[1].blocks, |
| 6282 | new_wm->wm[2].blocks, new_wm->wm[3].blocks, |
| 6283 | new_wm->wm[4].blocks, new_wm->wm[5].blocks, |
| 6284 | new_wm->wm[6].blocks, new_wm->wm[7].blocks, |
| 6285 | new_wm->trans_wm.blocks, |
| 6286 | new_wm->sagv.wm0.blocks, |
| 6287 | new_wm->sagv.trans_wm.blocks); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6288 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6289 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6290 | "[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d" |
| 6291 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6292 | plane->base.base.id, plane->base.name, |
| 6293 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 6294 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 6295 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 6296 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 6297 | old_wm->trans_wm.min_ddb_alloc, |
Ville Syrjälä | a68aa48 | 2021-02-26 17:32:01 +0200 | [diff] [blame] | 6298 | old_wm->sagv.wm0.min_ddb_alloc, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6299 | old_wm->sagv.trans_wm.min_ddb_alloc, |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6300 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 6301 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 6302 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 6303 | 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] | 6304 | new_wm->trans_wm.min_ddb_alloc, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6305 | new_wm->sagv.wm0.min_ddb_alloc, |
| 6306 | new_wm->sagv.trans_wm.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6307 | } |
| 6308 | } |
| 6309 | } |
| 6310 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6311 | static bool skl_plane_selected_wm_equals(struct intel_plane *plane, |
| 6312 | const struct skl_pipe_wm *old_pipe_wm, |
| 6313 | const struct skl_pipe_wm *new_pipe_wm) |
| 6314 | { |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6315 | struct drm_i915_private *i915 = to_i915(plane->base.dev); |
| 6316 | int level, max_level = ilk_wm_max_level(i915); |
| 6317 | |
| 6318 | for (level = 0; level <= max_level; level++) { |
| 6319 | /* |
| 6320 | * We don't check uv_wm as the hardware doesn't actually |
| 6321 | * use it. It only gets used for calculating the required |
| 6322 | * ddb allocation. |
| 6323 | */ |
Ville Syrjälä | 93fe862 | 2021-03-25 02:44:14 +0200 | [diff] [blame] | 6324 | if (!skl_wm_level_equals(skl_plane_wm_level(old_pipe_wm, plane->id, level), |
| 6325 | skl_plane_wm_level(new_pipe_wm, plane->id, level))) |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6326 | return false; |
| 6327 | } |
| 6328 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 6329 | if (HAS_HW_SAGV_WM(i915)) { |
| 6330 | const struct skl_plane_wm *old_wm = &old_pipe_wm->planes[plane->id]; |
| 6331 | const struct skl_plane_wm *new_wm = &new_pipe_wm->planes[plane->id]; |
| 6332 | |
| 6333 | if (!skl_wm_level_equals(&old_wm->sagv.wm0, &new_wm->sagv.wm0) || |
| 6334 | !skl_wm_level_equals(&old_wm->sagv.trans_wm, &new_wm->sagv.trans_wm)) |
| 6335 | return false; |
| 6336 | } |
| 6337 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6338 | return skl_wm_level_equals(skl_plane_trans_wm(old_pipe_wm, plane->id), |
| 6339 | skl_plane_trans_wm(new_pipe_wm, plane->id)); |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6340 | } |
| 6341 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6342 | /* |
| 6343 | * To make sure the cursor watermark registers are always consistent |
| 6344 | * with our computed state the following scenario needs special |
| 6345 | * treatment: |
| 6346 | * |
| 6347 | * 1. enable cursor |
| 6348 | * 2. move cursor entirely offscreen |
| 6349 | * 3. disable cursor |
| 6350 | * |
| 6351 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 6352 | * (since we consider an offscreen cursor still active for the purposes |
| 6353 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 6354 | * because the actual plane visibility isn't changing, and we don't |
| 6355 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 6356 | * force step 3. to call .disable_plane() to update the watermark |
| 6357 | * registers properly. |
| 6358 | * |
| 6359 | * Other planes do not suffer from this issues as their watermarks are |
| 6360 | * calculated based on the actual plane visibility. The only time this |
| 6361 | * can trigger for the other planes is during the initial readout as the |
| 6362 | * default value of the watermarks registers is not zero. |
| 6363 | */ |
| 6364 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 6365 | struct intel_crtc *crtc) |
| 6366 | { |
| 6367 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6368 | const struct intel_crtc_state *old_crtc_state = |
| 6369 | intel_atomic_get_old_crtc_state(state, crtc); |
| 6370 | struct intel_crtc_state *new_crtc_state = |
| 6371 | intel_atomic_get_new_crtc_state(state, crtc); |
| 6372 | struct intel_plane *plane; |
| 6373 | |
| 6374 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6375 | struct intel_plane_state *plane_state; |
| 6376 | enum plane_id plane_id = plane->id; |
| 6377 | |
| 6378 | /* |
| 6379 | * Force a full wm update for every plane on modeset. |
| 6380 | * Required because the reset value of the wm registers |
| 6381 | * is non-zero, whereas we want all disabled planes to |
| 6382 | * have zero watermarks. So if we turn off the relevant |
| 6383 | * power well the hardware state will go out of sync |
| 6384 | * with the software state. |
| 6385 | */ |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 6386 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) && |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6387 | skl_plane_selected_wm_equals(plane, |
| 6388 | &old_crtc_state->wm.skl.optimal, |
| 6389 | &new_crtc_state->wm.skl.optimal)) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6390 | continue; |
| 6391 | |
| 6392 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 6393 | if (IS_ERR(plane_state)) |
| 6394 | return PTR_ERR(plane_state); |
| 6395 | |
| 6396 | new_crtc_state->update_planes |= BIT(plane_id); |
| 6397 | } |
| 6398 | |
| 6399 | return 0; |
| 6400 | } |
| 6401 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6402 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6403 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6404 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6405 | struct intel_crtc *crtc; |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 6406 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6407 | int ret, i; |
| 6408 | |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 6409 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6410 | ret = skl_build_pipe_wm(state, crtc); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6411 | if (ret) |
| 6412 | return ret; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 6413 | } |
| 6414 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 6415 | ret = skl_compute_ddb(state); |
| 6416 | if (ret) |
| 6417 | return ret; |
| 6418 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 6419 | ret = intel_compute_sagv_mask(state); |
| 6420 | if (ret) |
| 6421 | return ret; |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 6422 | |
Ville Syrjälä | 23baedd | 2020-02-28 22:35:50 +0200 | [diff] [blame] | 6423 | /* |
| 6424 | * skl_compute_ddb() will have adjusted the final watermarks |
| 6425 | * based on how much ddb is available. Now we can actually |
| 6426 | * check if the final watermarks changed. |
| 6427 | */ |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 6428 | 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] | 6429 | ret = skl_wm_add_affected_planes(state, crtc); |
| 6430 | if (ret) |
| 6431 | return ret; |
| 6432 | } |
| 6433 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6434 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6435 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6436 | return 0; |
| 6437 | } |
| 6438 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6439 | 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] | 6440 | struct intel_wm_config *config) |
| 6441 | { |
| 6442 | struct intel_crtc *crtc; |
| 6443 | |
| 6444 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6445 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6446 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 6447 | |
| 6448 | if (!wm->pipe_enabled) |
| 6449 | continue; |
| 6450 | |
| 6451 | config->sprites_enabled |= wm->sprites_enabled; |
| 6452 | config->sprites_scaled |= wm->sprites_scaled; |
| 6453 | config->num_pipes_active++; |
| 6454 | } |
| 6455 | } |
| 6456 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6457 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 6458 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6459 | 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] | 6460 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6461 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6462 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 6463 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 6464 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6465 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6466 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6467 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 6468 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 6469 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 6470 | /* 5/6 split only in single pipe config on IVB+ */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 6471 | if (DISPLAY_VER(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6472 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6473 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 6474 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 6475 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6476 | 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] | 6477 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 6478 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6479 | } |
| 6480 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 6481 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 6482 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6483 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6484 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 6485 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6486 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 6487 | } |
| 6488 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 6489 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6490 | struct intel_crtc *crtc) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6491 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6492 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6493 | const struct intel_crtc_state *crtc_state = |
| 6494 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6495 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6496 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6497 | crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6498 | ilk_program_watermarks(dev_priv); |
| 6499 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6500 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6501 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 6502 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6503 | struct intel_crtc *crtc) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6504 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6505 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6506 | const struct intel_crtc_state *crtc_state = |
| 6507 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6508 | |
| 6509 | if (!crtc_state->wm.need_postvbl_update) |
| 6510 | return; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6511 | |
| 6512 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6513 | crtc->wm.active.ilk = crtc_state->wm.ilk.optimal; |
| 6514 | ilk_program_watermarks(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6515 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6516 | } |
| 6517 | |
Jani Nikula | 81b55ef | 2020-04-20 17:04:38 +0300 | [diff] [blame] | 6518 | 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] | 6519 | { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6520 | level->enable = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 6521 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6522 | level->blocks = val & PLANE_WM_BLOCKS_MASK; |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 6523 | level->lines = REG_FIELD_GET(PLANE_WM_LINES_MASK, val); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6524 | } |
| 6525 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6526 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6527 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6528 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6529 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6530 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6531 | int level, max_level; |
| 6532 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6533 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6534 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6535 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6536 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6537 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6538 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6539 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6540 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6541 | if (plane_id != PLANE_CURSOR) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6542 | val = intel_uncore_read(&dev_priv->uncore, PLANE_WM(pipe, plane_id, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6543 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6544 | val = intel_uncore_read(&dev_priv->uncore, CUR_WM(pipe, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6545 | |
| 6546 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 6547 | } |
| 6548 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6549 | if (plane_id != PLANE_CURSOR) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6550 | val = intel_uncore_read(&dev_priv->uncore, PLANE_WM_TRANS(pipe, plane_id)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6551 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6552 | val = intel_uncore_read(&dev_priv->uncore, CUR_WM_TRANS(pipe)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6553 | |
| 6554 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6555 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 6556 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 6557 | if (plane_id != PLANE_CURSOR) |
| 6558 | val = intel_uncore_read(&dev_priv->uncore, |
| 6559 | PLANE_WM_SAGV(pipe, plane_id)); |
| 6560 | else |
| 6561 | val = intel_uncore_read(&dev_priv->uncore, |
| 6562 | CUR_WM_SAGV(pipe)); |
| 6563 | |
| 6564 | skl_wm_level_from_reg_val(val, &wm->sagv.wm0); |
| 6565 | |
| 6566 | if (plane_id != PLANE_CURSOR) |
| 6567 | val = intel_uncore_read(&dev_priv->uncore, |
| 6568 | PLANE_WM_SAGV_TRANS(pipe, plane_id)); |
| 6569 | else |
| 6570 | val = intel_uncore_read(&dev_priv->uncore, |
| 6571 | CUR_WM_SAGV_TRANS(pipe)); |
| 6572 | |
| 6573 | skl_wm_level_from_reg_val(val, &wm->sagv.trans_wm); |
| 6574 | } else if (DISPLAY_VER(dev_priv) >= 12) { |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6575 | wm->sagv.wm0 = wm->wm[0]; |
| 6576 | wm->sagv.trans_wm = wm->trans_wm; |
| 6577 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6578 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6579 | } |
| 6580 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6581 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6582 | { |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6583 | struct intel_dbuf_state *dbuf_state = |
| 6584 | to_intel_dbuf_state(dev_priv->dbuf.obj.state); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6585 | struct intel_crtc *crtc; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6586 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6587 | if (IS_ALDERLAKE_P(dev_priv)) |
| 6588 | dbuf_state->joined_mbus = intel_de_read(dev_priv, MBUS_CTL) & MBUS_JOIN; |
| 6589 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6590 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6591 | struct intel_crtc_state *crtc_state = |
| 6592 | to_intel_crtc_state(crtc->base.state); |
| 6593 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 6594 | unsigned int mbus_offset; |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6595 | enum plane_id plane_id; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6596 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6597 | 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] | 6598 | crtc_state->wm.skl.raw = crtc_state->wm.skl.optimal; |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6599 | |
| 6600 | memset(&dbuf_state->ddb[pipe], 0, sizeof(dbuf_state->ddb[pipe])); |
| 6601 | |
| 6602 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6603 | struct skl_ddb_entry *ddb_y = |
| 6604 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 6605 | struct skl_ddb_entry *ddb_uv = |
| 6606 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
| 6607 | |
| 6608 | skl_ddb_get_hw_plane_state(dev_priv, crtc->pipe, |
| 6609 | plane_id, ddb_y, ddb_uv); |
| 6610 | |
| 6611 | skl_ddb_entry_union(&dbuf_state->ddb[pipe], ddb_y); |
| 6612 | skl_ddb_entry_union(&dbuf_state->ddb[pipe], ddb_uv); |
| 6613 | } |
| 6614 | |
| 6615 | dbuf_state->slices[pipe] = |
| 6616 | skl_compute_dbuf_slices(crtc, dbuf_state->active_pipes); |
| 6617 | |
| 6618 | dbuf_state->weight[pipe] = intel_crtc_ddb_weight(crtc_state); |
| 6619 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 6620 | /* |
| 6621 | * Used for checking overlaps, so we need absolute |
| 6622 | * offsets instead of MBUS relative offsets. |
| 6623 | */ |
| 6624 | mbus_offset = mbus_ddb_offset(dev_priv, dbuf_state->slices[pipe]); |
| 6625 | crtc_state->wm.skl.ddb.start = mbus_offset + dbuf_state->ddb[pipe].start; |
| 6626 | crtc_state->wm.skl.ddb.end = mbus_offset + dbuf_state->ddb[pipe].end; |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6627 | |
| 6628 | drm_dbg_kms(&dev_priv->drm, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6629 | "[CRTC:%d:%s] dbuf slices 0x%x, ddb (%d - %d), active pipes 0x%x, mbus joined: %s\n", |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6630 | crtc->base.base.id, crtc->base.name, |
| 6631 | dbuf_state->slices[pipe], dbuf_state->ddb[pipe].start, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6632 | dbuf_state->ddb[pipe].end, dbuf_state->active_pipes, |
| 6633 | yesno(dbuf_state->joined_mbus)); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6634 | } |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6635 | |
| 6636 | dbuf_state->enabled_slices = dev_priv->dbuf.enabled_slices; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6637 | } |
| 6638 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6639 | 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] | 6640 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6641 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6642 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6643 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6644 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 6645 | struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6646 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6647 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6648 | hw->wm_pipe[pipe] = intel_uncore_read(&dev_priv->uncore, WM0_PIPE_ILK(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6649 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 6650 | memset(active, 0, sizeof(*active)); |
| 6651 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6652 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 6653 | |
| 6654 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6655 | u32 tmp = hw->wm_pipe[pipe]; |
| 6656 | |
| 6657 | /* |
| 6658 | * For active pipes LP0 watermark is marked as |
| 6659 | * enabled, and LP1+ watermaks as disabled since |
| 6660 | * we can't really reverse compute them in case |
| 6661 | * multiple pipes are active. |
| 6662 | */ |
| 6663 | active->wm[0].enable = true; |
| 6664 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 6665 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 6666 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6667 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6668 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6669 | |
| 6670 | /* |
| 6671 | * For inactive pipes, all watermark levels |
| 6672 | * should be marked as enabled but zeroed, |
| 6673 | * which is what we'd compute them to. |
| 6674 | */ |
| 6675 | for (level = 0; level <= max_level; level++) |
| 6676 | active->wm[level].enable = true; |
| 6677 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 6678 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6679 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6680 | } |
| 6681 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6682 | #define _FW_WM(value, plane) \ |
| 6683 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 6684 | #define _FW_WM_VLV(value, plane) \ |
| 6685 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 6686 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6687 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 6688 | struct g4x_wm_values *wm) |
| 6689 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6690 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6691 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6692 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6693 | wm->sr.plane = _FW_WM(tmp, SR); |
| 6694 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 6695 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 6696 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 6697 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6698 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW2); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6699 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 6700 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 6701 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 6702 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 6703 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 6704 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 6705 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6706 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6707 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 6708 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 6709 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 6710 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 6711 | } |
| 6712 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6713 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 6714 | struct vlv_wm_values *wm) |
| 6715 | { |
| 6716 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6717 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6718 | |
| 6719 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6720 | tmp = intel_uncore_read(&dev_priv->uncore, VLV_DDL(pipe)); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6721 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6722 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6723 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6724 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6725 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6726 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6727 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6728 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6729 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 6730 | } |
| 6731 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6732 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6733 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6734 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 6735 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 6736 | 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] | 6737 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6738 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6739 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 6740 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 6741 | 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] | 6742 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6743 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6744 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 6745 | |
| 6746 | if (IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6747 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6748 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 6749 | 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] | 6750 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6751 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6752 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 6753 | 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] | 6754 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6755 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6756 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 6757 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6758 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6759 | tmp = intel_uncore_read(&dev_priv->uncore, DSPHOWM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6760 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6761 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 6762 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 6763 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 6764 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 6765 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 6766 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 6767 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 6768 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 6769 | 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] | 6770 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6771 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6772 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 6773 | 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] | 6774 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6775 | tmp = intel_uncore_read(&dev_priv->uncore, DSPHOWM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6776 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6777 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 6778 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 6779 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 6780 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 6781 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 6782 | 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] | 6783 | } |
| 6784 | } |
| 6785 | |
| 6786 | #undef _FW_WM |
| 6787 | #undef _FW_WM_VLV |
| 6788 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6789 | 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] | 6790 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6791 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 6792 | struct intel_crtc *crtc; |
| 6793 | |
| 6794 | g4x_read_wm_values(dev_priv, wm); |
| 6795 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6796 | wm->cxsr = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF) & FW_BLC_SELF_EN; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6797 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6798 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6799 | struct intel_crtc_state *crtc_state = |
| 6800 | to_intel_crtc_state(crtc->base.state); |
| 6801 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 6802 | struct g4x_pipe_wm *raw; |
| 6803 | enum pipe pipe = crtc->pipe; |
| 6804 | enum plane_id plane_id; |
| 6805 | int level, max_level; |
| 6806 | |
| 6807 | active->cxsr = wm->cxsr; |
| 6808 | active->hpll_en = wm->hpll_en; |
| 6809 | active->fbc_en = wm->fbc_en; |
| 6810 | |
| 6811 | active->sr = wm->sr; |
| 6812 | active->hpll = wm->hpll; |
| 6813 | |
| 6814 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6815 | active->wm.plane[plane_id] = |
| 6816 | wm->pipe[pipe].plane[plane_id]; |
| 6817 | } |
| 6818 | |
| 6819 | if (wm->cxsr && wm->hpll_en) |
| 6820 | max_level = G4X_WM_LEVEL_HPLL; |
| 6821 | else if (wm->cxsr) |
| 6822 | max_level = G4X_WM_LEVEL_SR; |
| 6823 | else |
| 6824 | max_level = G4X_WM_LEVEL_NORMAL; |
| 6825 | |
| 6826 | level = G4X_WM_LEVEL_NORMAL; |
| 6827 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6828 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6829 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 6830 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame^] | 6831 | level = G4X_WM_LEVEL_SR; |
| 6832 | if (level > max_level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6833 | goto out; |
| 6834 | |
| 6835 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6836 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 6837 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 6838 | raw->plane[PLANE_SPRITE0] = 0; |
| 6839 | raw->fbc = active->sr.fbc; |
| 6840 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame^] | 6841 | level = G4X_WM_LEVEL_HPLL; |
| 6842 | if (level > max_level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6843 | goto out; |
| 6844 | |
| 6845 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6846 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 6847 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 6848 | raw->plane[PLANE_SPRITE0] = 0; |
| 6849 | raw->fbc = active->hpll.fbc; |
| 6850 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame^] | 6851 | level++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6852 | out: |
| 6853 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6854 | g4x_raw_plane_wm_set(crtc_state, level, |
| 6855 | plane_id, USHRT_MAX); |
| 6856 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 6857 | |
| 6858 | crtc_state->wm.g4x.optimal = *active; |
| 6859 | crtc_state->wm.g4x.intermediate = *active; |
| 6860 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6861 | drm_dbg_kms(&dev_priv->drm, |
| 6862 | "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 6863 | pipe_name(pipe), |
| 6864 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6865 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6866 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6867 | } |
| 6868 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6869 | drm_dbg_kms(&dev_priv->drm, |
| 6870 | "Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 6871 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 6872 | drm_dbg_kms(&dev_priv->drm, |
| 6873 | "Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 6874 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 6875 | drm_dbg_kms(&dev_priv->drm, "Initial SR=%s HPLL=%s FBC=%s\n", |
| 6876 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6877 | } |
| 6878 | |
| 6879 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6880 | { |
| 6881 | struct intel_plane *plane; |
| 6882 | struct intel_crtc *crtc; |
| 6883 | |
| 6884 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6885 | |
| 6886 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6887 | struct intel_crtc *crtc = |
| 6888 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6889 | struct intel_crtc_state *crtc_state = |
| 6890 | to_intel_crtc_state(crtc->base.state); |
| 6891 | struct intel_plane_state *plane_state = |
| 6892 | to_intel_plane_state(plane->base.state); |
| 6893 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 6894 | enum plane_id plane_id = plane->id; |
| 6895 | int level; |
| 6896 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 6897 | if (plane_state->uapi.visible) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6898 | continue; |
| 6899 | |
| 6900 | for (level = 0; level < 3; level++) { |
| 6901 | struct g4x_pipe_wm *raw = |
| 6902 | &crtc_state->wm.g4x.raw[level]; |
| 6903 | |
| 6904 | raw->plane[plane_id] = 0; |
| 6905 | wm_state->wm.plane[plane_id] = 0; |
| 6906 | } |
| 6907 | |
| 6908 | if (plane_id == PLANE_PRIMARY) { |
| 6909 | for (level = 0; level < 3; level++) { |
| 6910 | struct g4x_pipe_wm *raw = |
| 6911 | &crtc_state->wm.g4x.raw[level]; |
| 6912 | raw->fbc = 0; |
| 6913 | } |
| 6914 | |
| 6915 | wm_state->sr.fbc = 0; |
| 6916 | wm_state->hpll.fbc = 0; |
| 6917 | wm_state->fbc_en = false; |
| 6918 | } |
| 6919 | } |
| 6920 | |
| 6921 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6922 | struct intel_crtc_state *crtc_state = |
| 6923 | to_intel_crtc_state(crtc->base.state); |
| 6924 | |
| 6925 | crtc_state->wm.g4x.intermediate = |
| 6926 | crtc_state->wm.g4x.optimal; |
| 6927 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 6928 | } |
| 6929 | |
| 6930 | g4x_program_watermarks(dev_priv); |
| 6931 | |
| 6932 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6933 | } |
| 6934 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6935 | 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] | 6936 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6937 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 6938 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6939 | u32 val; |
| 6940 | |
| 6941 | vlv_read_wm_values(dev_priv, wm); |
| 6942 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6943 | wm->cxsr = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6944 | wm->level = VLV_WM_LEVEL_PM2; |
| 6945 | |
| 6946 | if (IS_CHERRYVIEW(dev_priv)) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6947 | vlv_punit_get(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6948 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 6949 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6950 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 6951 | wm->level = VLV_WM_LEVEL_PM5; |
| 6952 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6953 | /* |
| 6954 | * If DDR DVFS is disabled in the BIOS, Punit |
| 6955 | * will never ack the request. So if that happens |
| 6956 | * assume we don't have to enable/disable DDR DVFS |
| 6957 | * dynamically. To test that just set the REQ_ACK |
| 6958 | * bit to poke the Punit, but don't change the |
| 6959 | * HIGH/LOW bits so that we don't actually change |
| 6960 | * the current state. |
| 6961 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6962 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6963 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 6964 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 6965 | |
| 6966 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 6967 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6968 | drm_dbg_kms(&dev_priv->drm, |
| 6969 | "Punit not acking DDR DVFS request, " |
| 6970 | "assuming DDR DVFS is disabled\n"); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6971 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 6972 | } else { |
| 6973 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 6974 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 6975 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 6976 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6977 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6978 | vlv_punit_put(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6979 | } |
| 6980 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6981 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6982 | struct intel_crtc_state *crtc_state = |
| 6983 | to_intel_crtc_state(crtc->base.state); |
| 6984 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 6985 | const struct vlv_fifo_state *fifo_state = |
| 6986 | &crtc_state->wm.vlv.fifo_state; |
| 6987 | enum pipe pipe = crtc->pipe; |
| 6988 | enum plane_id plane_id; |
| 6989 | int level; |
| 6990 | |
| 6991 | vlv_get_fifo_size(crtc_state); |
| 6992 | |
| 6993 | active->num_levels = wm->level + 1; |
| 6994 | active->cxsr = wm->cxsr; |
| 6995 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6996 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 6997 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6998 | &crtc_state->wm.vlv.raw[level]; |
| 6999 | |
| 7000 | active->sr[level].plane = wm->sr.plane; |
| 7001 | active->sr[level].cursor = wm->sr.cursor; |
| 7002 | |
| 7003 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 7004 | active->wm[level].plane[plane_id] = |
| 7005 | wm->pipe[pipe].plane[plane_id]; |
| 7006 | |
| 7007 | raw->plane[plane_id] = |
| 7008 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 7009 | fifo_state->plane[plane_id]); |
| 7010 | } |
| 7011 | } |
| 7012 | |
| 7013 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 7014 | vlv_raw_plane_wm_set(crtc_state, level, |
| 7015 | plane_id, USHRT_MAX); |
| 7016 | vlv_invalidate_wms(crtc, active, level); |
| 7017 | |
| 7018 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 7019 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7020 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7021 | drm_dbg_kms(&dev_priv->drm, |
| 7022 | "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n", |
| 7023 | pipe_name(pipe), |
| 7024 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 7025 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 7026 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 7027 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7028 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 7029 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7030 | drm_dbg_kms(&dev_priv->drm, |
| 7031 | "Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 7032 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 7033 | } |
| 7034 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7035 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 7036 | { |
| 7037 | struct intel_plane *plane; |
| 7038 | struct intel_crtc *crtc; |
| 7039 | |
| 7040 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 7041 | |
| 7042 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 7043 | struct intel_crtc *crtc = |
| 7044 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 7045 | struct intel_crtc_state *crtc_state = |
| 7046 | to_intel_crtc_state(crtc->base.state); |
| 7047 | struct intel_plane_state *plane_state = |
| 7048 | to_intel_plane_state(plane->base.state); |
| 7049 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 7050 | const struct vlv_fifo_state *fifo_state = |
| 7051 | &crtc_state->wm.vlv.fifo_state; |
| 7052 | enum plane_id plane_id = plane->id; |
| 7053 | int level; |
| 7054 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 7055 | if (plane_state->uapi.visible) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7056 | continue; |
| 7057 | |
| 7058 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 7059 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7060 | &crtc_state->wm.vlv.raw[level]; |
| 7061 | |
| 7062 | raw->plane[plane_id] = 0; |
| 7063 | |
| 7064 | wm_state->wm[level].plane[plane_id] = |
| 7065 | vlv_invert_wm_value(raw->plane[plane_id], |
| 7066 | fifo_state->plane[plane_id]); |
| 7067 | } |
| 7068 | } |
| 7069 | |
| 7070 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 7071 | struct intel_crtc_state *crtc_state = |
| 7072 | to_intel_crtc_state(crtc->base.state); |
| 7073 | |
| 7074 | crtc_state->wm.vlv.intermediate = |
| 7075 | crtc_state->wm.vlv.optimal; |
| 7076 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 7077 | } |
| 7078 | |
| 7079 | vlv_program_watermarks(dev_priv); |
| 7080 | |
| 7081 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 7082 | } |
| 7083 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 7084 | /* |
| 7085 | * FIXME should probably kill this and improve |
| 7086 | * the real watermark readout/sanitation instead |
| 7087 | */ |
| 7088 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 7089 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7090 | intel_uncore_write(&dev_priv->uncore, WM3_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 7091 | intel_uncore_write(&dev_priv->uncore, WM2_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 7092 | intel_uncore_write(&dev_priv->uncore, WM1_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM1_LP_ILK) & ~WM1_LP_SR_EN); |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 7093 | |
| 7094 | /* |
| 7095 | * Don't touch WM1S_LP_EN here. |
| 7096 | * Doing so could cause underruns. |
| 7097 | */ |
| 7098 | } |
| 7099 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7100 | 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] | 7101 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 7102 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7103 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7104 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 7105 | ilk_init_lp_watermarks(dev_priv); |
| 7106 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7107 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7108 | ilk_pipe_wm_get_hw_state(crtc); |
| 7109 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7110 | hw->wm_lp[0] = intel_uncore_read(&dev_priv->uncore, WM1_LP_ILK); |
| 7111 | hw->wm_lp[1] = intel_uncore_read(&dev_priv->uncore, WM2_LP_ILK); |
| 7112 | hw->wm_lp[2] = intel_uncore_read(&dev_priv->uncore, WM3_LP_ILK); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7113 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7114 | hw->wm_lp_spr[0] = intel_uncore_read(&dev_priv->uncore, WM1S_LP_ILK); |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 7115 | if (DISPLAY_VER(dev_priv) >= 7) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7116 | hw->wm_lp_spr[1] = intel_uncore_read(&dev_priv->uncore, WM2S_LP_IVB); |
| 7117 | hw->wm_lp_spr[2] = intel_uncore_read(&dev_priv->uncore, WM3S_LP_IVB); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 7118 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7119 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 7120 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7121 | hw->partitioning = (intel_uncore_read(&dev_priv->uncore, WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 7122 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 7123 | else if (IS_IVYBRIDGE(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7124 | hw->partitioning = (intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 7125 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7126 | |
| 7127 | hw->enable_fbc_wm = |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7128 | !(intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7129 | } |
| 7130 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 7131 | /** |
| 7132 | * intel_update_watermarks - update FIFO watermark values based on current modes |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 7133 | * @crtc: the #intel_crtc on which to compute the WM |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 7134 | * |
| 7135 | * Calculate watermark values for the various WM regs based on current mode |
| 7136 | * and plane configuration. |
| 7137 | * |
| 7138 | * There are several cases to deal with here: |
| 7139 | * - normal (i.e. non-self-refresh) |
| 7140 | * - self-refresh (SR) mode |
| 7141 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 7142 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 7143 | * lines), so need to account for TLB latency |
| 7144 | * |
| 7145 | * The normal calculation is: |
| 7146 | * watermark = dotclock * bytes per pixel * latency |
| 7147 | * where latency is platform & configuration dependent (we assume pessimal |
| 7148 | * values here). |
| 7149 | * |
| 7150 | * The SR calculation is: |
| 7151 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 7152 | * bytes per pixel |
| 7153 | * where |
| 7154 | * line time = htotal / dotclock |
| 7155 | * surface width = hdisplay for normal plane and 64 for cursor |
| 7156 | * and latency is assumed to be high, as above. |
| 7157 | * |
| 7158 | * The final value programmed to the register should always be rounded up, |
| 7159 | * and include an extra 2 entries to account for clock crossings. |
| 7160 | * |
| 7161 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 7162 | * to set the non-SR watermarks to 8. |
| 7163 | */ |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 7164 | void intel_update_watermarks(struct intel_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 7165 | { |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 7166 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 7167 | |
| 7168 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 7169 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 7170 | } |
| 7171 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7172 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 7173 | { |
| 7174 | u32 val; |
| 7175 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 7176 | if (!HAS_IPC(dev_priv)) |
| 7177 | return; |
| 7178 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7179 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2); |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7180 | |
| 7181 | if (dev_priv->ipc_enabled) |
| 7182 | val |= DISP_IPC_ENABLE; |
| 7183 | else |
| 7184 | val &= ~DISP_IPC_ENABLE; |
| 7185 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7186 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL2, val); |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7187 | } |
| 7188 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7189 | static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv) |
| 7190 | { |
| 7191 | /* Display WA #0477 WaDisableIPC: skl */ |
| 7192 | if (IS_SKYLAKE(dev_priv)) |
| 7193 | return false; |
| 7194 | |
| 7195 | /* Display WA #1141: SKL:all KBL:all CFL */ |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 7196 | if (IS_KABYLAKE(dev_priv) || |
| 7197 | IS_COFFEELAKE(dev_priv) || |
| 7198 | IS_COMETLAKE(dev_priv)) |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7199 | return dev_priv->dram_info.symmetric_memory; |
| 7200 | |
| 7201 | return true; |
| 7202 | } |
| 7203 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7204 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 7205 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7206 | if (!HAS_IPC(dev_priv)) |
| 7207 | return; |
| 7208 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7209 | dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv); |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 7210 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7211 | intel_enable_ipc(dev_priv); |
| 7212 | } |
| 7213 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7214 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7215 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7216 | /* |
| 7217 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7218 | * gating for the panel power sequencer or it will fail to |
| 7219 | * start up when no ports are active. |
| 7220 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7221 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7222 | } |
| 7223 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7224 | 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] | 7225 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7226 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7227 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7228 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7229 | intel_uncore_write(&dev_priv->uncore, DSPCNTR(pipe), |
| 7230 | intel_uncore_read(&dev_priv->uncore, DSPCNTR(pipe)) | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7231 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7232 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7233 | intel_uncore_write(&dev_priv->uncore, DSPSURF(pipe), intel_uncore_read(&dev_priv->uncore, DSPSURF(pipe))); |
| 7234 | intel_uncore_posting_read(&dev_priv->uncore, DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7235 | } |
| 7236 | } |
| 7237 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7238 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7239 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7240 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7241 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 7242 | /* |
| 7243 | * Required for FBC |
| 7244 | * WaFbcDisableDpfcClockGating:ilk |
| 7245 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7246 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 7247 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 7248 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7249 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7250 | intel_uncore_write(&dev_priv->uncore, PCH_3DCGDIS0, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7251 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 7252 | SVSMUNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7253 | intel_uncore_write(&dev_priv->uncore, PCH_3DCGDIS1, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7254 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 7255 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7256 | /* |
| 7257 | * According to the spec the following bits should be set in |
| 7258 | * order to enable memory self-refresh |
| 7259 | * The bit 22/21 of 0x42004 |
| 7260 | * The bit 5 of 0x42020 |
| 7261 | * The bit 15 of 0x45000 |
| 7262 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7263 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7264 | (intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7265 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7266 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7267 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, |
| 7268 | (intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7269 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7270 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7271 | /* |
| 7272 | * Based on the document from hardware guys the following bits |
| 7273 | * should be set unconditionally in order to enable FBC. |
| 7274 | * The bit 22 of 0x42000 |
| 7275 | * The bit 22 of 0x42004 |
| 7276 | * The bit 7,8,9 of 0x42020. |
| 7277 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7278 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7279 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7280 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7281 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7282 | ILK_FBCQ_DIS); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7283 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7284 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7285 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7286 | } |
| 7287 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7288 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, dspclk_gate); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7289 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7290 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7291 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7292 | ILK_ELPIN_409_SELECT); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7293 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7294 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 7295 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7296 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7297 | } |
| 7298 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7299 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7300 | { |
Ville Syrjälä | d048a26 | 2019-08-21 20:30:31 +0300 | [diff] [blame] | 7301 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7302 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7303 | |
| 7304 | /* |
| 7305 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7306 | * gating for the panel power sequencer or it will fail to |
| 7307 | * start up when no ports are active. |
| 7308 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7309 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 7310 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 7311 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7312 | intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN2, intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN2) | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7313 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 7314 | /* The below fixes the weird display corruption, a few pixels shifted |
| 7315 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 7316 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7317 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7318 | val = intel_uncore_read(&dev_priv->uncore, TRANS_CHICKEN2(pipe)); |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7319 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 7320 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7321 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7322 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7323 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 7324 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7325 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN2(pipe), val); |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7326 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7327 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7328 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7329 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN1(pipe), |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7330 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 7331 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7332 | } |
| 7333 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7334 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7335 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7336 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7337 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7338 | tmp = intel_uncore_read(&dev_priv->uncore, MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 7339 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7340 | drm_dbg_kms(&dev_priv->drm, |
| 7341 | "Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 7342 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7343 | } |
| 7344 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7345 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7346 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7347 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7348 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7349 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7350 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7351 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7352 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7353 | ILK_ELPIN_409_SELECT); |
| 7354 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7355 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, |
| 7356 | intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7357 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 7358 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 7359 | |
| 7360 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 7361 | * gating disable must be set. Failure to set it results in |
| 7362 | * flickering pixels due to Z write ordering failures after |
| 7363 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 7364 | * Sanctuary and Tropics, and apparently anything else with |
| 7365 | * alpha test or pixel discard. |
| 7366 | * |
| 7367 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 7368 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7369 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 7370 | * WaDisableRCCUnitClockGating:snb |
| 7371 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7372 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7373 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7374 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 7375 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 7376 | |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 7377 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7378 | * According to the spec the following bits should be |
| 7379 | * set in order to enable memory self-refresh and fbc: |
| 7380 | * The bit21 and bit22 of 0x42000 |
| 7381 | * The bit21 and bit22 of 0x42004 |
| 7382 | * The bit5 and bit7 of 0x42020 |
| 7383 | * The bit14 of 0x70180 |
| 7384 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7385 | * |
| 7386 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7387 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7388 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7389 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7390 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7391 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7392 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7393 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7394 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, |
| 7395 | intel_uncore_read(&dev_priv->uncore, ILK_DSPCLK_GATE_D) | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7396 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 7397 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7398 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7399 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 7400 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7401 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7402 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7403 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7404 | } |
| 7405 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7406 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7407 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7408 | /* |
| 7409 | * TODO: this bit should only be enabled when really needed, then |
| 7410 | * disabled when not needed anymore in order to save power. |
| 7411 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7412 | if (HAS_PCH_LPT_LP(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7413 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, |
| 7414 | intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D) | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7415 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7416 | |
| 7417 | /* WADPOClockGatingDisable:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7418 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN1(PIPE_A), |
| 7419 | intel_uncore_read(&dev_priv->uncore, TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7420 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7421 | } |
| 7422 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7423 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7424 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7425 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7426 | u32 val = intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7427 | |
| 7428 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7429 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, val); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7430 | } |
| 7431 | } |
| 7432 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7433 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 7434 | int general_prio_credits, |
| 7435 | int high_prio_credits) |
| 7436 | { |
| 7437 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 7438 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7439 | |
| 7440 | /* WaTempDisableDOPClkGating:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7441 | misccpctl = intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL); |
| 7442 | intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7443 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7444 | val = intel_uncore_read(&dev_priv->uncore, GEN8_L3SQCREG1); |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 7445 | val &= ~L3_PRIO_CREDITS_MASK; |
| 7446 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 7447 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7448 | intel_uncore_write(&dev_priv->uncore, GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7449 | |
| 7450 | /* |
| 7451 | * Wait at least 100 clocks before re-enabling clock gating. |
| 7452 | * See the definition of L3SQCREG1 in BSpec. |
| 7453 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7454 | intel_uncore_posting_read(&dev_priv->uncore, GEN8_L3SQCREG1); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7455 | udelay(1); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7456 | intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7457 | } |
| 7458 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7459 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7460 | { |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7461 | /* Wa_1409120013:icl,ehl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7462 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7463 | ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL); |
| 7464 | |
Matt Atwood | 6f4194c | 2020-01-13 23:11:28 -0500 | [diff] [blame] | 7465 | /*Wa_14010594013:icl, ehl */ |
| 7466 | intel_uncore_rmw(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1, |
Lucas De Marchi | dbac4f3 | 2021-07-28 14:59:38 -0700 | [diff] [blame] | 7467 | 0, ICL_DELAY_PMRSP); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7468 | } |
| 7469 | |
José Roberto de Souza | 35f0837 | 2021-01-13 05:37:59 -0800 | [diff] [blame] | 7470 | static void gen12lp_init_clock_gating(struct drm_i915_private *dev_priv) |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7471 | { |
José Roberto de Souza | c492405 | 2021-07-12 17:38:50 -0700 | [diff] [blame] | 7472 | /* Wa_1409120013:tgl,rkl,adl-s,dg1 */ |
Clint Taylor | 8c209f4 | 2021-06-08 10:47:21 -0700 | [diff] [blame] | 7473 | if (IS_TIGERLAKE(dev_priv) || IS_ROCKETLAKE(dev_priv) || |
| 7474 | IS_ALDERLAKE_S(dev_priv) || IS_DG1(dev_priv)) |
| 7475 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, |
| 7476 | ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL); |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7477 | |
Radhakrishna Sripada | f78d5da | 2020-01-09 14:37:27 -0800 | [diff] [blame] | 7478 | /* Wa_1409825376:tgl (pre-prod)*/ |
Matt Roper | 46b0d70 | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7479 | if (IS_TGL_DISPLAY_STEP(dev_priv, STEP_A0, STEP_C0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7480 | intel_uncore_write(&dev_priv->uncore, GEN9_CLKGATE_DIS_3, intel_uncore_read(&dev_priv->uncore, GEN9_CLKGATE_DIS_3) | |
Radhakrishna Sripada | f78d5da | 2020-01-09 14:37:27 -0800 | [diff] [blame] | 7481 | TGL_VRH_GATING_DIS); |
Matt Atwood | f9d7742 | 2020-04-15 15:35:35 -0400 | [diff] [blame] | 7482 | |
José Roberto de Souza | 41c70d2 | 2021-04-08 13:49:16 -0700 | [diff] [blame] | 7483 | /* Wa_14013723622:tgl,rkl,dg1,adl-s */ |
| 7484 | if (DISPLAY_VER(dev_priv) == 12) |
| 7485 | intel_uncore_rmw(&dev_priv->uncore, CLKREQ_POLICY, |
| 7486 | CLKREQ_POLICY_MEM_UP_OVRD, 0); |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7487 | } |
| 7488 | |
José Roberto de Souza | a8a56da | 2021-05-14 08:37:09 -0700 | [diff] [blame] | 7489 | static void adlp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7490 | { |
| 7491 | gen12lp_init_clock_gating(dev_priv); |
| 7492 | |
| 7493 | /* Wa_22011091694:adlp */ |
| 7494 | intel_de_rmw(dev_priv, GEN9_CLKGATE_DIS_5, 0, DPCE_GATING_DIS); |
| 7495 | } |
| 7496 | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7497 | static void dg1_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7498 | { |
José Roberto de Souza | 35f0837 | 2021-01-13 05:37:59 -0800 | [diff] [blame] | 7499 | gen12lp_init_clock_gating(dev_priv); |
| 7500 | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7501 | /* Wa_1409836686:dg1[a0] */ |
Matt Roper | 6b73a7f | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7502 | if (IS_DG1_GT_STEP(dev_priv, STEP_A0, STEP_B0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7503 | intel_uncore_write(&dev_priv->uncore, GEN9_CLKGATE_DIS_3, intel_uncore_read(&dev_priv->uncore, GEN9_CLKGATE_DIS_3) | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7504 | DPT_GATING_DIS); |
| 7505 | } |
| 7506 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7507 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7508 | { |
| 7509 | if (!HAS_PCH_CNP(dev_priv)) |
| 7510 | return; |
| 7511 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 7512 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7513 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D) | |
Rodrigo Vivi | 4cc6feb | 2017-09-08 16:45:33 -0700 | [diff] [blame] | 7514 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7515 | } |
| 7516 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7517 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7518 | { |
| 7519 | cnp_init_clock_gating(dev_priv); |
| 7520 | gen9_init_clock_gating(dev_priv); |
| 7521 | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7522 | /* WAC6entrylatency:cfl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7523 | intel_uncore_write(&dev_priv->uncore, FBC_LLC_READ_CTRL, intel_uncore_read(&dev_priv->uncore, FBC_LLC_READ_CTRL) | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7524 | FBC_LLC_FULLY_OPEN); |
| 7525 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7526 | /* |
| 7527 | * WaFbcTurnOffFbcWatermark:cfl |
| 7528 | * Display WA #0562: cfl |
| 7529 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7530 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) | |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 7531 | DISP_FBC_WM_DIS); |
| 7532 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7533 | /* |
| 7534 | * WaFbcNukeOnHostModify:cfl |
| 7535 | * Display WA #0873: cfl |
| 7536 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7537 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7538 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 7539 | } |
| 7540 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7541 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7542 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7543 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7544 | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7545 | /* WAC6entrylatency:kbl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7546 | intel_uncore_write(&dev_priv->uncore, FBC_LLC_READ_CTRL, intel_uncore_read(&dev_priv->uncore, FBC_LLC_READ_CTRL) | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7547 | FBC_LLC_FULLY_OPEN); |
| 7548 | |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7549 | /* WaDisableSDEUnitClockGating:kbl */ |
Matt Roper | 6b73a7f | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7550 | if (IS_KBL_GT_STEP(dev_priv, 0, STEP_C0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7551 | intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) | |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7552 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 7553 | |
| 7554 | /* WaDisableGamClockGating:kbl */ |
Matt Roper | 6b73a7f | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7555 | if (IS_KBL_GT_STEP(dev_priv, 0, STEP_C0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7556 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) | |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 7557 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7558 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7559 | /* |
| 7560 | * WaFbcTurnOffFbcWatermark:kbl |
| 7561 | * Display WA #0562: kbl |
| 7562 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7563 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) | |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 7564 | DISP_FBC_WM_DIS); |
| 7565 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7566 | /* |
| 7567 | * WaFbcNukeOnHostModify:kbl |
| 7568 | * Display WA #0873: kbl |
| 7569 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7570 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7571 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7572 | } |
| 7573 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7574 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7575 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7576 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7577 | |
Ville Syrjälä | f142119 | 2020-07-16 22:04:25 +0300 | [diff] [blame] | 7578 | /* WaDisableDopClockGating:skl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7579 | intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL) & |
Ville Syrjälä | f142119 | 2020-07-16 22:04:25 +0300 | [diff] [blame] | 7580 | ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 7581 | |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7582 | /* WAC6entrylatency:skl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7583 | intel_uncore_write(&dev_priv->uncore, FBC_LLC_READ_CTRL, intel_uncore_read(&dev_priv->uncore, FBC_LLC_READ_CTRL) | |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7584 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7585 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7586 | /* |
| 7587 | * WaFbcTurnOffFbcWatermark:skl |
| 7588 | * Display WA #0562: skl |
| 7589 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7590 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) | |
Ville Syrjälä | c4615b2 | 2020-07-08 16:12:21 +0300 | [diff] [blame] | 7591 | DISP_FBC_WM_DIS); |
| 7592 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7593 | /* |
| 7594 | * WaFbcNukeOnHostModify:skl |
| 7595 | * Display WA #0873: skl |
| 7596 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7597 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7598 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 7599 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7600 | /* |
| 7601 | * WaFbcHighMemBwCorruptionAvoidance:skl |
| 7602 | * Display WA #0883: skl |
| 7603 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7604 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 7605 | ILK_DPFC_DISABLE_DUMMY0); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7606 | } |
| 7607 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7608 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7609 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 7610 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7611 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7612 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7613 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A), |
| 7614 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A)) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7615 | HSW_FBCQ_DIS); |
| 7616 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7617 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7618 | intel_uncore_write(&dev_priv->uncore, GAM_ECOCHK, intel_uncore_read(&dev_priv->uncore, GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7619 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7620 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7621 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 7622 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7623 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7624 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | b7a7053 | 2021-02-20 12:33:03 +0200 | [diff] [blame] | 7625 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7626 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe), |
| 7627 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 7628 | BDW_DPRS_MASK_VBLANK_SRD); |
Ville Syrjälä | b7a7053 | 2021-02-20 12:33:03 +0200 | [diff] [blame] | 7629 | |
| 7630 | /* Undocumented but fixes async flip + VT-d corruption */ |
| 7631 | if (intel_vtd_active()) |
| 7632 | intel_uncore_rmw(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe), |
| 7633 | HSW_PRI_STRETCH_MAX_MASK, HSW_PRI_STRETCH_MAX_X1); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7634 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 7635 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7636 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 7637 | /* WaDSRefCountFullforceMissDisable:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7638 | intel_uncore_write(&dev_priv->uncore, GEN7_FF_THREAD_MODE, |
| 7639 | intel_uncore_read(&dev_priv->uncore, GEN7_FF_THREAD_MODE) & |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7640 | ~(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] | 7641 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7642 | intel_uncore_write(&dev_priv->uncore, GEN6_RC_SLEEP_PSMI_CONTROL, |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 7643 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 7644 | |
| 7645 | /* WaDisableSDEUnitClockGating:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7646 | intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) | |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 7647 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 7648 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7649 | /* WaProgramL3SqcReg1Default:bdw */ |
| 7650 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 7651 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 7652 | /* WaKVMNotificationOnConfigChange:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7653 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR2_1, intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR2_1) |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 7654 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 7655 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7656 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 7657 | |
| 7658 | /* WaDisableDopClockGating:bdw |
| 7659 | * |
| 7660 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 7661 | * clock gating. |
| 7662 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7663 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, |
| 7664 | intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7665 | } |
| 7666 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7667 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7668 | { |
Ville Syrjälä | b7a7053 | 2021-02-20 12:33:03 +0200 | [diff] [blame] | 7669 | enum pipe pipe; |
| 7670 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7671 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7672 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A), |
| 7673 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A)) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7674 | HSW_FBCQ_DIS); |
| 7675 | |
Ville Syrjälä | b7a7053 | 2021-02-20 12:33:03 +0200 | [diff] [blame] | 7676 | for_each_pipe(dev_priv, pipe) { |
| 7677 | /* Undocumented but fixes async flip + VT-d corruption */ |
| 7678 | if (intel_vtd_active()) |
| 7679 | intel_uncore_rmw(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe), |
| 7680 | HSW_PRI_STRETCH_MAX_MASK, HSW_PRI_STRETCH_MAX_X1); |
| 7681 | } |
| 7682 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7683 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7684 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7685 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Chris Wilson | f93ec5f | 2020-06-11 10:30:15 +0100 | [diff] [blame] | 7686 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 7687 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7688 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7689 | intel_uncore_write(&dev_priv->uncore, GAM_ECOCHK, intel_uncore_read(&dev_priv->uncore, GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 7690 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7691 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7692 | } |
| 7693 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7694 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7695 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7696 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7697 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7698 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7699 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7700 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7701 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7702 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7703 | ILK_FBCQ_DIS); |
| 7704 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7705 | /* WaDisableBackToBackFlipFix:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7706 | intel_uncore_write(&dev_priv->uncore, IVB_CHICKEN3, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7707 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7708 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7709 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7710 | if (IS_IVB_GT1(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7711 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7712 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7713 | else { |
| 7714 | /* must write both registers */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7715 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7716 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7717 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2_GT2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7718 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7719 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7720 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 7721 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7722 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7723 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7724 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7725 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 7726 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7727 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7728 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7729 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7730 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7731 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7732 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7733 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7734 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7735 | snpcr = intel_uncore_read(&dev_priv->uncore, GEN6_MBCUNIT_SNPCR); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 7736 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 7737 | snpcr |= GEN6_MBC_SNPCR_MED; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7738 | intel_uncore_write(&dev_priv->uncore, GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7739 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7740 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7741 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7742 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7743 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7744 | } |
| 7745 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7746 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7747 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7748 | /* WaDisableBackToBackFlipFix:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7749 | intel_uncore_write(&dev_priv->uncore, IVB_CHICKEN3, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7750 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7751 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7752 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7753 | /* WaDisableDopClockGating:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7754 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7755 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 7756 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7757 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7758 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7759 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7760 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7761 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7762 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7763 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7764 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7765 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7766 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7767 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7768 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 7769 | /* WaDisableL3Bank2xClockGate:vlv |
| 7770 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 7771 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7772 | intel_uncore_write(&dev_priv->uncore, GEN7_UCGCTL4, |
| 7773 | intel_uncore_read(&dev_priv->uncore, GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 7774 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 7775 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7776 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 7777 | * Disable clock gating on th GCFG unit to prevent a delay |
| 7778 | * in the reporting of vblank events. |
| 7779 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7780 | intel_uncore_write(&dev_priv->uncore, VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7781 | } |
| 7782 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7783 | 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] | 7784 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 7785 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 7786 | /* WaDSRefCountFullforceMissDisable:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7787 | intel_uncore_write(&dev_priv->uncore, GEN7_FF_THREAD_MODE, |
| 7788 | intel_uncore_read(&dev_priv->uncore, GEN7_FF_THREAD_MODE) & |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 7789 | ~(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] | 7790 | |
| 7791 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7792 | intel_uncore_write(&dev_priv->uncore, GEN6_RC_SLEEP_PSMI_CONTROL, |
Ville Syrjälä | acea6f9 | 2014-04-09 13:28:36 +0300 | [diff] [blame] | 7793 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 7794 | |
| 7795 | /* WaDisableCSUnitClockGating:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7796 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) | |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 7797 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 7798 | |
| 7799 | /* WaDisableSDEUnitClockGating:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7800 | intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) | |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 7801 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 7802 | |
| 7803 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7804 | * WaProgramL3SqcReg1Default:chv |
| 7805 | * See gfxspecs/Related Documents/Performance Guide/ |
| 7806 | * LSQC Setting Recommendations. |
| 7807 | */ |
| 7808 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7809 | } |
| 7810 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7811 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7812 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7813 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7814 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7815 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D1, 0); |
| 7816 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7817 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 7818 | CL_UNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7819 | intel_uncore_write(&dev_priv->uncore, RAMCLK_GATE_D, 0); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7820 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 7821 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 7822 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7823 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7824 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7825 | intel_uncore_write(&dev_priv->uncore, DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 7826 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7827 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7828 | } |
| 7829 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7830 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7831 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 7832 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 7833 | |
| 7834 | intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 7835 | intel_uncore_write(uncore, RENCLK_GATE_D2, 0); |
| 7836 | intel_uncore_write(uncore, DSPCLK_GATE_D, 0); |
| 7837 | intel_uncore_write(uncore, RAMCLK_GATE_D, 0); |
| 7838 | intel_uncore_write16(uncore, DEUC, 0); |
| 7839 | intel_uncore_write(uncore, |
| 7840 | MI_ARB_STATE, |
| 7841 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7842 | } |
| 7843 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7844 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7845 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7846 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7847 | I965_RCC_CLOCK_GATE_DISABLE | |
| 7848 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 7849 | I965_ISC_CLOCK_GATE_DISABLE | |
| 7850 | I965_FBC_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7851 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D2, 0); |
| 7852 | intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE, |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 7853 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7854 | } |
| 7855 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7856 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7857 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7858 | u32 dstate = intel_uncore_read(&dev_priv->uncore, D_STATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7859 | |
| 7860 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 7861 | DSTATE_DOT_CLOCK_GATING; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7862 | intel_uncore_write(&dev_priv->uncore, D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 7863 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7864 | if (IS_PINEVIEW(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7865 | intel_uncore_write(&dev_priv->uncore, ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 7866 | |
| 7867 | /* IIR "flip pending" means done if this bit is set */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7868 | intel_uncore_write(&dev_priv->uncore, ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 7869 | |
| 7870 | /* interrupts should cause a wake up from C3 */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7871 | intel_uncore_write(&dev_priv->uncore, INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 7872 | |
| 7873 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7874 | intel_uncore_write(&dev_priv->uncore, 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] | 7875 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7876 | intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7877 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7878 | } |
| 7879 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7880 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7881 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7882 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 7883 | |
| 7884 | /* interrupts should cause a wake up from C3 */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7885 | intel_uncore_write(&dev_priv->uncore, MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 7886 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7887 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7888 | intel_uncore_write(&dev_priv->uncore, MEM_MODE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7889 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Ville Syrjälä | 5cecf50 | 2020-07-02 18:37:23 +0300 | [diff] [blame] | 7890 | |
| 7891 | /* |
| 7892 | * Have FBC ignore 3D activity since we use software |
| 7893 | * render tracking, and otherwise a pure 3D workload |
| 7894 | * (even if it just renders a single frame and then does |
| 7895 | * abosultely nothing) would not allow FBC to recompress |
| 7896 | * until a 2D blit occurs. |
| 7897 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7898 | intel_uncore_write(&dev_priv->uncore, SCPD0, |
Ville Syrjälä | 5cecf50 | 2020-07-02 18:37:23 +0300 | [diff] [blame] | 7899 | _MASKED_BIT_ENABLE(SCPD_FBC_IGNORE_3D)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7900 | } |
| 7901 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7902 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7903 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7904 | intel_uncore_write(&dev_priv->uncore, MEM_MODE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7905 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 7906 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7907 | } |
| 7908 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7909 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7910 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7911 | dev_priv->display.init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7912 | } |
| 7913 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7914 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7915 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7916 | if (HAS_PCH_LPT(dev_priv)) |
| 7917 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7918 | } |
| 7919 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7920 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7921 | { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7922 | drm_dbg_kms(&dev_priv->drm, |
| 7923 | "No clock gating settings or workarounds applied.\n"); |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7924 | } |
| 7925 | |
| 7926 | /** |
| 7927 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 7928 | * @dev_priv: device private |
| 7929 | * |
| 7930 | * Setup the hooks that configure which clocks of a given platform can be |
| 7931 | * gated and also apply various GT and display specific workarounds for these |
| 7932 | * platforms. Note that some GT specific workarounds are applied separately |
| 7933 | * when GPU contexts or batchbuffers start their execution. |
| 7934 | */ |
| 7935 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 7936 | { |
José Roberto de Souza | a8a56da | 2021-05-14 08:37:09 -0700 | [diff] [blame] | 7937 | if (IS_ALDERLAKE_P(dev_priv)) |
| 7938 | dev_priv->display.init_clock_gating = adlp_init_clock_gating; |
| 7939 | else if (IS_DG1(dev_priv)) |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7940 | dev_priv->display.init_clock_gating = dg1_init_clock_gating; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7941 | else if (GRAPHICS_VER(dev_priv) == 12) |
José Roberto de Souza | 35f0837 | 2021-01-13 05:37:59 -0800 | [diff] [blame] | 7942 | dev_priv->display.init_clock_gating = gen12lp_init_clock_gating; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7943 | else if (GRAPHICS_VER(dev_priv) == 11) |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7944 | dev_priv->display.init_clock_gating = icl_init_clock_gating; |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 7945 | else if (IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7946 | dev_priv->display.init_clock_gating = cfl_init_clock_gating; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7947 | else if (IS_SKYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7948 | dev_priv->display.init_clock_gating = skl_init_clock_gating; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7949 | else if (IS_KABYLAKE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7950 | dev_priv->display.init_clock_gating = kbl_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7951 | else if (IS_BROXTON(dev_priv)) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7952 | dev_priv->display.init_clock_gating = bxt_init_clock_gating; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7953 | else if (IS_GEMINILAKE(dev_priv)) |
| 7954 | dev_priv->display.init_clock_gating = glk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7955 | else if (IS_BROADWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7956 | dev_priv->display.init_clock_gating = bdw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7957 | else if (IS_CHERRYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7958 | dev_priv->display.init_clock_gating = chv_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7959 | else if (IS_HASWELL(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7960 | dev_priv->display.init_clock_gating = hsw_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7961 | else if (IS_IVYBRIDGE(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7962 | dev_priv->display.init_clock_gating = ivb_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7963 | else if (IS_VALLEYVIEW(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7964 | dev_priv->display.init_clock_gating = vlv_init_clock_gating; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7965 | else if (GRAPHICS_VER(dev_priv) == 6) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7966 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7967 | else if (GRAPHICS_VER(dev_priv) == 5) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7968 | dev_priv->display.init_clock_gating = ilk_init_clock_gating; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7969 | else if (IS_G4X(dev_priv)) |
| 7970 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7971 | else if (IS_I965GM(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7972 | dev_priv->display.init_clock_gating = i965gm_init_clock_gating; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7973 | else if (IS_I965G(dev_priv)) |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7974 | dev_priv->display.init_clock_gating = i965g_init_clock_gating; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7975 | else if (GRAPHICS_VER(dev_priv) == 3) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7976 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 7977 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
| 7978 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7979 | else if (GRAPHICS_VER(dev_priv) == 2) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7980 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 7981 | else { |
| 7982 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 7983 | dev_priv->display.init_clock_gating = nop_init_clock_gating; |
| 7984 | } |
| 7985 | } |
| 7986 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7987 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 7988 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7989 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7990 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7991 | if (IS_PINEVIEW(dev_priv)) |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 7992 | pnv_get_mem_freq(dev_priv); |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7993 | else if (GRAPHICS_VER(dev_priv) == 5) |
Lucas De Marchi | 9eae5e2 | 2019-12-24 00:40:09 -0800 | [diff] [blame] | 7994 | ilk_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7995 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 7996 | if (intel_has_sagv(dev_priv)) |
| 7997 | skl_setup_sagv_block_time(dev_priv); |
| 7998 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7999 | /* For FIFO watermark updates */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 8000 | if (DISPLAY_VER(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8001 | skl_setup_wm_latency(dev_priv); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 8002 | dev_priv->display.compute_global_watermarks = skl_compute_wm; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8003 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8004 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 8005 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8006 | if ((DISPLAY_VER(dev_priv) == 5 && dev_priv->wm.pri_latency[1] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8007 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8008 | (DISPLAY_VER(dev_priv) != 5 && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8009 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 8010 | dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 8011 | dev_priv->display.compute_intermediate_wm = |
| 8012 | ilk_compute_intermediate_wm; |
| 8013 | dev_priv->display.initial_watermarks = |
| 8014 | ilk_initial_watermarks; |
| 8015 | dev_priv->display.optimize_watermarks = |
| 8016 | ilk_optimize_watermarks; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8017 | } else { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8018 | drm_dbg_kms(&dev_priv->drm, |
| 8019 | "Failed to read display plane latency. " |
| 8020 | "Disable CxSR\n"); |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8021 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 8022 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8023 | vlv_setup_wm_latency(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8024 | dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 8025 | dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8026 | dev_priv->display.initial_watermarks = vlv_initial_watermarks; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 8027 | dev_priv->display.optimize_watermarks = vlv_optimize_watermarks; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 8028 | dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 8029 | } else if (IS_G4X(dev_priv)) { |
| 8030 | g4x_setup_wm_latency(dev_priv); |
| 8031 | dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm; |
| 8032 | dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm; |
| 8033 | dev_priv->display.initial_watermarks = g4x_initial_watermarks; |
| 8034 | dev_priv->display.optimize_watermarks = g4x_optimize_watermarks; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8035 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 8036 | if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8037 | dev_priv->is_ddr3, |
| 8038 | dev_priv->fsb_freq, |
| 8039 | dev_priv->mem_freq)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8040 | drm_info(&dev_priv->drm, |
| 8041 | "failed to find known CxSR latency " |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8042 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 8043 | "disabling CxSR\n", |
| 8044 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 8045 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 8046 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 8047 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8048 | dev_priv->display.update_wm = NULL; |
| 8049 | } else |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 8050 | dev_priv->display.update_wm = pnv_update_wm; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8051 | } else if (DISPLAY_VER(dev_priv) == 4) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8052 | dev_priv->display.update_wm = i965_update_wm; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8053 | } else if (DISPLAY_VER(dev_priv) == 3) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8054 | dev_priv->display.update_wm = i9xx_update_wm; |
| 8055 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8056 | } else if (DISPLAY_VER(dev_priv) == 2) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 8057 | if (INTEL_NUM_PIPES(dev_priv) == 1) { |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8058 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8059 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8060 | } else { |
| 8061 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8062 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8063 | } |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8064 | } else { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8065 | drm_err(&dev_priv->drm, |
| 8066 | "unexpected fall-through in %s\n", __func__); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8067 | } |
| 8068 | } |
| 8069 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 8070 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8071 | { |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 8072 | dev_priv->runtime_pm.suspended = false; |
| 8073 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8074 | } |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 8075 | |
| 8076 | static struct intel_global_state *intel_dbuf_duplicate_state(struct intel_global_obj *obj) |
| 8077 | { |
| 8078 | struct intel_dbuf_state *dbuf_state; |
| 8079 | |
| 8080 | dbuf_state = kmemdup(obj->state, sizeof(*dbuf_state), GFP_KERNEL); |
| 8081 | if (!dbuf_state) |
| 8082 | return NULL; |
| 8083 | |
| 8084 | return &dbuf_state->base; |
| 8085 | } |
| 8086 | |
| 8087 | static void intel_dbuf_destroy_state(struct intel_global_obj *obj, |
| 8088 | struct intel_global_state *state) |
| 8089 | { |
| 8090 | kfree(state); |
| 8091 | } |
| 8092 | |
| 8093 | static const struct intel_global_state_funcs intel_dbuf_funcs = { |
| 8094 | .atomic_duplicate_state = intel_dbuf_duplicate_state, |
| 8095 | .atomic_destroy_state = intel_dbuf_destroy_state, |
| 8096 | }; |
| 8097 | |
| 8098 | struct intel_dbuf_state * |
| 8099 | intel_atomic_get_dbuf_state(struct intel_atomic_state *state) |
| 8100 | { |
| 8101 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8102 | struct intel_global_state *dbuf_state; |
| 8103 | |
| 8104 | dbuf_state = intel_atomic_get_global_obj_state(state, &dev_priv->dbuf.obj); |
| 8105 | if (IS_ERR(dbuf_state)) |
| 8106 | return ERR_CAST(dbuf_state); |
| 8107 | |
| 8108 | return to_intel_dbuf_state(dbuf_state); |
| 8109 | } |
| 8110 | |
| 8111 | int intel_dbuf_init(struct drm_i915_private *dev_priv) |
| 8112 | { |
| 8113 | struct intel_dbuf_state *dbuf_state; |
| 8114 | |
| 8115 | dbuf_state = kzalloc(sizeof(*dbuf_state), GFP_KERNEL); |
| 8116 | if (!dbuf_state) |
| 8117 | return -ENOMEM; |
| 8118 | |
| 8119 | intel_atomic_global_obj_init(dev_priv, &dev_priv->dbuf.obj, |
| 8120 | &dbuf_state->base, &intel_dbuf_funcs); |
| 8121 | |
| 8122 | return 0; |
| 8123 | } |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8124 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 8125 | /* |
| 8126 | * Configure MBUS_CTL and all DBUF_CTL_S of each slice to join_mbus state before |
| 8127 | * update the request state of all DBUS slices. |
| 8128 | */ |
| 8129 | static void update_mbus_pre_enable(struct intel_atomic_state *state) |
| 8130 | { |
| 8131 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8132 | u32 mbus_ctl, dbuf_min_tracker_val; |
| 8133 | enum dbuf_slice slice; |
| 8134 | const struct intel_dbuf_state *dbuf_state = |
| 8135 | intel_atomic_get_new_dbuf_state(state); |
| 8136 | |
| 8137 | if (!IS_ALDERLAKE_P(dev_priv)) |
| 8138 | return; |
| 8139 | |
| 8140 | /* |
| 8141 | * TODO: Implement vblank synchronized MBUS joining changes. |
| 8142 | * Must be properly coordinated with dbuf reprogramming. |
| 8143 | */ |
| 8144 | if (dbuf_state->joined_mbus) { |
| 8145 | mbus_ctl = MBUS_HASHING_MODE_1x4 | MBUS_JOIN | |
| 8146 | MBUS_JOIN_PIPE_SELECT_NONE; |
| 8147 | dbuf_min_tracker_val = DBUF_MIN_TRACKER_STATE_SERVICE(3); |
| 8148 | } else { |
| 8149 | mbus_ctl = MBUS_HASHING_MODE_2x2 | |
| 8150 | MBUS_JOIN_PIPE_SELECT_NONE; |
| 8151 | dbuf_min_tracker_val = DBUF_MIN_TRACKER_STATE_SERVICE(1); |
| 8152 | } |
| 8153 | |
| 8154 | intel_de_rmw(dev_priv, MBUS_CTL, |
| 8155 | MBUS_HASHING_MODE_MASK | MBUS_JOIN | |
| 8156 | MBUS_JOIN_PIPE_SELECT_MASK, mbus_ctl); |
| 8157 | |
| 8158 | for_each_dbuf_slice(dev_priv, slice) |
| 8159 | intel_de_rmw(dev_priv, DBUF_CTL_S(slice), |
| 8160 | DBUF_MIN_TRACKER_STATE_SERVICE_MASK, |
| 8161 | dbuf_min_tracker_val); |
| 8162 | } |
| 8163 | |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8164 | void intel_dbuf_pre_plane_update(struct intel_atomic_state *state) |
| 8165 | { |
| 8166 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8167 | const struct intel_dbuf_state *new_dbuf_state = |
| 8168 | intel_atomic_get_new_dbuf_state(state); |
| 8169 | const struct intel_dbuf_state *old_dbuf_state = |
| 8170 | intel_atomic_get_old_dbuf_state(state); |
| 8171 | |
| 8172 | if (!new_dbuf_state || |
Stanislav Lisovskiy | 0d6695b | 2021-05-27 14:01:06 +0300 | [diff] [blame] | 8173 | ((new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices) |
| 8174 | && (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus))) |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8175 | return; |
| 8176 | |
| 8177 | WARN_ON(!new_dbuf_state->base.changed); |
| 8178 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 8179 | update_mbus_pre_enable(state); |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8180 | gen9_dbuf_slices_update(dev_priv, |
| 8181 | old_dbuf_state->enabled_slices | |
| 8182 | new_dbuf_state->enabled_slices); |
| 8183 | } |
| 8184 | |
| 8185 | void intel_dbuf_post_plane_update(struct intel_atomic_state *state) |
| 8186 | { |
| 8187 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8188 | const struct intel_dbuf_state *new_dbuf_state = |
| 8189 | intel_atomic_get_new_dbuf_state(state); |
| 8190 | const struct intel_dbuf_state *old_dbuf_state = |
| 8191 | intel_atomic_get_old_dbuf_state(state); |
| 8192 | |
| 8193 | if (!new_dbuf_state || |
Stanislav Lisovskiy | 0d6695b | 2021-05-27 14:01:06 +0300 | [diff] [blame] | 8194 | ((new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices) |
| 8195 | && (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus))) |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8196 | return; |
| 8197 | |
| 8198 | WARN_ON(!new_dbuf_state->base.changed); |
| 8199 | |
| 8200 | gen9_dbuf_slices_update(dev_priv, |
| 8201 | new_dbuf_state->enabled_slices); |
| 8202 | } |