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 | 4dd4375 | 2021-10-14 13:28:57 +0300 | [diff] [blame] | 50 | #include "intel_pcode.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 51 | #include "intel_pm.h" |
Jani Nikula | 1eecf31e | 2021-10-13 13:11:59 +0300 | [diff] [blame] | 52 | #include "vlv_sideband.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 53 | #include "../../../platform/x86/intel_ips.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 54 | |
Jani Nikula | a10510a | 2020-02-27 19:00:47 +0200 | [diff] [blame] | 55 | /* Stores plane specific WM parameters */ |
| 56 | struct skl_wm_params { |
| 57 | bool x_tiled, y_tiled; |
| 58 | bool rc_surface; |
| 59 | bool is_planar; |
| 60 | u32 width; |
| 61 | u8 cpp; |
| 62 | u32 plane_pixel_rate; |
| 63 | u32 y_min_scanlines; |
| 64 | u32 plane_bytes_per_line; |
| 65 | uint_fixed_16_16_t plane_blocks_per_line; |
| 66 | uint_fixed_16_16_t y_tile_minimum; |
| 67 | u32 linetime_us; |
| 68 | u32 dbuf_block_size; |
| 69 | }; |
| 70 | |
| 71 | /* used in computing the new watermarks state */ |
| 72 | struct intel_wm_config { |
| 73 | unsigned int num_pipes_active; |
| 74 | bool sprites_enabled; |
| 75 | bool sprites_scaled; |
| 76 | }; |
| 77 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 78 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 79 | { |
Ville Syrjälä | b2d73de | 2021-09-30 22:09:42 +0300 | [diff] [blame] | 80 | enum pipe pipe; |
| 81 | |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 82 | if (HAS_LLC(dev_priv)) { |
| 83 | /* |
| 84 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
Lucas De Marchi | e0403cb | 2017-12-05 11:01:17 -0800 | [diff] [blame] | 85 | * Display WA #0390: skl,kbl |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 86 | * |
| 87 | * Must match Sampler, Pixel Back End, and Media. See |
| 88 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 89 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 90 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 91 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR1_1) | |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 92 | SKL_DE_COMPRESSED_HASH_MODE); |
| 93 | } |
| 94 | |
Ville Syrjälä | b2d73de | 2021-09-30 22:09:42 +0300 | [diff] [blame] | 95 | for_each_pipe(dev_priv, pipe) { |
| 96 | /* |
| 97 | * "Plane N strech max must be programmed to 11b (x1) |
| 98 | * when Async flips are enabled on that plane." |
| 99 | */ |
Tvrtko Ursulin | cca0846 | 2021-11-26 14:14:24 +0000 | [diff] [blame^] | 100 | if (!IS_GEMINILAKE(dev_priv) && intel_vtd_active(dev_priv)) |
Ville Syrjälä | b2d73de | 2021-09-30 22:09:42 +0300 | [diff] [blame] | 101 | intel_uncore_rmw(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe), |
| 102 | SKL_PLANE1_STRETCH_MAX_MASK, SKL_PLANE1_STRETCH_MAX_X1); |
| 103 | } |
| 104 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 105 | /* 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] | 106 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 107 | 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] | 108 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 109 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 110 | intel_uncore_write(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1, |
| 111 | intel_uncore_read(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 112 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 113 | /* |
| 114 | * WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl |
| 115 | * Display WA #0859: skl,bxt,kbl,glk,cfl |
| 116 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 117 | 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] | 118 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 119 | } |
| 120 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 121 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 122 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 123 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 124 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 125 | /* WaDisableSDEUnitClockGating:bxt */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 126 | 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] | 127 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 128 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 129 | /* |
| 130 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 131 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 132 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 133 | 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] | 134 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 138 | * to stay fully on. |
| 139 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 140 | 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] | 141 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Uma Shankar | 1d85a29 | 2018-08-07 21:15:35 +0530 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * Lower the display internal timeout. |
| 145 | * This is needed to avoid any hard hangs when DSI port PLL |
| 146 | * is off and a MMIO access is attempted by any privilege |
| 147 | * application, using batch buffers or any other means. |
| 148 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 149 | 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] | 150 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 151 | /* |
| 152 | * WaFbcTurnOffFbcWatermark:bxt |
| 153 | * Display WA #0562: bxt |
| 154 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 155 | 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] | 156 | DISP_FBC_WM_DIS); |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 157 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 158 | /* |
| 159 | * WaFbcHighMemBwCorruptionAvoidance:bxt |
| 160 | * Display WA #0883: bxt |
| 161 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 162 | 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] | 163 | ILK_DPFC_DISABLE_DUMMY0); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 164 | } |
| 165 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 166 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 167 | { |
| 168 | gen9_init_clock_gating(dev_priv); |
| 169 | |
| 170 | /* |
| 171 | * WaDisablePWMClockGating:glk |
| 172 | * Backlight PWM may stop in the asserted state, causing backlight |
| 173 | * to stay fully on. |
| 174 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 175 | 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] | 176 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
| 177 | } |
| 178 | |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 179 | static void pnv_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 180 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 181 | u32 tmp; |
| 182 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 183 | tmp = intel_uncore_read(&dev_priv->uncore, CLKCFG); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 184 | |
| 185 | switch (tmp & CLKCFG_FSB_MASK) { |
| 186 | case CLKCFG_FSB_533: |
| 187 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 188 | break; |
| 189 | case CLKCFG_FSB_800: |
| 190 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 191 | break; |
| 192 | case CLKCFG_FSB_667: |
| 193 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 194 | break; |
| 195 | case CLKCFG_FSB_400: |
| 196 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | switch (tmp & CLKCFG_MEM_MASK) { |
| 201 | case CLKCFG_MEM_533: |
| 202 | dev_priv->mem_freq = 533; |
| 203 | break; |
| 204 | case CLKCFG_MEM_667: |
| 205 | dev_priv->mem_freq = 667; |
| 206 | break; |
| 207 | case CLKCFG_MEM_800: |
| 208 | dev_priv->mem_freq = 800; |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | /* detect pineview DDR3 setting */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 213 | tmp = intel_uncore_read(&dev_priv->uncore, CSHRDDR3CTL); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 214 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 215 | } |
| 216 | |
Lucas De Marchi | 9eae5e2 | 2019-12-24 00:40:09 -0800 | [diff] [blame] | 217 | static void ilk_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 218 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 219 | u16 ddrpll, csipll; |
| 220 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 221 | ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1); |
| 222 | csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 223 | |
| 224 | switch (ddrpll & 0xff) { |
| 225 | case 0xc: |
| 226 | dev_priv->mem_freq = 800; |
| 227 | break; |
| 228 | case 0x10: |
| 229 | dev_priv->mem_freq = 1066; |
| 230 | break; |
| 231 | case 0x14: |
| 232 | dev_priv->mem_freq = 1333; |
| 233 | break; |
| 234 | case 0x18: |
| 235 | dev_priv->mem_freq = 1600; |
| 236 | break; |
| 237 | default: |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 238 | drm_dbg(&dev_priv->drm, "unknown memory frequency 0x%02x\n", |
| 239 | ddrpll & 0xff); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 240 | dev_priv->mem_freq = 0; |
| 241 | break; |
| 242 | } |
| 243 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 244 | switch (csipll & 0x3ff) { |
| 245 | case 0x00c: |
| 246 | dev_priv->fsb_freq = 3200; |
| 247 | break; |
| 248 | case 0x00e: |
| 249 | dev_priv->fsb_freq = 3733; |
| 250 | break; |
| 251 | case 0x010: |
| 252 | dev_priv->fsb_freq = 4266; |
| 253 | break; |
| 254 | case 0x012: |
| 255 | dev_priv->fsb_freq = 4800; |
| 256 | break; |
| 257 | case 0x014: |
| 258 | dev_priv->fsb_freq = 5333; |
| 259 | break; |
| 260 | case 0x016: |
| 261 | dev_priv->fsb_freq = 5866; |
| 262 | break; |
| 263 | case 0x018: |
| 264 | dev_priv->fsb_freq = 6400; |
| 265 | break; |
| 266 | default: |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 267 | drm_dbg(&dev_priv->drm, "unknown fsb frequency 0x%04x\n", |
| 268 | csipll & 0x3ff); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 269 | dev_priv->fsb_freq = 0; |
| 270 | break; |
| 271 | } |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 274 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 275 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 276 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 277 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 278 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 279 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 280 | |
| 281 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 282 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 283 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 284 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 285 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 286 | |
| 287 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 288 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 289 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 290 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 291 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 292 | |
| 293 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 294 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 295 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 296 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 297 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 298 | |
| 299 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 300 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 301 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 302 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 303 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 304 | |
| 305 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 306 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 307 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 308 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 309 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 310 | }; |
| 311 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 312 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 313 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 314 | int fsb, |
| 315 | int mem) |
| 316 | { |
| 317 | const struct cxsr_latency *latency; |
| 318 | int i; |
| 319 | |
| 320 | if (fsb == 0 || mem == 0) |
| 321 | return NULL; |
| 322 | |
| 323 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 324 | latency = &cxsr_latency_table[i]; |
| 325 | if (is_desktop == latency->is_desktop && |
| 326 | is_ddr3 == latency->is_ddr3 && |
| 327 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 328 | return latency; |
| 329 | } |
| 330 | |
| 331 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 332 | |
| 333 | return NULL; |
| 334 | } |
| 335 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 336 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 337 | { |
| 338 | u32 val; |
| 339 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 340 | vlv_punit_get(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 341 | |
| 342 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 343 | if (enable) |
| 344 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 345 | else |
| 346 | val |= FORCE_DDR_HIGH_FREQ; |
| 347 | val &= ~FORCE_DDR_LOW_FREQ; |
| 348 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 349 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 350 | |
| 351 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 352 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 353 | drm_err(&dev_priv->drm, |
| 354 | "timed out waiting for Punit DDR DVFS request\n"); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 355 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 356 | vlv_punit_put(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 359 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 360 | { |
| 361 | u32 val; |
| 362 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 363 | vlv_punit_get(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 364 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 365 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 366 | if (enable) |
| 367 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 368 | else |
| 369 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 370 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 371 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 372 | vlv_punit_put(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 375 | #define FW_WM(value, plane) \ |
| 376 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 377 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 378 | 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] | 379 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 380 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 381 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 382 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 383 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 384 | was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 385 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 386 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 387 | } else if (IS_G4X(dev_priv) || IS_I965GM(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; |
| 389 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 390 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 391 | } else if (IS_PINEVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 392 | val = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 393 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 394 | if (enable) |
| 395 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 396 | else |
| 397 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 398 | intel_uncore_write(&dev_priv->uncore, DSPFW3, val); |
| 399 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 400 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 401 | 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] | 402 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 403 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 404 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, val); |
| 405 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 406 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 407 | /* |
| 408 | * FIXME can't find a bit like this for 915G, and |
| 409 | * and yet it does have the related watermark in |
| 410 | * FW_BLC_SELF. What's going on? |
| 411 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 412 | was_enabled = intel_uncore_read(&dev_priv->uncore, INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 413 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 414 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 415 | intel_uncore_write(&dev_priv->uncore, INSTPM, val); |
| 416 | intel_uncore_posting_read(&dev_priv->uncore, INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 417 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 418 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 419 | } |
| 420 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 421 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 422 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 423 | drm_dbg_kms(&dev_priv->drm, "memory self-refresh is %s (was %s)\n", |
| 424 | enableddisabled(enable), |
| 425 | enableddisabled(was_enabled)); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 426 | |
| 427 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 428 | } |
| 429 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 430 | /** |
| 431 | * intel_set_memory_cxsr - Configure CxSR state |
| 432 | * @dev_priv: i915 device |
| 433 | * @enable: Allow vs. disallow CxSR |
| 434 | * |
| 435 | * Allow or disallow the system to enter a special CxSR |
| 436 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 437 | * is that several display FIFOs may get combined into a single larger |
| 438 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 439 | * system to defer memory fetches longer, and the memory will enter |
| 440 | * self refresh. |
| 441 | * |
| 442 | * Note that enabling CxSR does not guarantee that the system enter |
| 443 | * this special mode, nor does it guarantee that the system stays |
| 444 | * in that mode once entered. So this just allows/disallows the system |
| 445 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 446 | * C-states will affect when/if the system actually enters/exits the |
| 447 | * CxSR mode. |
| 448 | * |
| 449 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 450 | * and the system is free to enter/exit memory self refresh at any time |
| 451 | * even when the use of CxSR has been disallowed. |
| 452 | * |
| 453 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 454 | * control registers will not get latched on vblank. Thus in order to |
| 455 | * guarantee the system will respond to changes in the plane registers |
| 456 | * we must always disallow CxSR prior to making changes to those registers. |
| 457 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 458 | * frame start which happens after vblank start (which is when the plane |
| 459 | * registers would get latched), so we can't proceed with the plane update |
| 460 | * during the same frame where we disallowed CxSR. |
| 461 | * |
| 462 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 463 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 464 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 465 | * Disallowing just CxSR is sufficient. |
| 466 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 467 | 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] | 468 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 469 | bool ret; |
| 470 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 471 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 472 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 473 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 474 | dev_priv->wm.vlv.cxsr = enable; |
| 475 | else if (IS_G4X(dev_priv)) |
| 476 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 477 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 478 | |
| 479 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 480 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 481 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 482 | /* |
| 483 | * Latency for FIFO fetches is dependent on several factors: |
| 484 | * - memory configuration (speed, channels) |
| 485 | * - chipset |
| 486 | * - current MCH state |
| 487 | * It can be fairly high in some situations, so here we assume a fairly |
| 488 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 489 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 490 | * and power consumption (set it too low to save power and we might see |
| 491 | * FIFO underruns and display "flicker"). |
| 492 | * |
| 493 | * A value of 5us seems to be a good balance; safe for very low end |
| 494 | * platforms but not overly aggressive on lower latency configs. |
| 495 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 496 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 497 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 498 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 499 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 500 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 501 | 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] | 502 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 503 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 504 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 505 | 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] | 506 | enum pipe pipe = crtc->pipe; |
| 507 | int sprite0_start, sprite1_start; |
Kees Cook | 2713eb4 | 2020-02-20 16:05:17 -0800 | [diff] [blame] | 508 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 509 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 510 | switch (pipe) { |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 511 | case PIPE_A: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 512 | dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
| 513 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 514 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 515 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 516 | break; |
| 517 | case PIPE_B: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 518 | dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
| 519 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 520 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 521 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 522 | break; |
| 523 | case PIPE_C: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 524 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
| 525 | dsparb3 = intel_uncore_read(&dev_priv->uncore, DSPARB3); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 526 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 527 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 528 | break; |
| 529 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 530 | MISSING_CASE(pipe); |
| 531 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 532 | } |
| 533 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 534 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 535 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 536 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 537 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 538 | } |
| 539 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 540 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 541 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 542 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 543 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 544 | int size; |
| 545 | |
| 546 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 547 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 548 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 549 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 550 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 551 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 552 | |
| 553 | return size; |
| 554 | } |
| 555 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 556 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 557 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 558 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 559 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 560 | int size; |
| 561 | |
| 562 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 563 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 564 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 565 | size >>= 1; /* Convert to cachelines */ |
| 566 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 567 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 568 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 569 | |
| 570 | return size; |
| 571 | } |
| 572 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 573 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 574 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 575 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 576 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 577 | int size; |
| 578 | |
| 579 | size = dsparb & 0x7f; |
| 580 | size >>= 2; /* Convert to cachelines */ |
| 581 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 582 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 583 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 584 | |
| 585 | return size; |
| 586 | } |
| 587 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 588 | /* Pineview has different values for various configs */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 589 | static const struct intel_watermark_params pnv_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 590 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 591 | .max_wm = PINEVIEW_MAX_WM, |
| 592 | .default_wm = PINEVIEW_DFT_WM, |
| 593 | .guard_size = PINEVIEW_GUARD_WM, |
| 594 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 595 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 596 | |
| 597 | static const struct intel_watermark_params pnv_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 598 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 599 | .max_wm = PINEVIEW_MAX_WM, |
| 600 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 601 | .guard_size = PINEVIEW_GUARD_WM, |
| 602 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 603 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 604 | |
| 605 | static const struct intel_watermark_params pnv_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 606 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 607 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 608 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 609 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 610 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 611 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 612 | |
| 613 | static const struct intel_watermark_params pnv_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 614 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 615 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 616 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 617 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 618 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 619 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 620 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 621 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 622 | .fifo_size = I965_CURSOR_FIFO, |
| 623 | .max_wm = I965_CURSOR_MAX_WM, |
| 624 | .default_wm = I965_CURSOR_DFT_WM, |
| 625 | .guard_size = 2, |
| 626 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 627 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 628 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 629 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 630 | .fifo_size = I945_FIFO_SIZE, |
| 631 | .max_wm = I915_MAX_WM, |
| 632 | .default_wm = 1, |
| 633 | .guard_size = 2, |
| 634 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 635 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 636 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 637 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 638 | .fifo_size = I915_FIFO_SIZE, |
| 639 | .max_wm = I915_MAX_WM, |
| 640 | .default_wm = 1, |
| 641 | .guard_size = 2, |
| 642 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 643 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 644 | |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 645 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 646 | .fifo_size = I855GM_FIFO_SIZE, |
| 647 | .max_wm = I915_MAX_WM, |
| 648 | .default_wm = 1, |
| 649 | .guard_size = 2, |
| 650 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 651 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 652 | |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 653 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 654 | .fifo_size = I855GM_FIFO_SIZE, |
| 655 | .max_wm = I915_MAX_WM/2, |
| 656 | .default_wm = 1, |
| 657 | .guard_size = 2, |
| 658 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 659 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 660 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 661 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 662 | .fifo_size = I830_FIFO_SIZE, |
| 663 | .max_wm = I915_MAX_WM, |
| 664 | .default_wm = 1, |
| 665 | .guard_size = 2, |
| 666 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 667 | }; |
| 668 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 669 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 670 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 671 | * @pixel_rate: Pipe pixel rate in kHz |
| 672 | * @cpp: Plane bytes per pixel |
| 673 | * @latency: Memory wakeup latency in 0.1us units |
| 674 | * |
| 675 | * Compute the watermark using the method 1 or "small buffer" |
| 676 | * formula. The caller may additonally add extra cachelines |
| 677 | * to account for TLB misses and clock crossings. |
| 678 | * |
| 679 | * This method is concerned with the short term drain rate |
| 680 | * of the FIFO, ie. it does not account for blanking periods |
| 681 | * which would effectively reduce the average drain rate across |
| 682 | * a longer period. The name "small" refers to the fact the |
| 683 | * FIFO is relatively small compared to the amount of data |
| 684 | * fetched. |
| 685 | * |
| 686 | * The FIFO level vs. time graph might look something like: |
| 687 | * |
| 688 | * |\ |\ |
| 689 | * | \ | \ |
| 690 | * __---__---__ (- plane active, _ blanking) |
| 691 | * -> time |
| 692 | * |
| 693 | * or perhaps like this: |
| 694 | * |
| 695 | * |\|\ |\|\ |
| 696 | * __----__----__ (- plane active, _ blanking) |
| 697 | * -> time |
| 698 | * |
| 699 | * Returns: |
| 700 | * The watermark in bytes |
| 701 | */ |
| 702 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 703 | unsigned int cpp, |
| 704 | unsigned int latency) |
| 705 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 706 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 707 | |
Ville Syrjälä | d492a29 | 2019-04-08 18:27:01 +0300 | [diff] [blame] | 708 | ret = mul_u32_u32(pixel_rate, cpp * latency); |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 709 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 710 | |
| 711 | return ret; |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 716 | * @pixel_rate: Pipe pixel rate in kHz |
| 717 | * @htotal: Pipe horizontal total |
| 718 | * @width: Plane width in pixels |
| 719 | * @cpp: Plane bytes per pixel |
| 720 | * @latency: Memory wakeup latency in 0.1us units |
| 721 | * |
| 722 | * Compute the watermark using the method 2 or "large buffer" |
| 723 | * formula. The caller may additonally add extra cachelines |
| 724 | * to account for TLB misses and clock crossings. |
| 725 | * |
| 726 | * This method is concerned with the long term drain rate |
| 727 | * of the FIFO, ie. it does account for blanking periods |
| 728 | * which effectively reduce the average drain rate across |
| 729 | * a longer period. The name "large" refers to the fact the |
| 730 | * FIFO is relatively large compared to the amount of data |
| 731 | * fetched. |
| 732 | * |
| 733 | * The FIFO level vs. time graph might look something like: |
| 734 | * |
| 735 | * |\___ |\___ |
| 736 | * | \___ | \___ |
| 737 | * | \ | \ |
| 738 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 739 | * -> time |
| 740 | * |
| 741 | * Returns: |
| 742 | * The watermark in bytes |
| 743 | */ |
| 744 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 745 | unsigned int htotal, |
| 746 | unsigned int width, |
| 747 | unsigned int cpp, |
| 748 | unsigned int latency) |
| 749 | { |
| 750 | unsigned int ret; |
| 751 | |
| 752 | /* |
| 753 | * FIXME remove once all users are computing |
| 754 | * watermarks in the correct place. |
| 755 | */ |
| 756 | if (WARN_ON_ONCE(htotal == 0)) |
| 757 | htotal = 1; |
| 758 | |
| 759 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 760 | ret = (ret + 1) * width * cpp; |
| 761 | |
| 762 | return ret; |
| 763 | } |
| 764 | |
| 765 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 766 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 767 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 768 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 769 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 770 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 771 | * @latency_ns: memory latency for the platform |
| 772 | * |
| 773 | * Calculate the watermark level (the level at which the display plane will |
| 774 | * start fetching from memory again). Each chip has a different display |
| 775 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 776 | * in the correct intel_watermark_params structure. |
| 777 | * |
| 778 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 779 | * on the pixel size. When it reaches the watermark level, it'll start |
| 780 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 781 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 782 | * will occur, and a display engine hang could result. |
| 783 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 784 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 785 | const struct intel_watermark_params *wm, |
| 786 | int fifo_size, int cpp, |
| 787 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 788 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 789 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 790 | |
| 791 | /* |
| 792 | * Note: we need to make sure we don't overflow for various clock & |
| 793 | * latency values. |
| 794 | * clocks go from a few thousand to several hundred thousand. |
| 795 | * latency is usually a few thousand |
| 796 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 797 | entries = intel_wm_method1(pixel_rate, cpp, |
| 798 | latency_ns / 100); |
| 799 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 800 | wm->guard_size; |
| 801 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 802 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 803 | wm_size = fifo_size - entries; |
| 804 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 805 | |
| 806 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 807 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 808 | wm_size = wm->max_wm; |
| 809 | if (wm_size <= 0) |
| 810 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 811 | |
| 812 | /* |
| 813 | * Bspec seems to indicate that the value shouldn't be lower than |
| 814 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 815 | * Lets go for 8 which is the burst size since certain platforms |
| 816 | * already use a hardcoded 8 (which is what the spec says should be |
| 817 | * done). |
| 818 | */ |
| 819 | if (wm_size <= 8) |
| 820 | wm_size = 8; |
| 821 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 822 | return wm_size; |
| 823 | } |
| 824 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 825 | static bool is_disabling(int old, int new, int threshold) |
| 826 | { |
| 827 | return old >= threshold && new < threshold; |
| 828 | } |
| 829 | |
| 830 | static bool is_enabling(int old, int new, int threshold) |
| 831 | { |
| 832 | return old < threshold && new >= threshold; |
| 833 | } |
| 834 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 835 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 836 | { |
| 837 | return dev_priv->wm.max_level + 1; |
| 838 | } |
| 839 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 840 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 841 | const struct intel_plane_state *plane_state) |
| 842 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 843 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 844 | |
| 845 | /* FIXME check the 'enable' instead */ |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 846 | if (!crtc_state->hw.active) |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 847 | return false; |
| 848 | |
| 849 | /* |
| 850 | * Treat cursor with fb as always visible since cursor updates |
| 851 | * can happen faster than the vrefresh rate, and the current |
| 852 | * watermark code doesn't handle that correctly. Cursor updates |
| 853 | * which set/clear the fb or change the cursor size are going |
| 854 | * to get throttled by intel_legacy_cursor_update() to work |
| 855 | * around this problem with the watermark code. |
| 856 | */ |
| 857 | if (plane->id == PLANE_CURSOR) |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 858 | return plane_state->hw.fb != NULL; |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 859 | else |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 860 | return plane_state->uapi.visible; |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 861 | } |
| 862 | |
Ville Syrjälä | 04da7b9 | 2019-11-27 22:12:11 +0200 | [diff] [blame] | 863 | static bool intel_crtc_active(struct intel_crtc *crtc) |
| 864 | { |
| 865 | /* Be paranoid as we can arrive here with only partial |
| 866 | * state retrieved from the hardware during setup. |
| 867 | * |
| 868 | * We can ditch the adjusted_mode.crtc_clock check as soon |
| 869 | * as Haswell has gained clock readout/fastboot support. |
| 870 | * |
| 871 | * We can ditch the crtc->primary->state->fb check as soon as we can |
| 872 | * properly reconstruct framebuffers. |
| 873 | * |
| 874 | * FIXME: The intel_crtc->active here should be switched to |
| 875 | * crtc->state->active once we have proper CRTC states wired up |
| 876 | * for atomic. |
| 877 | */ |
| 878 | return crtc->active && crtc->base.primary->state->fb && |
| 879 | crtc->config->hw.adjusted_mode.crtc_clock; |
| 880 | } |
| 881 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 882 | 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] | 883 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 884 | struct intel_crtc *crtc, *enabled = NULL; |
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 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 887 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 888 | if (enabled) |
| 889 | return NULL; |
| 890 | enabled = crtc; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | return enabled; |
| 895 | } |
| 896 | |
Dave Airlie | ef9c66a | 2021-09-29 01:57:47 +0300 | [diff] [blame] | 897 | static void pnv_update_wm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 898 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 899 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 900 | const struct cxsr_latency *latency; |
| 901 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 902 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 903 | |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 904 | latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 905 | dev_priv->is_ddr3, |
| 906 | dev_priv->fsb_freq, |
| 907 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 908 | if (!latency) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 909 | drm_dbg_kms(&dev_priv->drm, |
| 910 | "Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 911 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 912 | return; |
| 913 | } |
| 914 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 915 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 916 | if (crtc) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 917 | const struct drm_display_mode *pipe_mode = |
| 918 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 919 | const struct drm_framebuffer *fb = |
| 920 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 921 | int cpp = fb->format->cpp[0]; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 922 | int clock = pipe_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 923 | |
| 924 | /* Display SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 925 | wm = intel_calculate_wm(clock, &pnv_display_wm, |
| 926 | pnv_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 927 | cpp, latency->display_sr); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 928 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 929 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 930 | reg |= FW_WM(wm, SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 931 | intel_uncore_write(&dev_priv->uncore, DSPFW1, reg); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 932 | drm_dbg_kms(&dev_priv->drm, "DSPFW1 register is %x\n", reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 933 | |
| 934 | /* cursor SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 935 | wm = intel_calculate_wm(clock, &pnv_cursor_wm, |
| 936 | pnv_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 937 | 4, latency->cursor_sr); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 938 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 939 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 940 | reg |= FW_WM(wm, CURSOR_SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 941 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 942 | |
| 943 | /* Display HPLL off SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 944 | wm = intel_calculate_wm(clock, &pnv_display_hplloff_wm, |
| 945 | pnv_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 946 | cpp, latency->display_hpll_disable); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 947 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 948 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 949 | reg |= FW_WM(wm, HPLL_SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 950 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 951 | |
| 952 | /* cursor HPLL off SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 953 | wm = intel_calculate_wm(clock, &pnv_cursor_hplloff_wm, |
| 954 | pnv_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 955 | 4, latency->cursor_hpll_disable); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 956 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 957 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 958 | reg |= FW_WM(wm, HPLL_CURSOR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 959 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 960 | drm_dbg_kms(&dev_priv->drm, "DSPFW3 register is %x\n", reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 961 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 962 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 963 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 964 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 968 | /* |
| 969 | * Documentation says: |
| 970 | * "If the line size is small, the TLB fetches can get in the way of the |
| 971 | * data fetches, causing some lag in the pixel data return which is not |
| 972 | * accounted for in the above formulas. The following adjustment only |
| 973 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 974 | * The WM is adjusted upwards by the difference between the FIFO size |
| 975 | * and the size of 8 whole lines. This adjustment is always performed |
| 976 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 977 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 978 | 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] | 979 | { |
| 980 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 981 | |
| 982 | return max(0, tlb_miss); |
| 983 | } |
| 984 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 985 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 986 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 987 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 988 | enum pipe pipe; |
| 989 | |
| 990 | for_each_pipe(dev_priv, pipe) |
| 991 | trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 992 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 993 | intel_uncore_write(&dev_priv->uncore, DSPFW1, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 994 | FW_WM(wm->sr.plane, SR) | |
| 995 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 996 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 997 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 998 | intel_uncore_write(&dev_priv->uncore, DSPFW2, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 999 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 1000 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 1001 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 1002 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 1003 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1004 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1005 | intel_uncore_write(&dev_priv->uncore, DSPFW3, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1006 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 1007 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 1008 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 1009 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1010 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1011 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1012 | } |
| 1013 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1014 | #define FW_WM_VLV(value, plane) \ |
| 1015 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 1016 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1017 | 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] | 1018 | const struct vlv_wm_values *wm) |
| 1019 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1020 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1021 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1022 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1023 | trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm); |
| 1024 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1025 | intel_uncore_write(&dev_priv->uncore, VLV_DDL(pipe), |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1026 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 1027 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 1028 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 1029 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 1030 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1031 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 1032 | /* |
| 1033 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 1034 | * high order bits so that there are no out of bounds values |
| 1035 | * present in the registers during the reprogramming. |
| 1036 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1037 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, 0); |
| 1038 | intel_uncore_write(&dev_priv->uncore, DSPHOWM1, 0); |
| 1039 | intel_uncore_write(&dev_priv->uncore, DSPFW4, 0); |
| 1040 | intel_uncore_write(&dev_priv->uncore, DSPFW5, 0); |
| 1041 | intel_uncore_write(&dev_priv->uncore, DSPFW6, 0); |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 1042 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1043 | intel_uncore_write(&dev_priv->uncore, DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1044 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1045 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 1046 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 1047 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1048 | intel_uncore_write(&dev_priv->uncore, DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1049 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 1050 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1051 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1052 | intel_uncore_write(&dev_priv->uncore, DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1053 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1054 | |
| 1055 | if (IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1056 | intel_uncore_write(&dev_priv->uncore, DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1057 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1058 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1059 | intel_uncore_write(&dev_priv->uncore, DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1060 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 1061 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1062 | intel_uncore_write(&dev_priv->uncore, DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1063 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1064 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1065 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1066 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1067 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1068 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1069 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 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 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1077 | intel_uncore_write(&dev_priv->uncore, DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1078 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1079 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1080 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1081 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1082 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1083 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1084 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1085 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1086 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1087 | 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] | 1088 | } |
| 1089 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1090 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1091 | } |
| 1092 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1093 | #undef FW_WM_VLV |
| 1094 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1095 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1096 | { |
| 1097 | /* all latencies in usec */ |
| 1098 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1099 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1100 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1101 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1102 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1106 | { |
| 1107 | /* |
| 1108 | * DSPCNTR[13] supposedly controls whether the |
| 1109 | * primary plane can use the FIFO space otherwise |
| 1110 | * reserved for the sprite plane. It's not 100% clear |
| 1111 | * what the actual FIFO size is, but it looks like we |
| 1112 | * can happily set both primary and sprite watermarks |
| 1113 | * up to 127 cachelines. So that would seem to mean |
| 1114 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1115 | * the total FIFO is >= 256 cachelines in size. Either |
| 1116 | * way, we don't seem to have to worry about this |
| 1117 | * repartitioning as the maximum watermark value the |
| 1118 | * register can hold for each plane is lower than the |
| 1119 | * minimum FIFO size. |
| 1120 | */ |
| 1121 | switch (plane_id) { |
| 1122 | case PLANE_CURSOR: |
| 1123 | return 63; |
| 1124 | case PLANE_PRIMARY: |
| 1125 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1126 | case PLANE_SPRITE0: |
| 1127 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1128 | default: |
| 1129 | MISSING_CASE(plane_id); |
| 1130 | return 0; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | static int g4x_fbc_fifo_size(int level) |
| 1135 | { |
| 1136 | switch (level) { |
| 1137 | case G4X_WM_LEVEL_SR: |
| 1138 | return 7; |
| 1139 | case G4X_WM_LEVEL_HPLL: |
| 1140 | return 15; |
| 1141 | default: |
| 1142 | MISSING_CASE(level); |
| 1143 | return 0; |
| 1144 | } |
| 1145 | } |
| 1146 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1147 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1148 | const struct intel_plane_state *plane_state, |
| 1149 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1150 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1151 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1152 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1153 | const struct drm_display_mode *pipe_mode = |
| 1154 | &crtc_state->hw.pipe_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1155 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1156 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1157 | |
| 1158 | if (latency == 0) |
| 1159 | return USHRT_MAX; |
| 1160 | |
| 1161 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1162 | return 0; |
| 1163 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1164 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1165 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1166 | /* |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1167 | * WaUse32BppForSRWM:ctg,elk |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1168 | * |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1169 | * The spec fails to list this restriction for the |
| 1170 | * HPLL watermark, which seems a little strange. |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1171 | * Let's use 32bpp for the HPLL watermark as well. |
| 1172 | */ |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1173 | if (plane->id == PLANE_PRIMARY && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1174 | level != G4X_WM_LEVEL_NORMAL) |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1175 | cpp = max(cpp, 4u); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1176 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1177 | clock = pipe_mode->crtc_clock; |
| 1178 | htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1179 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1180 | width = drm_rect_width(&plane_state->uapi.dst); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1181 | |
| 1182 | if (plane->id == PLANE_CURSOR) { |
| 1183 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1184 | } else if (plane->id == PLANE_PRIMARY && |
| 1185 | level == G4X_WM_LEVEL_NORMAL) { |
| 1186 | wm = intel_wm_method1(clock, cpp, latency); |
| 1187 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1188 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1189 | |
| 1190 | small = intel_wm_method1(clock, cpp, latency); |
| 1191 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1192 | |
| 1193 | wm = min(small, large); |
| 1194 | } |
| 1195 | |
| 1196 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1197 | width, cpp); |
| 1198 | |
| 1199 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1200 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1201 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1205 | int level, enum plane_id plane_id, u16 value) |
| 1206 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1207 | 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] | 1208 | bool dirty = false; |
| 1209 | |
| 1210 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1211 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1212 | |
| 1213 | dirty |= raw->plane[plane_id] != value; |
| 1214 | raw->plane[plane_id] = value; |
| 1215 | } |
| 1216 | |
| 1217 | return dirty; |
| 1218 | } |
| 1219 | |
| 1220 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1221 | int level, u16 value) |
| 1222 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1223 | 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] | 1224 | bool dirty = false; |
| 1225 | |
| 1226 | /* NORMAL level doesn't have an FBC watermark */ |
| 1227 | level = max(level, G4X_WM_LEVEL_SR); |
| 1228 | |
| 1229 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1230 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1231 | |
| 1232 | dirty |= raw->fbc != value; |
| 1233 | raw->fbc = value; |
| 1234 | } |
| 1235 | |
| 1236 | return dirty; |
| 1237 | } |
| 1238 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 1239 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 1240 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1241 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1242 | |
| 1243 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1244 | const struct intel_plane_state *plane_state) |
| 1245 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1246 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1247 | 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] | 1248 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1249 | enum plane_id plane_id = plane->id; |
| 1250 | bool dirty = false; |
| 1251 | int level; |
| 1252 | |
| 1253 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1254 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1255 | if (plane_id == PLANE_PRIMARY) |
| 1256 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1257 | goto out; |
| 1258 | } |
| 1259 | |
| 1260 | for (level = 0; level < num_levels; level++) { |
| 1261 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1262 | int wm, max_wm; |
| 1263 | |
| 1264 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1265 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1266 | |
| 1267 | if (wm > max_wm) |
| 1268 | break; |
| 1269 | |
| 1270 | dirty |= raw->plane[plane_id] != wm; |
| 1271 | raw->plane[plane_id] = wm; |
| 1272 | |
| 1273 | if (plane_id != PLANE_PRIMARY || |
| 1274 | level == G4X_WM_LEVEL_NORMAL) |
| 1275 | continue; |
| 1276 | |
| 1277 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1278 | raw->plane[plane_id]); |
| 1279 | max_wm = g4x_fbc_fifo_size(level); |
| 1280 | |
| 1281 | /* |
| 1282 | * FBC wm is not mandatory as we |
| 1283 | * can always just disable its use. |
| 1284 | */ |
| 1285 | if (wm > max_wm) |
| 1286 | wm = USHRT_MAX; |
| 1287 | |
| 1288 | dirty |= raw->fbc != wm; |
| 1289 | raw->fbc = wm; |
| 1290 | } |
| 1291 | |
| 1292 | /* mark watermarks as invalid */ |
| 1293 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1294 | |
| 1295 | if (plane_id == PLANE_PRIMARY) |
| 1296 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1297 | |
| 1298 | out: |
| 1299 | if (dirty) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1300 | drm_dbg_kms(&dev_priv->drm, |
| 1301 | "%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1302 | plane->base.name, |
| 1303 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1304 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1305 | 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] | 1306 | |
| 1307 | if (plane_id == PLANE_PRIMARY) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1308 | drm_dbg_kms(&dev_priv->drm, |
| 1309 | "FBC watermarks: SR=%d, HPLL=%d\n", |
| 1310 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1311 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | return dirty; |
| 1315 | } |
| 1316 | |
| 1317 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1318 | enum plane_id plane_id, int level) |
| 1319 | { |
| 1320 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1321 | |
| 1322 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1323 | } |
| 1324 | |
| 1325 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1326 | int level) |
| 1327 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1328 | 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] | 1329 | |
| 1330 | if (level > dev_priv->wm.max_level) |
| 1331 | return false; |
| 1332 | |
| 1333 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1334 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1335 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1336 | } |
| 1337 | |
| 1338 | /* mark all levels starting from 'level' as invalid */ |
| 1339 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1340 | struct g4x_wm_state *wm_state, int level) |
| 1341 | { |
| 1342 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1343 | enum plane_id plane_id; |
| 1344 | |
| 1345 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1346 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1347 | } |
| 1348 | |
| 1349 | if (level <= G4X_WM_LEVEL_SR) { |
| 1350 | wm_state->cxsr = false; |
| 1351 | wm_state->sr.cursor = USHRT_MAX; |
| 1352 | wm_state->sr.plane = USHRT_MAX; |
| 1353 | wm_state->sr.fbc = USHRT_MAX; |
| 1354 | } |
| 1355 | |
| 1356 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1357 | wm_state->hpll_en = false; |
| 1358 | wm_state->hpll.cursor = USHRT_MAX; |
| 1359 | wm_state->hpll.plane = USHRT_MAX; |
| 1360 | wm_state->hpll.fbc = USHRT_MAX; |
| 1361 | } |
| 1362 | } |
| 1363 | |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1364 | static bool g4x_compute_fbc_en(const struct g4x_wm_state *wm_state, |
| 1365 | int level) |
| 1366 | { |
| 1367 | if (level < G4X_WM_LEVEL_SR) |
| 1368 | return false; |
| 1369 | |
| 1370 | if (level >= G4X_WM_LEVEL_SR && |
| 1371 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1372 | return false; |
| 1373 | |
| 1374 | if (level >= G4X_WM_LEVEL_HPLL && |
| 1375 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1376 | return false; |
| 1377 | |
| 1378 | return true; |
| 1379 | } |
| 1380 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1381 | static int g4x_compute_pipe_wm(struct intel_atomic_state *state, |
| 1382 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1383 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1384 | struct intel_crtc_state *crtc_state = |
| 1385 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1386 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 0cf771b | 2021-05-14 15:57:39 +0300 | [diff] [blame] | 1387 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1388 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1389 | const struct intel_plane_state *old_plane_state; |
| 1390 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1391 | struct intel_plane *plane; |
| 1392 | enum plane_id plane_id; |
| 1393 | int i, level; |
| 1394 | unsigned int dirty = 0; |
| 1395 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1396 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1397 | old_plane_state, |
| 1398 | new_plane_state, i) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1399 | if (new_plane_state->hw.crtc != &crtc->base && |
| 1400 | old_plane_state->hw.crtc != &crtc->base) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1401 | continue; |
| 1402 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1403 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1404 | dirty |= BIT(plane->id); |
| 1405 | } |
| 1406 | |
| 1407 | if (!dirty) |
| 1408 | return 0; |
| 1409 | |
| 1410 | level = G4X_WM_LEVEL_NORMAL; |
| 1411 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1412 | goto out; |
| 1413 | |
| 1414 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1415 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1416 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1417 | |
| 1418 | level = G4X_WM_LEVEL_SR; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1419 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1420 | goto out; |
| 1421 | |
| 1422 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1423 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1424 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1425 | wm_state->sr.fbc = raw->fbc; |
| 1426 | |
Ville Syrjälä | 0cf771b | 2021-05-14 15:57:39 +0300 | [diff] [blame] | 1427 | wm_state->cxsr = active_planes == BIT(PLANE_PRIMARY); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1428 | |
| 1429 | level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1430 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1431 | goto out; |
| 1432 | |
| 1433 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1434 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1435 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1436 | wm_state->hpll.fbc = raw->fbc; |
| 1437 | |
| 1438 | wm_state->hpll_en = wm_state->cxsr; |
| 1439 | |
| 1440 | level++; |
| 1441 | |
| 1442 | out: |
| 1443 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1444 | return -EINVAL; |
| 1445 | |
| 1446 | /* invalidate the higher levels */ |
| 1447 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1448 | |
| 1449 | /* |
| 1450 | * Determine if the FBC watermark(s) can be used. IF |
| 1451 | * this isn't the case we prefer to disable the FBC |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1452 | * watermark(s) rather than disable the SR/HPLL |
| 1453 | * level(s) entirely. 'level-1' is the highest valid |
| 1454 | * level here. |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1455 | */ |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1456 | 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] | 1457 | |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1461 | static int g4x_compute_intermediate_wm(struct intel_atomic_state *state, |
| 1462 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1463 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1464 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1465 | struct intel_crtc_state *new_crtc_state = |
| 1466 | intel_atomic_get_new_crtc_state(state, crtc); |
| 1467 | const struct intel_crtc_state *old_crtc_state = |
| 1468 | intel_atomic_get_old_crtc_state(state, crtc); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1469 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1470 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1471 | 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] | 1472 | enum plane_id plane_id; |
| 1473 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1474 | if (!new_crtc_state->hw.active || |
| 1475 | drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) { |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1476 | *intermediate = *optimal; |
| 1477 | |
| 1478 | intermediate->cxsr = false; |
| 1479 | intermediate->hpll_en = false; |
| 1480 | goto out; |
| 1481 | } |
| 1482 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1483 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1484 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1485 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1486 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1487 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1488 | |
| 1489 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1490 | intermediate->wm.plane[plane_id] = |
| 1491 | max(optimal->wm.plane[plane_id], |
| 1492 | active->wm.plane[plane_id]); |
| 1493 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1494 | drm_WARN_ON(&dev_priv->drm, intermediate->wm.plane[plane_id] > |
| 1495 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1499 | active->sr.plane); |
| 1500 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1501 | active->sr.cursor); |
| 1502 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1503 | active->sr.fbc); |
| 1504 | |
| 1505 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1506 | active->hpll.plane); |
| 1507 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1508 | active->hpll.cursor); |
| 1509 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1510 | active->hpll.fbc); |
| 1511 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1512 | drm_WARN_ON(&dev_priv->drm, |
| 1513 | (intermediate->sr.plane > |
| 1514 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1515 | intermediate->sr.cursor > |
| 1516 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1517 | intermediate->cxsr); |
| 1518 | drm_WARN_ON(&dev_priv->drm, |
| 1519 | (intermediate->sr.plane > |
| 1520 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1521 | intermediate->sr.cursor > |
| 1522 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1523 | intermediate->hpll_en); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1524 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1525 | drm_WARN_ON(&dev_priv->drm, |
| 1526 | intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1527 | intermediate->fbc_en && intermediate->cxsr); |
| 1528 | drm_WARN_ON(&dev_priv->drm, |
| 1529 | intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1530 | intermediate->fbc_en && intermediate->hpll_en); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1531 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1532 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1533 | /* |
| 1534 | * If our intermediate WM are identical to the final WM, then we can |
| 1535 | * omit the post-vblank programming; only update if it's different. |
| 1536 | */ |
| 1537 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1538 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1539 | |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
| 1543 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1544 | struct g4x_wm_values *wm) |
| 1545 | { |
| 1546 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1547 | int num_active_pipes = 0; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1548 | |
| 1549 | wm->cxsr = true; |
| 1550 | wm->hpll_en = true; |
| 1551 | wm->fbc_en = true; |
| 1552 | |
| 1553 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1554 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1555 | |
| 1556 | if (!crtc->active) |
| 1557 | continue; |
| 1558 | |
| 1559 | if (!wm_state->cxsr) |
| 1560 | wm->cxsr = false; |
| 1561 | if (!wm_state->hpll_en) |
| 1562 | wm->hpll_en = false; |
| 1563 | if (!wm_state->fbc_en) |
| 1564 | wm->fbc_en = false; |
| 1565 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1566 | num_active_pipes++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1567 | } |
| 1568 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1569 | if (num_active_pipes != 1) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1570 | wm->cxsr = false; |
| 1571 | wm->hpll_en = false; |
| 1572 | wm->fbc_en = false; |
| 1573 | } |
| 1574 | |
| 1575 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1576 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1577 | enum pipe pipe = crtc->pipe; |
| 1578 | |
| 1579 | wm->pipe[pipe] = wm_state->wm; |
| 1580 | if (crtc->active && wm->cxsr) |
| 1581 | wm->sr = wm_state->sr; |
| 1582 | if (crtc->active && wm->hpll_en) |
| 1583 | wm->hpll = wm_state->hpll; |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1588 | { |
| 1589 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1590 | struct g4x_wm_values new_wm = {}; |
| 1591 | |
| 1592 | g4x_merge_wm(dev_priv, &new_wm); |
| 1593 | |
| 1594 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1595 | return; |
| 1596 | |
| 1597 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1598 | _intel_set_memory_cxsr(dev_priv, false); |
| 1599 | |
| 1600 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1601 | |
| 1602 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1603 | _intel_set_memory_cxsr(dev_priv, true); |
| 1604 | |
| 1605 | *old_wm = new_wm; |
| 1606 | } |
| 1607 | |
| 1608 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1609 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1610 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1611 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1612 | const struct intel_crtc_state *crtc_state = |
| 1613 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1614 | |
| 1615 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1616 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1617 | g4x_program_watermarks(dev_priv); |
| 1618 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1619 | } |
| 1620 | |
| 1621 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1622 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1623 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1624 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1625 | const struct intel_crtc_state *crtc_state = |
| 1626 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1627 | |
| 1628 | if (!crtc_state->wm.need_postvbl_update) |
| 1629 | return; |
| 1630 | |
| 1631 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 1632 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1633 | g4x_program_watermarks(dev_priv); |
| 1634 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1635 | } |
| 1636 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1637 | /* latency must be in 0.1us units. */ |
| 1638 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1639 | unsigned int htotal, |
| 1640 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1641 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1642 | unsigned int latency) |
| 1643 | { |
| 1644 | unsigned int ret; |
| 1645 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1646 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1647 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1648 | ret = DIV_ROUND_UP(ret, 64); |
| 1649 | |
| 1650 | return ret; |
| 1651 | } |
| 1652 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1653 | 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] | 1654 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1655 | /* all latencies in usec */ |
| 1656 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1657 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1658 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1659 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1660 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1661 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1662 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1663 | |
| 1664 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1668 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1669 | const struct intel_plane_state *plane_state, |
| 1670 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1671 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1672 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1673 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1674 | const struct drm_display_mode *pipe_mode = |
| 1675 | &crtc_state->hw.pipe_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1676 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1677 | |
| 1678 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1679 | return USHRT_MAX; |
| 1680 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1681 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1682 | return 0; |
| 1683 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1684 | cpp = plane_state->hw.fb->format->cpp[0]; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1685 | clock = pipe_mode->crtc_clock; |
| 1686 | htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1687 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1688 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1689 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1690 | /* |
| 1691 | * FIXME the formula gives values that are |
| 1692 | * too big for the cursor FIFO, and hence we |
| 1693 | * would never be able to use cursors. For |
| 1694 | * now just hardcode the watermark. |
| 1695 | */ |
| 1696 | wm = 63; |
| 1697 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1698 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1699 | dev_priv->wm.pri_latency[level] * 10); |
| 1700 | } |
| 1701 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1702 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1703 | } |
| 1704 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1705 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1706 | { |
| 1707 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1708 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1709 | } |
| 1710 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1711 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1712 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1713 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1714 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1715 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1716 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1717 | 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] | 1718 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1719 | int num_active_planes = hweight8(active_planes); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1720 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1721 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1722 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1723 | unsigned int total_rate; |
| 1724 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1725 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1726 | /* |
| 1727 | * When enabling sprite0 after sprite1 has already been enabled |
| 1728 | * we tend to get an underrun unless sprite0 already has some |
| 1729 | * FIFO space allcoated. Hence we always allocate at least one |
| 1730 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1731 | * |
| 1732 | * All other plane enable sequences appear immune to this problem. |
| 1733 | */ |
| 1734 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1735 | sprite0_fifo_extra = 1; |
| 1736 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1737 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1738 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1739 | raw->plane[PLANE_SPRITE1] + |
| 1740 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1741 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1742 | if (total_rate > fifo_size) |
| 1743 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1744 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1745 | if (total_rate == 0) |
| 1746 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1747 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1748 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1749 | unsigned int rate; |
| 1750 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1751 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1752 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1753 | continue; |
| 1754 | } |
| 1755 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1756 | rate = raw->plane[plane_id]; |
| 1757 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1758 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1759 | } |
| 1760 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1761 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1762 | fifo_left -= sprite0_fifo_extra; |
| 1763 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1764 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1765 | |
| 1766 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1767 | |
| 1768 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1769 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1770 | int plane_extra; |
| 1771 | |
| 1772 | if (fifo_left == 0) |
| 1773 | break; |
| 1774 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1775 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1776 | continue; |
| 1777 | |
| 1778 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1779 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1780 | fifo_left -= plane_extra; |
| 1781 | } |
| 1782 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1783 | 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] | 1784 | |
| 1785 | /* give it all to the first plane if none are active */ |
| 1786 | if (active_planes == 0) { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1787 | drm_WARN_ON(&dev_priv->drm, fifo_left != fifo_size); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1788 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1789 | } |
| 1790 | |
| 1791 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1792 | } |
| 1793 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1794 | /* mark all levels starting from 'level' as invalid */ |
| 1795 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1796 | struct vlv_wm_state *wm_state, int level) |
| 1797 | { |
| 1798 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1799 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1800 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1801 | enum plane_id plane_id; |
| 1802 | |
| 1803 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1804 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1805 | |
| 1806 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1807 | wm_state->sr[level].plane = USHRT_MAX; |
| 1808 | } |
| 1809 | } |
| 1810 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1811 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1812 | { |
| 1813 | if (wm > fifo_size) |
| 1814 | return USHRT_MAX; |
| 1815 | else |
| 1816 | return fifo_size - wm; |
| 1817 | } |
| 1818 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1819 | /* |
| 1820 | * Starting from 'level' set all higher |
| 1821 | * levels to 'value' in the "raw" watermarks. |
| 1822 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1823 | 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] | 1824 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1825 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1826 | 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] | 1827 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1828 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1829 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1830 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1831 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1832 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1833 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1834 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1835 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1836 | |
| 1837 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1838 | } |
| 1839 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1840 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1841 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1842 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1843 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1844 | 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] | 1845 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1846 | 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] | 1847 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1848 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1849 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1850 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1851 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1852 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1856 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1857 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1858 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1859 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1860 | if (wm > max_wm) |
| 1861 | break; |
| 1862 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1863 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1864 | raw->plane[plane_id] = wm; |
| 1865 | } |
| 1866 | |
| 1867 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1868 | 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] | 1869 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1870 | out: |
| 1871 | if (dirty) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1872 | drm_dbg_kms(&dev_priv->drm, |
| 1873 | "%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n", |
| 1874 | plane->base.name, |
| 1875 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1876 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1877 | 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] | 1878 | |
| 1879 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1880 | } |
| 1881 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1882 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1883 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1884 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1885 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1886 | &crtc_state->wm.vlv.raw[level]; |
| 1887 | const struct vlv_fifo_state *fifo_state = |
| 1888 | &crtc_state->wm.vlv.fifo_state; |
| 1889 | |
| 1890 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1891 | } |
| 1892 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1893 | 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] | 1894 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1895 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1896 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1897 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1898 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1899 | } |
| 1900 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1901 | static int vlv_compute_pipe_wm(struct intel_atomic_state *state, |
| 1902 | struct intel_crtc *crtc) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1903 | { |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1904 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1905 | struct intel_crtc_state *crtc_state = |
| 1906 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1907 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1908 | const struct vlv_fifo_state *fifo_state = |
| 1909 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | 8f27dbf | 2021-05-14 15:57:40 +0300 | [diff] [blame] | 1910 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1911 | int num_active_planes = hweight8(active_planes); |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1912 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->uapi); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1913 | const struct intel_plane_state *old_plane_state; |
| 1914 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1915 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1916 | enum plane_id plane_id; |
| 1917 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1918 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1919 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1920 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1921 | old_plane_state, |
| 1922 | new_plane_state, i) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1923 | if (new_plane_state->hw.crtc != &crtc->base && |
| 1924 | old_plane_state->hw.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1925 | continue; |
| 1926 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1927 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1928 | dirty |= BIT(plane->id); |
| 1929 | } |
| 1930 | |
| 1931 | /* |
| 1932 | * DSPARB registers may have been reset due to the |
| 1933 | * power well being turned off. Make sure we restore |
| 1934 | * them to a consistent state even if no primary/sprite |
| 1935 | * planes are initially active. |
| 1936 | */ |
| 1937 | if (needs_modeset) |
| 1938 | crtc_state->fifo_changed = true; |
| 1939 | |
| 1940 | if (!dirty) |
| 1941 | return 0; |
| 1942 | |
| 1943 | /* cursor changes don't warrant a FIFO recompute */ |
| 1944 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1945 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1946 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1947 | const struct vlv_fifo_state *old_fifo_state = |
| 1948 | &old_crtc_state->wm.vlv.fifo_state; |
| 1949 | |
| 1950 | ret = vlv_compute_fifo(crtc_state); |
| 1951 | if (ret) |
| 1952 | return ret; |
| 1953 | |
| 1954 | if (needs_modeset || |
| 1955 | memcmp(old_fifo_state, fifo_state, |
| 1956 | sizeof(*fifo_state)) != 0) |
| 1957 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1958 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1959 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1960 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1961 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1962 | /* |
| 1963 | * Note that enabling cxsr with no primary/sprite planes |
| 1964 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1965 | * with exactly one enabled primary/sprite plane. |
| 1966 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1967 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1968 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1969 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1970 | const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 1971 | 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] | 1972 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1973 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1974 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1975 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1976 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1977 | wm_state->wm[level].plane[plane_id] = |
| 1978 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1979 | fifo_state->plane[plane_id]); |
| 1980 | } |
| 1981 | |
| 1982 | wm_state->sr[level].plane = |
| 1983 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1984 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1985 | raw->plane[PLANE_SPRITE1]), |
| 1986 | sr_fifo_size); |
| 1987 | |
| 1988 | wm_state->sr[level].cursor = |
| 1989 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1990 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1991 | } |
| 1992 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1993 | if (level == 0) |
| 1994 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1995 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1996 | /* limit to only levels we can actually handle */ |
| 1997 | wm_state->num_levels = level; |
| 1998 | |
| 1999 | /* invalidate the higher levels */ |
| 2000 | vlv_invalidate_wms(crtc, wm_state, level); |
| 2001 | |
| 2002 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2003 | } |
| 2004 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2005 | #define VLV_FIFO(plane, value) \ |
| 2006 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 2007 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2008 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2009 | struct intel_crtc *crtc) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2010 | { |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2011 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2012 | struct intel_uncore *uncore = &dev_priv->uncore; |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2013 | const struct intel_crtc_state *crtc_state = |
| 2014 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 2015 | const struct vlv_fifo_state *fifo_state = |
| 2016 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2017 | int sprite0_start, sprite1_start, fifo_size; |
Kees Cook | 2713eb4 | 2020-02-20 16:05:17 -0800 | [diff] [blame] | 2018 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2019 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 2020 | if (!crtc_state->fifo_changed) |
| 2021 | return; |
| 2022 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2023 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 2024 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 2025 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2026 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 2027 | drm_WARN_ON(&dev_priv->drm, fifo_state->plane[PLANE_CURSOR] != 63); |
| 2028 | drm_WARN_ON(&dev_priv->drm, fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2029 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 2030 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 2031 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2032 | /* |
| 2033 | * uncore.lock serves a double purpose here. It allows us to |
| 2034 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 2035 | * it protects the DSPARB registers from getting clobbered by |
| 2036 | * parallel updates from multiple pipes. |
| 2037 | * |
| 2038 | * intel_pipe_update_start() has already disabled interrupts |
| 2039 | * for us, so a plain spin_lock() is sufficient here. |
| 2040 | */ |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2041 | spin_lock(&uncore->lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2042 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2043 | switch (crtc->pipe) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2044 | case PIPE_A: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2045 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2046 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2047 | |
| 2048 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 2049 | VLV_FIFO(SPRITEB, 0xff)); |
| 2050 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 2051 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 2052 | |
| 2053 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 2054 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 2055 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 2056 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 2057 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2058 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2059 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2060 | break; |
| 2061 | case PIPE_B: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2062 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2063 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2064 | |
| 2065 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 2066 | VLV_FIFO(SPRITED, 0xff)); |
| 2067 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 2068 | VLV_FIFO(SPRITED, sprite1_start)); |
| 2069 | |
| 2070 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 2071 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 2072 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 2073 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 2074 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2075 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2076 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2077 | break; |
| 2078 | case PIPE_C: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2079 | dsparb3 = intel_uncore_read_fw(uncore, DSPARB3); |
| 2080 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2081 | |
| 2082 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2083 | VLV_FIFO(SPRITEF, 0xff)); |
| 2084 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2085 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2086 | |
| 2087 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2088 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2089 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2090 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2091 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2092 | intel_uncore_write_fw(uncore, DSPARB3, dsparb3); |
| 2093 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2094 | break; |
| 2095 | default: |
| 2096 | break; |
| 2097 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2098 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2099 | intel_uncore_posting_read_fw(uncore, DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2100 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2101 | spin_unlock(&uncore->lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | #undef VLV_FIFO |
| 2105 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2106 | static int vlv_compute_intermediate_wm(struct intel_atomic_state *state, |
| 2107 | struct intel_crtc *crtc) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2108 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2109 | struct intel_crtc_state *new_crtc_state = |
| 2110 | intel_atomic_get_new_crtc_state(state, crtc); |
| 2111 | const struct intel_crtc_state *old_crtc_state = |
| 2112 | intel_atomic_get_old_crtc_state(state, crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2113 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2114 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2115 | 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] | 2116 | int level; |
| 2117 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2118 | if (!new_crtc_state->hw.active || |
| 2119 | drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) { |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2120 | *intermediate = *optimal; |
| 2121 | |
| 2122 | intermediate->cxsr = false; |
| 2123 | goto out; |
| 2124 | } |
| 2125 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2126 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2127 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2128 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2129 | |
| 2130 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2131 | enum plane_id plane_id; |
| 2132 | |
| 2133 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2134 | intermediate->wm[level].plane[plane_id] = |
| 2135 | min(optimal->wm[level].plane[plane_id], |
| 2136 | active->wm[level].plane[plane_id]); |
| 2137 | } |
| 2138 | |
| 2139 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2140 | active->sr[level].plane); |
| 2141 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2142 | active->sr[level].cursor); |
| 2143 | } |
| 2144 | |
| 2145 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2146 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2147 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2148 | /* |
| 2149 | * If our intermediate WM are identical to the final WM, then we can |
| 2150 | * omit the post-vblank programming; only update if it's different. |
| 2151 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2152 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2153 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2154 | |
| 2155 | return 0; |
| 2156 | } |
| 2157 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2158 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2159 | struct vlv_wm_values *wm) |
| 2160 | { |
| 2161 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2162 | int num_active_pipes = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2163 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2164 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2165 | wm->cxsr = true; |
| 2166 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2167 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2168 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2169 | |
| 2170 | if (!crtc->active) |
| 2171 | continue; |
| 2172 | |
| 2173 | if (!wm_state->cxsr) |
| 2174 | wm->cxsr = false; |
| 2175 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2176 | num_active_pipes++; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2177 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2178 | } |
| 2179 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2180 | if (num_active_pipes != 1) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2181 | wm->cxsr = false; |
| 2182 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2183 | if (num_active_pipes > 1) |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2184 | wm->level = VLV_WM_LEVEL_PM2; |
| 2185 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2186 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2187 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2188 | enum pipe pipe = crtc->pipe; |
| 2189 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2190 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2191 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2192 | wm->sr = wm_state->sr[wm->level]; |
| 2193 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2194 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2195 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2196 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2197 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2201 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2202 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2203 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2204 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2205 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2206 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2207 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2208 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2209 | return; |
| 2210 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2211 | 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] | 2212 | chv_set_memory_dvfs(dev_priv, false); |
| 2213 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2214 | 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] | 2215 | chv_set_memory_pm5(dev_priv, false); |
| 2216 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2217 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2218 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2219 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2220 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2221 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2222 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2223 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2224 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2225 | 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] | 2226 | chv_set_memory_pm5(dev_priv, true); |
| 2227 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2228 | 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] | 2229 | chv_set_memory_dvfs(dev_priv, true); |
| 2230 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2231 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2232 | } |
| 2233 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2234 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2235 | struct intel_crtc *crtc) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2236 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2237 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 2238 | const struct intel_crtc_state *crtc_state = |
| 2239 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2240 | |
| 2241 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2242 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2243 | vlv_program_watermarks(dev_priv); |
| 2244 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2245 | } |
| 2246 | |
| 2247 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2248 | struct intel_crtc *crtc) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2249 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2250 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 2251 | const struct intel_crtc_state *crtc_state = |
| 2252 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2253 | |
| 2254 | if (!crtc_state->wm.need_postvbl_update) |
| 2255 | return; |
| 2256 | |
| 2257 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 2258 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2259 | vlv_program_watermarks(dev_priv); |
| 2260 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2261 | } |
| 2262 | |
Dave Airlie | ef9c66a | 2021-09-29 01:57:47 +0300 | [diff] [blame] | 2263 | static void i965_update_wm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2264 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2265 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2266 | int srwm = 1; |
| 2267 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2268 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2269 | |
| 2270 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2271 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2272 | if (crtc) { |
| 2273 | /* self-refresh has much higher latency */ |
| 2274 | static const int sr_latency_ns = 12000; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2275 | const struct drm_display_mode *pipe_mode = |
| 2276 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2277 | const struct drm_framebuffer *fb = |
| 2278 | crtc->base.primary->state->fb; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2279 | int clock = pipe_mode->crtc_clock; |
| 2280 | int htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2281 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2282 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2283 | int entries; |
| 2284 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2285 | entries = intel_wm_method2(clock, htotal, |
| 2286 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2287 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2288 | srwm = I965_FIFO_SIZE - entries; |
| 2289 | if (srwm < 0) |
| 2290 | srwm = 1; |
| 2291 | srwm &= 0x1ff; |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2292 | drm_dbg_kms(&dev_priv->drm, |
| 2293 | "self-refresh entries: %d, wm: %d\n", |
| 2294 | entries, srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2295 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2296 | entries = intel_wm_method2(clock, htotal, |
| 2297 | crtc->base.cursor->state->crtc_w, 4, |
| 2298 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2299 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2300 | i965_cursor_wm_info.cacheline_size) + |
| 2301 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2302 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2303 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2304 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2305 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2306 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2307 | drm_dbg_kms(&dev_priv->drm, |
| 2308 | "self-refresh watermark: display plane %d " |
| 2309 | "cursor %d\n", srwm, cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2310 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2311 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2312 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2313 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2314 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2315 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2316 | } |
| 2317 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2318 | drm_dbg_kms(&dev_priv->drm, |
| 2319 | "Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2320 | srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2321 | |
| 2322 | /* 965 has limitations... */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2323 | intel_uncore_write(&dev_priv->uncore, DSPFW1, FW_WM(srwm, SR) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2324 | FW_WM(8, CURSORB) | |
| 2325 | FW_WM(8, PLANEB) | |
| 2326 | FW_WM(8, PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2327 | intel_uncore_write(&dev_priv->uncore, DSPFW2, FW_WM(8, CURSORA) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2328 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2329 | /* update cursor SR watermark */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2330 | 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] | 2331 | |
| 2332 | if (cxsr_enabled) |
| 2333 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2334 | } |
| 2335 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2336 | #undef FW_WM |
| 2337 | |
Dave Airlie | ef9c66a | 2021-09-29 01:57:47 +0300 | [diff] [blame] | 2338 | static void i9xx_update_wm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2339 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2340 | const struct intel_watermark_params *wm_info; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2341 | u32 fwater_lo; |
| 2342 | u32 fwater_hi; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2343 | int cwm, srwm = 1; |
| 2344 | int fifo_size; |
| 2345 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2346 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2347 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2348 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2349 | wm_info = &i945_wm_info; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2350 | else if (DISPLAY_VER(dev_priv) != 2) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2351 | wm_info = &i915_wm_info; |
| 2352 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2353 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2354 | |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 2355 | if (DISPLAY_VER(dev_priv) == 2) |
| 2356 | fifo_size = i830_get_fifo_size(dev_priv, PLANE_A); |
| 2357 | else |
| 2358 | fifo_size = i9xx_get_fifo_size(dev_priv, PLANE_A); |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2359 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2360 | if (intel_crtc_active(crtc)) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2361 | const struct drm_display_mode *pipe_mode = |
| 2362 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2363 | const struct drm_framebuffer *fb = |
| 2364 | crtc->base.primary->state->fb; |
| 2365 | int cpp; |
| 2366 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2367 | if (DISPLAY_VER(dev_priv) == 2) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2368 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2369 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2370 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2371 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2372 | planea_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2373 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2374 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2375 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2376 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2377 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2378 | if (planea_wm > (long)wm_info->max_wm) |
| 2379 | planea_wm = wm_info->max_wm; |
| 2380 | } |
| 2381 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2382 | if (DISPLAY_VER(dev_priv) == 2) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2383 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2384 | |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 2385 | if (DISPLAY_VER(dev_priv) == 2) |
| 2386 | fifo_size = i830_get_fifo_size(dev_priv, PLANE_B); |
| 2387 | else |
| 2388 | fifo_size = i9xx_get_fifo_size(dev_priv, PLANE_B); |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 2389 | crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2390 | if (intel_crtc_active(crtc)) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2391 | const struct drm_display_mode *pipe_mode = |
| 2392 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2393 | const struct drm_framebuffer *fb = |
| 2394 | crtc->base.primary->state->fb; |
| 2395 | int cpp; |
| 2396 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2397 | if (DISPLAY_VER(dev_priv) == 2) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2398 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2399 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2400 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2401 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2402 | planeb_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2403 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2404 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2405 | if (enabled == NULL) |
| 2406 | enabled = crtc; |
| 2407 | else |
| 2408 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2409 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2410 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2411 | if (planeb_wm > (long)wm_info->max_wm) |
| 2412 | planeb_wm = wm_info->max_wm; |
| 2413 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2414 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2415 | drm_dbg_kms(&dev_priv->drm, |
| 2416 | "FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2417 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2418 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2419 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2420 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2421 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2422 | |
| 2423 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2424 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2425 | enabled = NULL; |
| 2426 | } |
| 2427 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2428 | /* |
| 2429 | * Overlay gets an aggressive default since video jitter is bad. |
| 2430 | */ |
| 2431 | cwm = 2; |
| 2432 | |
| 2433 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2434 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2435 | |
| 2436 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2437 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2438 | /* self-refresh has much higher latency */ |
| 2439 | static const int sr_latency_ns = 6000; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2440 | const struct drm_display_mode *pipe_mode = |
| 2441 | &enabled->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2442 | const struct drm_framebuffer *fb = |
| 2443 | enabled->base.primary->state->fb; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2444 | int clock = pipe_mode->crtc_clock; |
| 2445 | int htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2446 | int hdisplay = enabled->config->pipe_src_w; |
| 2447 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2448 | int entries; |
| 2449 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2450 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2451 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2452 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2453 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2454 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2455 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2456 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2457 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2458 | drm_dbg_kms(&dev_priv->drm, |
| 2459 | "self-refresh entries: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2460 | srwm = wm_info->fifo_size - entries; |
| 2461 | if (srwm < 0) |
| 2462 | srwm = 1; |
| 2463 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2464 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2465 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2466 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2467 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2468 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, srwm & 0x3f); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2469 | } |
| 2470 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2471 | drm_dbg_kms(&dev_priv->drm, |
| 2472 | "Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2473 | planea_wm, planeb_wm, cwm, srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2474 | |
| 2475 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2476 | fwater_hi = (cwm & 0x1f); |
| 2477 | |
| 2478 | /* Set request length to 8 cachelines per fetch */ |
| 2479 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2480 | fwater_hi = fwater_hi | (1 << 8); |
| 2481 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2482 | intel_uncore_write(&dev_priv->uncore, FW_BLC, fwater_lo); |
| 2483 | intel_uncore_write(&dev_priv->uncore, FW_BLC2, fwater_hi); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2484 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2485 | if (enabled) |
| 2486 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2487 | } |
| 2488 | |
Dave Airlie | ef9c66a | 2021-09-29 01:57:47 +0300 | [diff] [blame] | 2489 | static void i845_update_wm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2490 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2491 | struct intel_crtc *crtc; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2492 | const struct drm_display_mode *pipe_mode; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2493 | u32 fwater_lo; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2494 | int planea_wm; |
| 2495 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2496 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2497 | if (crtc == NULL) |
| 2498 | return; |
| 2499 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2500 | pipe_mode = &crtc->config->hw.pipe_mode; |
| 2501 | planea_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2502 | &i845_wm_info, |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 2503 | i845_get_fifo_size(dev_priv, PLANE_A), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2504 | 4, pessimal_latency_ns); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2505 | fwater_lo = intel_uncore_read(&dev_priv->uncore, FW_BLC) & ~0xfff; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2506 | fwater_lo |= (3<<8) | planea_wm; |
| 2507 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2508 | drm_dbg_kms(&dev_priv->drm, |
| 2509 | "Setting FIFO watermarks - A: %d\n", planea_wm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2510 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2511 | intel_uncore_write(&dev_priv->uncore, FW_BLC, fwater_lo); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2512 | } |
| 2513 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2514 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2515 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 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_method1(pixel_rate, cpp, latency); |
| 2522 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2523 | |
| 2524 | return ret; |
| 2525 | } |
| 2526 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2527 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2528 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2529 | unsigned int htotal, |
| 2530 | unsigned int width, |
| 2531 | unsigned int cpp, |
| 2532 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2533 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2534 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2535 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2536 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2537 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2538 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2539 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2540 | return ret; |
| 2541 | } |
| 2542 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2543 | 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] | 2544 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2545 | /* |
| 2546 | * Neither of these should be possible since this function shouldn't be |
| 2547 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2548 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2549 | * elsewhere in the driver. |
| 2550 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2551 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2552 | return 0; |
| 2553 | if (WARN_ON(!horiz_pixels)) |
| 2554 | return 0; |
| 2555 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2556 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2557 | } |
| 2558 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2559 | struct ilk_wm_maximums { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2560 | u16 pri; |
| 2561 | u16 spr; |
| 2562 | u16 cur; |
| 2563 | u16 fbc; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2564 | }; |
| 2565 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2566 | /* |
| 2567 | * For both WM_PIPE and WM_LP. |
| 2568 | * mem_value must be in 0.1us units. |
| 2569 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2570 | static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state, |
| 2571 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2572 | u32 mem_value, bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2573 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2574 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2575 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2576 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2577 | if (mem_value == 0) |
| 2578 | return U32_MAX; |
| 2579 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2580 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2581 | return 0; |
| 2582 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2583 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2584 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2585 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2586 | |
| 2587 | if (!is_lp) |
| 2588 | return method1; |
| 2589 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2590 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2591 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2592 | drm_rect_width(&plane_state->uapi.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2593 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2594 | |
| 2595 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2596 | } |
| 2597 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2598 | /* |
| 2599 | * For both WM_PIPE and WM_LP. |
| 2600 | * mem_value must be in 0.1us units. |
| 2601 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2602 | static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state, |
| 2603 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2604 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2605 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2606 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2607 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2608 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2609 | if (mem_value == 0) |
| 2610 | return U32_MAX; |
| 2611 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2612 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2613 | return 0; |
| 2614 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2615 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2616 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2617 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
| 2618 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2619 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2620 | drm_rect_width(&plane_state->uapi.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2621 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2622 | return min(method1, method2); |
| 2623 | } |
| 2624 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2625 | /* |
| 2626 | * For both WM_PIPE and WM_LP. |
| 2627 | * mem_value must be in 0.1us units. |
| 2628 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2629 | static u32 ilk_compute_cur_wm(const struct intel_crtc_state *crtc_state, |
| 2630 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2631 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2632 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2633 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2634 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2635 | if (mem_value == 0) |
| 2636 | return U32_MAX; |
| 2637 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2638 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2639 | return 0; |
| 2640 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2641 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2642 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2643 | return ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2644 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2645 | drm_rect_width(&plane_state->uapi.dst), |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 2646 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2647 | } |
| 2648 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2649 | /* Only for WM_LP. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2650 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 2651 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2652 | u32 pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2653 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2654 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2655 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2656 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2657 | return 0; |
| 2658 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2659 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2660 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2661 | return ilk_wm_fbc(pri_val, drm_rect_width(&plane_state->uapi.dst), |
| 2662 | cpp); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2663 | } |
| 2664 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2665 | static unsigned int |
| 2666 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2667 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2668 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2669 | return 3072; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2670 | else if (DISPLAY_VER(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2671 | return 768; |
| 2672 | else |
| 2673 | return 512; |
| 2674 | } |
| 2675 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2676 | static unsigned int |
| 2677 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2678 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2679 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2680 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2681 | /* BDW primary/sprite plane watermarks */ |
| 2682 | return level == 0 ? 255 : 2047; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2683 | else if (DISPLAY_VER(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2684 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2685 | return level == 0 ? 127 : 1023; |
| 2686 | else if (!is_sprite) |
| 2687 | /* ILK/SNB primary plane watermarks */ |
| 2688 | return level == 0 ? 127 : 511; |
| 2689 | else |
| 2690 | /* ILK/SNB sprite plane watermarks */ |
| 2691 | return level == 0 ? 63 : 255; |
| 2692 | } |
| 2693 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2694 | static unsigned int |
| 2695 | 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] | 2696 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2697 | if (DISPLAY_VER(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2698 | return level == 0 ? 63 : 255; |
| 2699 | else |
| 2700 | return level == 0 ? 31 : 63; |
| 2701 | } |
| 2702 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2703 | 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] | 2704 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2705 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2706 | return 31; |
| 2707 | else |
| 2708 | return 15; |
| 2709 | } |
| 2710 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2711 | /* Calculate the maximum primary/sprite plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2712 | 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] | 2713 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2714 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2715 | enum intel_ddb_partitioning ddb_partitioning, |
| 2716 | bool is_sprite) |
| 2717 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2718 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2719 | |
| 2720 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2721 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2722 | return 0; |
| 2723 | |
| 2724 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2725 | if (level == 0 || config->num_pipes_active > 1) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 2726 | fifo_size /= INTEL_NUM_PIPES(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2727 | |
| 2728 | /* |
| 2729 | * For some reason the non self refresh |
| 2730 | * FIFO size is only half of the self |
| 2731 | * refresh FIFO size on ILK/SNB. |
| 2732 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2733 | if (DISPLAY_VER(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2734 | fifo_size /= 2; |
| 2735 | } |
| 2736 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2737 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2738 | /* level 0 is always calculated with 1:1 split */ |
| 2739 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2740 | if (is_sprite) |
| 2741 | fifo_size *= 5; |
| 2742 | fifo_size /= 6; |
| 2743 | } else { |
| 2744 | fifo_size /= 2; |
| 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2749 | 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] | 2750 | } |
| 2751 | |
| 2752 | /* Calculate the maximum cursor plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2753 | 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] | 2754 | int level, |
| 2755 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2756 | { |
| 2757 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2758 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2759 | return 64; |
| 2760 | |
| 2761 | /* otherwise just report max that registers can hold */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2762 | return ilk_cursor_wm_reg_max(dev_priv, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2763 | } |
| 2764 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2765 | 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] | 2766 | int level, |
| 2767 | const struct intel_wm_config *config, |
| 2768 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2769 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2770 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2771 | max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false); |
| 2772 | max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true); |
| 2773 | max->cur = ilk_cursor_wm_max(dev_priv, level, config); |
| 2774 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2775 | } |
| 2776 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2777 | 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] | 2778 | int level, |
| 2779 | struct ilk_wm_maximums *max) |
| 2780 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2781 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2782 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2783 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2784 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2785 | } |
| 2786 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2787 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2788 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2789 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2790 | { |
| 2791 | bool ret; |
| 2792 | |
| 2793 | /* already determined to be invalid? */ |
| 2794 | if (!result->enable) |
| 2795 | return false; |
| 2796 | |
| 2797 | result->enable = result->pri_val <= max->pri && |
| 2798 | result->spr_val <= max->spr && |
| 2799 | result->cur_val <= max->cur; |
| 2800 | |
| 2801 | ret = result->enable; |
| 2802 | |
| 2803 | /* |
| 2804 | * HACK until we can pre-compute everything, |
| 2805 | * and thus fail gracefully if LP0 watermarks |
| 2806 | * are exceeded... |
| 2807 | */ |
| 2808 | if (level == 0 && !result->enable) { |
| 2809 | if (result->pri_val > max->pri) |
| 2810 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2811 | level, result->pri_val, max->pri); |
| 2812 | if (result->spr_val > max->spr) |
| 2813 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2814 | level, result->spr_val, max->spr); |
| 2815 | if (result->cur_val > max->cur) |
| 2816 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2817 | level, result->cur_val, max->cur); |
| 2818 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2819 | result->pri_val = min_t(u32, result->pri_val, max->pri); |
| 2820 | result->spr_val = min_t(u32, result->spr_val, max->spr); |
| 2821 | result->cur_val = min_t(u32, result->cur_val, max->cur); |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2822 | result->enable = true; |
| 2823 | } |
| 2824 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2825 | return ret; |
| 2826 | } |
| 2827 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2828 | 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] | 2829 | const struct intel_crtc *crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2830 | int level, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2831 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2832 | const struct intel_plane_state *pristate, |
| 2833 | const struct intel_plane_state *sprstate, |
| 2834 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2835 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2836 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2837 | u16 pri_latency = dev_priv->wm.pri_latency[level]; |
| 2838 | u16 spr_latency = dev_priv->wm.spr_latency[level]; |
| 2839 | u16 cur_latency = dev_priv->wm.cur_latency[level]; |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2840 | |
| 2841 | /* WM1+ latency values stored in 0.5us units */ |
| 2842 | if (level > 0) { |
| 2843 | pri_latency *= 5; |
| 2844 | spr_latency *= 5; |
| 2845 | cur_latency *= 5; |
| 2846 | } |
| 2847 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2848 | if (pristate) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2849 | result->pri_val = ilk_compute_pri_wm(crtc_state, pristate, |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2850 | pri_latency, level); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2851 | 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] | 2852 | } |
| 2853 | |
| 2854 | if (sprstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2855 | result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2856 | |
| 2857 | if (curstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2858 | result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2859 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2860 | result->enable = true; |
| 2861 | } |
| 2862 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2863 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2864 | u16 wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2865 | { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2866 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 2867 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2868 | if (DISPLAY_VER(dev_priv) >= 9) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2869 | u32 val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2870 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2871 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2872 | int mult = IS_DG2(dev_priv) ? 2 : 1; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2873 | |
| 2874 | /* read the first set of memory latencies[0:3] */ |
| 2875 | val = 0; /* data0 to be programmed to 0 for first set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2876 | ret = sandybridge_pcode_read(dev_priv, |
| 2877 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2878 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2879 | |
| 2880 | if (ret) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2881 | drm_err(&dev_priv->drm, |
| 2882 | "SKL Mailbox read error = %d\n", ret); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2883 | return; |
| 2884 | } |
| 2885 | |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2886 | wm[0] = (val & GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2887 | wm[1] = ((val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2888 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2889 | wm[2] = ((val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2890 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2891 | wm[3] = ((val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2892 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2893 | |
| 2894 | /* read the second set of memory latencies[4:7] */ |
| 2895 | val = 1; /* data0 to be programmed to 1 for second set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2896 | ret = sandybridge_pcode_read(dev_priv, |
| 2897 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2898 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2899 | if (ret) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2900 | drm_err(&dev_priv->drm, |
| 2901 | "SKL Mailbox read error = %d\n", ret); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2902 | return; |
| 2903 | } |
| 2904 | |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2905 | wm[4] = (val & GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2906 | wm[5] = ((val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2907 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2908 | wm[6] = ((val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2909 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2910 | wm[7] = ((val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2911 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2912 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2913 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2914 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2915 | * need to be disabled. We make sure to sanitize the values out |
| 2916 | * of the punit to satisfy this requirement. |
| 2917 | */ |
| 2918 | for (level = 1; level <= max_level; level++) { |
| 2919 | if (wm[level] == 0) { |
| 2920 | for (i = level + 1; i <= max_level; i++) |
| 2921 | wm[i] = 0; |
Lucas De Marchi | 0bc3a4e | 2021-06-22 14:22:10 -0700 | [diff] [blame] | 2922 | |
| 2923 | max_level = level - 1; |
| 2924 | |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2925 | break; |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | /* |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2930 | * WaWmMemoryReadLatency |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2931 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2932 | * 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] | 2933 | * to add proper adjustement to each valid level we retrieve |
| 2934 | * from the punit when level 0 response data is 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2935 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2936 | if (wm[0] == 0) { |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2937 | u8 adjust = DISPLAY_VER(dev_priv) >= 12 ? 3 : 2; |
| 2938 | |
Lucas De Marchi | 0bc3a4e | 2021-06-22 14:22:10 -0700 | [diff] [blame] | 2939 | for (level = 0; level <= max_level; level++) |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2940 | wm[level] += adjust; |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2941 | } |
| 2942 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2943 | /* |
| 2944 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2945 | * If we could not get dimm info enable this WA to prevent from |
| 2946 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2947 | * to avoid any underrun. |
| 2948 | */ |
José Roberto de Souza | 66a2450 | 2021-01-28 08:43:12 -0800 | [diff] [blame] | 2949 | if (dev_priv->dram_info.wm_lv_0_adjust_needed) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2950 | wm[0] += 1; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2951 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2952 | u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2953 | |
| 2954 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2955 | if (wm[0] == 0) |
| 2956 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2957 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2958 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2959 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2960 | wm[4] = (sskpd >> 32) & 0x1FF; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2961 | } else if (DISPLAY_VER(dev_priv) >= 6) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2962 | u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2963 | |
| 2964 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2965 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2966 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2967 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2968 | } else if (DISPLAY_VER(dev_priv) >= 5) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2969 | u32 mltr = intel_uncore_read(uncore, MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2970 | |
| 2971 | /* ILK primary LP0 latency is 700 ns */ |
| 2972 | wm[0] = 7; |
| 2973 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2974 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2975 | } else { |
| 2976 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2977 | } |
| 2978 | } |
| 2979 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2980 | 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] | 2981 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2982 | { |
| 2983 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2984 | if (DISPLAY_VER(dev_priv) == 5) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2985 | wm[0] = 13; |
| 2986 | } |
| 2987 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 2988 | 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] | 2989 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2990 | { |
| 2991 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2992 | if (DISPLAY_VER(dev_priv) == 5) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2993 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2994 | } |
| 2995 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2996 | 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] | 2997 | { |
| 2998 | /* how many WM levels are we expecting */ |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 2999 | if (HAS_HW_SAGV_WM(dev_priv)) |
| 3000 | return 5; |
| 3001 | else if (DISPLAY_VER(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3002 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3003 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 3004 | return 4; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3005 | else if (DISPLAY_VER(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 3006 | return 3; |
| 3007 | else |
| 3008 | return 2; |
| 3009 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 3010 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3011 | 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] | 3012 | const char *name, |
Linus Torvalds | e7c6e40 | 2021-04-27 17:05:53 -0700 | [diff] [blame] | 3013 | const u16 wm[]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3014 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3015 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3016 | |
| 3017 | for (level = 0; level <= max_level; level++) { |
| 3018 | unsigned int latency = wm[level]; |
| 3019 | |
| 3020 | if (latency == 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3021 | drm_dbg_kms(&dev_priv->drm, |
| 3022 | "%s WM%d latency not provided\n", |
| 3023 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3024 | continue; |
| 3025 | } |
| 3026 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3027 | /* |
| 3028 | * - latencies are in us on gen9. |
| 3029 | * - before then, WM1+ latency values are in 0.5us units |
| 3030 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3031 | if (DISPLAY_VER(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3032 | latency *= 10; |
| 3033 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3034 | latency *= 5; |
| 3035 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3036 | drm_dbg_kms(&dev_priv->drm, |
| 3037 | "%s WM%d latency %u (%u.%u usec)\n", name, level, |
| 3038 | wm[level], latency / 10, latency % 10); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3039 | } |
| 3040 | } |
| 3041 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3042 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3043 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3044 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3045 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3046 | |
| 3047 | if (wm[0] >= min) |
| 3048 | return false; |
| 3049 | |
| 3050 | wm[0] = max(wm[0], min); |
| 3051 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3052 | 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] | 3053 | |
| 3054 | return true; |
| 3055 | } |
| 3056 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3057 | 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] | 3058 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3059 | bool changed; |
| 3060 | |
| 3061 | /* |
| 3062 | * The BIOS provided WM memory latency values are often |
| 3063 | * inadequate for high resolution displays. Adjust them. |
| 3064 | */ |
| 3065 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 3066 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 3067 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 3068 | |
| 3069 | if (!changed) |
| 3070 | return; |
| 3071 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3072 | drm_dbg_kms(&dev_priv->drm, |
| 3073 | "WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3074 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3075 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3076 | 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] | 3077 | } |
| 3078 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3079 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 3080 | { |
| 3081 | /* |
| 3082 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 3083 | * LP3 usage can cause vblank interrupts to be lost. |
| 3084 | * The DEIIR bit will go high but it looks like the CPU |
| 3085 | * never gets interrupted. |
| 3086 | * |
| 3087 | * It's not clear whether other interrupt source could |
| 3088 | * be affected or if this is somehow limited to vblank |
| 3089 | * interrupts only. To play it safe we disable LP3 |
| 3090 | * watermarks entirely. |
| 3091 | */ |
| 3092 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3093 | dev_priv->wm.spr_latency[3] == 0 && |
| 3094 | dev_priv->wm.cur_latency[3] == 0) |
| 3095 | return; |
| 3096 | |
| 3097 | dev_priv->wm.pri_latency[3] = 0; |
| 3098 | dev_priv->wm.spr_latency[3] = 0; |
| 3099 | dev_priv->wm.cur_latency[3] = 0; |
| 3100 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3101 | drm_dbg_kms(&dev_priv->drm, |
| 3102 | "LP3 watermarks disabled due to potential for lost interrupts\n"); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3103 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3104 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3105 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3106 | } |
| 3107 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3108 | 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] | 3109 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3110 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3111 | |
| 3112 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3113 | sizeof(dev_priv->wm.pri_latency)); |
| 3114 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3115 | sizeof(dev_priv->wm.pri_latency)); |
| 3116 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3117 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3118 | 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] | 3119 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3120 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3121 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3122 | 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] | 3123 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3124 | if (DISPLAY_VER(dev_priv) == 6) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3125 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3126 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3127 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3128 | } |
| 3129 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3130 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3131 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3132 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3133 | 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] | 3134 | } |
| 3135 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3136 | 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] | 3137 | struct intel_pipe_wm *pipe_wm) |
| 3138 | { |
| 3139 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3140 | const struct intel_wm_config config = { |
| 3141 | .num_pipes_active = 1, |
| 3142 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3143 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3144 | }; |
| 3145 | struct ilk_wm_maximums max; |
| 3146 | |
| 3147 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3148 | 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] | 3149 | |
| 3150 | /* At least LP0 must be valid */ |
| 3151 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3152 | drm_dbg_kms(&dev_priv->drm, "LP0 watermark invalid\n"); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3153 | return false; |
| 3154 | } |
| 3155 | |
| 3156 | return true; |
| 3157 | } |
| 3158 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3159 | /* Compute new watermarks for the pipe */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3160 | static int ilk_compute_pipe_wm(struct intel_atomic_state *state, |
| 3161 | struct intel_crtc *crtc) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3162 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3163 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 3164 | struct intel_crtc_state *crtc_state = |
| 3165 | intel_atomic_get_new_crtc_state(state, crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3166 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3167 | struct intel_plane *plane; |
| 3168 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3169 | const struct intel_plane_state *pristate = NULL; |
| 3170 | const struct intel_plane_state *sprstate = NULL; |
| 3171 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3172 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3173 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3174 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3175 | pipe_wm = &crtc_state->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3176 | |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3177 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 3178 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 3179 | pristate = plane_state; |
| 3180 | else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
| 3181 | sprstate = plane_state; |
| 3182 | else if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 3183 | curstate = plane_state; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 3186 | pipe_wm->pipe_enabled = crtc_state->hw.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3187 | if (sprstate) { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 3188 | pipe_wm->sprites_enabled = sprstate->uapi.visible; |
| 3189 | pipe_wm->sprites_scaled = sprstate->uapi.visible && |
| 3190 | (drm_rect_width(&sprstate->uapi.dst) != drm_rect_width(&sprstate->uapi.src) >> 16 || |
| 3191 | 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] | 3192 | } |
| 3193 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3194 | usable_level = max_level; |
| 3195 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3196 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3197 | if (DISPLAY_VER(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3198 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3199 | |
| 3200 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3201 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3202 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3203 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3204 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3205 | ilk_compute_wm_level(dev_priv, crtc, 0, crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3206 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3207 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3208 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3209 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3210 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3211 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3212 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3213 | for (level = 1; level <= usable_level; level++) { |
| 3214 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3215 | |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3216 | ilk_compute_wm_level(dev_priv, crtc, level, crtc_state, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3217 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3218 | |
| 3219 | /* |
| 3220 | * Disable any watermark level that exceeds the |
| 3221 | * register maximums since such watermarks are |
| 3222 | * always invalid. |
| 3223 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3224 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3225 | memset(wm, 0, sizeof(*wm)); |
| 3226 | break; |
| 3227 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3228 | } |
| 3229 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3230 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3234 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3235 | * state and the new state. These can be programmed to the hardware |
| 3236 | * immediately. |
| 3237 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3238 | static int ilk_compute_intermediate_wm(struct intel_atomic_state *state, |
| 3239 | struct intel_crtc *crtc) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3240 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3241 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3242 | struct intel_crtc_state *new_crtc_state = |
| 3243 | intel_atomic_get_new_crtc_state(state, crtc); |
| 3244 | const struct intel_crtc_state *old_crtc_state = |
| 3245 | intel_atomic_get_old_crtc_state(state, crtc); |
| 3246 | struct intel_pipe_wm *a = &new_crtc_state->wm.ilk.intermediate; |
| 3247 | const struct intel_pipe_wm *b = &old_crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3248 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3249 | |
| 3250 | /* |
| 3251 | * Start with the final, target watermarks, then combine with the |
| 3252 | * currently active watermarks to get values that are safe both before |
| 3253 | * and after the vblank. |
| 3254 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3255 | *a = new_crtc_state->wm.ilk.optimal; |
| 3256 | if (!new_crtc_state->hw.active || |
| 3257 | drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) || |
| 3258 | state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3259 | return 0; |
| 3260 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3261 | a->pipe_enabled |= b->pipe_enabled; |
| 3262 | a->sprites_enabled |= b->sprites_enabled; |
| 3263 | a->sprites_scaled |= b->sprites_scaled; |
| 3264 | |
| 3265 | for (level = 0; level <= max_level; level++) { |
| 3266 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3267 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3268 | |
| 3269 | a_wm->enable &= b_wm->enable; |
| 3270 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3271 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3272 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3273 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3274 | } |
| 3275 | |
| 3276 | /* |
| 3277 | * We need to make sure that these merged watermark values are |
| 3278 | * actually a valid configuration themselves. If they're not, |
| 3279 | * there's no safe way to transition from the old state to |
| 3280 | * the new state, so we need to fail the atomic transaction. |
| 3281 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3282 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3283 | return -EINVAL; |
| 3284 | |
| 3285 | /* |
| 3286 | * If our intermediate WM are identical to the final WM, then we can |
| 3287 | * omit the post-vblank programming; only update if it's different. |
| 3288 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3289 | if (memcmp(a, &new_crtc_state->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3290 | new_crtc_state->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3291 | |
| 3292 | return 0; |
| 3293 | } |
| 3294 | |
| 3295 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3296 | * Merge the watermarks from all active pipes for a specific level. |
| 3297 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3298 | 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] | 3299 | int level, |
| 3300 | struct intel_wm_level *ret_wm) |
| 3301 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3302 | const struct intel_crtc *crtc; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3303 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3304 | ret_wm->enable = true; |
| 3305 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3306 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 3307 | const struct intel_pipe_wm *active = &crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3308 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3309 | |
| 3310 | if (!active->pipe_enabled) |
| 3311 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3312 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3313 | /* |
| 3314 | * The watermark values may have been used in the past, |
| 3315 | * so we must maintain them in the registers for some |
| 3316 | * time even if the level is now disabled. |
| 3317 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3318 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3319 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3320 | |
| 3321 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3322 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3323 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3324 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3325 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | /* |
| 3329 | * Merge all low power watermarks for all active pipes. |
| 3330 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3331 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3332 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3333 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3334 | struct intel_pipe_wm *merged) |
| 3335 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3336 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3337 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3338 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3339 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3340 | if ((DISPLAY_VER(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3341 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3342 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3343 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3344 | /* ILK: FBC WM must be disabled always */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3345 | merged->fbc_wm_enabled = DISPLAY_VER(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3346 | |
| 3347 | /* merge each WM1+ level */ |
| 3348 | for (level = 1; level <= max_level; level++) { |
| 3349 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3350 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3351 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3352 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3353 | if (level > last_enabled_level) |
| 3354 | wm->enable = false; |
| 3355 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3356 | /* make sure all following levels get disabled */ |
| 3357 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3358 | |
| 3359 | /* |
| 3360 | * The spec says it is preferred to disable |
| 3361 | * FBC WMs instead of disabling a WM level. |
| 3362 | */ |
| 3363 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3364 | if (wm->enable) |
| 3365 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3366 | wm->fbc_val = 0; |
| 3367 | } |
| 3368 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3369 | |
| 3370 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 3371 | /* |
| 3372 | * FIXME this is racy. FBC might get enabled later. |
| 3373 | * What we should check here is whether FBC can be |
| 3374 | * enabled sometime later. |
| 3375 | */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3376 | if (DISPLAY_VER(dev_priv) == 5 && !merged->fbc_wm_enabled && |
Paulo Zanoni | 0e631ad | 2015-10-14 17:45:36 -0300 | [diff] [blame] | 3377 | intel_fbc_is_active(dev_priv)) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3378 | for (level = 2; level <= max_level; level++) { |
| 3379 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3380 | |
| 3381 | wm->enable = false; |
| 3382 | } |
| 3383 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3384 | } |
| 3385 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3386 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3387 | { |
| 3388 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3389 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3390 | } |
| 3391 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3392 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3393 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3394 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3395 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3396 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3397 | return 2 * level; |
| 3398 | else |
| 3399 | return dev_priv->wm.pri_latency[level]; |
| 3400 | } |
| 3401 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3402 | 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] | 3403 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3404 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3405 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3406 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3407 | struct intel_crtc *crtc; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3408 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3409 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3410 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3411 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3412 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3413 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3414 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3415 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3416 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3417 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3418 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3419 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3420 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3421 | /* |
| 3422 | * Maintain the watermark values even if the level is |
| 3423 | * disabled. Doing otherwise could cause underruns. |
| 3424 | */ |
| 3425 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3426 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3427 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3428 | r->cur_val; |
| 3429 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3430 | if (r->enable) |
| 3431 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3432 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3433 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3434 | results->wm_lp[wm_lp - 1] |= |
| 3435 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3436 | else |
| 3437 | results->wm_lp[wm_lp - 1] |= |
| 3438 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3439 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3440 | /* |
| 3441 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3442 | * level is disabled. Doing otherwise could cause underruns. |
| 3443 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3444 | if (DISPLAY_VER(dev_priv) <= 6 && r->spr_val) { |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 3445 | drm_WARN_ON(&dev_priv->drm, wm_lp != 1); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3446 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3447 | } else |
| 3448 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3449 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3450 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3451 | /* LP0 register values */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3452 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 3453 | enum pipe pipe = crtc->pipe; |
| 3454 | const struct intel_pipe_wm *pipe_wm = &crtc->wm.active.ilk; |
Ville Syrjälä | 0560b0c | 2020-01-20 19:47:11 +0200 | [diff] [blame] | 3455 | const struct intel_wm_level *r = &pipe_wm->wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3456 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 3457 | if (drm_WARN_ON(&dev_priv->drm, !r->enable)) |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3458 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3459 | |
| 3460 | results->wm_pipe[pipe] = |
| 3461 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3462 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3463 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3464 | } |
| 3465 | } |
| 3466 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3467 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3468 | * 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] | 3469 | static struct intel_pipe_wm * |
| 3470 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3471 | struct intel_pipe_wm *r1, |
| 3472 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3473 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3474 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3475 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3476 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3477 | for (level = 1; level <= max_level; level++) { |
| 3478 | if (r1->wm[level].enable) |
| 3479 | level1 = level; |
| 3480 | if (r2->wm[level].enable) |
| 3481 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3482 | } |
| 3483 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3484 | if (level1 == level2) { |
| 3485 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3486 | return r2; |
| 3487 | else |
| 3488 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3489 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3490 | return r1; |
| 3491 | } else { |
| 3492 | return r2; |
| 3493 | } |
| 3494 | } |
| 3495 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3496 | /* dirty bits used to track which watermarks need changes */ |
| 3497 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3498 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3499 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3500 | #define WM_DIRTY_FBC (1 << 24) |
| 3501 | #define WM_DIRTY_DDB (1 << 25) |
| 3502 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3503 | 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] | 3504 | const struct ilk_wm_values *old, |
| 3505 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3506 | { |
| 3507 | unsigned int dirty = 0; |
| 3508 | enum pipe pipe; |
| 3509 | int wm_lp; |
| 3510 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3511 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3512 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3513 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3514 | /* Must disable LP1+ watermarks too */ |
| 3515 | dirty |= WM_DIRTY_LP_ALL; |
| 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3520 | dirty |= WM_DIRTY_FBC; |
| 3521 | /* Must disable LP1+ watermarks too */ |
| 3522 | dirty |= WM_DIRTY_LP_ALL; |
| 3523 | } |
| 3524 | |
| 3525 | if (old->partitioning != new->partitioning) { |
| 3526 | dirty |= WM_DIRTY_DDB; |
| 3527 | /* Must disable LP1+ watermarks too */ |
| 3528 | dirty |= WM_DIRTY_LP_ALL; |
| 3529 | } |
| 3530 | |
| 3531 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3532 | if (dirty & WM_DIRTY_LP_ALL) |
| 3533 | return dirty; |
| 3534 | |
| 3535 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3536 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3537 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3538 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3539 | break; |
| 3540 | } |
| 3541 | |
| 3542 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3543 | for (; wm_lp <= 3; wm_lp++) |
| 3544 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3545 | |
| 3546 | return dirty; |
| 3547 | } |
| 3548 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3549 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3550 | unsigned int dirty) |
| 3551 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3552 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3553 | bool changed = false; |
| 3554 | |
| 3555 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3556 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3557 | 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] | 3558 | changed = true; |
| 3559 | } |
| 3560 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3561 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3562 | 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] | 3563 | changed = true; |
| 3564 | } |
| 3565 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3566 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3567 | 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] | 3568 | changed = true; |
| 3569 | } |
| 3570 | |
| 3571 | /* |
| 3572 | * Don't touch WM1S_LP_EN here. |
| 3573 | * Doing so could cause underruns. |
| 3574 | */ |
| 3575 | |
| 3576 | return changed; |
| 3577 | } |
| 3578 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3579 | /* |
| 3580 | * The spec says we shouldn't write when we don't need, because every write |
| 3581 | * causes WMs to be re-evaluated, expending some power. |
| 3582 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3583 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3584 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3585 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3586 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3587 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3588 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3589 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3590 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3591 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3592 | return; |
| 3593 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3594 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3595 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3596 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3597 | 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] | 3598 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3599 | 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] | 3600 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3601 | 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] | 3602 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3603 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3604 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3605 | val = intel_uncore_read(&dev_priv->uncore, WM_MISC); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3606 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3607 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3608 | else |
| 3609 | val |= WM_MISC_DATA_PARTITION_5_6; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3610 | intel_uncore_write(&dev_priv->uncore, WM_MISC, val); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3611 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3612 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3613 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3614 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3615 | else |
| 3616 | val |= DISP_DATA_PARTITION_5_6; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3617 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL2, val); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3618 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3619 | } |
| 3620 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3621 | if (dirty & WM_DIRTY_FBC) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3622 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3623 | if (results->enable_fbc_wm) |
| 3624 | val &= ~DISP_FBC_WM_DIS; |
| 3625 | else |
| 3626 | val |= DISP_FBC_WM_DIS; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3627 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, val); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3628 | } |
| 3629 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3630 | if (dirty & WM_DIRTY_LP(1) && |
| 3631 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3632 | 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] | 3633 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3634 | if (DISPLAY_VER(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3635 | 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] | 3636 | 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] | 3637 | 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] | 3638 | 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] | 3639 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3640 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3641 | 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] | 3642 | 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] | 3643 | 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] | 3644 | 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] | 3645 | 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] | 3646 | 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] | 3647 | |
| 3648 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3649 | } |
| 3650 | |
Ville Syrjälä | 60aca57 | 2019-11-27 21:05:51 +0200 | [diff] [blame] | 3651 | bool ilk_disable_lp_wm(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3652 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3653 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3654 | } |
| 3655 | |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3656 | u8 intel_enabled_dbuf_slices_mask(struct drm_i915_private *dev_priv) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3657 | { |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3658 | u8 enabled_slices = 0; |
| 3659 | enum dbuf_slice slice; |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3660 | |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3661 | for_each_dbuf_slice(dev_priv, slice) { |
| 3662 | if (intel_uncore_read(&dev_priv->uncore, |
| 3663 | DBUF_CTL_S(slice)) & DBUF_POWER_STATE) |
| 3664 | enabled_slices |= BIT(slice); |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3665 | } |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3666 | |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3667 | return enabled_slices; |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3668 | } |
| 3669 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3670 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3671 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3672 | * so assume we'll always need it in order to avoid underruns. |
| 3673 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3674 | 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] | 3675 | { |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3676 | return DISPLAY_VER(dev_priv) == 9; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3677 | } |
| 3678 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3679 | static bool |
| 3680 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3681 | { |
Matt Roper | 70bfb30 | 2021-04-07 13:39:45 -0700 | [diff] [blame] | 3682 | return DISPLAY_VER(dev_priv) >= 9 && !IS_LP(dev_priv) && |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3683 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3684 | } |
| 3685 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3686 | static void |
| 3687 | skl_setup_sagv_block_time(struct drm_i915_private *dev_priv) |
| 3688 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3689 | if (DISPLAY_VER(dev_priv) >= 12) { |
James Ausmus | da80f04 | 2019-10-09 10:23:15 -0700 | [diff] [blame] | 3690 | u32 val = 0; |
| 3691 | int ret; |
| 3692 | |
| 3693 | ret = sandybridge_pcode_read(dev_priv, |
| 3694 | GEN12_PCODE_READ_SAGV_BLOCK_TIME_US, |
| 3695 | &val, NULL); |
| 3696 | if (!ret) { |
| 3697 | dev_priv->sagv_block_time_us = val; |
| 3698 | return; |
| 3699 | } |
| 3700 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3701 | 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] | 3702 | } else if (DISPLAY_VER(dev_priv) == 11) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3703 | dev_priv->sagv_block_time_us = 10; |
| 3704 | return; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3705 | } else if (DISPLAY_VER(dev_priv) == 10) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3706 | dev_priv->sagv_block_time_us = 20; |
| 3707 | return; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3708 | } else if (DISPLAY_VER(dev_priv) == 9) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3709 | dev_priv->sagv_block_time_us = 30; |
| 3710 | return; |
| 3711 | } else { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3712 | MISSING_CASE(DISPLAY_VER(dev_priv)); |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | /* Default to an unusable block time */ |
| 3716 | dev_priv->sagv_block_time_us = -1; |
| 3717 | } |
| 3718 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3719 | /* |
| 3720 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3721 | * depending on power and performance requirements. The display engine access |
| 3722 | * to system memory is blocked during the adjustment time. Because of the |
| 3723 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3724 | * underruns if we don't meet all of the following requirements: |
| 3725 | * |
| 3726 | * - <= 1 pipe enabled |
| 3727 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3728 | * - We're not using an interlaced display configuration |
| 3729 | */ |
Ville Syrjälä | 7102404 | 2020-09-25 15:17:48 +0300 | [diff] [blame] | 3730 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3731 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3732 | { |
| 3733 | int ret; |
| 3734 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3735 | if (!intel_has_sagv(dev_priv)) |
| 3736 | return 0; |
| 3737 | |
| 3738 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3739 | return 0; |
| 3740 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3741 | drm_dbg_kms(&dev_priv->drm, "Enabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3742 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3743 | GEN9_SAGV_ENABLE); |
| 3744 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3745 | /* We don't need to wait for SAGV when enabling */ |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3746 | |
| 3747 | /* |
| 3748 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3749 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3750 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3751 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3752 | drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3753 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3754 | return 0; |
| 3755 | } else if (ret < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3756 | drm_err(&dev_priv->drm, "Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3757 | return ret; |
| 3758 | } |
| 3759 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3760 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3761 | return 0; |
| 3762 | } |
| 3763 | |
Ville Syrjälä | 7102404 | 2020-09-25 15:17:48 +0300 | [diff] [blame] | 3764 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3765 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3766 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3767 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3768 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3769 | if (!intel_has_sagv(dev_priv)) |
| 3770 | return 0; |
| 3771 | |
| 3772 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3773 | return 0; |
| 3774 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3775 | drm_dbg_kms(&dev_priv->drm, "Disabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3776 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3777 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3778 | GEN9_SAGV_DISABLE, |
| 3779 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3780 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3781 | /* |
| 3782 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3783 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3784 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3785 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3786 | drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3787 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3788 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3789 | } else if (ret < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3790 | drm_err(&dev_priv->drm, "Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3791 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3792 | } |
| 3793 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3794 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3795 | return 0; |
| 3796 | } |
| 3797 | |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3798 | void intel_sagv_pre_plane_update(struct intel_atomic_state *state) |
| 3799 | { |
| 3800 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3801 | const struct intel_bw_state *new_bw_state; |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3802 | const struct intel_bw_state *old_bw_state; |
| 3803 | u32 new_mask = 0; |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3804 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3805 | /* |
| 3806 | * Just return if we can't control SAGV or don't have it. |
| 3807 | * This is different from situation when we have SAGV but just can't |
| 3808 | * afford it due to DBuf limitation - in case if SAGV is completely |
| 3809 | * disabled in a BIOS, we are not even allowed to send a PCode request, |
| 3810 | * as it will throw an error. So have to check it here. |
| 3811 | */ |
| 3812 | if (!intel_has_sagv(dev_priv)) |
| 3813 | return; |
| 3814 | |
| 3815 | new_bw_state = intel_atomic_get_new_bw_state(state); |
| 3816 | if (!new_bw_state) |
| 3817 | return; |
| 3818 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3819 | 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] | 3820 | intel_disable_sagv(dev_priv); |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3821 | return; |
| 3822 | } |
| 3823 | |
| 3824 | old_bw_state = intel_atomic_get_old_bw_state(state); |
| 3825 | /* |
| 3826 | * Nothing to mask |
| 3827 | */ |
| 3828 | if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask) |
| 3829 | return; |
| 3830 | |
| 3831 | new_mask = old_bw_state->qgv_points_mask | new_bw_state->qgv_points_mask; |
| 3832 | |
| 3833 | /* |
| 3834 | * If new mask is zero - means there is nothing to mask, |
| 3835 | * we can only unmask, which should be done in unmask. |
| 3836 | */ |
| 3837 | if (!new_mask) |
| 3838 | return; |
| 3839 | |
| 3840 | /* |
| 3841 | * Restrict required qgv points before updating the configuration. |
| 3842 | * According to BSpec we can't mask and unmask qgv points at the same |
| 3843 | * time. Also masking should be done before updating the configuration |
| 3844 | * and unmasking afterwards. |
| 3845 | */ |
| 3846 | icl_pcode_restrict_qgv_points(dev_priv, new_mask); |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | void intel_sagv_post_plane_update(struct intel_atomic_state *state) |
| 3850 | { |
| 3851 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3852 | const struct intel_bw_state *new_bw_state; |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3853 | const struct intel_bw_state *old_bw_state; |
| 3854 | u32 new_mask = 0; |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3855 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3856 | /* |
| 3857 | * Just return if we can't control SAGV or don't have it. |
| 3858 | * This is different from situation when we have SAGV but just can't |
| 3859 | * afford it due to DBuf limitation - in case if SAGV is completely |
| 3860 | * disabled in a BIOS, we are not even allowed to send a PCode request, |
| 3861 | * as it will throw an error. So have to check it here. |
| 3862 | */ |
| 3863 | if (!intel_has_sagv(dev_priv)) |
| 3864 | return; |
| 3865 | |
| 3866 | new_bw_state = intel_atomic_get_new_bw_state(state); |
| 3867 | if (!new_bw_state) |
| 3868 | return; |
| 3869 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3870 | 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] | 3871 | intel_enable_sagv(dev_priv); |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3872 | return; |
| 3873 | } |
| 3874 | |
| 3875 | old_bw_state = intel_atomic_get_old_bw_state(state); |
| 3876 | /* |
| 3877 | * Nothing to unmask |
| 3878 | */ |
| 3879 | if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask) |
| 3880 | return; |
| 3881 | |
| 3882 | new_mask = new_bw_state->qgv_points_mask; |
| 3883 | |
| 3884 | /* |
| 3885 | * Allow required qgv points after updating the configuration. |
| 3886 | * According to BSpec we can't mask and unmask qgv points at the same |
| 3887 | * time. Also masking should be done before updating the configuration |
| 3888 | * and unmasking afterwards. |
| 3889 | */ |
| 3890 | icl_pcode_restrict_qgv_points(dev_priv, new_mask); |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3891 | } |
| 3892 | |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3893 | 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] | 3894 | { |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3895 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3896 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3897 | enum plane_id plane_id; |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3898 | int max_level = INT_MAX; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3899 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3900 | if (!intel_has_sagv(dev_priv)) |
| 3901 | return false; |
| 3902 | |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3903 | if (!crtc_state->hw.active) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3904 | return true; |
Lucas De Marchi | da17223 | 2019-04-04 16:04:26 -0700 | [diff] [blame] | 3905 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 3906 | if (crtc_state->hw.pipe_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3907 | return false; |
| 3908 | |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3909 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3910 | const struct skl_plane_wm *wm = |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3911 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3912 | int level; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3913 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3914 | /* Skip this plane if it's not enabled */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3915 | if (!wm->wm[0].enable) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3916 | continue; |
| 3917 | |
| 3918 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3919 | for (level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3920 | !wm->wm[level].enable; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3921 | { } |
| 3922 | |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3923 | /* Highest common enabled wm level for all planes */ |
| 3924 | max_level = min(level, max_level); |
| 3925 | } |
| 3926 | |
| 3927 | /* No enabled planes? */ |
| 3928 | if (max_level == INT_MAX) |
| 3929 | return true; |
| 3930 | |
| 3931 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 3932 | const struct skl_plane_wm *wm = |
| 3933 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3934 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3935 | /* |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3936 | * All enabled planes must have enabled a common wm level that |
| 3937 | * can tolerate memory latencies higher than sagv_block_time_us |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3938 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3939 | if (wm->wm[0].enable && !wm->wm[max_level].can_sagv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3940 | return false; |
| 3941 | } |
| 3942 | |
| 3943 | return true; |
| 3944 | } |
| 3945 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3946 | static bool tgl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
| 3947 | { |
| 3948 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 3949 | enum plane_id plane_id; |
| 3950 | |
| 3951 | if (!crtc_state->hw.active) |
| 3952 | return true; |
| 3953 | |
| 3954 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3955 | const struct skl_plane_wm *wm = |
| 3956 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3957 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3958 | if (wm->wm[0].enable && !wm->sagv.wm0.enable) |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3959 | return false; |
| 3960 | } |
| 3961 | |
| 3962 | return true; |
| 3963 | } |
| 3964 | |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3965 | static bool intel_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
| 3966 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3967 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 3968 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3969 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3970 | if (DISPLAY_VER(dev_priv) >= 12) |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3971 | return tgl_crtc_can_enable_sagv(crtc_state); |
| 3972 | else |
| 3973 | return skl_crtc_can_enable_sagv(crtc_state); |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3974 | } |
| 3975 | |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3976 | bool intel_can_enable_sagv(struct drm_i915_private *dev_priv, |
| 3977 | const struct intel_bw_state *bw_state) |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3978 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3979 | if (DISPLAY_VER(dev_priv) < 11 && |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3980 | bw_state->active_pipes && !is_power_of_2(bw_state->active_pipes)) |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 3981 | return false; |
| 3982 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3983 | return bw_state->pipe_sagv_reject == 0; |
| 3984 | } |
| 3985 | |
| 3986 | static int intel_compute_sagv_mask(struct intel_atomic_state *state) |
| 3987 | { |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3988 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3989 | int ret; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3990 | struct intel_crtc *crtc; |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3991 | struct intel_crtc_state *new_crtc_state; |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3992 | struct intel_bw_state *new_bw_state = NULL; |
| 3993 | const struct intel_bw_state *old_bw_state = NULL; |
| 3994 | int i; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3995 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3996 | for_each_new_intel_crtc_in_state(state, crtc, |
| 3997 | new_crtc_state, i) { |
| 3998 | new_bw_state = intel_atomic_get_bw_state(state); |
| 3999 | if (IS_ERR(new_bw_state)) |
| 4000 | return PTR_ERR(new_bw_state); |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4001 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4002 | old_bw_state = intel_atomic_get_old_bw_state(state); |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4003 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4004 | if (intel_crtc_can_enable_sagv(new_crtc_state)) |
| 4005 | new_bw_state->pipe_sagv_reject &= ~BIT(crtc->pipe); |
| 4006 | else |
| 4007 | new_bw_state->pipe_sagv_reject |= BIT(crtc->pipe); |
| 4008 | } |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4009 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4010 | if (!new_bw_state) |
| 4011 | return 0; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4012 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 4013 | new_bw_state->active_pipes = |
| 4014 | intel_calc_active_pipes(state, old_bw_state->active_pipes); |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 4015 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 4016 | if (new_bw_state->active_pipes != old_bw_state->active_pipes) { |
| 4017 | ret = intel_atomic_lock_global_state(&new_bw_state->base); |
| 4018 | if (ret) |
| 4019 | return ret; |
| 4020 | } |
| 4021 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 4022 | for_each_new_intel_crtc_in_state(state, crtc, |
| 4023 | new_crtc_state, i) { |
| 4024 | struct skl_pipe_wm *pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 4025 | |
| 4026 | /* |
| 4027 | * We store use_sagv_wm in the crtc state rather than relying on |
| 4028 | * that bw state since we have no convenient way to get at the |
| 4029 | * latter from the plane commit hooks (especially in the legacy |
| 4030 | * cursor case) |
| 4031 | */ |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 4032 | pipe_wm->use_sagv_wm = !HAS_HW_SAGV_WM(dev_priv) && |
| 4033 | DISPLAY_VER(dev_priv) >= 12 && |
| 4034 | intel_can_enable_sagv(dev_priv, new_bw_state); |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 4035 | } |
| 4036 | |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 4037 | if (intel_can_enable_sagv(dev_priv, new_bw_state) != |
| 4038 | intel_can_enable_sagv(dev_priv, old_bw_state)) { |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4039 | ret = intel_atomic_serialize_global_state(&new_bw_state->base); |
| 4040 | if (ret) |
| 4041 | return ret; |
| 4042 | } else if (new_bw_state->pipe_sagv_reject != old_bw_state->pipe_sagv_reject) { |
| 4043 | ret = intel_atomic_lock_global_state(&new_bw_state->base); |
| 4044 | if (ret) |
| 4045 | return ret; |
| 4046 | } |
| 4047 | |
| 4048 | return 0; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4049 | } |
| 4050 | |
Ville Syrjälä | 944a5e3 | 2021-01-22 22:56:28 +0200 | [diff] [blame] | 4051 | static int intel_dbuf_slice_size(struct drm_i915_private *dev_priv) |
| 4052 | { |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 4053 | return INTEL_INFO(dev_priv)->dbuf.size / |
| 4054 | hweight8(INTEL_INFO(dev_priv)->dbuf.slice_mask); |
Ville Syrjälä | 944a5e3 | 2021-01-22 22:56:28 +0200 | [diff] [blame] | 4055 | } |
| 4056 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4057 | static void |
| 4058 | skl_ddb_entry_for_slices(struct drm_i915_private *dev_priv, u8 slice_mask, |
| 4059 | struct skl_ddb_entry *ddb) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 4060 | { |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4061 | int slice_size = intel_dbuf_slice_size(dev_priv); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4062 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4063 | if (!slice_mask) { |
| 4064 | ddb->start = 0; |
| 4065 | ddb->end = 0; |
| 4066 | return; |
| 4067 | } |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4068 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4069 | ddb->start = (ffs(slice_mask) - 1) * slice_size; |
| 4070 | ddb->end = fls(slice_mask) * slice_size; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4071 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4072 | WARN_ON(ddb->start >= ddb->end); |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 4073 | WARN_ON(ddb->end > INTEL_INFO(dev_priv)->dbuf.size); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4074 | } |
| 4075 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4076 | static unsigned int mbus_ddb_offset(struct drm_i915_private *i915, u8 slice_mask) |
| 4077 | { |
| 4078 | struct skl_ddb_entry ddb; |
| 4079 | |
| 4080 | if (slice_mask & (BIT(DBUF_S1) | BIT(DBUF_S2))) |
| 4081 | slice_mask = BIT(DBUF_S1); |
| 4082 | else if (slice_mask & (BIT(DBUF_S3) | BIT(DBUF_S4))) |
| 4083 | slice_mask = BIT(DBUF_S3); |
| 4084 | |
| 4085 | skl_ddb_entry_for_slices(i915, slice_mask, &ddb); |
| 4086 | |
| 4087 | return ddb.start; |
| 4088 | } |
| 4089 | |
Stanislav Lisovskiy | cd19154 | 2020-05-20 18:00:58 +0300 | [diff] [blame] | 4090 | u32 skl_ddb_dbuf_slice_mask(struct drm_i915_private *dev_priv, |
| 4091 | const struct skl_ddb_entry *entry) |
| 4092 | { |
Ville Syrjälä | 6390e5a | 2021-04-16 20:10:07 +0300 | [diff] [blame] | 4093 | int slice_size = intel_dbuf_slice_size(dev_priv); |
| 4094 | enum dbuf_slice start_slice, end_slice; |
| 4095 | u8 slice_mask = 0; |
Stanislav Lisovskiy | cd19154 | 2020-05-20 18:00:58 +0300 | [diff] [blame] | 4096 | |
| 4097 | if (!skl_ddb_entry_size(entry)) |
| 4098 | return 0; |
| 4099 | |
| 4100 | start_slice = entry->start / slice_size; |
| 4101 | end_slice = (entry->end - 1) / slice_size; |
| 4102 | |
| 4103 | /* |
| 4104 | * Per plane DDB entry can in a really worst case be on multiple slices |
| 4105 | * but single entry is anyway contigious. |
| 4106 | */ |
| 4107 | while (start_slice <= end_slice) { |
| 4108 | slice_mask |= BIT(start_slice); |
| 4109 | start_slice++; |
| 4110 | } |
| 4111 | |
| 4112 | return slice_mask; |
| 4113 | } |
| 4114 | |
Ville Syrjälä | 2791a40 | 2021-01-22 22:56:26 +0200 | [diff] [blame] | 4115 | static unsigned int intel_crtc_ddb_weight(const struct intel_crtc_state *crtc_state) |
| 4116 | { |
| 4117 | const struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode; |
| 4118 | int hdisplay, vdisplay; |
| 4119 | |
| 4120 | if (!crtc_state->hw.active) |
| 4121 | return 0; |
| 4122 | |
| 4123 | /* |
| 4124 | * Watermark/ddb requirement highly depends upon width of the |
| 4125 | * framebuffer, So instead of allocating DDB equally among pipes |
| 4126 | * distribute DDB based on resolution/width of the display. |
| 4127 | */ |
| 4128 | drm_mode_get_hv_timing(pipe_mode, &hdisplay, &vdisplay); |
| 4129 | |
| 4130 | return hdisplay; |
| 4131 | } |
| 4132 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4133 | static void intel_crtc_dbuf_weights(const struct intel_dbuf_state *dbuf_state, |
| 4134 | enum pipe for_pipe, |
| 4135 | unsigned int *weight_start, |
| 4136 | unsigned int *weight_end, |
| 4137 | unsigned int *weight_total) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4138 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4139 | struct drm_i915_private *dev_priv = |
| 4140 | to_i915(dbuf_state->base.state->base.dev); |
| 4141 | enum pipe pipe; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4142 | |
| 4143 | *weight_start = 0; |
| 4144 | *weight_end = 0; |
| 4145 | *weight_total = 0; |
| 4146 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4147 | for_each_pipe(dev_priv, pipe) { |
| 4148 | int weight = dbuf_state->weight[pipe]; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4149 | |
| 4150 | /* |
| 4151 | * Do not account pipes using other slice sets |
| 4152 | * luckily as of current BSpec slice sets do not partially |
| 4153 | * intersect(pipes share either same one slice or same slice set |
| 4154 | * i.e no partial intersection), so it is enough to check for |
| 4155 | * equality for now. |
| 4156 | */ |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4157 | if (dbuf_state->slices[pipe] != dbuf_state->slices[for_pipe]) |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4158 | continue; |
| 4159 | |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4160 | *weight_total += weight; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4161 | if (pipe < for_pipe) { |
| 4162 | *weight_start += weight; |
| 4163 | *weight_end += weight; |
| 4164 | } else if (pipe == for_pipe) { |
| 4165 | *weight_end += weight; |
| 4166 | } |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4167 | } |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | static int |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4171 | 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] | 4172 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4173 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4174 | unsigned int weight_total, weight_start, weight_end; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4175 | const struct intel_dbuf_state *old_dbuf_state = |
| 4176 | intel_atomic_get_old_dbuf_state(state); |
| 4177 | struct intel_dbuf_state *new_dbuf_state = |
| 4178 | intel_atomic_get_new_dbuf_state(state); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4179 | struct intel_crtc_state *crtc_state; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4180 | struct skl_ddb_entry ddb_slices; |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4181 | enum pipe pipe = crtc->pipe; |
Manasi Navare | e2bebb9 | 2021-06-03 14:53:38 -0700 | [diff] [blame] | 4182 | unsigned int mbus_offset = 0; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4183 | u32 ddb_range_size; |
| 4184 | u32 dbuf_slice_mask; |
| 4185 | u32 start, end; |
| 4186 | int ret; |
| 4187 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4188 | if (new_dbuf_state->weight[pipe] == 0) { |
| 4189 | new_dbuf_state->ddb[pipe].start = 0; |
| 4190 | new_dbuf_state->ddb[pipe].end = 0; |
| 4191 | goto out; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4192 | } |
| 4193 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4194 | dbuf_slice_mask = new_dbuf_state->slices[pipe]; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4195 | |
| 4196 | 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] | 4197 | mbus_offset = mbus_ddb_offset(dev_priv, dbuf_slice_mask); |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4198 | ddb_range_size = skl_ddb_entry_size(&ddb_slices); |
| 4199 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4200 | intel_crtc_dbuf_weights(new_dbuf_state, pipe, |
| 4201 | &weight_start, &weight_end, &weight_total); |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4202 | |
| 4203 | start = ddb_range_size * weight_start / weight_total; |
| 4204 | end = ddb_range_size * weight_end / weight_total; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4205 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4206 | new_dbuf_state->ddb[pipe].start = ddb_slices.start - mbus_offset + start; |
| 4207 | 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] | 4208 | out: |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4209 | if (old_dbuf_state->slices[pipe] == new_dbuf_state->slices[pipe] && |
| 4210 | skl_ddb_entry_equal(&old_dbuf_state->ddb[pipe], |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4211 | &new_dbuf_state->ddb[pipe])) |
| 4212 | return 0; |
| 4213 | |
| 4214 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 4215 | if (ret) |
| 4216 | return ret; |
| 4217 | |
| 4218 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 4219 | if (IS_ERR(crtc_state)) |
| 4220 | return PTR_ERR(crtc_state); |
| 4221 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4222 | /* |
| 4223 | * Used for checking overlaps, so we need absolute |
| 4224 | * offsets instead of MBUS relative offsets. |
| 4225 | */ |
| 4226 | crtc_state->wm.skl.ddb.start = mbus_offset + new_dbuf_state->ddb[pipe].start; |
| 4227 | 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] | 4228 | |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 4229 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4230 | "[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] | 4231 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4232 | old_dbuf_state->slices[pipe], new_dbuf_state->slices[pipe], |
| 4233 | old_dbuf_state->ddb[pipe].start, old_dbuf_state->ddb[pipe].end, |
| 4234 | new_dbuf_state->ddb[pipe].start, new_dbuf_state->ddb[pipe].end, |
| 4235 | old_dbuf_state->active_pipes, new_dbuf_state->active_pipes); |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4236 | |
| 4237 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4240 | static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 4241 | int width, const struct drm_format_info *format, |
| 4242 | u64 modifier, unsigned int rotation, |
| 4243 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 4244 | int color_plane); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4245 | 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] | 4246 | int level, |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 4247 | unsigned int latency, |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4248 | const struct skl_wm_params *wp, |
| 4249 | const struct skl_wm_level *result_prev, |
| 4250 | struct skl_wm_level *result /* out */); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4251 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4252 | static unsigned int |
| 4253 | skl_cursor_allocation(const struct intel_crtc_state *crtc_state, |
| 4254 | int num_active) |
| 4255 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 4256 | 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] | 4257 | int level, max_level = ilk_wm_max_level(dev_priv); |
| 4258 | struct skl_wm_level wm = {}; |
| 4259 | int ret, min_ddb_alloc = 0; |
| 4260 | struct skl_wm_params wp; |
| 4261 | |
| 4262 | ret = skl_compute_wm_params(crtc_state, 256, |
| 4263 | drm_format_info(DRM_FORMAT_ARGB8888), |
| 4264 | DRM_FORMAT_MOD_LINEAR, |
| 4265 | DRM_MODE_ROTATE_0, |
| 4266 | crtc_state->pixel_rate, &wp, 0); |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 4267 | drm_WARN_ON(&dev_priv->drm, ret); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4268 | |
| 4269 | for (level = 0; level <= max_level; level++) { |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 4270 | unsigned int latency = dev_priv->wm.skl_latency[level]; |
| 4271 | |
| 4272 | skl_compute_plane_wm(crtc_state, level, latency, &wp, &wm, &wm); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4273 | if (wm.min_ddb_alloc == U16_MAX) |
| 4274 | break; |
| 4275 | |
| 4276 | min_ddb_alloc = wm.min_ddb_alloc; |
| 4277 | } |
| 4278 | |
| 4279 | return max(num_active == 1 ? 32 : 8, min_ddb_alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4280 | } |
| 4281 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4282 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 4283 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4284 | { |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 4285 | entry->start = reg & DDB_ENTRY_MASK; |
| 4286 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4287 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 4288 | if (entry->end) |
| 4289 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4290 | } |
| 4291 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4292 | static void |
| 4293 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 4294 | const enum pipe pipe, |
| 4295 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4296 | struct skl_ddb_entry *ddb_y, |
| 4297 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4298 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4299 | u32 val, val2; |
| 4300 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4301 | |
| 4302 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 4303 | if (plane_id == PLANE_CURSOR) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4304 | val = intel_uncore_read(&dev_priv->uncore, CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4305 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4306 | return; |
| 4307 | } |
| 4308 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4309 | val = intel_uncore_read(&dev_priv->uncore, PLANE_CTL(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4310 | |
| 4311 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4312 | if (val & PLANE_CTL_ENABLE) |
| 4313 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 4314 | val & PLANE_CTL_ORDER_RGBX, |
| 4315 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4316 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 4317 | if (DISPLAY_VER(dev_priv) >= 11) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4318 | 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] | 4319 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4320 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4321 | val = intel_uncore_read(&dev_priv->uncore, PLANE_BUF_CFG(pipe, plane_id)); |
| 4322 | 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] | 4323 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4324 | if (fourcc && |
| 4325 | drm_format_info_is_yuv_semiplanar(drm_format_info(fourcc))) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4326 | swap(val, val2); |
| 4327 | |
| 4328 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4329 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4330 | } |
| 4331 | } |
| 4332 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4333 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 4334 | struct skl_ddb_entry *ddb_y, |
| 4335 | struct skl_ddb_entry *ddb_uv) |
| 4336 | { |
| 4337 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4338 | enum intel_display_power_domain power_domain; |
| 4339 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4340 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4341 | enum plane_id plane_id; |
| 4342 | |
| 4343 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4344 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 4345 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4346 | return; |
| 4347 | |
| 4348 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4349 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4350 | plane_id, |
| 4351 | &ddb_y[plane_id], |
| 4352 | &ddb_uv[plane_id]); |
| 4353 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4354 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4355 | } |
| 4356 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4357 | /* |
| 4358 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4359 | * The bspec defines downscale amount as: |
| 4360 | * |
| 4361 | * """ |
| 4362 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4363 | * Horizontal destination size] |
| 4364 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4365 | * Vertical destination size] |
| 4366 | * Total down scale amount = Horizontal down scale amount * |
| 4367 | * Vertical down scale amount |
| 4368 | * """ |
| 4369 | * |
| 4370 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4371 | * Caller should take care of dividing & rounding off the value. |
| 4372 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4373 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4374 | skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state, |
| 4375 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4376 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 4377 | 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] | 4378 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4379 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4380 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4381 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 4382 | if (drm_WARN_ON(&dev_priv->drm, |
| 4383 | !intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4384 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4385 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 4386 | /* |
| 4387 | * Src coordinates are already rotated by 270 degrees for |
| 4388 | * the 90/270 degree plane rotation cases (to match the |
| 4389 | * GTT mapping), hence no need to account for rotation here. |
| 4390 | * |
| 4391 | * n.b., src is 16.16 fixed point, dst is whole integer. |
| 4392 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4393 | src_w = drm_rect_width(&plane_state->uapi.src) >> 16; |
| 4394 | src_h = drm_rect_height(&plane_state->uapi.src) >> 16; |
| 4395 | dst_w = drm_rect_width(&plane_state->uapi.dst); |
| 4396 | dst_h = drm_rect_height(&plane_state->uapi.dst); |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4397 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4398 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4399 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4400 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4401 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4402 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4403 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4404 | } |
| 4405 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4406 | struct dbuf_slice_conf_entry { |
| 4407 | u8 active_pipes; |
| 4408 | u8 dbuf_mask[I915_MAX_PIPES]; |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4409 | bool join_mbus; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4410 | }; |
| 4411 | |
| 4412 | /* |
| 4413 | * Table taken from Bspec 12716 |
| 4414 | * Pipes do have some preferred DBuf slice affinity, |
| 4415 | * plus there are some hardcoded requirements on how |
| 4416 | * those should be distributed for multipipe scenarios. |
| 4417 | * For more DBuf slices algorithm can get even more messy |
| 4418 | * and less readable, so decided to use a table almost |
| 4419 | * as is from BSpec itself - that way it is at least easier |
| 4420 | * to compare, change and check. |
| 4421 | */ |
Jani Nikula | f8226d0 | 2020-02-19 17:45:42 +0200 | [diff] [blame] | 4422 | static const struct dbuf_slice_conf_entry icl_allowed_dbufs[] = |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4423 | /* Autogenerated with igt/tools/intel_dbuf_map tool: */ |
| 4424 | { |
| 4425 | { |
| 4426 | .active_pipes = BIT(PIPE_A), |
| 4427 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4428 | [PIPE_A] = BIT(DBUF_S1), |
| 4429 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4430 | }, |
| 4431 | { |
| 4432 | .active_pipes = BIT(PIPE_B), |
| 4433 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4434 | [PIPE_B] = BIT(DBUF_S1), |
| 4435 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4436 | }, |
| 4437 | { |
| 4438 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4439 | .dbuf_mask = { |
| 4440 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4441 | [PIPE_B] = BIT(DBUF_S2), |
| 4442 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4443 | }, |
| 4444 | { |
| 4445 | .active_pipes = BIT(PIPE_C), |
| 4446 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4447 | [PIPE_C] = BIT(DBUF_S2), |
| 4448 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4449 | }, |
| 4450 | { |
| 4451 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4452 | .dbuf_mask = { |
| 4453 | [PIPE_A] = 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 | }, |
| 4457 | { |
| 4458 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4459 | .dbuf_mask = { |
| 4460 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4461 | [PIPE_C] = BIT(DBUF_S2), |
| 4462 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4463 | }, |
| 4464 | { |
| 4465 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4466 | .dbuf_mask = { |
| 4467 | [PIPE_A] = BIT(DBUF_S1), |
| 4468 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4469 | [PIPE_C] = BIT(DBUF_S2), |
| 4470 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4471 | }, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4472 | {} |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4473 | }; |
| 4474 | |
| 4475 | /* |
| 4476 | * Table taken from Bspec 49255 |
| 4477 | * Pipes do have some preferred DBuf slice affinity, |
| 4478 | * plus there are some hardcoded requirements on how |
| 4479 | * those should be distributed for multipipe scenarios. |
| 4480 | * For more DBuf slices algorithm can get even more messy |
| 4481 | * and less readable, so decided to use a table almost |
| 4482 | * as is from BSpec itself - that way it is at least easier |
| 4483 | * to compare, change and check. |
| 4484 | */ |
Jani Nikula | f8226d0 | 2020-02-19 17:45:42 +0200 | [diff] [blame] | 4485 | static const struct dbuf_slice_conf_entry tgl_allowed_dbufs[] = |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4486 | /* Autogenerated with igt/tools/intel_dbuf_map tool: */ |
| 4487 | { |
| 4488 | { |
| 4489 | .active_pipes = BIT(PIPE_A), |
| 4490 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4491 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4492 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4493 | }, |
| 4494 | { |
| 4495 | .active_pipes = BIT(PIPE_B), |
| 4496 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4497 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4498 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4499 | }, |
| 4500 | { |
| 4501 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4502 | .dbuf_mask = { |
| 4503 | [PIPE_A] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4504 | [PIPE_B] = BIT(DBUF_S1), |
| 4505 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4506 | }, |
| 4507 | { |
| 4508 | .active_pipes = BIT(PIPE_C), |
| 4509 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4510 | [PIPE_C] = BIT(DBUF_S2) | BIT(DBUF_S1), |
| 4511 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4512 | }, |
| 4513 | { |
| 4514 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4515 | .dbuf_mask = { |
| 4516 | [PIPE_A] = 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_B) | BIT(PIPE_C), |
| 4522 | .dbuf_mask = { |
| 4523 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4524 | [PIPE_C] = BIT(DBUF_S2), |
| 4525 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4526 | }, |
| 4527 | { |
| 4528 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4529 | .dbuf_mask = { |
| 4530 | [PIPE_A] = BIT(DBUF_S1), |
| 4531 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4532 | [PIPE_C] = BIT(DBUF_S2), |
| 4533 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4534 | }, |
| 4535 | { |
| 4536 | .active_pipes = BIT(PIPE_D), |
| 4537 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4538 | [PIPE_D] = BIT(DBUF_S2) | BIT(DBUF_S1), |
| 4539 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4540 | }, |
| 4541 | { |
| 4542 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4543 | .dbuf_mask = { |
| 4544 | [PIPE_A] = 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_B) | BIT(PIPE_D), |
| 4550 | .dbuf_mask = { |
| 4551 | [PIPE_B] = 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_B) | BIT(PIPE_D), |
| 4557 | .dbuf_mask = { |
| 4558 | [PIPE_A] = BIT(DBUF_S1), |
| 4559 | [PIPE_B] = BIT(DBUF_S1), |
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_C) | BIT(PIPE_D), |
| 4565 | .dbuf_mask = { |
| 4566 | [PIPE_C] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4567 | [PIPE_D] = BIT(DBUF_S2), |
| 4568 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4569 | }, |
| 4570 | { |
| 4571 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4572 | .dbuf_mask = { |
| 4573 | [PIPE_A] = BIT(DBUF_S1), |
| 4574 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4575 | [PIPE_D] = BIT(DBUF_S2), |
| 4576 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4577 | }, |
| 4578 | { |
| 4579 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4580 | .dbuf_mask = { |
| 4581 | [PIPE_B] = BIT(DBUF_S1), |
| 4582 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4583 | [PIPE_D] = BIT(DBUF_S2), |
| 4584 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4585 | }, |
| 4586 | { |
| 4587 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4588 | .dbuf_mask = { |
| 4589 | [PIPE_A] = BIT(DBUF_S1), |
| 4590 | [PIPE_B] = BIT(DBUF_S1), |
| 4591 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4592 | [PIPE_D] = BIT(DBUF_S2), |
| 4593 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4594 | }, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4595 | {} |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4596 | }; |
| 4597 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4598 | static const struct dbuf_slice_conf_entry dg2_allowed_dbufs[] = { |
| 4599 | { |
| 4600 | .active_pipes = BIT(PIPE_A), |
| 4601 | .dbuf_mask = { |
| 4602 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4603 | }, |
| 4604 | }, |
| 4605 | { |
| 4606 | .active_pipes = BIT(PIPE_B), |
| 4607 | .dbuf_mask = { |
| 4608 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4609 | }, |
| 4610 | }, |
| 4611 | { |
| 4612 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4613 | .dbuf_mask = { |
| 4614 | [PIPE_A] = BIT(DBUF_S1), |
| 4615 | [PIPE_B] = BIT(DBUF_S2), |
| 4616 | }, |
| 4617 | }, |
| 4618 | { |
| 4619 | .active_pipes = BIT(PIPE_C), |
| 4620 | .dbuf_mask = { |
| 4621 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4622 | }, |
| 4623 | }, |
| 4624 | { |
| 4625 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4626 | .dbuf_mask = { |
| 4627 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4628 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4629 | }, |
| 4630 | }, |
| 4631 | { |
| 4632 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4633 | .dbuf_mask = { |
| 4634 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4635 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4636 | }, |
| 4637 | }, |
| 4638 | { |
| 4639 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4640 | .dbuf_mask = { |
| 4641 | [PIPE_A] = BIT(DBUF_S1), |
| 4642 | [PIPE_B] = BIT(DBUF_S2), |
| 4643 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4644 | }, |
| 4645 | }, |
| 4646 | { |
| 4647 | .active_pipes = BIT(PIPE_D), |
| 4648 | .dbuf_mask = { |
| 4649 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4650 | }, |
| 4651 | }, |
| 4652 | { |
| 4653 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4654 | .dbuf_mask = { |
| 4655 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4656 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4657 | }, |
| 4658 | }, |
| 4659 | { |
| 4660 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4661 | .dbuf_mask = { |
| 4662 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4663 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4664 | }, |
| 4665 | }, |
| 4666 | { |
| 4667 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D), |
| 4668 | .dbuf_mask = { |
| 4669 | [PIPE_A] = BIT(DBUF_S1), |
| 4670 | [PIPE_B] = BIT(DBUF_S2), |
| 4671 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4672 | }, |
| 4673 | }, |
| 4674 | { |
| 4675 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4676 | .dbuf_mask = { |
| 4677 | [PIPE_C] = BIT(DBUF_S3), |
| 4678 | [PIPE_D] = BIT(DBUF_S4), |
| 4679 | }, |
| 4680 | }, |
| 4681 | { |
| 4682 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4683 | .dbuf_mask = { |
| 4684 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4685 | [PIPE_C] = BIT(DBUF_S3), |
| 4686 | [PIPE_D] = BIT(DBUF_S4), |
| 4687 | }, |
| 4688 | }, |
| 4689 | { |
| 4690 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4691 | .dbuf_mask = { |
| 4692 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4693 | [PIPE_C] = BIT(DBUF_S3), |
| 4694 | [PIPE_D] = BIT(DBUF_S4), |
| 4695 | }, |
| 4696 | }, |
| 4697 | { |
| 4698 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4699 | .dbuf_mask = { |
| 4700 | [PIPE_A] = BIT(DBUF_S1), |
| 4701 | [PIPE_B] = BIT(DBUF_S2), |
| 4702 | [PIPE_C] = BIT(DBUF_S3), |
| 4703 | [PIPE_D] = BIT(DBUF_S4), |
| 4704 | }, |
| 4705 | }, |
| 4706 | {} |
| 4707 | }; |
| 4708 | |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4709 | static const struct dbuf_slice_conf_entry adlp_allowed_dbufs[] = { |
| 4710 | { |
| 4711 | .active_pipes = BIT(PIPE_A), |
| 4712 | .dbuf_mask = { |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4713 | [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] | 4714 | }, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4715 | .join_mbus = true, |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4716 | }, |
| 4717 | { |
| 4718 | .active_pipes = BIT(PIPE_B), |
| 4719 | .dbuf_mask = { |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4720 | [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] | 4721 | }, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4722 | .join_mbus = true, |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4723 | }, |
| 4724 | { |
| 4725 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4726 | .dbuf_mask = { |
| 4727 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4728 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4729 | }, |
| 4730 | }, |
| 4731 | { |
| 4732 | .active_pipes = BIT(PIPE_C), |
| 4733 | .dbuf_mask = { |
| 4734 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4735 | }, |
| 4736 | }, |
| 4737 | { |
| 4738 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4739 | .dbuf_mask = { |
| 4740 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4741 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4742 | }, |
| 4743 | }, |
| 4744 | { |
| 4745 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4746 | .dbuf_mask = { |
| 4747 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4748 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4749 | }, |
| 4750 | }, |
| 4751 | { |
| 4752 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4753 | .dbuf_mask = { |
| 4754 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4755 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4756 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4757 | }, |
| 4758 | }, |
| 4759 | { |
| 4760 | .active_pipes = BIT(PIPE_D), |
| 4761 | .dbuf_mask = { |
| 4762 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4763 | }, |
| 4764 | }, |
| 4765 | { |
| 4766 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4767 | .dbuf_mask = { |
| 4768 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4769 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4770 | }, |
| 4771 | }, |
| 4772 | { |
| 4773 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4774 | .dbuf_mask = { |
| 4775 | [PIPE_B] = 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_B) | BIT(PIPE_D), |
| 4781 | .dbuf_mask = { |
| 4782 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4783 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4784 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4785 | }, |
| 4786 | }, |
| 4787 | { |
| 4788 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4789 | .dbuf_mask = { |
| 4790 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4791 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4792 | }, |
| 4793 | }, |
| 4794 | { |
| 4795 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4796 | .dbuf_mask = { |
| 4797 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4798 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4799 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4800 | }, |
| 4801 | }, |
| 4802 | { |
| 4803 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4804 | .dbuf_mask = { |
| 4805 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4806 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4807 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4808 | }, |
| 4809 | }, |
| 4810 | { |
| 4811 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4812 | .dbuf_mask = { |
| 4813 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4814 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4815 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4816 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4817 | }, |
| 4818 | }, |
| 4819 | {} |
| 4820 | |
| 4821 | }; |
| 4822 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4823 | static bool check_mbus_joined(u8 active_pipes, |
| 4824 | const struct dbuf_slice_conf_entry *dbuf_slices) |
| 4825 | { |
| 4826 | int i; |
| 4827 | |
| 4828 | for (i = 0; i < dbuf_slices[i].active_pipes; i++) { |
| 4829 | if (dbuf_slices[i].active_pipes == active_pipes) |
| 4830 | return dbuf_slices[i].join_mbus; |
| 4831 | } |
| 4832 | return false; |
| 4833 | } |
| 4834 | |
| 4835 | static bool adlp_check_mbus_joined(u8 active_pipes) |
| 4836 | { |
| 4837 | return check_mbus_joined(active_pipes, adlp_allowed_dbufs); |
| 4838 | } |
| 4839 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4840 | static u8 compute_dbuf_slices(enum pipe pipe, u8 active_pipes, |
| 4841 | const struct dbuf_slice_conf_entry *dbuf_slices) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4842 | { |
| 4843 | int i; |
| 4844 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4845 | for (i = 0; i < dbuf_slices[i].active_pipes; i++) { |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4846 | if (dbuf_slices[i].active_pipes == active_pipes) |
| 4847 | return dbuf_slices[i].dbuf_mask[pipe]; |
| 4848 | } |
| 4849 | return 0; |
| 4850 | } |
| 4851 | |
| 4852 | /* |
| 4853 | * This function finds an entry with same enabled pipe configuration and |
| 4854 | * returns correspondent DBuf slice mask as stated in BSpec for particular |
| 4855 | * platform. |
| 4856 | */ |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4857 | static u8 icl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4858 | { |
| 4859 | /* |
| 4860 | * FIXME: For ICL this is still a bit unclear as prev BSpec revision |
| 4861 | * required calculating "pipe ratio" in order to determine |
| 4862 | * if one or two slices can be used for single pipe configurations |
| 4863 | * as additional constraint to the existing table. |
| 4864 | * However based on recent info, it should be not "pipe ratio" |
| 4865 | * but rather ratio between pixel_rate and cdclk with additional |
| 4866 | * constants, so for now we are using only table until this is |
| 4867 | * clarified. Also this is the reason why crtc_state param is |
| 4868 | * still here - we will need it once those additional constraints |
| 4869 | * pop up. |
| 4870 | */ |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4871 | return compute_dbuf_slices(pipe, active_pipes, icl_allowed_dbufs); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4872 | } |
| 4873 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4874 | static u8 tgl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4875 | { |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4876 | return compute_dbuf_slices(pipe, active_pipes, tgl_allowed_dbufs); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4877 | } |
| 4878 | |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4879 | static u32 adlp_compute_dbuf_slices(enum pipe pipe, u32 active_pipes) |
| 4880 | { |
| 4881 | return compute_dbuf_slices(pipe, active_pipes, adlp_allowed_dbufs); |
| 4882 | } |
| 4883 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4884 | static u32 dg2_compute_dbuf_slices(enum pipe pipe, u32 active_pipes) |
| 4885 | { |
| 4886 | return compute_dbuf_slices(pipe, active_pipes, dg2_allowed_dbufs); |
| 4887 | } |
| 4888 | |
Ville Syrjälä | 2d42f32 | 2021-01-22 22:56:27 +0200 | [diff] [blame] | 4889 | 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] | 4890 | { |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4891 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4892 | enum pipe pipe = crtc->pipe; |
| 4893 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4894 | if (IS_DG2(dev_priv)) |
| 4895 | return dg2_compute_dbuf_slices(pipe, active_pipes); |
| 4896 | else if (IS_ALDERLAKE_P(dev_priv)) |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4897 | return adlp_compute_dbuf_slices(pipe, active_pipes); |
| 4898 | else if (DISPLAY_VER(dev_priv) == 12) |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4899 | return tgl_compute_dbuf_slices(pipe, active_pipes); |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 4900 | else if (DISPLAY_VER(dev_priv) == 11) |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4901 | return icl_compute_dbuf_slices(pipe, active_pipes); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4902 | /* |
| 4903 | * For anything else just return one slice yet. |
| 4904 | * Should be extended for other platforms. |
| 4905 | */ |
Ville Syrjälä | 2f9078c | 2020-02-25 19:11:10 +0200 | [diff] [blame] | 4906 | return active_pipes & BIT(pipe) ? BIT(DBUF_S1) : 0; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4907 | } |
| 4908 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4909 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4910 | skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state, |
| 4911 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4912 | int color_plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4913 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4914 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 4915 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4916 | u32 data_rate; |
| 4917 | u32 width = 0, height = 0; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4918 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4919 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4920 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4921 | if (!plane_state->uapi.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4922 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4923 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4924 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4925 | return 0; |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4926 | |
| 4927 | if (color_plane == 1 && |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 4928 | !intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4929 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4930 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4931 | /* |
| 4932 | * Src coordinates are already rotated by 270 degrees for |
| 4933 | * the 90/270 degree plane rotation cases (to match the |
| 4934 | * GTT mapping), hence no need to account for rotation here. |
| 4935 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4936 | width = drm_rect_width(&plane_state->uapi.src) >> 16; |
| 4937 | height = drm_rect_height(&plane_state->uapi.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4938 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4939 | /* UV plane does 1/2 pixel sub-sampling */ |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4940 | if (color_plane == 1) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4941 | width /= 2; |
| 4942 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4943 | } |
| 4944 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4945 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4946 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4947 | down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4948 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4949 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4950 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4951 | rate *= fb->format->cpp[color_plane]; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4952 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4955 | static u64 |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4956 | skl_get_total_relative_data_rate(struct intel_atomic_state *state, |
| 4957 | struct intel_crtc *crtc) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4958 | { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4959 | struct intel_crtc_state *crtc_state = |
| 4960 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4961 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4962 | struct intel_plane *plane; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4963 | u64 total_data_rate = 0; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4964 | enum plane_id plane_id; |
| 4965 | int i; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4966 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4967 | /* Calculate and cache data rate for each plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4968 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 4969 | if (plane->pipe != crtc->pipe) |
| 4970 | continue; |
| 4971 | |
| 4972 | plane_id = plane->id; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4973 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4974 | /* packed/y */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4975 | crtc_state->plane_data_rate[plane_id] = |
| 4976 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4977 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4978 | /* uv-plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4979 | crtc_state->uv_plane_data_rate[plane_id] = |
| 4980 | skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
| 4981 | } |
| 4982 | |
| 4983 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 4984 | total_data_rate += crtc_state->plane_data_rate[plane_id]; |
| 4985 | total_data_rate += crtc_state->uv_plane_data_rate[plane_id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | return total_data_rate; |
| 4989 | } |
| 4990 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4991 | static u64 |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4992 | icl_get_total_relative_data_rate(struct intel_atomic_state *state, |
| 4993 | struct intel_crtc *crtc) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4994 | { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4995 | struct intel_crtc_state *crtc_state = |
| 4996 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4997 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4998 | struct intel_plane *plane; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 4999 | u64 total_data_rate = 0; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5000 | enum plane_id plane_id; |
| 5001 | int i; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5002 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5003 | /* Calculate and cache data rate for each plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5004 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 5005 | if (plane->pipe != crtc->pipe) |
| 5006 | continue; |
| 5007 | |
| 5008 | plane_id = plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5009 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5010 | if (!plane_state->planar_linked_plane) { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5011 | crtc_state->plane_data_rate[plane_id] = |
| 5012 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5013 | } else { |
| 5014 | enum plane_id y_plane_id; |
| 5015 | |
| 5016 | /* |
| 5017 | * The slave plane might not iterate in |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5018 | * intel_atomic_crtc_state_for_each_plane_state(), |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5019 | * and needs the master plane state which may be |
| 5020 | * NULL if we try get_new_plane_state(), so we |
| 5021 | * always calculate from the master. |
| 5022 | */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5023 | if (plane_state->planar_slave) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5024 | continue; |
| 5025 | |
| 5026 | /* Y plane rate is calculated on the slave */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5027 | y_plane_id = plane_state->planar_linked_plane->id; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5028 | crtc_state->plane_data_rate[y_plane_id] = |
| 5029 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5030 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5031 | crtc_state->plane_data_rate[plane_id] = |
| 5032 | skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5033 | } |
| 5034 | } |
| 5035 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5036 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5037 | total_data_rate += crtc_state->plane_data_rate[plane_id]; |
| 5038 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5039 | return total_data_rate; |
| 5040 | } |
| 5041 | |
Ville Syrjälä | 5516e89 | 2021-02-26 17:32:03 +0200 | [diff] [blame] | 5042 | const struct skl_wm_level * |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5043 | skl_plane_wm_level(const struct skl_pipe_wm *pipe_wm, |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5044 | enum plane_id plane_id, |
| 5045 | int level) |
| 5046 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5047 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5048 | |
| 5049 | if (level == 0 && pipe_wm->use_sagv_wm) |
Ville Syrjälä | a68aa48 | 2021-02-26 17:32:01 +0200 | [diff] [blame] | 5050 | return &wm->sagv.wm0; |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5051 | |
| 5052 | return &wm->wm[level]; |
| 5053 | } |
| 5054 | |
Ville Syrjälä | 5516e89 | 2021-02-26 17:32:03 +0200 | [diff] [blame] | 5055 | const struct skl_wm_level * |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5056 | skl_plane_trans_wm(const struct skl_pipe_wm *pipe_wm, |
| 5057 | enum plane_id plane_id) |
| 5058 | { |
| 5059 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5060 | |
| 5061 | if (pipe_wm->use_sagv_wm) |
| 5062 | return &wm->sagv.trans_wm; |
| 5063 | |
| 5064 | return &wm->trans_wm; |
| 5065 | } |
| 5066 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5067 | /* |
| 5068 | * We only disable the watermarks for each plane if |
| 5069 | * they exceed the ddb allocation of said plane. This |
| 5070 | * is done so that we don't end up touching cursor |
| 5071 | * watermarks needlessly when some other plane reduces |
| 5072 | * our max possible watermark level. |
| 5073 | * |
| 5074 | * Bspec has this to say about the PLANE_WM enable bit: |
| 5075 | * "All the watermarks at this level for all enabled |
| 5076 | * planes must be enabled before the level will be used." |
| 5077 | * So this is actually safe to do. |
| 5078 | */ |
| 5079 | static void |
| 5080 | skl_check_wm_level(struct skl_wm_level *wm, u64 total) |
| 5081 | { |
| 5082 | if (wm->min_ddb_alloc > total) |
| 5083 | memset(wm, 0, sizeof(*wm)); |
| 5084 | } |
| 5085 | |
| 5086 | static void |
| 5087 | skl_check_nv12_wm_level(struct skl_wm_level *wm, struct skl_wm_level *uv_wm, |
| 5088 | u64 total, u64 uv_total) |
| 5089 | { |
| 5090 | if (wm->min_ddb_alloc > total || |
| 5091 | uv_wm->min_ddb_alloc > uv_total) { |
| 5092 | memset(wm, 0, sizeof(*wm)); |
| 5093 | memset(uv_wm, 0, sizeof(*uv_wm)); |
| 5094 | } |
| 5095 | } |
| 5096 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5097 | static int |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5098 | skl_allocate_plane_ddb(struct intel_atomic_state *state, |
| 5099 | struct intel_crtc *crtc) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5100 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5101 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5102 | struct intel_crtc_state *crtc_state = |
| 5103 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5104 | const struct intel_dbuf_state *dbuf_state = |
Ville Syrjälä | 47a1495 | 2021-01-22 22:56:30 +0200 | [diff] [blame] | 5105 | intel_atomic_get_new_dbuf_state(state); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5106 | const struct skl_ddb_entry *alloc = &dbuf_state->ddb[crtc->pipe]; |
| 5107 | int num_active = hweight8(dbuf_state->active_pipes); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5108 | u16 alloc_size, start = 0; |
| 5109 | u16 total[I915_MAX_PLANES] = {}; |
| 5110 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 5111 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5112 | enum plane_id plane_id; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5113 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5114 | int level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5115 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 5116 | /* Clear the partitioning for disabled planes. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5117 | memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y)); |
| 5118 | 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] | 5119 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5120 | if (!crtc_state->hw.active) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5121 | return 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5122 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5123 | if (DISPLAY_VER(dev_priv) >= 11) |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5124 | total_data_rate = |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5125 | icl_get_total_relative_data_rate(state, crtc); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5126 | else |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5127 | total_data_rate = |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5128 | skl_get_total_relative_data_rate(state, crtc); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5129 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 5130 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 5131 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5132 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5133 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5134 | /* Allocate fixed number of blocks for cursor. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5135 | total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5136 | alloc_size -= total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5137 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5138 | alloc->end - total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5139 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 5140 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5141 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5142 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5143 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5144 | /* |
| 5145 | * Find the highest watermark level for which we can satisfy the block |
| 5146 | * requirement of active planes. |
| 5147 | */ |
| 5148 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 5149 | blocks = 0; |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5150 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5151 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5152 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 5153 | |
| 5154 | if (plane_id == PLANE_CURSOR) { |
Vandita Kulkarni | 4ba4870 | 2019-12-16 13:36:19 +0530 | [diff] [blame] | 5155 | if (wm->wm[level].min_ddb_alloc > total[PLANE_CURSOR]) { |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5156 | drm_WARN_ON(&dev_priv->drm, |
| 5157 | wm->wm[level].min_ddb_alloc != U16_MAX); |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 5158 | blocks = U32_MAX; |
| 5159 | break; |
| 5160 | } |
| 5161 | continue; |
| 5162 | } |
| 5163 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5164 | blocks += wm->wm[level].min_ddb_alloc; |
| 5165 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5166 | } |
| 5167 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame] | 5168 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5169 | alloc_size -= blocks; |
| 5170 | break; |
| 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | if (level < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5175 | drm_dbg_kms(&dev_priv->drm, |
| 5176 | "Requested display configuration exceeds system DDB limitations"); |
| 5177 | drm_dbg_kms(&dev_priv->drm, "minimum required %d/%d\n", |
| 5178 | blocks, alloc_size); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5179 | return -EINVAL; |
| 5180 | } |
| 5181 | |
| 5182 | /* |
| 5183 | * Grant each plane the blocks it requires at the highest achievable |
| 5184 | * watermark level, plus an extra share of the leftover blocks |
| 5185 | * proportional to its relative data rate. |
| 5186 | */ |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5187 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5188 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5189 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5190 | u64 rate; |
| 5191 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5192 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5193 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 5194 | continue; |
| 5195 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5196 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5197 | * We've accounted for all active planes; remaining planes are |
| 5198 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5199 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5200 | if (total_data_rate == 0) |
| 5201 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5202 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5203 | rate = crtc_state->plane_data_rate[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5204 | extra = min_t(u16, alloc_size, |
| 5205 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 5206 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5207 | total[plane_id] = wm->wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5208 | alloc_size -= extra; |
| 5209 | total_data_rate -= rate; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5210 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5211 | if (total_data_rate == 0) |
| 5212 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 5213 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5214 | rate = crtc_state->uv_plane_data_rate[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5215 | extra = min_t(u16, alloc_size, |
| 5216 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 5217 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5218 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5219 | alloc_size -= extra; |
| 5220 | total_data_rate -= rate; |
| 5221 | } |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5222 | 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] | 5223 | |
| 5224 | /* Set the actual DDB start/end points for each plane */ |
| 5225 | start = alloc->start; |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5226 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5227 | struct skl_ddb_entry *plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5228 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5229 | struct skl_ddb_entry *uv_plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5230 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5231 | |
| 5232 | if (plane_id == PLANE_CURSOR) |
| 5233 | continue; |
| 5234 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5235 | /* Gen11+ uses a separate plane for UV watermarks */ |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5236 | drm_WARN_ON(&dev_priv->drm, |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5237 | DISPLAY_VER(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5238 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5239 | /* Leave disabled planes at (0,0) */ |
| 5240 | if (total[plane_id]) { |
| 5241 | plane_alloc->start = start; |
| 5242 | start += total[plane_id]; |
| 5243 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5244 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5245 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5246 | if (uv_total[plane_id]) { |
| 5247 | uv_plane_alloc->start = start; |
| 5248 | start += uv_total[plane_id]; |
| 5249 | uv_plane_alloc->end = start; |
| 5250 | } |
| 5251 | } |
| 5252 | |
| 5253 | /* |
| 5254 | * When we calculated watermark values we didn't know how high |
| 5255 | * of a level we'd actually be able to hit, so we just marked |
| 5256 | * all levels as "enabled." Go back now and disable the ones |
| 5257 | * that aren't actually possible. |
| 5258 | */ |
| 5259 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5260 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5261 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5262 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | a301cb0 | 2019-03-12 22:58:41 +0200 | [diff] [blame] | 5263 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5264 | skl_check_nv12_wm_level(&wm->wm[level], &wm->uv_wm[level], |
| 5265 | total[plane_id], uv_total[plane_id]); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5266 | |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5267 | /* |
Bob Paauwe | 39564ae | 2019-04-12 11:09:20 -0700 | [diff] [blame] | 5268 | * Wa_1408961008:icl, ehl |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5269 | * Underruns with WM1+ disabled |
| 5270 | */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5271 | if (DISPLAY_VER(dev_priv) == 11 && |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5272 | level == 1 && wm->wm[0].enable) { |
| 5273 | wm->wm[level].blocks = wm->wm[0].blocks; |
| 5274 | wm->wm[level].lines = wm->wm[0].lines; |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5275 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5276 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | /* |
Ville Syrjälä | df4a50a | 2021-02-26 17:31:59 +0200 | [diff] [blame] | 5281 | * Go back and disable the transition and SAGV watermarks |
| 5282 | * 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] | 5283 | */ |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5284 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5285 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5286 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5287 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5288 | skl_check_wm_level(&wm->trans_wm, total[plane_id]); |
| 5289 | skl_check_wm_level(&wm->sagv.wm0, total[plane_id]); |
| 5290 | skl_check_wm_level(&wm->sagv.trans_wm, total[plane_id]); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5291 | } |
| 5292 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5293 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5296 | /* |
| 5297 | * 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] | 5298 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5299 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 5300 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 5301 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5302 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5303 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 5304 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5305 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5306 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5307 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5308 | |
| 5309 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5310 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5311 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5312 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5313 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5314 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5315 | if (DISPLAY_VER(dev_priv) >= 10) |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5316 | ret = add_fixed16_u32(ret, 1); |
| 5317 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5318 | return ret; |
| 5319 | } |
| 5320 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5321 | static uint_fixed_16_16_t |
| 5322 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 5323 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5324 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5325 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5326 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5327 | |
| 5328 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5329 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5330 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5331 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5332 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 5333 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5334 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5335 | return ret; |
| 5336 | } |
| 5337 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5338 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5339 | intel_get_linetime_us(const struct intel_crtc_state *crtc_state) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5340 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5341 | 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] | 5342 | u32 pixel_rate; |
| 5343 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5344 | uint_fixed_16_16_t linetime_us; |
| 5345 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 5346 | if (!crtc_state->hw.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5347 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5348 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5349 | pixel_rate = crtc_state->pixel_rate; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5350 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5351 | if (drm_WARN_ON(&dev_priv->drm, pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5352 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5353 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5354 | crtc_htotal = crtc_state->hw.pipe_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5355 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5356 | |
| 5357 | return linetime_us; |
| 5358 | } |
| 5359 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5360 | static int |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5361 | skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 5362 | int width, const struct drm_format_info *format, |
| 5363 | u64 modifier, unsigned int rotation, |
| 5364 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 5365 | int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5366 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5367 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5368 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5369 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5370 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 5371 | /* only planar format has two planes */ |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 5372 | if (color_plane == 1 && |
| 5373 | !intel_format_info_is_yuv_semiplanar(format, modifier)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5374 | drm_dbg_kms(&dev_priv->drm, |
| 5375 | "Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5376 | return -EINVAL; |
| 5377 | } |
| 5378 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5379 | wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED || |
| 5380 | modifier == I915_FORMAT_MOD_Yf_TILED || |
| 5381 | modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 5382 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 5383 | wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED; |
| 5384 | wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 5385 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 5386 | wp->is_planar = intel_format_info_is_yuv_semiplanar(format, modifier); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5387 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5388 | wp->width = width; |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 5389 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5390 | wp->width /= 2; |
| 5391 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5392 | wp->cpp = format->cpp[color_plane]; |
| 5393 | wp->plane_pixel_rate = plane_pixel_rate; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5394 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5395 | if (DISPLAY_VER(dev_priv) >= 11 && |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5396 | modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5397 | wp->dbuf_block_size = 256; |
| 5398 | else |
| 5399 | wp->dbuf_block_size = 512; |
| 5400 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5401 | if (drm_rotation_90_or_270(rotation)) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5402 | switch (wp->cpp) { |
| 5403 | case 1: |
| 5404 | wp->y_min_scanlines = 16; |
| 5405 | break; |
| 5406 | case 2: |
| 5407 | wp->y_min_scanlines = 8; |
| 5408 | break; |
| 5409 | case 4: |
| 5410 | wp->y_min_scanlines = 4; |
| 5411 | break; |
| 5412 | default: |
| 5413 | MISSING_CASE(wp->cpp); |
| 5414 | return -EINVAL; |
| 5415 | } |
| 5416 | } else { |
| 5417 | wp->y_min_scanlines = 4; |
| 5418 | } |
| 5419 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 5420 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5421 | wp->y_min_scanlines *= 2; |
| 5422 | |
| 5423 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 5424 | if (wp->y_tiled) { |
| 5425 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5426 | wp->y_min_scanlines, |
| 5427 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5428 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5429 | if (DISPLAY_VER(dev_priv) >= 10) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5430 | interm_pbpl++; |
| 5431 | |
| 5432 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 5433 | wp->y_min_scanlines); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5434 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5435 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5436 | wp->dbuf_block_size); |
| 5437 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5438 | if (!wp->x_tiled || DISPLAY_VER(dev_priv) >= 10) |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5439 | interm_pbpl++; |
| 5440 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5441 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 5442 | } |
| 5443 | |
| 5444 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 5445 | wp->plane_blocks_per_line); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5446 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5447 | wp->linetime_us = fixed16_to_u32_round_up( |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5448 | intel_get_linetime_us(crtc_state)); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5449 | |
| 5450 | return 0; |
| 5451 | } |
| 5452 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5453 | static int |
| 5454 | skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state, |
| 5455 | const struct intel_plane_state *plane_state, |
| 5456 | struct skl_wm_params *wp, int color_plane) |
| 5457 | { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5458 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5459 | int width; |
| 5460 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 5461 | /* |
| 5462 | * Src coordinates are already rotated by 270 degrees for |
| 5463 | * the 90/270 degree plane rotation cases (to match the |
| 5464 | * GTT mapping), hence no need to account for rotation here. |
| 5465 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 5466 | width = drm_rect_width(&plane_state->uapi.src) >> 16; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5467 | |
| 5468 | return skl_compute_wm_params(crtc_state, width, |
| 5469 | fb->format, fb->modifier, |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5470 | plane_state->hw.rotation, |
Ville Syrjälä | 3df3fe2 | 2020-11-06 19:30:42 +0200 | [diff] [blame] | 5471 | intel_plane_pixel_rate(crtc_state, plane_state), |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5472 | wp, color_plane); |
| 5473 | } |
| 5474 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5475 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 5476 | { |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5477 | if (DISPLAY_VER(dev_priv) >= 10) |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5478 | return true; |
| 5479 | |
| 5480 | /* The number of lines are ignored for the level 0 watermark. */ |
| 5481 | return level > 0; |
| 5482 | } |
| 5483 | |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5484 | static int skl_wm_max_lines(struct drm_i915_private *dev_priv) |
| 5485 | { |
| 5486 | if (DISPLAY_VER(dev_priv) >= 13) |
| 5487 | return 255; |
| 5488 | else |
| 5489 | return 31; |
| 5490 | } |
| 5491 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5492 | 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] | 5493 | int level, |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5494 | unsigned int latency, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5495 | const struct skl_wm_params *wp, |
| 5496 | const struct skl_wm_level *result_prev, |
| 5497 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5498 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5499 | 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] | 5500 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5501 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5502 | u32 blocks, lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 5503 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5504 | if (latency == 0) { |
| 5505 | /* reject it */ |
| 5506 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 5507 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5508 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 5509 | |
Ville Syrjälä | 25312ef | 2019-05-03 20:38:05 +0300 | [diff] [blame] | 5510 | /* |
| 5511 | * WaIncreaseLatencyIPCEnabled: kbl,cfl |
| 5512 | * Display WA #1141: kbl,cfl |
| 5513 | */ |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 5514 | if ((IS_KABYLAKE(dev_priv) || |
| 5515 | IS_COFFEELAKE(dev_priv) || |
| 5516 | IS_COMETLAKE(dev_priv)) && |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 5517 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 5518 | latency += 4; |
| 5519 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 5520 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 5521 | latency += 15; |
| 5522 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5523 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5524 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5525 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5526 | crtc_state->hw.pipe_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 5527 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5528 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5529 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5530 | if (wp->y_tiled) { |
| 5531 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5532 | } else { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5533 | if ((wp->cpp * crtc_state->hw.pipe_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5534 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5535 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 5536 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5537 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5538 | if (DISPLAY_VER(dev_priv) == 9) |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5539 | selected_result = min_fixed16(method1, method2); |
| 5540 | else |
| 5541 | selected_result = method2; |
| 5542 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5543 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5544 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5545 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5546 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5547 | blocks = fixed16_to_u32_round_up(selected_result) + 1; |
| 5548 | lines = div_round_up_fixed16(selected_result, |
| 5549 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 5550 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5551 | if (DISPLAY_VER(dev_priv) == 9) { |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5552 | /* Display WA #1125: skl,bxt,kbl */ |
| 5553 | if (level == 0 && wp->rc_surface) |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5554 | blocks += fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 5555 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5556 | /* Display WA #1126: skl,bxt,kbl */ |
| 5557 | if (level >= 1 && level <= 7) { |
| 5558 | if (wp->y_tiled) { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5559 | blocks += fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 5560 | lines += wp->y_min_scanlines; |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5561 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5562 | blocks++; |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | /* |
| 5566 | * Make sure result blocks for higher latency levels are |
| 5567 | * atleast as high as level below the current level. |
| 5568 | * Assumption in DDB algorithm optimization for special |
| 5569 | * cases. Also covers Display WA #1125 for RC. |
| 5570 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5571 | if (result_prev->blocks > blocks) |
| 5572 | blocks = result_prev->blocks; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 5573 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5574 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 5575 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5576 | if (DISPLAY_VER(dev_priv) >= 11) { |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5577 | if (wp->y_tiled) { |
| 5578 | int extra_lines; |
| 5579 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5580 | if (lines % wp->y_min_scanlines == 0) |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5581 | extra_lines = wp->y_min_scanlines; |
| 5582 | else |
| 5583 | extra_lines = wp->y_min_scanlines * 2 - |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5584 | lines % wp->y_min_scanlines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5585 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5586 | min_ddb_alloc = mul_round_up_u32_fixed16(lines + extra_lines, |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5587 | wp->plane_blocks_per_line); |
| 5588 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5589 | min_ddb_alloc = blocks + DIV_ROUND_UP(blocks, 10); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5590 | } |
| 5591 | } |
| 5592 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5593 | if (!skl_wm_has_lines(dev_priv, level)) |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5594 | lines = 0; |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5595 | |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5596 | if (lines > skl_wm_max_lines(dev_priv)) { |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5597 | /* reject it */ |
| 5598 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5599 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5600 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5601 | |
| 5602 | /* |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5603 | * If lines is valid, assume we can use this watermark level |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5604 | * for now. We'll come back and disable it after we calculate the |
| 5605 | * DDB allocation if it turns out we don't actually have enough |
| 5606 | * blocks to satisfy it. |
| 5607 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5608 | result->blocks = blocks; |
| 5609 | result->lines = lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5610 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5611 | result->min_ddb_alloc = max(min_ddb_alloc, blocks) + 1; |
| 5612 | result->enable = true; |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 5613 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5614 | if (DISPLAY_VER(dev_priv) < 12) |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 5615 | result->can_sagv = latency >= dev_priv->sagv_block_time_us; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5616 | } |
| 5617 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5618 | static void |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5619 | skl_compute_wm_levels(const struct intel_crtc_state *crtc_state, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5620 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5621 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5622 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5623 | 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] | 5624 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5625 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 5626 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5627 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5628 | struct skl_wm_level *result = &levels[level]; |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5629 | unsigned int latency = dev_priv->wm.skl_latency[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5630 | |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5631 | skl_compute_plane_wm(crtc_state, level, latency, |
| 5632 | wm_params, result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5633 | |
| 5634 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5635 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5638 | static void tgl_compute_sagv_wm(const struct intel_crtc_state *crtc_state, |
| 5639 | const struct skl_wm_params *wm_params, |
| 5640 | struct skl_plane_wm *plane_wm) |
| 5641 | { |
| 5642 | 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] | 5643 | struct skl_wm_level *sagv_wm = &plane_wm->sagv.wm0; |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5644 | struct skl_wm_level *levels = plane_wm->wm; |
| 5645 | unsigned int latency = dev_priv->wm.skl_latency[0] + dev_priv->sagv_block_time_us; |
| 5646 | |
| 5647 | skl_compute_plane_wm(crtc_state, 0, latency, |
| 5648 | wm_params, &levels[0], |
| 5649 | sagv_wm); |
| 5650 | } |
| 5651 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5652 | static void skl_compute_transition_wm(struct drm_i915_private *dev_priv, |
| 5653 | struct skl_wm_level *trans_wm, |
| 5654 | const struct skl_wm_level *wm0, |
| 5655 | const struct skl_wm_params *wp) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 5656 | { |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5657 | u16 trans_min, trans_amount, trans_y_tile_min; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5658 | u16 wm0_blocks, trans_offset, blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 5659 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5660 | /* Transition WM don't make any sense if ipc is disabled */ |
| 5661 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 5662 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5663 | |
Ville Syrjälä | a7f1e8e | 2020-02-28 22:35:51 +0200 | [diff] [blame] | 5664 | /* |
| 5665 | * WaDisableTWM:skl,kbl,cfl,bxt |
| 5666 | * Transition WM are not recommended by HW team for GEN9 |
| 5667 | */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5668 | if (DISPLAY_VER(dev_priv) == 9) |
Ville Syrjälä | a7f1e8e | 2020-02-28 22:35:51 +0200 | [diff] [blame] | 5669 | return; |
| 5670 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5671 | if (DISPLAY_VER(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5672 | trans_min = 4; |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5673 | else |
| 5674 | trans_min = 14; |
| 5675 | |
| 5676 | /* Display WA #1140: glk,cnl */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5677 | if (DISPLAY_VER(dev_priv) == 10) |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5678 | trans_amount = 0; |
| 5679 | else |
| 5680 | trans_amount = 10; /* This is configurable amount */ |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5681 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5682 | trans_offset = trans_min + trans_amount; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5683 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5684 | /* |
| 5685 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 5686 | * not Result Blocks (the integer value). Pay attention to the capital |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5687 | * letters. The value wm_l0->blocks is actually Result Blocks, but |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5688 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 5689 | * and since we later will have to get the ceiling of the sum in the |
| 5690 | * transition watermarks calculation, we can just pretend Selected |
| 5691 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 5692 | * current platforms. |
| 5693 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5694 | wm0_blocks = wm0->blocks - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5695 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5696 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5697 | trans_y_tile_min = |
| 5698 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5699 | blocks = max(wm0_blocks, trans_y_tile_min) + trans_offset; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5700 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5701 | blocks = wm0_blocks + trans_offset; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5702 | } |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5703 | blocks++; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5704 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5705 | /* |
| 5706 | * Just assume we can enable the transition watermark. After |
| 5707 | * computing the DDB we'll come back and disable it if that |
| 5708 | * assumption turns out to be false. |
| 5709 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5710 | trans_wm->blocks = blocks; |
| 5711 | trans_wm->min_ddb_alloc = max_t(u16, wm0->min_ddb_alloc, blocks + 1); |
| 5712 | trans_wm->enable = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 5713 | } |
| 5714 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5715 | 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] | 5716 | const struct intel_plane_state *plane_state, |
| 5717 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5718 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5719 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 5720 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5721 | 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] | 5722 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5723 | int ret; |
| 5724 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5725 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5726 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5727 | if (ret) |
| 5728 | return ret; |
| 5729 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5730 | skl_compute_wm_levels(crtc_state, &wm_params, wm->wm); |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5731 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5732 | skl_compute_transition_wm(dev_priv, &wm->trans_wm, |
| 5733 | &wm->wm[0], &wm_params); |
| 5734 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5735 | if (DISPLAY_VER(dev_priv) >= 12) { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5736 | tgl_compute_sagv_wm(crtc_state, &wm_params, wm); |
| 5737 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5738 | skl_compute_transition_wm(dev_priv, &wm->sagv.trans_wm, |
| 5739 | &wm->sagv.wm0, &wm_params); |
| 5740 | } |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5741 | |
| 5742 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5743 | } |
| 5744 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5745 | 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] | 5746 | const struct intel_plane_state *plane_state, |
| 5747 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5748 | { |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5749 | 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] | 5750 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5751 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5752 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5753 | wm->is_planar = true; |
| 5754 | |
| 5755 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5756 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5757 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5758 | if (ret) |
| 5759 | return ret; |
| 5760 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5761 | skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5762 | |
| 5763 | return 0; |
| 5764 | } |
| 5765 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5766 | 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] | 5767 | const struct intel_plane_state *plane_state) |
| 5768 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 5769 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5770 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5771 | struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id]; |
| 5772 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5773 | int ret; |
| 5774 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5775 | memset(wm, 0, sizeof(*wm)); |
| 5776 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5777 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 5778 | return 0; |
| 5779 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5780 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5781 | plane_id, 0); |
| 5782 | if (ret) |
| 5783 | return ret; |
| 5784 | |
| 5785 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5786 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5787 | plane_id); |
| 5788 | if (ret) |
| 5789 | return ret; |
| 5790 | } |
| 5791 | |
| 5792 | return 0; |
| 5793 | } |
| 5794 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5795 | 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] | 5796 | const struct intel_plane_state *plane_state) |
| 5797 | { |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5798 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
| 5799 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 5800 | enum plane_id plane_id = plane->id; |
| 5801 | 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] | 5802 | int ret; |
| 5803 | |
| 5804 | /* Watermarks calculated in master */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5805 | if (plane_state->planar_slave) |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5806 | return 0; |
| 5807 | |
Ville Syrjälä | f99b805 | 2021-03-27 02:59:45 +0200 | [diff] [blame] | 5808 | memset(wm, 0, sizeof(*wm)); |
| 5809 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5810 | if (plane_state->planar_linked_plane) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5811 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5812 | 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] | 5813 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5814 | drm_WARN_ON(&dev_priv->drm, |
| 5815 | !intel_wm_plane_visible(crtc_state, plane_state)); |
| 5816 | drm_WARN_ON(&dev_priv->drm, !fb->format->is_yuv || |
| 5817 | fb->format->num_planes == 1); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5818 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5819 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5820 | y_plane_id, 0); |
| 5821 | if (ret) |
| 5822 | return ret; |
| 5823 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5824 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5825 | plane_id, 1); |
| 5826 | if (ret) |
| 5827 | return ret; |
| 5828 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5829 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5830 | plane_id, 0); |
| 5831 | if (ret) |
| 5832 | return ret; |
| 5833 | } |
| 5834 | |
| 5835 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5836 | } |
| 5837 | |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5838 | static int skl_build_pipe_wm(struct intel_atomic_state *state, |
| 5839 | struct intel_crtc *crtc) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5840 | { |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5841 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5842 | struct intel_crtc_state *crtc_state = |
| 5843 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5844 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5845 | struct intel_plane *plane; |
| 5846 | int ret, i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5847 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5848 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 5849 | /* |
| 5850 | * FIXME should perhaps check {old,new}_plane_crtc->hw.crtc |
| 5851 | * instead but we don't populate that correctly for NV12 Y |
| 5852 | * planes so for now hack this. |
| 5853 | */ |
| 5854 | if (plane->pipe != crtc->pipe) |
| 5855 | continue; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5856 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5857 | if (DISPLAY_VER(dev_priv) >= 11) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5858 | ret = icl_build_plane_wm(crtc_state, plane_state); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5859 | else |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5860 | ret = skl_build_plane_wm(crtc_state, plane_state); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5861 | if (ret) |
| 5862 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5863 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5864 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5865 | crtc_state->wm.skl.optimal = crtc_state->wm.skl.raw; |
| 5866 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5867 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5868 | } |
| 5869 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5870 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 5871 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5872 | const struct skl_ddb_entry *entry) |
| 5873 | { |
| 5874 | if (entry->end) |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5875 | intel_de_write_fw(dev_priv, reg, |
| 5876 | (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5877 | else |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5878 | intel_de_write_fw(dev_priv, reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5881 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5882 | i915_reg_t reg, |
| 5883 | const struct skl_wm_level *level) |
| 5884 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5885 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5886 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5887 | if (level->enable) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5888 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5889 | if (level->ignore_lines) |
| 5890 | val |= PLANE_WM_IGNORE_LINES; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5891 | val |= level->blocks; |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5892 | val |= REG_FIELD_PREP(PLANE_WM_LINES_MASK, level->lines); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5893 | |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5894 | intel_de_write_fw(dev_priv, reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5895 | } |
| 5896 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5897 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5898 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5899 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5900 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5901 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5902 | enum plane_id plane_id = plane->id; |
| 5903 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5904 | const struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
| 5905 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5906 | const struct skl_ddb_entry *ddb_y = |
| 5907 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5908 | const struct skl_ddb_entry *ddb_uv = |
| 5909 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5910 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5911 | for (level = 0; level <= max_level; level++) |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5912 | 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] | 5913 | skl_plane_wm_level(pipe_wm, plane_id, level)); |
| 5914 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5915 | 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] | 5916 | skl_plane_trans_wm(pipe_wm, plane_id)); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5917 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 5918 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 5919 | skl_write_wm_level(dev_priv, PLANE_WM_SAGV(pipe, plane_id), |
| 5920 | &wm->sagv.wm0); |
| 5921 | skl_write_wm_level(dev_priv, PLANE_WM_SAGV_TRANS(pipe, plane_id), |
| 5922 | &wm->sagv.trans_wm); |
| 5923 | } |
| 5924 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5925 | if (DISPLAY_VER(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5926 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5927 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5928 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5929 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5930 | |
| 5931 | if (wm->is_planar) |
| 5932 | swap(ddb_y, ddb_uv); |
| 5933 | |
| 5934 | skl_ddb_entry_write(dev_priv, |
| 5935 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5936 | skl_ddb_entry_write(dev_priv, |
| 5937 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5938 | } |
| 5939 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5940 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5941 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5942 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5943 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5944 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5945 | enum plane_id plane_id = plane->id; |
| 5946 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5947 | 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] | 5948 | const struct skl_ddb_entry *ddb = |
| 5949 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5950 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5951 | for (level = 0; level <= max_level; level++) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5952 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5953 | skl_plane_wm_level(pipe_wm, plane_id, level)); |
| 5954 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5955 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), |
| 5956 | skl_plane_trans_wm(pipe_wm, plane_id)); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5957 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 5958 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 5959 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5960 | |
| 5961 | skl_write_wm_level(dev_priv, CUR_WM_SAGV(pipe), |
| 5962 | &wm->sagv.wm0); |
| 5963 | skl_write_wm_level(dev_priv, CUR_WM_SAGV_TRANS(pipe), |
| 5964 | &wm->sagv.trans_wm); |
| 5965 | } |
| 5966 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5967 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5968 | } |
| 5969 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5970 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5971 | const struct skl_wm_level *l2) |
| 5972 | { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5973 | return l1->enable == l2->enable && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5974 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5975 | l1->lines == l2->lines && |
| 5976 | l1->blocks == l2->blocks; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5977 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5978 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5979 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5980 | const struct skl_plane_wm *wm1, |
| 5981 | const struct skl_plane_wm *wm2) |
| 5982 | { |
| 5983 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5984 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5985 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | e7f54e6 | 2020-02-28 22:35:49 +0200 | [diff] [blame] | 5986 | /* |
| 5987 | * We don't check uv_wm as the hardware doesn't actually |
| 5988 | * use it. It only gets used for calculating the required |
| 5989 | * ddb allocation. |
| 5990 | */ |
| 5991 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level])) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5992 | return false; |
| 5993 | } |
| 5994 | |
Ville Syrjälä | f11449d | 2021-02-26 17:32:00 +0200 | [diff] [blame] | 5995 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm) && |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5996 | skl_wm_level_equals(&wm1->sagv.wm0, &wm2->sagv.wm0) && |
| 5997 | 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] | 5998 | } |
| 5999 | |
Jani Nikula | 81b55ef | 2020-04-20 17:04:38 +0300 | [diff] [blame] | 6000 | static bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 6001 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6002 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 6003 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6004 | } |
| 6005 | |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6006 | static void skl_ddb_entry_union(struct skl_ddb_entry *a, |
| 6007 | const struct skl_ddb_entry *b) |
| 6008 | { |
| 6009 | if (a->end && b->end) { |
| 6010 | a->start = min(a->start, b->start); |
| 6011 | a->end = max(a->end, b->end); |
| 6012 | } else if (b->end) { |
| 6013 | a->start = b->start; |
| 6014 | a->end = b->end; |
| 6015 | } |
| 6016 | } |
| 6017 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6018 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 6019 | const struct skl_ddb_entry *entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6020 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6021 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6022 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6023 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6024 | for (i = 0; i < num_entries; i++) { |
| 6025 | if (i != ignore_idx && |
| 6026 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 6027 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 6028 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6029 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 6030 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6031 | } |
| 6032 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 6033 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6034 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 6035 | struct intel_crtc_state *new_crtc_state) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6036 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 6037 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->uapi.state); |
| 6038 | 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] | 6039 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6040 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6041 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6042 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6043 | struct intel_plane_state *plane_state; |
| 6044 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6045 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6046 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 6047 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 6048 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 6049 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6050 | continue; |
| 6051 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6052 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6053 | if (IS_ERR(plane_state)) |
| 6054 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 6055 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6056 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | return 0; |
| 6060 | } |
| 6061 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6062 | static u8 intel_dbuf_enabled_slices(const struct intel_dbuf_state *dbuf_state) |
| 6063 | { |
| 6064 | struct drm_i915_private *dev_priv = to_i915(dbuf_state->base.state->base.dev); |
| 6065 | u8 enabled_slices; |
| 6066 | enum pipe pipe; |
| 6067 | |
| 6068 | /* |
| 6069 | * FIXME: For now we always enable slice S1 as per |
| 6070 | * the Bspec display initialization sequence. |
| 6071 | */ |
| 6072 | enabled_slices = BIT(DBUF_S1); |
| 6073 | |
| 6074 | for_each_pipe(dev_priv, pipe) |
| 6075 | enabled_slices |= dbuf_state->slices[pipe]; |
| 6076 | |
| 6077 | return enabled_slices; |
| 6078 | } |
| 6079 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6080 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6081 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6082 | { |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 6083 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 6084 | const struct intel_dbuf_state *old_dbuf_state; |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6085 | struct intel_dbuf_state *new_dbuf_state = NULL; |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 6086 | const struct intel_crtc_state *old_crtc_state; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6087 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6088 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6089 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6090 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6091 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6092 | new_dbuf_state = intel_atomic_get_dbuf_state(state); |
| 6093 | if (IS_ERR(new_dbuf_state)) |
| 6094 | return PTR_ERR(new_dbuf_state); |
| 6095 | |
| 6096 | old_dbuf_state = intel_atomic_get_old_dbuf_state(state); |
| 6097 | break; |
| 6098 | } |
| 6099 | |
| 6100 | if (!new_dbuf_state) |
| 6101 | return 0; |
| 6102 | |
| 6103 | new_dbuf_state->active_pipes = |
| 6104 | intel_calc_active_pipes(state, old_dbuf_state->active_pipes); |
| 6105 | |
| 6106 | if (old_dbuf_state->active_pipes != new_dbuf_state->active_pipes) { |
| 6107 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6108 | if (ret) |
| 6109 | return ret; |
| 6110 | } |
| 6111 | |
| 6112 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6113 | enum pipe pipe = crtc->pipe; |
| 6114 | |
| 6115 | new_dbuf_state->slices[pipe] = |
| 6116 | skl_compute_dbuf_slices(crtc, new_dbuf_state->active_pipes); |
| 6117 | |
| 6118 | if (old_dbuf_state->slices[pipe] == new_dbuf_state->slices[pipe]) |
| 6119 | continue; |
| 6120 | |
| 6121 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6122 | if (ret) |
| 6123 | return ret; |
| 6124 | } |
| 6125 | |
| 6126 | new_dbuf_state->enabled_slices = intel_dbuf_enabled_slices(new_dbuf_state); |
| 6127 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6128 | if (IS_ALDERLAKE_P(dev_priv)) |
| 6129 | new_dbuf_state->joined_mbus = adlp_check_mbus_joined(new_dbuf_state->active_pipes); |
| 6130 | |
| 6131 | if (old_dbuf_state->enabled_slices != new_dbuf_state->enabled_slices || |
| 6132 | old_dbuf_state->joined_mbus != new_dbuf_state->joined_mbus) { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6133 | ret = intel_atomic_serialize_global_state(&new_dbuf_state->base); |
| 6134 | if (ret) |
| 6135 | return ret; |
| 6136 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6137 | if (old_dbuf_state->joined_mbus != new_dbuf_state->joined_mbus) { |
| 6138 | /* TODO: Implement vblank synchronized MBUS joining changes */ |
| 6139 | ret = intel_modeset_all_pipes(state); |
| 6140 | if (ret) |
| 6141 | return ret; |
| 6142 | } |
| 6143 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6144 | drm_dbg_kms(&dev_priv->drm, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6145 | "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] | 6146 | old_dbuf_state->enabled_slices, |
| 6147 | new_dbuf_state->enabled_slices, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6148 | INTEL_INFO(dev_priv)->dbuf.slice_mask, |
| 6149 | yesno(old_dbuf_state->joined_mbus), |
| 6150 | yesno(new_dbuf_state->joined_mbus)); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6154 | enum pipe pipe = crtc->pipe; |
| 6155 | |
| 6156 | new_dbuf_state->weight[pipe] = intel_crtc_ddb_weight(new_crtc_state); |
| 6157 | |
| 6158 | if (old_dbuf_state->weight[pipe] == new_dbuf_state->weight[pipe]) |
| 6159 | continue; |
| 6160 | |
| 6161 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6162 | if (ret) |
| 6163 | return ret; |
| 6164 | } |
| 6165 | |
| 6166 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6167 | ret = skl_crtc_allocate_ddb(state, crtc); |
| 6168 | if (ret) |
| 6169 | return ret; |
| 6170 | } |
| 6171 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6172 | 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] | 6173 | new_crtc_state, i) { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6174 | ret = skl_allocate_plane_ddb(state, crtc); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6175 | if (ret) |
| 6176 | return ret; |
| 6177 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6178 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 6179 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6180 | if (ret) |
| 6181 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6182 | } |
| 6183 | |
| 6184 | return 0; |
| 6185 | } |
| 6186 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6187 | static char enast(bool enable) |
| 6188 | { |
| 6189 | return enable ? '*' : ' '; |
| 6190 | } |
| 6191 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 6192 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6193 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6194 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6195 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 6196 | const struct intel_crtc_state *old_crtc_state; |
| 6197 | const struct intel_crtc_state *new_crtc_state; |
| 6198 | struct intel_plane *plane; |
| 6199 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 6200 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6201 | |
Jani Nikula | bdbf43d | 2019-10-28 12:38:15 +0200 | [diff] [blame] | 6202 | if (!drm_debug_enabled(DRM_UT_KMS)) |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6203 | return; |
| 6204 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6205 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 6206 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6207 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 6208 | |
| 6209 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 6210 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 6211 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6212 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6213 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6214 | const struct skl_ddb_entry *old, *new; |
| 6215 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6216 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 6217 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6218 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6219 | if (skl_ddb_entry_equal(old, new)) |
| 6220 | continue; |
| 6221 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6222 | drm_dbg_kms(&dev_priv->drm, |
| 6223 | "[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n", |
| 6224 | plane->base.base.id, plane->base.name, |
| 6225 | old->start, old->end, new->start, new->end, |
| 6226 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6230 | enum plane_id plane_id = plane->id; |
| 6231 | const struct skl_plane_wm *old_wm, *new_wm; |
| 6232 | |
| 6233 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 6234 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 6235 | |
| 6236 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 6237 | continue; |
| 6238 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6239 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6240 | "[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm,%cstwm" |
| 6241 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm,%cstwm\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6242 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6243 | enast(old_wm->wm[0].enable), enast(old_wm->wm[1].enable), |
| 6244 | enast(old_wm->wm[2].enable), enast(old_wm->wm[3].enable), |
| 6245 | enast(old_wm->wm[4].enable), enast(old_wm->wm[5].enable), |
| 6246 | enast(old_wm->wm[6].enable), enast(old_wm->wm[7].enable), |
| 6247 | enast(old_wm->trans_wm.enable), |
| 6248 | enast(old_wm->sagv.wm0.enable), |
| 6249 | enast(old_wm->sagv.trans_wm.enable), |
| 6250 | enast(new_wm->wm[0].enable), enast(new_wm->wm[1].enable), |
| 6251 | enast(new_wm->wm[2].enable), enast(new_wm->wm[3].enable), |
| 6252 | enast(new_wm->wm[4].enable), enast(new_wm->wm[5].enable), |
| 6253 | enast(new_wm->wm[6].enable), enast(new_wm->wm[7].enable), |
| 6254 | enast(new_wm->trans_wm.enable), |
| 6255 | enast(new_wm->sagv.wm0.enable), |
| 6256 | enast(new_wm->sagv.trans_wm.enable)); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6257 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6258 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6259 | "[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" |
| 6260 | " -> %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] | 6261 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6262 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].lines, |
| 6263 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].lines, |
| 6264 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].lines, |
| 6265 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].lines, |
| 6266 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].lines, |
| 6267 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].lines, |
| 6268 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].lines, |
| 6269 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].lines, |
| 6270 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.lines, |
| 6271 | enast(old_wm->sagv.wm0.ignore_lines), old_wm->sagv.wm0.lines, |
| 6272 | enast(old_wm->sagv.trans_wm.ignore_lines), old_wm->sagv.trans_wm.lines, |
| 6273 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].lines, |
| 6274 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].lines, |
| 6275 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].lines, |
| 6276 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].lines, |
| 6277 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].lines, |
| 6278 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].lines, |
| 6279 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].lines, |
| 6280 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].lines, |
| 6281 | enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.lines, |
| 6282 | enast(new_wm->sagv.wm0.ignore_lines), new_wm->sagv.wm0.lines, |
| 6283 | 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] | 6284 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6285 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6286 | "[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d" |
| 6287 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6288 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6289 | old_wm->wm[0].blocks, old_wm->wm[1].blocks, |
| 6290 | old_wm->wm[2].blocks, old_wm->wm[3].blocks, |
| 6291 | old_wm->wm[4].blocks, old_wm->wm[5].blocks, |
| 6292 | old_wm->wm[6].blocks, old_wm->wm[7].blocks, |
| 6293 | old_wm->trans_wm.blocks, |
| 6294 | old_wm->sagv.wm0.blocks, |
| 6295 | old_wm->sagv.trans_wm.blocks, |
| 6296 | new_wm->wm[0].blocks, new_wm->wm[1].blocks, |
| 6297 | new_wm->wm[2].blocks, new_wm->wm[3].blocks, |
| 6298 | new_wm->wm[4].blocks, new_wm->wm[5].blocks, |
| 6299 | new_wm->wm[6].blocks, new_wm->wm[7].blocks, |
| 6300 | new_wm->trans_wm.blocks, |
| 6301 | new_wm->sagv.wm0.blocks, |
| 6302 | new_wm->sagv.trans_wm.blocks); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6303 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6304 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6305 | "[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d" |
| 6306 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6307 | plane->base.base.id, plane->base.name, |
| 6308 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 6309 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 6310 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 6311 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 6312 | old_wm->trans_wm.min_ddb_alloc, |
Ville Syrjälä | a68aa48 | 2021-02-26 17:32:01 +0200 | [diff] [blame] | 6313 | old_wm->sagv.wm0.min_ddb_alloc, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6314 | old_wm->sagv.trans_wm.min_ddb_alloc, |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6315 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 6316 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 6317 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 6318 | 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] | 6319 | new_wm->trans_wm.min_ddb_alloc, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6320 | new_wm->sagv.wm0.min_ddb_alloc, |
| 6321 | new_wm->sagv.trans_wm.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6322 | } |
| 6323 | } |
| 6324 | } |
| 6325 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6326 | static bool skl_plane_selected_wm_equals(struct intel_plane *plane, |
| 6327 | const struct skl_pipe_wm *old_pipe_wm, |
| 6328 | const struct skl_pipe_wm *new_pipe_wm) |
| 6329 | { |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6330 | struct drm_i915_private *i915 = to_i915(plane->base.dev); |
| 6331 | int level, max_level = ilk_wm_max_level(i915); |
| 6332 | |
| 6333 | for (level = 0; level <= max_level; level++) { |
| 6334 | /* |
| 6335 | * We don't check uv_wm as the hardware doesn't actually |
| 6336 | * use it. It only gets used for calculating the required |
| 6337 | * ddb allocation. |
| 6338 | */ |
Ville Syrjälä | 93fe862 | 2021-03-25 02:44:14 +0200 | [diff] [blame] | 6339 | if (!skl_wm_level_equals(skl_plane_wm_level(old_pipe_wm, plane->id, level), |
| 6340 | skl_plane_wm_level(new_pipe_wm, plane->id, level))) |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6341 | return false; |
| 6342 | } |
| 6343 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 6344 | if (HAS_HW_SAGV_WM(i915)) { |
| 6345 | const struct skl_plane_wm *old_wm = &old_pipe_wm->planes[plane->id]; |
| 6346 | const struct skl_plane_wm *new_wm = &new_pipe_wm->planes[plane->id]; |
| 6347 | |
| 6348 | if (!skl_wm_level_equals(&old_wm->sagv.wm0, &new_wm->sagv.wm0) || |
| 6349 | !skl_wm_level_equals(&old_wm->sagv.trans_wm, &new_wm->sagv.trans_wm)) |
| 6350 | return false; |
| 6351 | } |
| 6352 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6353 | return skl_wm_level_equals(skl_plane_trans_wm(old_pipe_wm, plane->id), |
| 6354 | skl_plane_trans_wm(new_pipe_wm, plane->id)); |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6355 | } |
| 6356 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6357 | /* |
| 6358 | * To make sure the cursor watermark registers are always consistent |
| 6359 | * with our computed state the following scenario needs special |
| 6360 | * treatment: |
| 6361 | * |
| 6362 | * 1. enable cursor |
| 6363 | * 2. move cursor entirely offscreen |
| 6364 | * 3. disable cursor |
| 6365 | * |
| 6366 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 6367 | * (since we consider an offscreen cursor still active for the purposes |
| 6368 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 6369 | * because the actual plane visibility isn't changing, and we don't |
| 6370 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 6371 | * force step 3. to call .disable_plane() to update the watermark |
| 6372 | * registers properly. |
| 6373 | * |
| 6374 | * Other planes do not suffer from this issues as their watermarks are |
| 6375 | * calculated based on the actual plane visibility. The only time this |
| 6376 | * can trigger for the other planes is during the initial readout as the |
| 6377 | * default value of the watermarks registers is not zero. |
| 6378 | */ |
| 6379 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 6380 | struct intel_crtc *crtc) |
| 6381 | { |
| 6382 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6383 | const struct intel_crtc_state *old_crtc_state = |
| 6384 | intel_atomic_get_old_crtc_state(state, crtc); |
| 6385 | struct intel_crtc_state *new_crtc_state = |
| 6386 | intel_atomic_get_new_crtc_state(state, crtc); |
| 6387 | struct intel_plane *plane; |
| 6388 | |
| 6389 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6390 | struct intel_plane_state *plane_state; |
| 6391 | enum plane_id plane_id = plane->id; |
| 6392 | |
| 6393 | /* |
| 6394 | * Force a full wm update for every plane on modeset. |
| 6395 | * Required because the reset value of the wm registers |
| 6396 | * is non-zero, whereas we want all disabled planes to |
| 6397 | * have zero watermarks. So if we turn off the relevant |
| 6398 | * power well the hardware state will go out of sync |
| 6399 | * with the software state. |
| 6400 | */ |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 6401 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) && |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6402 | skl_plane_selected_wm_equals(plane, |
| 6403 | &old_crtc_state->wm.skl.optimal, |
| 6404 | &new_crtc_state->wm.skl.optimal)) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6405 | continue; |
| 6406 | |
| 6407 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 6408 | if (IS_ERR(plane_state)) |
| 6409 | return PTR_ERR(plane_state); |
| 6410 | |
| 6411 | new_crtc_state->update_planes |= BIT(plane_id); |
| 6412 | } |
| 6413 | |
| 6414 | return 0; |
| 6415 | } |
| 6416 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6417 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6418 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6419 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6420 | struct intel_crtc *crtc; |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 6421 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6422 | int ret, i; |
| 6423 | |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 6424 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6425 | ret = skl_build_pipe_wm(state, crtc); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6426 | if (ret) |
| 6427 | return ret; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 6428 | } |
| 6429 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 6430 | ret = skl_compute_ddb(state); |
| 6431 | if (ret) |
| 6432 | return ret; |
| 6433 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 6434 | ret = intel_compute_sagv_mask(state); |
| 6435 | if (ret) |
| 6436 | return ret; |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 6437 | |
Ville Syrjälä | 23baedd | 2020-02-28 22:35:50 +0200 | [diff] [blame] | 6438 | /* |
| 6439 | * skl_compute_ddb() will have adjusted the final watermarks |
| 6440 | * based on how much ddb is available. Now we can actually |
| 6441 | * check if the final watermarks changed. |
| 6442 | */ |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 6443 | 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] | 6444 | ret = skl_wm_add_affected_planes(state, crtc); |
| 6445 | if (ret) |
| 6446 | return ret; |
| 6447 | } |
| 6448 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6449 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6450 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6451 | return 0; |
| 6452 | } |
| 6453 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6454 | 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] | 6455 | struct intel_wm_config *config) |
| 6456 | { |
| 6457 | struct intel_crtc *crtc; |
| 6458 | |
| 6459 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6460 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6461 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 6462 | |
| 6463 | if (!wm->pipe_enabled) |
| 6464 | continue; |
| 6465 | |
| 6466 | config->sprites_enabled |= wm->sprites_enabled; |
| 6467 | config->sprites_scaled |= wm->sprites_scaled; |
| 6468 | config->num_pipes_active++; |
| 6469 | } |
| 6470 | } |
| 6471 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6472 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 6473 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6474 | 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] | 6475 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6476 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6477 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 6478 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 6479 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6480 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6481 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6482 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 6483 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 6484 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 6485 | /* 5/6 split only in single pipe config on IVB+ */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 6486 | if (DISPLAY_VER(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6487 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6488 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 6489 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 6490 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6491 | 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] | 6492 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 6493 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6494 | } |
| 6495 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 6496 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 6497 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6498 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6499 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 6500 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6501 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 6502 | } |
| 6503 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 6504 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6505 | struct intel_crtc *crtc) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6506 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6507 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6508 | const struct intel_crtc_state *crtc_state = |
| 6509 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6510 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6511 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6512 | crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6513 | ilk_program_watermarks(dev_priv); |
| 6514 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6515 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6516 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 6517 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6518 | struct intel_crtc *crtc) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6519 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6520 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6521 | const struct intel_crtc_state *crtc_state = |
| 6522 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6523 | |
| 6524 | if (!crtc_state->wm.need_postvbl_update) |
| 6525 | return; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6526 | |
| 6527 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6528 | crtc->wm.active.ilk = crtc_state->wm.ilk.optimal; |
| 6529 | ilk_program_watermarks(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6530 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6531 | } |
| 6532 | |
Jani Nikula | 81b55ef | 2020-04-20 17:04:38 +0300 | [diff] [blame] | 6533 | 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] | 6534 | { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6535 | level->enable = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 6536 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6537 | level->blocks = val & PLANE_WM_BLOCKS_MASK; |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 6538 | level->lines = REG_FIELD_GET(PLANE_WM_LINES_MASK, val); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6539 | } |
| 6540 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6541 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6542 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6543 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6544 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6545 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6546 | int level, max_level; |
| 6547 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6548 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6549 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6550 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6551 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6552 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6553 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6554 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6555 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6556 | if (plane_id != PLANE_CURSOR) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6557 | 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] | 6558 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6559 | val = intel_uncore_read(&dev_priv->uncore, CUR_WM(pipe, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6560 | |
| 6561 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 6562 | } |
| 6563 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6564 | if (plane_id != PLANE_CURSOR) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6565 | 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] | 6566 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6567 | val = intel_uncore_read(&dev_priv->uncore, CUR_WM_TRANS(pipe)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6568 | |
| 6569 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6570 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 6571 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 6572 | if (plane_id != PLANE_CURSOR) |
| 6573 | val = intel_uncore_read(&dev_priv->uncore, |
| 6574 | PLANE_WM_SAGV(pipe, plane_id)); |
| 6575 | else |
| 6576 | val = intel_uncore_read(&dev_priv->uncore, |
| 6577 | CUR_WM_SAGV(pipe)); |
| 6578 | |
| 6579 | skl_wm_level_from_reg_val(val, &wm->sagv.wm0); |
| 6580 | |
| 6581 | if (plane_id != PLANE_CURSOR) |
| 6582 | val = intel_uncore_read(&dev_priv->uncore, |
| 6583 | PLANE_WM_SAGV_TRANS(pipe, plane_id)); |
| 6584 | else |
| 6585 | val = intel_uncore_read(&dev_priv->uncore, |
| 6586 | CUR_WM_SAGV_TRANS(pipe)); |
| 6587 | |
| 6588 | skl_wm_level_from_reg_val(val, &wm->sagv.trans_wm); |
| 6589 | } else if (DISPLAY_VER(dev_priv) >= 12) { |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6590 | wm->sagv.wm0 = wm->wm[0]; |
| 6591 | wm->sagv.trans_wm = wm->trans_wm; |
| 6592 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6593 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6594 | } |
| 6595 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6596 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6597 | { |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6598 | struct intel_dbuf_state *dbuf_state = |
| 6599 | to_intel_dbuf_state(dev_priv->dbuf.obj.state); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6600 | struct intel_crtc *crtc; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6601 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6602 | if (IS_ALDERLAKE_P(dev_priv)) |
| 6603 | dbuf_state->joined_mbus = intel_de_read(dev_priv, MBUS_CTL) & MBUS_JOIN; |
| 6604 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6605 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6606 | struct intel_crtc_state *crtc_state = |
| 6607 | to_intel_crtc_state(crtc->base.state); |
| 6608 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 6609 | unsigned int mbus_offset; |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6610 | enum plane_id plane_id; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6611 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6612 | 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] | 6613 | crtc_state->wm.skl.raw = crtc_state->wm.skl.optimal; |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6614 | |
| 6615 | memset(&dbuf_state->ddb[pipe], 0, sizeof(dbuf_state->ddb[pipe])); |
| 6616 | |
| 6617 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6618 | struct skl_ddb_entry *ddb_y = |
| 6619 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 6620 | struct skl_ddb_entry *ddb_uv = |
| 6621 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
| 6622 | |
| 6623 | skl_ddb_get_hw_plane_state(dev_priv, crtc->pipe, |
| 6624 | plane_id, ddb_y, ddb_uv); |
| 6625 | |
| 6626 | skl_ddb_entry_union(&dbuf_state->ddb[pipe], ddb_y); |
| 6627 | skl_ddb_entry_union(&dbuf_state->ddb[pipe], ddb_uv); |
| 6628 | } |
| 6629 | |
| 6630 | dbuf_state->slices[pipe] = |
| 6631 | skl_compute_dbuf_slices(crtc, dbuf_state->active_pipes); |
| 6632 | |
| 6633 | dbuf_state->weight[pipe] = intel_crtc_ddb_weight(crtc_state); |
| 6634 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 6635 | /* |
| 6636 | * Used for checking overlaps, so we need absolute |
| 6637 | * offsets instead of MBUS relative offsets. |
| 6638 | */ |
| 6639 | mbus_offset = mbus_ddb_offset(dev_priv, dbuf_state->slices[pipe]); |
| 6640 | crtc_state->wm.skl.ddb.start = mbus_offset + dbuf_state->ddb[pipe].start; |
| 6641 | 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] | 6642 | |
| 6643 | drm_dbg_kms(&dev_priv->drm, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6644 | "[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] | 6645 | crtc->base.base.id, crtc->base.name, |
| 6646 | dbuf_state->slices[pipe], dbuf_state->ddb[pipe].start, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6647 | dbuf_state->ddb[pipe].end, dbuf_state->active_pipes, |
| 6648 | yesno(dbuf_state->joined_mbus)); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6649 | } |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6650 | |
| 6651 | dbuf_state->enabled_slices = dev_priv->dbuf.enabled_slices; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6652 | } |
| 6653 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6654 | 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] | 6655 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6656 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6657 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6658 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6659 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 6660 | struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6661 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6662 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6663 | 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] | 6664 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 6665 | memset(active, 0, sizeof(*active)); |
| 6666 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6667 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 6668 | |
| 6669 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6670 | u32 tmp = hw->wm_pipe[pipe]; |
| 6671 | |
| 6672 | /* |
| 6673 | * For active pipes LP0 watermark is marked as |
| 6674 | * enabled, and LP1+ watermaks as disabled since |
| 6675 | * we can't really reverse compute them in case |
| 6676 | * multiple pipes are active. |
| 6677 | */ |
| 6678 | active->wm[0].enable = true; |
| 6679 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 6680 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 6681 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6682 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6683 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6684 | |
| 6685 | /* |
| 6686 | * For inactive pipes, all watermark levels |
| 6687 | * should be marked as enabled but zeroed, |
| 6688 | * which is what we'd compute them to. |
| 6689 | */ |
| 6690 | for (level = 0; level <= max_level; level++) |
| 6691 | active->wm[level].enable = true; |
| 6692 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 6693 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6694 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6695 | } |
| 6696 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6697 | #define _FW_WM(value, plane) \ |
| 6698 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 6699 | #define _FW_WM_VLV(value, plane) \ |
| 6700 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 6701 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6702 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 6703 | struct g4x_wm_values *wm) |
| 6704 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6705 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6706 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6707 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6708 | wm->sr.plane = _FW_WM(tmp, SR); |
| 6709 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 6710 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 6711 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 6712 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6713 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW2); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6714 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 6715 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 6716 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 6717 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 6718 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 6719 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 6720 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6721 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6722 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 6723 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 6724 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 6725 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 6726 | } |
| 6727 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6728 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 6729 | struct vlv_wm_values *wm) |
| 6730 | { |
| 6731 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6732 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6733 | |
| 6734 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6735 | tmp = intel_uncore_read(&dev_priv->uncore, VLV_DDL(pipe)); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6736 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6737 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6738 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6739 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6740 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6741 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6742 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6743 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6744 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 6745 | } |
| 6746 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6747 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6748 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6749 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 6750 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 6751 | 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] | 6752 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6753 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6754 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 6755 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 6756 | 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] | 6757 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6758 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6759 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 6760 | |
| 6761 | if (IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6762 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6763 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 6764 | 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] | 6765 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6766 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6767 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 6768 | 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] | 6769 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6770 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6771 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 6772 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6773 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6774 | tmp = intel_uncore_read(&dev_priv->uncore, DSPHOWM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6775 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6776 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 6777 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 6778 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 6779 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 6780 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 6781 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 6782 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 6783 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 6784 | 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] | 6785 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6786 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6787 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 6788 | 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] | 6789 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6790 | tmp = intel_uncore_read(&dev_priv->uncore, DSPHOWM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6791 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6792 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 6793 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 6794 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 6795 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 6796 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 6797 | 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] | 6798 | } |
| 6799 | } |
| 6800 | |
| 6801 | #undef _FW_WM |
| 6802 | #undef _FW_WM_VLV |
| 6803 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6804 | 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] | 6805 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6806 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 6807 | struct intel_crtc *crtc; |
| 6808 | |
| 6809 | g4x_read_wm_values(dev_priv, wm); |
| 6810 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6811 | 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] | 6812 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6813 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6814 | struct intel_crtc_state *crtc_state = |
| 6815 | to_intel_crtc_state(crtc->base.state); |
| 6816 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 6817 | struct g4x_pipe_wm *raw; |
| 6818 | enum pipe pipe = crtc->pipe; |
| 6819 | enum plane_id plane_id; |
| 6820 | int level, max_level; |
| 6821 | |
| 6822 | active->cxsr = wm->cxsr; |
| 6823 | active->hpll_en = wm->hpll_en; |
| 6824 | active->fbc_en = wm->fbc_en; |
| 6825 | |
| 6826 | active->sr = wm->sr; |
| 6827 | active->hpll = wm->hpll; |
| 6828 | |
| 6829 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6830 | active->wm.plane[plane_id] = |
| 6831 | wm->pipe[pipe].plane[plane_id]; |
| 6832 | } |
| 6833 | |
| 6834 | if (wm->cxsr && wm->hpll_en) |
| 6835 | max_level = G4X_WM_LEVEL_HPLL; |
| 6836 | else if (wm->cxsr) |
| 6837 | max_level = G4X_WM_LEVEL_SR; |
| 6838 | else |
| 6839 | max_level = G4X_WM_LEVEL_NORMAL; |
| 6840 | |
| 6841 | level = G4X_WM_LEVEL_NORMAL; |
| 6842 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6843 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6844 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 6845 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame] | 6846 | level = G4X_WM_LEVEL_SR; |
| 6847 | if (level > max_level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6848 | goto out; |
| 6849 | |
| 6850 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6851 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 6852 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 6853 | raw->plane[PLANE_SPRITE0] = 0; |
| 6854 | raw->fbc = active->sr.fbc; |
| 6855 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame] | 6856 | level = G4X_WM_LEVEL_HPLL; |
| 6857 | if (level > max_level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6858 | goto out; |
| 6859 | |
| 6860 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6861 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 6862 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 6863 | raw->plane[PLANE_SPRITE0] = 0; |
| 6864 | raw->fbc = active->hpll.fbc; |
| 6865 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame] | 6866 | level++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6867 | out: |
| 6868 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6869 | g4x_raw_plane_wm_set(crtc_state, level, |
| 6870 | plane_id, USHRT_MAX); |
| 6871 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 6872 | |
| 6873 | crtc_state->wm.g4x.optimal = *active; |
| 6874 | crtc_state->wm.g4x.intermediate = *active; |
| 6875 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6876 | drm_dbg_kms(&dev_priv->drm, |
| 6877 | "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 6878 | pipe_name(pipe), |
| 6879 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6880 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6881 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6882 | } |
| 6883 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6884 | drm_dbg_kms(&dev_priv->drm, |
| 6885 | "Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 6886 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 6887 | drm_dbg_kms(&dev_priv->drm, |
| 6888 | "Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 6889 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 6890 | drm_dbg_kms(&dev_priv->drm, "Initial SR=%s HPLL=%s FBC=%s\n", |
| 6891 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6892 | } |
| 6893 | |
| 6894 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6895 | { |
| 6896 | struct intel_plane *plane; |
| 6897 | struct intel_crtc *crtc; |
| 6898 | |
| 6899 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6900 | |
| 6901 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6902 | struct intel_crtc *crtc = |
| 6903 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 6904 | struct intel_crtc_state *crtc_state = |
| 6905 | to_intel_crtc_state(crtc->base.state); |
| 6906 | struct intel_plane_state *plane_state = |
| 6907 | to_intel_plane_state(plane->base.state); |
| 6908 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 6909 | enum plane_id plane_id = plane->id; |
| 6910 | int level; |
| 6911 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 6912 | if (plane_state->uapi.visible) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6913 | continue; |
| 6914 | |
| 6915 | for (level = 0; level < 3; level++) { |
| 6916 | struct g4x_pipe_wm *raw = |
| 6917 | &crtc_state->wm.g4x.raw[level]; |
| 6918 | |
| 6919 | raw->plane[plane_id] = 0; |
| 6920 | wm_state->wm.plane[plane_id] = 0; |
| 6921 | } |
| 6922 | |
| 6923 | if (plane_id == PLANE_PRIMARY) { |
| 6924 | for (level = 0; level < 3; level++) { |
| 6925 | struct g4x_pipe_wm *raw = |
| 6926 | &crtc_state->wm.g4x.raw[level]; |
| 6927 | raw->fbc = 0; |
| 6928 | } |
| 6929 | |
| 6930 | wm_state->sr.fbc = 0; |
| 6931 | wm_state->hpll.fbc = 0; |
| 6932 | wm_state->fbc_en = false; |
| 6933 | } |
| 6934 | } |
| 6935 | |
| 6936 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6937 | struct intel_crtc_state *crtc_state = |
| 6938 | to_intel_crtc_state(crtc->base.state); |
| 6939 | |
| 6940 | crtc_state->wm.g4x.intermediate = |
| 6941 | crtc_state->wm.g4x.optimal; |
| 6942 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 6943 | } |
| 6944 | |
| 6945 | g4x_program_watermarks(dev_priv); |
| 6946 | |
| 6947 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6948 | } |
| 6949 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6950 | 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] | 6951 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6952 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 6953 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6954 | u32 val; |
| 6955 | |
| 6956 | vlv_read_wm_values(dev_priv, wm); |
| 6957 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6958 | 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] | 6959 | wm->level = VLV_WM_LEVEL_PM2; |
| 6960 | |
| 6961 | if (IS_CHERRYVIEW(dev_priv)) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6962 | vlv_punit_get(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6963 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 6964 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6965 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 6966 | wm->level = VLV_WM_LEVEL_PM5; |
| 6967 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6968 | /* |
| 6969 | * If DDR DVFS is disabled in the BIOS, Punit |
| 6970 | * will never ack the request. So if that happens |
| 6971 | * assume we don't have to enable/disable DDR DVFS |
| 6972 | * dynamically. To test that just set the REQ_ACK |
| 6973 | * bit to poke the Punit, but don't change the |
| 6974 | * HIGH/LOW bits so that we don't actually change |
| 6975 | * the current state. |
| 6976 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6977 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6978 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 6979 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 6980 | |
| 6981 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 6982 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6983 | drm_dbg_kms(&dev_priv->drm, |
| 6984 | "Punit not acking DDR DVFS request, " |
| 6985 | "assuming DDR DVFS is disabled\n"); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6986 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 6987 | } else { |
| 6988 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 6989 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 6990 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 6991 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6992 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6993 | vlv_punit_put(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6994 | } |
| 6995 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6996 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6997 | struct intel_crtc_state *crtc_state = |
| 6998 | to_intel_crtc_state(crtc->base.state); |
| 6999 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 7000 | const struct vlv_fifo_state *fifo_state = |
| 7001 | &crtc_state->wm.vlv.fifo_state; |
| 7002 | enum pipe pipe = crtc->pipe; |
| 7003 | enum plane_id plane_id; |
| 7004 | int level; |
| 7005 | |
| 7006 | vlv_get_fifo_size(crtc_state); |
| 7007 | |
| 7008 | active->num_levels = wm->level + 1; |
| 7009 | active->cxsr = wm->cxsr; |
| 7010 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7011 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 7012 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7013 | &crtc_state->wm.vlv.raw[level]; |
| 7014 | |
| 7015 | active->sr[level].plane = wm->sr.plane; |
| 7016 | active->sr[level].cursor = wm->sr.cursor; |
| 7017 | |
| 7018 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 7019 | active->wm[level].plane[plane_id] = |
| 7020 | wm->pipe[pipe].plane[plane_id]; |
| 7021 | |
| 7022 | raw->plane[plane_id] = |
| 7023 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 7024 | fifo_state->plane[plane_id]); |
| 7025 | } |
| 7026 | } |
| 7027 | |
| 7028 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 7029 | vlv_raw_plane_wm_set(crtc_state, level, |
| 7030 | plane_id, USHRT_MAX); |
| 7031 | vlv_invalidate_wms(crtc, active, level); |
| 7032 | |
| 7033 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 7034 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7035 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7036 | drm_dbg_kms(&dev_priv->drm, |
| 7037 | "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n", |
| 7038 | pipe_name(pipe), |
| 7039 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 7040 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 7041 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 7042 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7043 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 7044 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7045 | drm_dbg_kms(&dev_priv->drm, |
| 7046 | "Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 7047 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 7048 | } |
| 7049 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7050 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 7051 | { |
| 7052 | struct intel_plane *plane; |
| 7053 | struct intel_crtc *crtc; |
| 7054 | |
| 7055 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 7056 | |
| 7057 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 7058 | struct intel_crtc *crtc = |
| 7059 | intel_get_crtc_for_pipe(dev_priv, plane->pipe); |
| 7060 | struct intel_crtc_state *crtc_state = |
| 7061 | to_intel_crtc_state(crtc->base.state); |
| 7062 | struct intel_plane_state *plane_state = |
| 7063 | to_intel_plane_state(plane->base.state); |
| 7064 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 7065 | const struct vlv_fifo_state *fifo_state = |
| 7066 | &crtc_state->wm.vlv.fifo_state; |
| 7067 | enum plane_id plane_id = plane->id; |
| 7068 | int level; |
| 7069 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 7070 | if (plane_state->uapi.visible) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7071 | continue; |
| 7072 | |
| 7073 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 7074 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7075 | &crtc_state->wm.vlv.raw[level]; |
| 7076 | |
| 7077 | raw->plane[plane_id] = 0; |
| 7078 | |
| 7079 | wm_state->wm[level].plane[plane_id] = |
| 7080 | vlv_invert_wm_value(raw->plane[plane_id], |
| 7081 | fifo_state->plane[plane_id]); |
| 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 7086 | struct intel_crtc_state *crtc_state = |
| 7087 | to_intel_crtc_state(crtc->base.state); |
| 7088 | |
| 7089 | crtc_state->wm.vlv.intermediate = |
| 7090 | crtc_state->wm.vlv.optimal; |
| 7091 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 7092 | } |
| 7093 | |
| 7094 | vlv_program_watermarks(dev_priv); |
| 7095 | |
| 7096 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 7097 | } |
| 7098 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 7099 | /* |
| 7100 | * FIXME should probably kill this and improve |
| 7101 | * the real watermark readout/sanitation instead |
| 7102 | */ |
| 7103 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 7104 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7105 | intel_uncore_write(&dev_priv->uncore, WM3_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 7106 | intel_uncore_write(&dev_priv->uncore, WM2_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 7107 | 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] | 7108 | |
| 7109 | /* |
| 7110 | * Don't touch WM1S_LP_EN here. |
| 7111 | * Doing so could cause underruns. |
| 7112 | */ |
| 7113 | } |
| 7114 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7115 | 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] | 7116 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 7117 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7118 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7119 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 7120 | ilk_init_lp_watermarks(dev_priv); |
| 7121 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7122 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7123 | ilk_pipe_wm_get_hw_state(crtc); |
| 7124 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7125 | hw->wm_lp[0] = intel_uncore_read(&dev_priv->uncore, WM1_LP_ILK); |
| 7126 | hw->wm_lp[1] = intel_uncore_read(&dev_priv->uncore, WM2_LP_ILK); |
| 7127 | 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] | 7128 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7129 | 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] | 7130 | if (DISPLAY_VER(dev_priv) >= 7) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7131 | hw->wm_lp_spr[1] = intel_uncore_read(&dev_priv->uncore, WM2S_LP_IVB); |
| 7132 | 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] | 7133 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7134 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 7135 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7136 | 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] | 7137 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 7138 | else if (IS_IVYBRIDGE(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7139 | 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] | 7140 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7141 | |
| 7142 | hw->enable_fbc_wm = |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7143 | !(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] | 7144 | } |
| 7145 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7146 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 7147 | { |
| 7148 | u32 val; |
| 7149 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 7150 | if (!HAS_IPC(dev_priv)) |
| 7151 | return; |
| 7152 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7153 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2); |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7154 | |
| 7155 | if (dev_priv->ipc_enabled) |
| 7156 | val |= DISP_IPC_ENABLE; |
| 7157 | else |
| 7158 | val &= ~DISP_IPC_ENABLE; |
| 7159 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7160 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL2, val); |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7161 | } |
| 7162 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7163 | static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv) |
| 7164 | { |
| 7165 | /* Display WA #0477 WaDisableIPC: skl */ |
| 7166 | if (IS_SKYLAKE(dev_priv)) |
| 7167 | return false; |
| 7168 | |
| 7169 | /* Display WA #1141: SKL:all KBL:all CFL */ |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 7170 | if (IS_KABYLAKE(dev_priv) || |
| 7171 | IS_COFFEELAKE(dev_priv) || |
| 7172 | IS_COMETLAKE(dev_priv)) |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7173 | return dev_priv->dram_info.symmetric_memory; |
| 7174 | |
| 7175 | return true; |
| 7176 | } |
| 7177 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7178 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 7179 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7180 | if (!HAS_IPC(dev_priv)) |
| 7181 | return; |
| 7182 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7183 | dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv); |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 7184 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7185 | intel_enable_ipc(dev_priv); |
| 7186 | } |
| 7187 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7188 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7189 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7190 | /* |
| 7191 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7192 | * gating for the panel power sequencer or it will fail to |
| 7193 | * start up when no ports are active. |
| 7194 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7195 | 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] | 7196 | } |
| 7197 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7198 | 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] | 7199 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7200 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7201 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7202 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7203 | intel_uncore_write(&dev_priv->uncore, DSPCNTR(pipe), |
| 7204 | intel_uncore_read(&dev_priv->uncore, DSPCNTR(pipe)) | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7205 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7206 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7207 | intel_uncore_write(&dev_priv->uncore, DSPSURF(pipe), intel_uncore_read(&dev_priv->uncore, DSPSURF(pipe))); |
| 7208 | intel_uncore_posting_read(&dev_priv->uncore, DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7209 | } |
| 7210 | } |
| 7211 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7212 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7213 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7214 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7215 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 7216 | /* |
| 7217 | * Required for FBC |
| 7218 | * WaFbcDisableDpfcClockGating:ilk |
| 7219 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7220 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 7221 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 7222 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7223 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7224 | intel_uncore_write(&dev_priv->uncore, PCH_3DCGDIS0, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7225 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 7226 | SVSMUNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7227 | intel_uncore_write(&dev_priv->uncore, PCH_3DCGDIS1, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7228 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 7229 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7230 | /* |
| 7231 | * According to the spec the following bits should be set in |
| 7232 | * order to enable memory self-refresh |
| 7233 | * The bit 22/21 of 0x42004 |
| 7234 | * The bit 5 of 0x42020 |
| 7235 | * The bit 15 of 0x45000 |
| 7236 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7237 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7238 | (intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7239 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7240 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7241 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, |
| 7242 | (intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7243 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7244 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7245 | /* |
| 7246 | * Based on the document from hardware guys the following bits |
| 7247 | * should be set unconditionally in order to enable FBC. |
| 7248 | * The bit 22 of 0x42000 |
| 7249 | * The bit 22 of 0x42004 |
| 7250 | * The bit 7,8,9 of 0x42020. |
| 7251 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7252 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7253 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7254 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7255 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7256 | ILK_FBCQ_DIS); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7257 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7258 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7259 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7260 | } |
| 7261 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7262 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, dspclk_gate); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7263 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7264 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7265 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7266 | ILK_ELPIN_409_SELECT); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7267 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7268 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 7269 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7270 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7271 | } |
| 7272 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7273 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7274 | { |
Ville Syrjälä | d048a26 | 2019-08-21 20:30:31 +0300 | [diff] [blame] | 7275 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7276 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7277 | |
| 7278 | /* |
| 7279 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7280 | * gating for the panel power sequencer or it will fail to |
| 7281 | * start up when no ports are active. |
| 7282 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7283 | 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] | 7284 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 7285 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7286 | 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] | 7287 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 7288 | /* The below fixes the weird display corruption, a few pixels shifted |
| 7289 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 7290 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7291 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7292 | val = intel_uncore_read(&dev_priv->uncore, TRANS_CHICKEN2(pipe)); |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7293 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 7294 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7295 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7296 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7297 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 7298 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7299 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN2(pipe), val); |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7300 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7301 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7302 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7303 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN1(pipe), |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7304 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 7305 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7306 | } |
| 7307 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7308 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7309 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7310 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7311 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7312 | tmp = intel_uncore_read(&dev_priv->uncore, MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 7313 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7314 | drm_dbg_kms(&dev_priv->drm, |
| 7315 | "Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 7316 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7317 | } |
| 7318 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7319 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7320 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7321 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7322 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7323 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7324 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7325 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7326 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7327 | ILK_ELPIN_409_SELECT); |
| 7328 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7329 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, |
| 7330 | intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7331 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 7332 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 7333 | |
| 7334 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 7335 | * gating disable must be set. Failure to set it results in |
| 7336 | * flickering pixels due to Z write ordering failures after |
| 7337 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 7338 | * Sanctuary and Tropics, and apparently anything else with |
| 7339 | * alpha test or pixel discard. |
| 7340 | * |
| 7341 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 7342 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7343 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 7344 | * WaDisableRCCUnitClockGating:snb |
| 7345 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7346 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7347 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7348 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 7349 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 7350 | |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 7351 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7352 | * According to the spec the following bits should be |
| 7353 | * set in order to enable memory self-refresh and fbc: |
| 7354 | * The bit21 and bit22 of 0x42000 |
| 7355 | * The bit21 and bit22 of 0x42004 |
| 7356 | * The bit5 and bit7 of 0x42020 |
| 7357 | * The bit14 of 0x70180 |
| 7358 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7359 | * |
| 7360 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7361 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7362 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7363 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7364 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7365 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7366 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7367 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7368 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, |
| 7369 | intel_uncore_read(&dev_priv->uncore, ILK_DSPCLK_GATE_D) | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7370 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 7371 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7372 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7373 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 7374 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7375 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7376 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7377 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7378 | } |
| 7379 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7380 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7381 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7382 | /* |
| 7383 | * TODO: this bit should only be enabled when really needed, then |
| 7384 | * disabled when not needed anymore in order to save power. |
| 7385 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7386 | if (HAS_PCH_LPT_LP(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7387 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, |
| 7388 | intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D) | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7389 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7390 | |
| 7391 | /* WADPOClockGatingDisable:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7392 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN1(PIPE_A), |
| 7393 | intel_uncore_read(&dev_priv->uncore, TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7394 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7395 | } |
| 7396 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7397 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7398 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7399 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7400 | u32 val = intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7401 | |
| 7402 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7403 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, val); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7404 | } |
| 7405 | } |
| 7406 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7407 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 7408 | int general_prio_credits, |
| 7409 | int high_prio_credits) |
| 7410 | { |
| 7411 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 7412 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7413 | |
| 7414 | /* WaTempDisableDOPClkGating:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7415 | misccpctl = intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL); |
| 7416 | 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] | 7417 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7418 | val = intel_uncore_read(&dev_priv->uncore, GEN8_L3SQCREG1); |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 7419 | val &= ~L3_PRIO_CREDITS_MASK; |
| 7420 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 7421 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7422 | intel_uncore_write(&dev_priv->uncore, GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7423 | |
| 7424 | /* |
| 7425 | * Wait at least 100 clocks before re-enabling clock gating. |
| 7426 | * See the definition of L3SQCREG1 in BSpec. |
| 7427 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7428 | intel_uncore_posting_read(&dev_priv->uncore, GEN8_L3SQCREG1); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7429 | udelay(1); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7430 | intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7431 | } |
| 7432 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7433 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7434 | { |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7435 | /* Wa_1409120013:icl,ehl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7436 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7437 | ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL); |
| 7438 | |
Matt Atwood | 6f4194c | 2020-01-13 23:11:28 -0500 | [diff] [blame] | 7439 | /*Wa_14010594013:icl, ehl */ |
| 7440 | intel_uncore_rmw(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1, |
Lucas De Marchi | dbac4f3 | 2021-07-28 14:59:38 -0700 | [diff] [blame] | 7441 | 0, ICL_DELAY_PMRSP); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7442 | } |
| 7443 | |
José Roberto de Souza | 35f0837 | 2021-01-13 05:37:59 -0800 | [diff] [blame] | 7444 | static void gen12lp_init_clock_gating(struct drm_i915_private *dev_priv) |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7445 | { |
José Roberto de Souza | c492405 | 2021-07-12 17:38:50 -0700 | [diff] [blame] | 7446 | /* Wa_1409120013:tgl,rkl,adl-s,dg1 */ |
Clint Taylor | 8c209f4 | 2021-06-08 10:47:21 -0700 | [diff] [blame] | 7447 | if (IS_TIGERLAKE(dev_priv) || IS_ROCKETLAKE(dev_priv) || |
| 7448 | IS_ALDERLAKE_S(dev_priv) || IS_DG1(dev_priv)) |
| 7449 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, |
| 7450 | ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL); |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7451 | |
Radhakrishna Sripada | f78d5da | 2020-01-09 14:37:27 -0800 | [diff] [blame] | 7452 | /* Wa_1409825376:tgl (pre-prod)*/ |
Matt Roper | 46b0d70 | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7453 | if (IS_TGL_DISPLAY_STEP(dev_priv, STEP_A0, STEP_C0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7454 | 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] | 7455 | TGL_VRH_GATING_DIS); |
Matt Atwood | f9d7742 | 2020-04-15 15:35:35 -0400 | [diff] [blame] | 7456 | |
José Roberto de Souza | 41c70d2 | 2021-04-08 13:49:16 -0700 | [diff] [blame] | 7457 | /* Wa_14013723622:tgl,rkl,dg1,adl-s */ |
| 7458 | if (DISPLAY_VER(dev_priv) == 12) |
| 7459 | intel_uncore_rmw(&dev_priv->uncore, CLKREQ_POLICY, |
| 7460 | CLKREQ_POLICY_MEM_UP_OVRD, 0); |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7461 | } |
| 7462 | |
José Roberto de Souza | a8a56da | 2021-05-14 08:37:09 -0700 | [diff] [blame] | 7463 | static void adlp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7464 | { |
| 7465 | gen12lp_init_clock_gating(dev_priv); |
| 7466 | |
| 7467 | /* Wa_22011091694:adlp */ |
| 7468 | intel_de_rmw(dev_priv, GEN9_CLKGATE_DIS_5, 0, DPCE_GATING_DIS); |
| 7469 | } |
| 7470 | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7471 | static void dg1_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7472 | { |
José Roberto de Souza | 35f0837 | 2021-01-13 05:37:59 -0800 | [diff] [blame] | 7473 | gen12lp_init_clock_gating(dev_priv); |
| 7474 | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7475 | /* Wa_1409836686:dg1[a0] */ |
José Roberto de Souza | c1f110e | 2021-10-19 17:23:53 -0700 | [diff] [blame] | 7476 | if (IS_DG1_GRAPHICS_STEP(dev_priv, STEP_A0, STEP_B0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7477 | 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] | 7478 | DPT_GATING_DIS); |
| 7479 | } |
| 7480 | |
Stuart Summers | d73dd1f | 2021-11-02 15:25:09 -0700 | [diff] [blame] | 7481 | static void xehpsdv_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7482 | { |
| 7483 | /* Wa_22010146351:xehpsdv */ |
| 7484 | if (IS_XEHPSDV_GRAPHICS_STEP(dev_priv, STEP_A0, STEP_B0)) |
| 7485 | intel_uncore_rmw(&dev_priv->uncore, XEHP_CLOCK_GATE_DIS, 0, SGR_DIS); |
| 7486 | } |
| 7487 | |
Matt Roper | 645cc0b | 2021-11-02 15:25:10 -0700 | [diff] [blame] | 7488 | static void dg2_init_clock_gating(struct drm_i915_private *i915) |
| 7489 | { |
| 7490 | /* Wa_22010954014:dg2_g10 */ |
| 7491 | if (IS_DG2_G10(i915)) |
| 7492 | intel_uncore_rmw(&i915->uncore, XEHP_CLOCK_GATE_DIS, 0, |
| 7493 | SGSI_SIDECLK_DIS); |
| 7494 | |
| 7495 | /* |
| 7496 | * Wa_14010733611:dg2_g10 |
| 7497 | * Wa_22010146351:dg2_g10 |
| 7498 | */ |
| 7499 | if (IS_DG2_GRAPHICS_STEP(i915, G10, STEP_A0, STEP_B0)) |
| 7500 | intel_uncore_rmw(&i915->uncore, XEHP_CLOCK_GATE_DIS, 0, |
| 7501 | SGR_DIS | SGGI_DIS); |
| 7502 | } |
| 7503 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7504 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7505 | { |
| 7506 | if (!HAS_PCH_CNP(dev_priv)) |
| 7507 | return; |
| 7508 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 7509 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7510 | 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] | 7511 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7512 | } |
| 7513 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7514 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7515 | { |
| 7516 | cnp_init_clock_gating(dev_priv); |
| 7517 | gen9_init_clock_gating(dev_priv); |
| 7518 | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7519 | /* WAC6entrylatency:cfl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7520 | 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] | 7521 | FBC_LLC_FULLY_OPEN); |
| 7522 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7523 | /* |
| 7524 | * WaFbcTurnOffFbcWatermark:cfl |
| 7525 | * Display WA #0562: cfl |
| 7526 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7527 | 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] | 7528 | DISP_FBC_WM_DIS); |
| 7529 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7530 | /* |
| 7531 | * WaFbcNukeOnHostModify:cfl |
| 7532 | * Display WA #0873: cfl |
| 7533 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7534 | 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] | 7535 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
| 7536 | } |
| 7537 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7538 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7539 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7540 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7541 | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7542 | /* WAC6entrylatency:kbl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7543 | 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] | 7544 | FBC_LLC_FULLY_OPEN); |
| 7545 | |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7546 | /* WaDisableSDEUnitClockGating:kbl */ |
José Roberto de Souza | c1f110e | 2021-10-19 17:23:53 -0700 | [diff] [blame] | 7547 | if (IS_KBL_GRAPHICS_STEP(dev_priv, 0, STEP_C0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7548 | 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] | 7549 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 7550 | |
| 7551 | /* WaDisableGamClockGating:kbl */ |
José Roberto de Souza | c1f110e | 2021-10-19 17:23:53 -0700 | [diff] [blame] | 7552 | if (IS_KBL_GRAPHICS_STEP(dev_priv, 0, STEP_C0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7553 | 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] | 7554 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7555 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7556 | /* |
| 7557 | * WaFbcTurnOffFbcWatermark:kbl |
| 7558 | * Display WA #0562: kbl |
| 7559 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7560 | 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] | 7561 | DISP_FBC_WM_DIS); |
| 7562 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7563 | /* |
| 7564 | * WaFbcNukeOnHostModify:kbl |
| 7565 | * Display WA #0873: kbl |
| 7566 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7567 | 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] | 7568 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7569 | } |
| 7570 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7571 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7572 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7573 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7574 | |
Ville Syrjälä | f142119 | 2020-07-16 22:04:25 +0300 | [diff] [blame] | 7575 | /* WaDisableDopClockGating:skl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7576 | 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] | 7577 | ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 7578 | |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7579 | /* WAC6entrylatency:skl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7580 | 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] | 7581 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7582 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7583 | /* |
| 7584 | * WaFbcTurnOffFbcWatermark:skl |
| 7585 | * Display WA #0562: skl |
| 7586 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7587 | 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] | 7588 | DISP_FBC_WM_DIS); |
| 7589 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7590 | /* |
| 7591 | * WaFbcNukeOnHostModify:skl |
| 7592 | * Display WA #0873: skl |
| 7593 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7594 | 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] | 7595 | ILK_DPFC_NUKE_ON_ANY_MODIFICATION); |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 7596 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7597 | /* |
| 7598 | * WaFbcHighMemBwCorruptionAvoidance:skl |
| 7599 | * Display WA #0883: skl |
| 7600 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7601 | 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] | 7602 | ILK_DPFC_DISABLE_DUMMY0); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7603 | } |
| 7604 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7605 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7606 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 7607 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7608 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7609 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7610 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A), |
| 7611 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A)) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7612 | HSW_FBCQ_DIS); |
| 7613 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7614 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7615 | 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] | 7616 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7617 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7618 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 7619 | 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] | 7620 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7621 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | b7a7053 | 2021-02-20 12:33:03 +0200 | [diff] [blame] | 7622 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7623 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe), |
| 7624 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 7625 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7626 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 7627 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7628 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 7629 | /* WaDSRefCountFullforceMissDisable:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7630 | intel_uncore_write(&dev_priv->uncore, GEN7_FF_THREAD_MODE, |
| 7631 | intel_uncore_read(&dev_priv->uncore, GEN7_FF_THREAD_MODE) & |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7632 | ~(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] | 7633 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7634 | intel_uncore_write(&dev_priv->uncore, GEN6_RC_SLEEP_PSMI_CONTROL, |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 7635 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 7636 | |
| 7637 | /* WaDisableSDEUnitClockGating:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7638 | 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] | 7639 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 7640 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7641 | /* WaProgramL3SqcReg1Default:bdw */ |
| 7642 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 7643 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 7644 | /* WaKVMNotificationOnConfigChange:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7645 | 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] | 7646 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 7647 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7648 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 7649 | |
| 7650 | /* WaDisableDopClockGating:bdw |
| 7651 | * |
| 7652 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 7653 | * clock gating. |
| 7654 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7655 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, |
| 7656 | 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] | 7657 | } |
| 7658 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7659 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7660 | { |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7661 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7662 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A), |
| 7663 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A)) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7664 | HSW_FBCQ_DIS); |
| 7665 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7666 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7667 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7668 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Chris Wilson | f93ec5f | 2020-06-11 10:30:15 +0100 | [diff] [blame] | 7669 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 7670 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7671 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7672 | 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] | 7673 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7674 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7675 | } |
| 7676 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7677 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7678 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7679 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7680 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7681 | 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] | 7682 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7683 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7684 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7685 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7686 | ILK_FBCQ_DIS); |
| 7687 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7688 | /* WaDisableBackToBackFlipFix:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7689 | intel_uncore_write(&dev_priv->uncore, IVB_CHICKEN3, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7690 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7691 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7692 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7693 | if (IS_IVB_GT1(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7694 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7695 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7696 | else { |
| 7697 | /* must write both registers */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7698 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7699 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7700 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2_GT2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7701 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7702 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7703 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 7704 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7705 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7706 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7707 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7708 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 7709 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7710 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7711 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7712 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7713 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7714 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7715 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7716 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7717 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7718 | snpcr = intel_uncore_read(&dev_priv->uncore, GEN6_MBCUNIT_SNPCR); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 7719 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 7720 | snpcr |= GEN6_MBC_SNPCR_MED; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7721 | intel_uncore_write(&dev_priv->uncore, GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7722 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7723 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7724 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7725 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7726 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7727 | } |
| 7728 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7729 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7730 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7731 | /* WaDisableBackToBackFlipFix:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7732 | intel_uncore_write(&dev_priv->uncore, IVB_CHICKEN3, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7733 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7734 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7735 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7736 | /* WaDisableDopClockGating:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7737 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7738 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 7739 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7740 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7741 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7742 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7743 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7744 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7745 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7746 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7747 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7748 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7749 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7750 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7751 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 7752 | /* WaDisableL3Bank2xClockGate:vlv |
| 7753 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 7754 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7755 | intel_uncore_write(&dev_priv->uncore, GEN7_UCGCTL4, |
| 7756 | 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] | 7757 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 7758 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7759 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 7760 | * Disable clock gating on th GCFG unit to prevent a delay |
| 7761 | * in the reporting of vblank events. |
| 7762 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7763 | intel_uncore_write(&dev_priv->uncore, VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7764 | } |
| 7765 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7766 | 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] | 7767 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 7768 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 7769 | /* WaDSRefCountFullforceMissDisable:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7770 | intel_uncore_write(&dev_priv->uncore, GEN7_FF_THREAD_MODE, |
| 7771 | intel_uncore_read(&dev_priv->uncore, GEN7_FF_THREAD_MODE) & |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 7772 | ~(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] | 7773 | |
| 7774 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7775 | intel_uncore_write(&dev_priv->uncore, GEN6_RC_SLEEP_PSMI_CONTROL, |
Ville Syrjälä | acea6f9 | 2014-04-09 13:28:36 +0300 | [diff] [blame] | 7776 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 7777 | |
| 7778 | /* WaDisableCSUnitClockGating:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7779 | 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] | 7780 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 7781 | |
| 7782 | /* WaDisableSDEUnitClockGating:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7783 | 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] | 7784 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 7785 | |
| 7786 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7787 | * WaProgramL3SqcReg1Default:chv |
| 7788 | * See gfxspecs/Related Documents/Performance Guide/ |
| 7789 | * LSQC Setting Recommendations. |
| 7790 | */ |
| 7791 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7792 | } |
| 7793 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7794 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7795 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7796 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7797 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7798 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D1, 0); |
| 7799 | 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] | 7800 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 7801 | CL_UNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7802 | intel_uncore_write(&dev_priv->uncore, RAMCLK_GATE_D, 0); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7803 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 7804 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 7805 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7806 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7807 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7808 | intel_uncore_write(&dev_priv->uncore, DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 7809 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7810 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7811 | } |
| 7812 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7813 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7814 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 7815 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 7816 | |
| 7817 | intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 7818 | intel_uncore_write(uncore, RENCLK_GATE_D2, 0); |
| 7819 | intel_uncore_write(uncore, DSPCLK_GATE_D, 0); |
| 7820 | intel_uncore_write(uncore, RAMCLK_GATE_D, 0); |
| 7821 | intel_uncore_write16(uncore, DEUC, 0); |
| 7822 | intel_uncore_write(uncore, |
| 7823 | MI_ARB_STATE, |
| 7824 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7825 | } |
| 7826 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7827 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7828 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7829 | 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] | 7830 | I965_RCC_CLOCK_GATE_DISABLE | |
| 7831 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 7832 | I965_ISC_CLOCK_GATE_DISABLE | |
| 7833 | I965_FBC_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7834 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D2, 0); |
| 7835 | intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE, |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 7836 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7837 | } |
| 7838 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7839 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7840 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7841 | u32 dstate = intel_uncore_read(&dev_priv->uncore, D_STATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7842 | |
| 7843 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 7844 | DSTATE_DOT_CLOCK_GATING; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7845 | intel_uncore_write(&dev_priv->uncore, D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 7846 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7847 | if (IS_PINEVIEW(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7848 | 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] | 7849 | |
| 7850 | /* IIR "flip pending" means done if this bit is set */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7851 | 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] | 7852 | |
| 7853 | /* interrupts should cause a wake up from C3 */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7854 | 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] | 7855 | |
| 7856 | /* 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] | 7857 | 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] | 7858 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7859 | intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7860 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7861 | } |
| 7862 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7863 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7864 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7865 | 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] | 7866 | |
| 7867 | /* interrupts should cause a wake up from C3 */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7868 | 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] | 7869 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7870 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7871 | intel_uncore_write(&dev_priv->uncore, MEM_MODE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7872 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Ville Syrjälä | 5cecf50 | 2020-07-02 18:37:23 +0300 | [diff] [blame] | 7873 | |
| 7874 | /* |
| 7875 | * Have FBC ignore 3D activity since we use software |
| 7876 | * render tracking, and otherwise a pure 3D workload |
| 7877 | * (even if it just renders a single frame and then does |
| 7878 | * abosultely nothing) would not allow FBC to recompress |
| 7879 | * until a 2D blit occurs. |
| 7880 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7881 | intel_uncore_write(&dev_priv->uncore, SCPD0, |
Ville Syrjälä | 5cecf50 | 2020-07-02 18:37:23 +0300 | [diff] [blame] | 7882 | _MASKED_BIT_ENABLE(SCPD_FBC_IGNORE_3D)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7883 | } |
| 7884 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7885 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7886 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7887 | intel_uncore_write(&dev_priv->uncore, MEM_MODE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7888 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 7889 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7890 | } |
| 7891 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7892 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7893 | { |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7894 | dev_priv->clock_gating_funcs->init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7895 | } |
| 7896 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7897 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7898 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7899 | if (HAS_PCH_LPT(dev_priv)) |
| 7900 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7901 | } |
| 7902 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7903 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7904 | { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7905 | drm_dbg_kms(&dev_priv->drm, |
| 7906 | "No clock gating settings or workarounds applied.\n"); |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7907 | } |
| 7908 | |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7909 | #define CG_FUNCS(platform) \ |
| 7910 | static const struct drm_i915_clock_gating_funcs platform##_clock_gating_funcs = { \ |
| 7911 | .init_clock_gating = platform##_init_clock_gating, \ |
| 7912 | } |
| 7913 | |
Matt Roper | 645cc0b | 2021-11-02 15:25:10 -0700 | [diff] [blame] | 7914 | CG_FUNCS(dg2); |
Stuart Summers | d73dd1f | 2021-11-02 15:25:09 -0700 | [diff] [blame] | 7915 | CG_FUNCS(xehpsdv); |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7916 | CG_FUNCS(adlp); |
| 7917 | CG_FUNCS(dg1); |
| 7918 | CG_FUNCS(gen12lp); |
| 7919 | CG_FUNCS(icl); |
| 7920 | CG_FUNCS(cfl); |
| 7921 | CG_FUNCS(skl); |
| 7922 | CG_FUNCS(kbl); |
| 7923 | CG_FUNCS(bxt); |
| 7924 | CG_FUNCS(glk); |
| 7925 | CG_FUNCS(bdw); |
| 7926 | CG_FUNCS(chv); |
| 7927 | CG_FUNCS(hsw); |
| 7928 | CG_FUNCS(ivb); |
| 7929 | CG_FUNCS(vlv); |
| 7930 | CG_FUNCS(gen6); |
| 7931 | CG_FUNCS(ilk); |
| 7932 | CG_FUNCS(g4x); |
| 7933 | CG_FUNCS(i965gm); |
| 7934 | CG_FUNCS(i965g); |
| 7935 | CG_FUNCS(gen3); |
| 7936 | CG_FUNCS(i85x); |
| 7937 | CG_FUNCS(i830); |
| 7938 | CG_FUNCS(nop); |
| 7939 | #undef CG_FUNCS |
| 7940 | |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7941 | /** |
| 7942 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 7943 | * @dev_priv: device private |
| 7944 | * |
| 7945 | * Setup the hooks that configure which clocks of a given platform can be |
| 7946 | * gated and also apply various GT and display specific workarounds for these |
| 7947 | * platforms. Note that some GT specific workarounds are applied separately |
| 7948 | * when GPU contexts or batchbuffers start their execution. |
| 7949 | */ |
| 7950 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 7951 | { |
Matt Roper | 645cc0b | 2021-11-02 15:25:10 -0700 | [diff] [blame] | 7952 | if (IS_DG2(dev_priv)) |
| 7953 | dev_priv->clock_gating_funcs = &dg2_clock_gating_funcs; |
| 7954 | else if (IS_XEHPSDV(dev_priv)) |
Stuart Summers | d73dd1f | 2021-11-02 15:25:09 -0700 | [diff] [blame] | 7955 | dev_priv->clock_gating_funcs = &xehpsdv_clock_gating_funcs; |
| 7956 | else if (IS_ALDERLAKE_P(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7957 | dev_priv->clock_gating_funcs = &adlp_clock_gating_funcs; |
José Roberto de Souza | a8a56da | 2021-05-14 08:37:09 -0700 | [diff] [blame] | 7958 | else if (IS_DG1(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7959 | dev_priv->clock_gating_funcs = &dg1_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7960 | else if (GRAPHICS_VER(dev_priv) == 12) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7961 | dev_priv->clock_gating_funcs = &gen12lp_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7962 | else if (GRAPHICS_VER(dev_priv) == 11) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7963 | dev_priv->clock_gating_funcs = &icl_clock_gating_funcs; |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 7964 | else if (IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7965 | dev_priv->clock_gating_funcs = &cfl_clock_gating_funcs; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7966 | else if (IS_SKYLAKE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7967 | dev_priv->clock_gating_funcs = &skl_clock_gating_funcs; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7968 | else if (IS_KABYLAKE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7969 | dev_priv->clock_gating_funcs = &kbl_clock_gating_funcs; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7970 | else if (IS_BROXTON(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7971 | dev_priv->clock_gating_funcs = &bxt_clock_gating_funcs; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7972 | else if (IS_GEMINILAKE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7973 | dev_priv->clock_gating_funcs = &glk_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7974 | else if (IS_BROADWELL(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7975 | dev_priv->clock_gating_funcs = &bdw_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7976 | else if (IS_CHERRYVIEW(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7977 | dev_priv->clock_gating_funcs = &chv_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7978 | else if (IS_HASWELL(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7979 | dev_priv->clock_gating_funcs = &hsw_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7980 | else if (IS_IVYBRIDGE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7981 | dev_priv->clock_gating_funcs = &ivb_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7982 | else if (IS_VALLEYVIEW(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7983 | dev_priv->clock_gating_funcs = &vlv_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7984 | else if (GRAPHICS_VER(dev_priv) == 6) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7985 | dev_priv->clock_gating_funcs = &gen6_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7986 | else if (GRAPHICS_VER(dev_priv) == 5) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7987 | dev_priv->clock_gating_funcs = &ilk_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7988 | else if (IS_G4X(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7989 | dev_priv->clock_gating_funcs = &g4x_clock_gating_funcs; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7990 | else if (IS_I965GM(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7991 | dev_priv->clock_gating_funcs = &i965gm_clock_gating_funcs; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7992 | else if (IS_I965G(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7993 | dev_priv->clock_gating_funcs = &i965g_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7994 | else if (GRAPHICS_VER(dev_priv) == 3) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7995 | dev_priv->clock_gating_funcs = &gen3_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7996 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7997 | dev_priv->clock_gating_funcs = &i85x_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7998 | else if (GRAPHICS_VER(dev_priv) == 2) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7999 | dev_priv->clock_gating_funcs = &i830_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8000 | else { |
| 8001 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 8002 | dev_priv->clock_gating_funcs = &nop_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 8003 | } |
| 8004 | } |
| 8005 | |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8006 | static const struct drm_i915_wm_disp_funcs skl_wm_funcs = { |
| 8007 | .compute_global_watermarks = skl_compute_wm, |
| 8008 | }; |
| 8009 | |
| 8010 | static const struct drm_i915_wm_disp_funcs ilk_wm_funcs = { |
| 8011 | .compute_pipe_wm = ilk_compute_pipe_wm, |
| 8012 | .compute_intermediate_wm = ilk_compute_intermediate_wm, |
| 8013 | .initial_watermarks = ilk_initial_watermarks, |
| 8014 | .optimize_watermarks = ilk_optimize_watermarks, |
| 8015 | }; |
| 8016 | |
| 8017 | static const struct drm_i915_wm_disp_funcs vlv_wm_funcs = { |
| 8018 | .compute_pipe_wm = vlv_compute_pipe_wm, |
| 8019 | .compute_intermediate_wm = vlv_compute_intermediate_wm, |
| 8020 | .initial_watermarks = vlv_initial_watermarks, |
| 8021 | .optimize_watermarks = vlv_optimize_watermarks, |
| 8022 | .atomic_update_watermarks = vlv_atomic_update_fifo, |
| 8023 | }; |
| 8024 | |
| 8025 | static const struct drm_i915_wm_disp_funcs g4x_wm_funcs = { |
| 8026 | .compute_pipe_wm = g4x_compute_pipe_wm, |
| 8027 | .compute_intermediate_wm = g4x_compute_intermediate_wm, |
| 8028 | .initial_watermarks = g4x_initial_watermarks, |
| 8029 | .optimize_watermarks = g4x_optimize_watermarks, |
| 8030 | }; |
| 8031 | |
| 8032 | static const struct drm_i915_wm_disp_funcs pnv_wm_funcs = { |
| 8033 | .update_wm = pnv_update_wm, |
| 8034 | }; |
| 8035 | |
| 8036 | static const struct drm_i915_wm_disp_funcs i965_wm_funcs = { |
| 8037 | .update_wm = i965_update_wm, |
| 8038 | }; |
| 8039 | |
| 8040 | static const struct drm_i915_wm_disp_funcs i9xx_wm_funcs = { |
| 8041 | .update_wm = i9xx_update_wm, |
| 8042 | }; |
| 8043 | |
| 8044 | static const struct drm_i915_wm_disp_funcs i845_wm_funcs = { |
| 8045 | .update_wm = i845_update_wm, |
| 8046 | }; |
| 8047 | |
| 8048 | static const struct drm_i915_wm_disp_funcs nop_funcs = { |
| 8049 | }; |
| 8050 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8051 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8052 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8053 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8054 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8055 | if (IS_PINEVIEW(dev_priv)) |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 8056 | pnv_get_mem_freq(dev_priv); |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 8057 | else if (GRAPHICS_VER(dev_priv) == 5) |
Lucas De Marchi | 9eae5e2 | 2019-12-24 00:40:09 -0800 | [diff] [blame] | 8058 | ilk_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8059 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 8060 | if (intel_has_sagv(dev_priv)) |
| 8061 | skl_setup_sagv_block_time(dev_priv); |
| 8062 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8063 | /* For FIFO watermark updates */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 8064 | if (DISPLAY_VER(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8065 | skl_setup_wm_latency(dev_priv); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8066 | dev_priv->wm_disp = &skl_wm_funcs; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8067 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8068 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 8069 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8070 | 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] | 8071 | 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] | 8072 | (DISPLAY_VER(dev_priv) != 5 && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8073 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8074 | dev_priv->wm_disp = &ilk_wm_funcs; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8075 | } else { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8076 | drm_dbg_kms(&dev_priv->drm, |
| 8077 | "Failed to read display plane latency. " |
| 8078 | "Disable CxSR\n"); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8079 | dev_priv->wm_disp = &nop_funcs; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8080 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 8081 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8082 | vlv_setup_wm_latency(dev_priv); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8083 | dev_priv->wm_disp = &vlv_wm_funcs; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 8084 | } else if (IS_G4X(dev_priv)) { |
| 8085 | g4x_setup_wm_latency(dev_priv); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8086 | dev_priv->wm_disp = &g4x_wm_funcs; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8087 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 8088 | if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8089 | dev_priv->is_ddr3, |
| 8090 | dev_priv->fsb_freq, |
| 8091 | dev_priv->mem_freq)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8092 | drm_info(&dev_priv->drm, |
| 8093 | "failed to find known CxSR latency " |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8094 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 8095 | "disabling CxSR\n", |
| 8096 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 8097 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 8098 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 8099 | intel_set_memory_cxsr(dev_priv, false); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8100 | dev_priv->wm_disp = &nop_funcs; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8101 | } else |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8102 | dev_priv->wm_disp = &pnv_wm_funcs; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8103 | } else if (DISPLAY_VER(dev_priv) == 4) { |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8104 | dev_priv->wm_disp = &i965_wm_funcs; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8105 | } else if (DISPLAY_VER(dev_priv) == 3) { |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8106 | dev_priv->wm_disp = &i9xx_wm_funcs; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8107 | } else if (DISPLAY_VER(dev_priv) == 2) { |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 8108 | if (INTEL_NUM_PIPES(dev_priv) == 1) |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8109 | dev_priv->wm_disp = &i845_wm_funcs; |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 8110 | else |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8111 | dev_priv->wm_disp = &i9xx_wm_funcs; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8112 | } else { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8113 | drm_err(&dev_priv->drm, |
| 8114 | "unexpected fall-through in %s\n", __func__); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8115 | dev_priv->wm_disp = &nop_funcs; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8116 | } |
| 8117 | } |
| 8118 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 8119 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8120 | { |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 8121 | dev_priv->runtime_pm.suspended = false; |
| 8122 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8123 | } |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 8124 | |
| 8125 | static struct intel_global_state *intel_dbuf_duplicate_state(struct intel_global_obj *obj) |
| 8126 | { |
| 8127 | struct intel_dbuf_state *dbuf_state; |
| 8128 | |
| 8129 | dbuf_state = kmemdup(obj->state, sizeof(*dbuf_state), GFP_KERNEL); |
| 8130 | if (!dbuf_state) |
| 8131 | return NULL; |
| 8132 | |
| 8133 | return &dbuf_state->base; |
| 8134 | } |
| 8135 | |
| 8136 | static void intel_dbuf_destroy_state(struct intel_global_obj *obj, |
| 8137 | struct intel_global_state *state) |
| 8138 | { |
| 8139 | kfree(state); |
| 8140 | } |
| 8141 | |
| 8142 | static const struct intel_global_state_funcs intel_dbuf_funcs = { |
| 8143 | .atomic_duplicate_state = intel_dbuf_duplicate_state, |
| 8144 | .atomic_destroy_state = intel_dbuf_destroy_state, |
| 8145 | }; |
| 8146 | |
| 8147 | struct intel_dbuf_state * |
| 8148 | intel_atomic_get_dbuf_state(struct intel_atomic_state *state) |
| 8149 | { |
| 8150 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8151 | struct intel_global_state *dbuf_state; |
| 8152 | |
| 8153 | dbuf_state = intel_atomic_get_global_obj_state(state, &dev_priv->dbuf.obj); |
| 8154 | if (IS_ERR(dbuf_state)) |
| 8155 | return ERR_CAST(dbuf_state); |
| 8156 | |
| 8157 | return to_intel_dbuf_state(dbuf_state); |
| 8158 | } |
| 8159 | |
| 8160 | int intel_dbuf_init(struct drm_i915_private *dev_priv) |
| 8161 | { |
| 8162 | struct intel_dbuf_state *dbuf_state; |
| 8163 | |
| 8164 | dbuf_state = kzalloc(sizeof(*dbuf_state), GFP_KERNEL); |
| 8165 | if (!dbuf_state) |
| 8166 | return -ENOMEM; |
| 8167 | |
| 8168 | intel_atomic_global_obj_init(dev_priv, &dev_priv->dbuf.obj, |
| 8169 | &dbuf_state->base, &intel_dbuf_funcs); |
| 8170 | |
| 8171 | return 0; |
| 8172 | } |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8173 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 8174 | /* |
| 8175 | * Configure MBUS_CTL and all DBUF_CTL_S of each slice to join_mbus state before |
| 8176 | * update the request state of all DBUS slices. |
| 8177 | */ |
| 8178 | static void update_mbus_pre_enable(struct intel_atomic_state *state) |
| 8179 | { |
| 8180 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8181 | u32 mbus_ctl, dbuf_min_tracker_val; |
| 8182 | enum dbuf_slice slice; |
| 8183 | const struct intel_dbuf_state *dbuf_state = |
| 8184 | intel_atomic_get_new_dbuf_state(state); |
| 8185 | |
| 8186 | if (!IS_ALDERLAKE_P(dev_priv)) |
| 8187 | return; |
| 8188 | |
| 8189 | /* |
| 8190 | * TODO: Implement vblank synchronized MBUS joining changes. |
| 8191 | * Must be properly coordinated with dbuf reprogramming. |
| 8192 | */ |
| 8193 | if (dbuf_state->joined_mbus) { |
| 8194 | mbus_ctl = MBUS_HASHING_MODE_1x4 | MBUS_JOIN | |
| 8195 | MBUS_JOIN_PIPE_SELECT_NONE; |
| 8196 | dbuf_min_tracker_val = DBUF_MIN_TRACKER_STATE_SERVICE(3); |
| 8197 | } else { |
| 8198 | mbus_ctl = MBUS_HASHING_MODE_2x2 | |
| 8199 | MBUS_JOIN_PIPE_SELECT_NONE; |
| 8200 | dbuf_min_tracker_val = DBUF_MIN_TRACKER_STATE_SERVICE(1); |
| 8201 | } |
| 8202 | |
| 8203 | intel_de_rmw(dev_priv, MBUS_CTL, |
| 8204 | MBUS_HASHING_MODE_MASK | MBUS_JOIN | |
| 8205 | MBUS_JOIN_PIPE_SELECT_MASK, mbus_ctl); |
| 8206 | |
| 8207 | for_each_dbuf_slice(dev_priv, slice) |
| 8208 | intel_de_rmw(dev_priv, DBUF_CTL_S(slice), |
| 8209 | DBUF_MIN_TRACKER_STATE_SERVICE_MASK, |
| 8210 | dbuf_min_tracker_val); |
| 8211 | } |
| 8212 | |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8213 | void intel_dbuf_pre_plane_update(struct intel_atomic_state *state) |
| 8214 | { |
| 8215 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8216 | const struct intel_dbuf_state *new_dbuf_state = |
| 8217 | intel_atomic_get_new_dbuf_state(state); |
| 8218 | const struct intel_dbuf_state *old_dbuf_state = |
| 8219 | intel_atomic_get_old_dbuf_state(state); |
| 8220 | |
| 8221 | if (!new_dbuf_state || |
Stanislav Lisovskiy | 0d6695b | 2021-05-27 14:01:06 +0300 | [diff] [blame] | 8222 | ((new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices) |
| 8223 | && (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus))) |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8224 | return; |
| 8225 | |
| 8226 | WARN_ON(!new_dbuf_state->base.changed); |
| 8227 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 8228 | update_mbus_pre_enable(state); |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8229 | gen9_dbuf_slices_update(dev_priv, |
| 8230 | old_dbuf_state->enabled_slices | |
| 8231 | new_dbuf_state->enabled_slices); |
| 8232 | } |
| 8233 | |
| 8234 | void intel_dbuf_post_plane_update(struct intel_atomic_state *state) |
| 8235 | { |
| 8236 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8237 | const struct intel_dbuf_state *new_dbuf_state = |
| 8238 | intel_atomic_get_new_dbuf_state(state); |
| 8239 | const struct intel_dbuf_state *old_dbuf_state = |
| 8240 | intel_atomic_get_old_dbuf_state(state); |
| 8241 | |
| 8242 | if (!new_dbuf_state || |
Stanislav Lisovskiy | 0d6695b | 2021-05-27 14:01:06 +0300 | [diff] [blame] | 8243 | ((new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices) |
| 8244 | && (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus))) |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8245 | return; |
| 8246 | |
| 8247 | WARN_ON(!new_dbuf_state->base.changed); |
| 8248 | |
| 8249 | gen9_dbuf_slices_update(dev_priv, |
| 8250 | new_dbuf_state->enabled_slices); |
| 8251 | } |